cutedriver-driver 2.0.0.20210120164037
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +16 -0
- data/bin/start_app_perf +200 -0
- data/bin/tdriver-devtools +3 -0
- data/config/sut_parameters.rb +52 -0
- data/config/sut_setup.rb +32 -0
- data/config/sut_teardown.rb +32 -0
- data/config/tdriver_custom_error_recovery.rb +83 -0
- data/ext/extconf.rb +70 -0
- data/ext/native_extensions.c +315 -0
- data/lib/matti.rb +25 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +120 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
- data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
- data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
- data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
- data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1945 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/generate.rb +917 -0
- data/lib/tdriver-devtools/doc/update +1 -0
- data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
- data/lib/tdriver-devtools/doc/xslt/template.xsl +2170 -0
- data/lib/tdriver-devtools/doc/xslt/update +3 -0
- data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
- data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
- data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
- data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
- data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
- data/lib/tdriver.rb +23 -0
- data/lib/tdriver/base/behaviour/abstract.rb +29 -0
- data/lib/tdriver/base/behaviour/behaviours/object_abstract.rb +107 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +99 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +278 -0
- data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +119 -0
- data/lib/tdriver/base/behaviour/factory.rb +495 -0
- data/lib/tdriver/base/behaviour/loader.rb +46 -0
- data/lib/tdriver/base/command_data/command_data.rb +51 -0
- data/lib/tdriver/base/command_data/loader.rb +29 -0
- data/lib/tdriver/base/controller/abstraction.rb +56 -0
- data/lib/tdriver/base/controller/loader.rb +21 -0
- data/lib/tdriver/base/errors.rb +134 -0
- data/lib/tdriver/base/loader.rb +47 -0
- data/lib/tdriver/base/state_object.rb +373 -0
- data/lib/tdriver/base/sut/adapter.rb +54 -0
- data/lib/tdriver/base/sut/controller.rb +151 -0
- data/lib/tdriver/base/sut/factory.rb +339 -0
- data/lib/tdriver/base/sut/generic/behaviours/agent.rb +77 -0
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +427 -0
- data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +107 -0
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +337 -0
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1888 -0
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +210 -0
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +222 -0
- data/lib/tdriver/base/sut/generic/commands/agent.rb +43 -0
- data/lib/tdriver/base/sut/generic/commands/application.rb +274 -0
- data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +94 -0
- data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +64 -0
- data/lib/tdriver/base/sut/generic/plugin.rb +97 -0
- data/lib/tdriver/base/sut/loader.rb +35 -0
- data/lib/tdriver/base/sut/sut.rb +98 -0
- data/lib/tdriver/base/test_object/abstract.rb +208 -0
- data/lib/tdriver/base/test_object/adapter.rb +740 -0
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +144 -0
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +1047 -0
- data/lib/tdriver/base/test_object/cache.rb +134 -0
- data/lib/tdriver/base/test_object/factory.rb +684 -0
- data/lib/tdriver/base/test_object/loader.rb +51 -0
- data/lib/tdriver/base/test_object/verification.rb +178 -0
- data/lib/tdriver/base/test_object/xml/abstraction.rb +63 -0
- data/lib/tdriver/base/test_object/xml/adapter.rb +773 -0
- data/lib/tdriver/env.rb +21 -0
- data/lib/tdriver/loader.rb +57 -0
- data/lib/tdriver/matti.rb +35 -0
- data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +168 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +106 -0
- data/lib/tdriver/report/report.rb +61 -0
- data/lib/tdriver/report/report_api.rb +348 -0
- data/lib/tdriver/report/report_combine.rb +86 -0
- data/lib/tdriver/report/report_crash_file_capture.rb +178 -0
- data/lib/tdriver/report/report_creator.rb +665 -0
- data/lib/tdriver/report/report_cucumber.rb +158 -0
- data/lib/tdriver/report/report_cucumber_listener.rb +184 -0
- data/lib/tdriver/report/report_cucumber_reporter.rb +181 -0
- data/lib/tdriver/report/report_data_presentation.rb +156 -0
- data/lib/tdriver/report/report_data_table.rb +64 -0
- data/lib/tdriver/report/report_execution_statistics.rb +400 -0
- data/lib/tdriver/report/report_file_capture.rb +159 -0
- data/lib/tdriver/report/report_graph_generator.rb +59 -0
- data/lib/tdriver/report/report_grouping.rb +541 -0
- data/lib/tdriver/report/report_javascript.rb +199 -0
- data/lib/tdriver/report/report_junit_xml.rb +147 -0
- data/lib/tdriver/report/report_rspec.rb +108 -0
- data/lib/tdriver/report/report_test_case_run.rb +725 -0
- data/lib/tdriver/report/report_test_run.rb +1476 -0
- data/lib/tdriver/report/report_test_unit.rb +223 -0
- data/lib/tdriver/report/report_writer.rb +1621 -0
- data/lib/tdriver/tdriver.rb +209 -0
- data/lib/tdriver/util/agent/loader.rb +22 -0
- data/lib/tdriver/util/agent/service.rb +107 -0
- data/lib/tdriver/util/common/array.rb +39 -0
- data/lib/tdriver/util/common/boolean.rb +48 -0
- data/lib/tdriver/util/common/crc16.rb +149 -0
- data/lib/tdriver/util/common/environment.rb +154 -0
- data/lib/tdriver/util/common/error.rb +40 -0
- data/lib/tdriver/util/common/exception.rb +53 -0
- data/lib/tdriver/util/common/exceptions.rb +12 -0
- data/lib/tdriver/util/common/file.rb +328 -0
- data/lib/tdriver/util/common/gem.rb +109 -0
- data/lib/tdriver/util/common/hash.rb +288 -0
- data/lib/tdriver/util/common/kernel.rb +253 -0
- data/lib/tdriver/util/common/loader.rb +47 -0
- data/lib/tdriver/util/common/numeric.rb +159 -0
- data/lib/tdriver/util/common/object.rb +159 -0
- data/lib/tdriver/util/common/retryable.rb +179 -0
- data/lib/tdriver/util/common/stackable.rb +185 -0
- data/lib/tdriver/util/common/string.rb +174 -0
- data/lib/tdriver/util/database/access.rb +240 -0
- data/lib/tdriver/util/database/connection.rb +44 -0
- data/lib/tdriver/util/database/error.rb +34 -0
- data/lib/tdriver/util/database/loader.rb +28 -0
- data/lib/tdriver/util/filters/attribute_filter.rb +121 -0
- data/lib/tdriver/util/filters/loader.rb +29 -0
- data/lib/tdriver/util/fixture/loader.rb +22 -0
- data/lib/tdriver/util/fixture/service.rb +211 -0
- data/lib/tdriver/util/hooking/hooking.rb +477 -0
- data/lib/tdriver/util/keymap/keymap.rb +81 -0
- data/lib/tdriver/util/loader.rb +80 -0
- data/lib/tdriver/util/localisation/error.rb +31 -0
- data/lib/tdriver/util/localisation/loader.rb +25 -0
- data/lib/tdriver/util/localisation/localisation.rb +762 -0
- data/lib/tdriver/util/logger/loader.rb +22 -0
- data/lib/tdriver/util/logger/logger.rb +591 -0
- data/lib/tdriver/util/operator_data/error.rb +29 -0
- data/lib/tdriver/util/operator_data/loader.rb +27 -0
- data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
- data/lib/tdriver/util/other/config.rb +221 -0
- data/lib/tdriver/util/parameter/error.rb +48 -0
- data/lib/tdriver/util/parameter/loader.rb +25 -0
- data/lib/tdriver/util/parameter/parameter.rb +1161 -0
- data/lib/tdriver/util/plugin/abstract.rb +61 -0
- data/lib/tdriver/util/plugin/error.rb +0 -0
- data/lib/tdriver/util/plugin/loader.rb +28 -0
- data/lib/tdriver/util/plugin/service.rb +319 -0
- data/lib/tdriver/util/recorder/loader.rb +25 -0
- data/lib/tdriver/util/recorder/recorder.rb +72 -0
- data/lib/tdriver/util/recorder/scripter.rb +294 -0
- data/lib/tdriver/util/statistics/statistics.rb +89 -0
- data/lib/tdriver/util/user_data/error.rb +28 -0
- data/lib/tdriver/util/user_data/loader.rb +25 -0
- data/lib/tdriver/util/user_data/user_data.rb +104 -0
- data/lib/tdriver/util/video/camera.rb +67 -0
- data/lib/tdriver/util/video/camera_linux.rb +153 -0
- data/lib/tdriver/util/video/camera_windows.rb +174 -0
- data/lib/tdriver/util/video/loader.rb +31 -0
- data/lib/tdriver/util/video/video_utils.rb +139 -0
- data/lib/tdriver/util/xml/abstraction.rb +117 -0
- data/lib/tdriver/util/xml/attribute.rb +32 -0
- data/lib/tdriver/util/xml/builder.rb +53 -0
- data/lib/tdriver/util/xml/comment.rb +32 -0
- data/lib/tdriver/util/xml/document.rb +32 -0
- data/lib/tdriver/util/xml/element.rb +32 -0
- data/lib/tdriver/util/xml/error.rb +46 -0
- data/lib/tdriver/util/xml/loader.rb +62 -0
- data/lib/tdriver/util/xml/nil_node.rb +95 -0
- data/lib/tdriver/util/xml/nodeset.rb +32 -0
- data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
- data/lib/tdriver/util/xml/parsers/loader.rb +21 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +167 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +66 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +64 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +66 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +39 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +58 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +212 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +237 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +39 -0
- data/lib/tdriver/util/xml/text.rb +32 -0
- data/lib/tdriver/util/xml/xml.rb +332 -0
- data/lib/tdriver/verify/verify.rb +2398 -0
- data/lib/tdriver/version.rb +21 -0
- data/xml/behaviours/generic.xml +530 -0
- data/xml/defaults/generic.xml +11 -0
- data/xml/defaults/sut_generic.xml +8 -0
- data/xml/parameters/tdriver_parameters.xml +23 -0
- data/xml/templates/generic.xml +292 -0
- metadata +324 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
require 'rbconfig' # ??
|
21
|
+
|
22
|
+
# common modules - should be generic and runnable as standalone
|
23
|
+
[
|
24
|
+
# Ruby object extensions
|
25
|
+
'object.rb',
|
26
|
+
'numeric.rb',
|
27
|
+
'hash.rb',
|
28
|
+
'string.rb',
|
29
|
+
'boolean.rb',
|
30
|
+
|
31
|
+
'exceptions.rb',
|
32
|
+
'error.rb', # TODO: move custom exceptions to exceptions.rb
|
33
|
+
|
34
|
+
'array.rb',
|
35
|
+
'crc16.rb',
|
36
|
+
'environment.rb',
|
37
|
+
'file.rb',
|
38
|
+
'gem.rb',
|
39
|
+
'kernel.rb',
|
40
|
+
'retryable.rb',
|
41
|
+
'stackable.rb'
|
42
|
+
|
43
|
+
].each{ | filename |
|
44
|
+
|
45
|
+
require File.expand_path( File.join( File.dirname( __FILE__ ), filename ) )
|
46
|
+
|
47
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
# extend Ruby Numeric class functionality
|
21
|
+
class Numeric
|
22
|
+
|
23
|
+
# TODO: document me
|
24
|
+
def positive?
|
25
|
+
|
26
|
+
self > 0
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: document me
|
31
|
+
def non_negative?
|
32
|
+
|
33
|
+
self >= 0
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO: document me
|
38
|
+
def non_positive?
|
39
|
+
|
40
|
+
self <= 0
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: document me
|
45
|
+
def negative?
|
46
|
+
|
47
|
+
self < 0
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
# TODO: document me
|
52
|
+
def not_negative( message = 'Given value ($1) must not be negative', exception = ArgumentError )
|
53
|
+
|
54
|
+
if negative?
|
55
|
+
|
56
|
+
# replace macros
|
57
|
+
message.gsub!( '$1', inspect )
|
58
|
+
|
59
|
+
raise exception, message, caller
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
self
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
# TODO: document me
|
68
|
+
def not_zero( message = 'Given value must not be zero', exception = ArgumentError )
|
69
|
+
|
70
|
+
if zero?
|
71
|
+
|
72
|
+
# replace macros
|
73
|
+
message.gsub!( '$1', inspect )
|
74
|
+
|
75
|
+
raise exception, message, caller
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
self
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
# TODO: document me
|
84
|
+
def not_positive( message = 'Given value ($1) must not be positive', exception = ArgumentError )
|
85
|
+
|
86
|
+
if positive?
|
87
|
+
|
88
|
+
# replace macros
|
89
|
+
message.gsub!( '$1', inspect )
|
90
|
+
|
91
|
+
raise exception, message, caller
|
92
|
+
|
93
|
+
end
|
94
|
+
|
95
|
+
self
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
# TODO: document me
|
100
|
+
def check_range( range, message = "value $1 is out of range ($2)" )
|
101
|
+
|
102
|
+
# check that given argument is type of Range
|
103
|
+
raise TypeError, 'wrong argument type #{ range.class } for range (expected Range)' unless range.kind_of?( Range )
|
104
|
+
|
105
|
+
# check that given argument is type of Range
|
106
|
+
raise TypeError, 'wrong argument type #{ message.class } for exception message (expected String)' unless message.kind_of?( String )
|
107
|
+
|
108
|
+
# replace macros
|
109
|
+
message.gsub!( '$1', inspect )
|
110
|
+
|
111
|
+
message.gsub!( '$2', range.inspect )
|
112
|
+
|
113
|
+
# raise exception if number is out of range
|
114
|
+
raise RangeError, message unless range.include?( self )
|
115
|
+
|
116
|
+
# return self
|
117
|
+
self
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
# TODO: document me
|
122
|
+
def limit( minimum_value, maximum_value )
|
123
|
+
|
124
|
+
# limit current value
|
125
|
+
min( minimum_value ).max( maximum_value )
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
# TODO: document me
|
130
|
+
def max( value )
|
131
|
+
|
132
|
+
if value.kind_of?( Numeric )
|
133
|
+
|
134
|
+
self > value ? value : self
|
135
|
+
|
136
|
+
else
|
137
|
+
|
138
|
+
raise TypeError, "wrong type #{ value.class } for value (expected Numeric)"
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
# TODO: document me
|
145
|
+
def min( value )
|
146
|
+
|
147
|
+
if value.kind_of?( Numeric )
|
148
|
+
|
149
|
+
self < value ? value : self
|
150
|
+
|
151
|
+
else
|
152
|
+
|
153
|
+
raise TypeError, "wrong type #{ value.class } for value (expected Numeric)"
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,159 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
# extend Ruby Object class functionality
|
21
|
+
class Object
|
22
|
+
|
23
|
+
# TODO: document me
|
24
|
+
def blank?
|
25
|
+
|
26
|
+
respond_to?( :empty? ) ? empty? : !self
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: document me
|
31
|
+
def true?
|
32
|
+
|
33
|
+
false
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
# TODO: document me
|
38
|
+
def false?
|
39
|
+
|
40
|
+
false
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# TODO: document me
|
45
|
+
def not_blank( message = "object must not be blank", exception = ArgumentError )
|
46
|
+
|
47
|
+
raise exception, message, caller if blank?
|
48
|
+
|
49
|
+
self
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# define method to class instance
|
54
|
+
def meta_def( method_name, &block )
|
55
|
+
|
56
|
+
( class << self; self; end ).instance_eval{ define_method method_name, &block }
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
# Compare receiver object type with given types. Raises exception is class name does not equal.
|
61
|
+
def check_type( types, message = "wrong argument type $1 (expected $2)" )
|
62
|
+
|
63
|
+
# raise exception if message is not type of String
|
64
|
+
raise TypeError, "wrong argument type #{ message.class } for message (expected String)", caller unless message.kind_of?( String )
|
65
|
+
|
66
|
+
# create array of types
|
67
|
+
type_array = Array( types )
|
68
|
+
|
69
|
+
# default result value
|
70
|
+
found = false
|
71
|
+
|
72
|
+
# collect verbose type list
|
73
|
+
verbose_type_list = type_array.each_with_index.collect{ | type, index |
|
74
|
+
|
75
|
+
raise TypeError, "invalid argument type #{ type } for check_type. Did you mean #{ type.class }?", caller unless type.kind_of?( Class )
|
76
|
+
|
77
|
+
if kind_of?( type )
|
78
|
+
|
79
|
+
found = true
|
80
|
+
|
81
|
+
break
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
# result string, separate types if multiple types given
|
86
|
+
"#{ ( ( index > 0 ) ? ( index + 1 < type_array.count ? ", " : " or " ) : "" ) }#{ type.to_s }"
|
87
|
+
|
88
|
+
}
|
89
|
+
|
90
|
+
# raise exception if type did not match
|
91
|
+
unless found
|
92
|
+
|
93
|
+
# convert macros
|
94
|
+
[ self.class, verbose_type_list.join, inspect ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
95
|
+
|
96
|
+
# raise the exception
|
97
|
+
raise TypeError, message, caller
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
# pass self as return value
|
102
|
+
self
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
def not_nil( message = "Value must not be nil", exception = ArgumentError )
|
107
|
+
|
108
|
+
raise exception, message, caller unless self
|
109
|
+
|
110
|
+
self
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
def validate( values, message = "Unexpected value $3 for $1 (expected $2)" )
|
115
|
+
|
116
|
+
# raise exception if message is not type of String
|
117
|
+
raise TypeError, "wrong argument type #{ message.class } for message (expected String)", caller unless message.kind_of?( String )
|
118
|
+
|
119
|
+
# create array of values
|
120
|
+
values_array = Array( values )
|
121
|
+
|
122
|
+
# default result value
|
123
|
+
found = false
|
124
|
+
|
125
|
+
# collect verbose type list
|
126
|
+
verbose_values_list = values_array.each_with_index.collect{ | value, index |
|
127
|
+
|
128
|
+
raise TypeError, "Invalid argument type #{ value.class } for value (expected #{ self.class })", caller unless value.kind_of?( self.class )
|
129
|
+
|
130
|
+
if self == value
|
131
|
+
|
132
|
+
found = true
|
133
|
+
|
134
|
+
break
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
# result string, separate types if multiple types given
|
139
|
+
"#{ ( ( index > 0 ) ? ( index + 1 < values_array.count ? ", " : " or " ) : "" ) }#{ value.inspect }"
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
# raise exception if value was not found
|
144
|
+
unless found
|
145
|
+
|
146
|
+
# convert macros
|
147
|
+
[ self.class, verbose_values_list.join, inspect ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
148
|
+
|
149
|
+
# raise the exception
|
150
|
+
raise ArgumentError, message, caller
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
# pass self as return value
|
155
|
+
self
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
############################################################################
|
2
|
+
##
|
3
|
+
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
4
|
+
## All rights reserved.
|
5
|
+
## Contact: Nokia Corporation (testabilitydriver@nokia.com)
|
6
|
+
##
|
7
|
+
## This file is part of Testability Driver.
|
8
|
+
##
|
9
|
+
## If you have questions regarding the use of this file, please contact
|
10
|
+
## Nokia at testabilitydriver@nokia.com .
|
11
|
+
##
|
12
|
+
## This library is free software; you can redistribute it and/or
|
13
|
+
## modify it under the terms of the GNU Lesser General Public
|
14
|
+
## License version 2.1 as published by the Free Software Foundation
|
15
|
+
## and appearing in the file LICENSE.LGPL included in the packaging
|
16
|
+
## of this file.
|
17
|
+
##
|
18
|
+
############################################################################
|
19
|
+
|
20
|
+
module MobyUtil
|
21
|
+
|
22
|
+
class Retryable
|
23
|
+
|
24
|
+
# TODO: document me
|
25
|
+
def self.sleep_retry_interval( time )
|
26
|
+
|
27
|
+
sleep( time )
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# Function to retry code block for x times if exception raises
|
32
|
+
# == params
|
33
|
+
# options:: Hash of options
|
34
|
+
# :tries Number of tries to perform. Default is 1
|
35
|
+
# :interval Timeout between retry. Default is 0
|
36
|
+
# :exception Retry if given type of exception occures. Default is Exception (any error)
|
37
|
+
# == returns
|
38
|
+
def self.while( options = {}, &block )
|
39
|
+
|
40
|
+
# default options
|
41
|
+
options.default_values( :tries => 1, :interval => 0, :exception => Exception )
|
42
|
+
|
43
|
+
attempt = 1
|
44
|
+
|
45
|
+
|
46
|
+
# number of block arguments
|
47
|
+
_block_arity = block.arity
|
48
|
+
|
49
|
+
if _block_arity > 1
|
50
|
+
|
51
|
+
_block_arity = 2
|
52
|
+
|
53
|
+
elsif _block_arity < 1
|
54
|
+
|
55
|
+
_block_arity = 0
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
# last exception
|
60
|
+
_exception = nil
|
61
|
+
|
62
|
+
# default
|
63
|
+
_arguments = []
|
64
|
+
|
65
|
+
begin
|
66
|
+
|
67
|
+
case _block_arity
|
68
|
+
|
69
|
+
when 1
|
70
|
+
arguments = [ attempt ]
|
71
|
+
|
72
|
+
when 2
|
73
|
+
arguments = [ attempt, _exception ]
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# yield given block and pass attempt number as parameter
|
78
|
+
yield( *arguments )
|
79
|
+
|
80
|
+
rescue *options[ :exception ]
|
81
|
+
|
82
|
+
_exception = $!
|
83
|
+
|
84
|
+
if ( attempt < options[ :tries ] ) && ![ *options[ :unless ] ].include?( $!.class )
|
85
|
+
|
86
|
+
sleep_retry_interval( options[ :interval ] ) if options[ :interval ] > 0
|
87
|
+
|
88
|
+
attempt += 1
|
89
|
+
|
90
|
+
retry
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
# raise exception with correct exception backtrace
|
95
|
+
raise $!
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
# Function to retry code block until timeout expires if exception raises
|
102
|
+
# == params
|
103
|
+
# options:: Hash of options
|
104
|
+
# :timeout Timeout until fail. Default is 0
|
105
|
+
# :interval Timeout between retry. Default is 0
|
106
|
+
# :exception Retry if given type of exception occures. Default is Exception (any error)
|
107
|
+
# == returns
|
108
|
+
def self.until( options = {}, &block )
|
109
|
+
|
110
|
+
# default options
|
111
|
+
options.default_values( :timeout => 0, :interval => 0, :exception => Exception )
|
112
|
+
|
113
|
+
# store start time
|
114
|
+
start_time = Time.now
|
115
|
+
|
116
|
+
# attempt number
|
117
|
+
attempt = 0
|
118
|
+
|
119
|
+
# number of block arguments
|
120
|
+
_block_arity = block.arity
|
121
|
+
|
122
|
+
if _block_arity > 1
|
123
|
+
|
124
|
+
_block_arity = 2
|
125
|
+
|
126
|
+
elsif _block_arity < 1
|
127
|
+
|
128
|
+
_block_arity = 0
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
# last exception
|
133
|
+
_exception = nil
|
134
|
+
|
135
|
+
# default
|
136
|
+
_arguments = []
|
137
|
+
|
138
|
+
begin
|
139
|
+
|
140
|
+
case _block_arity
|
141
|
+
|
142
|
+
when 1
|
143
|
+
arguments = [ attempt ]
|
144
|
+
|
145
|
+
when 2
|
146
|
+
arguments = [ attempt, _exception ]
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
# execute block
|
151
|
+
yield( *arguments )
|
152
|
+
|
153
|
+
rescue *options[ :exception ]
|
154
|
+
|
155
|
+
_exception = $!
|
156
|
+
|
157
|
+
if (Time.now - start_time) <= options[ :timeout ] && ![ *options[ :unless ] ].include?( $!.class )
|
158
|
+
|
159
|
+
sleep_retry_interval( options[ :interval ] ) if options[ :interval ] > 0
|
160
|
+
|
161
|
+
attempt += 1
|
162
|
+
|
163
|
+
retry
|
164
|
+
|
165
|
+
end
|
166
|
+
|
167
|
+
# raise exception with correct exception backtrace
|
168
|
+
raise $!
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|
173
|
+
|
174
|
+
# enable hooking for performance measurement & debug logging
|
175
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
176
|
+
|
177
|
+
end # Retryable
|
178
|
+
|
179
|
+
end # MobyUtil
|