testability-driver 1.1.1 → 1.2.1
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.
- data/config/sut_parameters.rb +21 -8
- data/config/tdriver_custom_error_recovery.rb +83 -0
- data/ext/extconf.rb +3 -2
- data/ext/native_extensions.c +60 -2
- data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +2 -105
- data/lib/tdriver/base/behaviour/factory.rb +154 -89
- data/lib/tdriver/base/behaviour/factory_new.rb +409 -0
- data/lib/tdriver/base/errors.rb +3 -3
- data/lib/tdriver/base/state_object.rb +85 -22
- data/lib/tdriver/base/sut/adapter.rb +26 -0
- data/lib/tdriver/base/sut/controller.rb +1 -1
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +89 -118
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +67 -62
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +296 -187
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +7 -7
- data/lib/tdriver/base/sut/generic/commands/application.rb +366 -295
- data/lib/tdriver/base/sut/sut.rb +19 -3
- data/lib/tdriver/base/test_object/abstract.rb +41 -21
- data/lib/tdriver/base/test_object/adapter.rb +62 -9
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +10 -6
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +84 -47
- data/lib/tdriver/base/test_object/factory.rb +124 -68
- data/lib/tdriver/base/test_object/loader.rb +3 -4
- data/lib/tdriver/base/test_object/verification.rb +3 -3
- data/lib/tdriver/base/test_object/xml/adapter.rb +734 -0
- data/lib/tdriver/loader.rb +12 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +3 -2
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +14 -14
- data/lib/tdriver/report/report.rb +4 -8
- data/lib/tdriver/report/report_api.rb +9 -0
- data/lib/tdriver/report/report_crash_file_capture.rb +4 -4
- data/lib/tdriver/report/report_creator.rb +57 -35
- data/lib/tdriver/report/report_cucumber.rb +1 -1
- data/lib/tdriver/report/report_cucumber_listener.rb +5 -158
- data/lib/tdriver/report/report_cucumber_reporter.rb +7 -161
- data/lib/tdriver/report/report_execution_statistics.rb +4 -4
- data/lib/tdriver/report/report_file_capture.rb +5 -5
- data/lib/tdriver/report/report_grouping.rb +24 -22
- data/lib/tdriver/report/report_junit_xml.rb +5 -5
- data/lib/tdriver/report/report_test_case_run.rb +31 -22
- data/lib/tdriver/report/report_test_run.rb +107 -104
- data/lib/tdriver/report/report_writer.rb +150 -83
- data/lib/tdriver/tdriver.rb +147 -103
- data/lib/tdriver/util/common/boolean.rb +51 -0
- data/lib/tdriver/util/common/crc16.rb +110 -68
- data/lib/tdriver/util/common/hash.rb +63 -7
- data/lib/tdriver/util/common/kernel.rb +46 -1
- data/lib/tdriver/util/common/loader.rb +1 -0
- data/lib/tdriver/util/common/object.rb +20 -8
- data/lib/tdriver/util/common/string.rb +21 -2
- data/lib/tdriver/util/logger/logger.rb +4 -4
- data/lib/tdriver/util/parameter/loader.rb +2 -19
- data/lib/tdriver/util/parameter/parameter.rb +874 -177
- data/lib/tdriver/util/plugin/service.rb +1 -1
- data/lib/tdriver/util/recorder/recorder.rb +7 -1
- data/lib/tdriver/util/xml/abstraction.rb +13 -1
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +63 -10
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +8 -2
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +16 -3
- data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +36 -32
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +19 -22
- data/lib/tdriver/util/xml/xml.rb +147 -32
- data/lib/tdriver/verify/verify.rb +1112 -289
- data/lib/tdriver/version.rb +1 -1
- data/xml/templates/generic.xml +14 -2
- metadata +51 -24
- data/lib/tdriver/util/parameter/parameter_hash.rb +0 -104
- data/lib/tdriver/util/parameter/parameter_new.rb +0 -869
- data/lib/tdriver/util/parameter/parameter_template.rb +0 -120
- data/lib/tdriver/util/parameter/parameter_user_api.rb +0 -116
- data/lib/tdriver/util/parameter/parameter_xml.rb +0 -261
data/lib/tdriver/util/xml/xml.rb
CHANGED
@@ -21,6 +21,25 @@ module MobyUtil
|
|
21
21
|
|
22
22
|
module XML
|
23
23
|
|
24
|
+
class << self
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def initialize_class
|
29
|
+
|
30
|
+
# empty xml cache hash
|
31
|
+
@document_cache = { :cache => [], :objects => {} }
|
32
|
+
|
33
|
+
# default xml cache buffer size
|
34
|
+
@document_cache_buffer_size = 10
|
35
|
+
|
36
|
+
# set used parser module
|
37
|
+
self.current_parser = MobyUtil::XML::Nokogiri
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
24
43
|
# Get current XML parser
|
25
44
|
# == params
|
26
45
|
# == return
|
@@ -32,6 +51,31 @@ module MobyUtil
|
|
32
51
|
|
33
52
|
end
|
34
53
|
|
54
|
+
# Set XML document cache buffering size, set 0 to disable
|
55
|
+
# == params
|
56
|
+
# == return
|
57
|
+
# Integer::
|
58
|
+
# == raises
|
59
|
+
# TypeError::
|
60
|
+
def self.buffer_size=( value )
|
61
|
+
|
62
|
+
value.check_type Integer, 'wrong argument type $1 for XML cache buffer size (expected $2)'
|
63
|
+
|
64
|
+
@document_cache_buffer_size = value
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get current XML document cache buffering size
|
69
|
+
# == params
|
70
|
+
# == return
|
71
|
+
# Integer::
|
72
|
+
# == raises
|
73
|
+
def self.buffer_size
|
74
|
+
|
75
|
+
@document_cache_buffer_size
|
76
|
+
|
77
|
+
end
|
78
|
+
|
35
79
|
# Set XML parser to be used
|
36
80
|
# == params
|
37
81
|
# Module::
|
@@ -48,20 +92,31 @@ module MobyUtil
|
|
48
92
|
|
49
93
|
# apply parser implementation to abstraction modules
|
50
94
|
[
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
95
|
+
:Document,
|
96
|
+
:Element,
|
97
|
+
:Nodeset,
|
98
|
+
:Attribute,
|
99
|
+
:Text,
|
100
|
+
:Builder,
|
101
|
+
:Comment
|
102
|
+
|
103
|
+
].each do | _module |
|
104
|
+
|
105
|
+
const_get( _module ).module_exec{
|
106
|
+
|
107
|
+
begin
|
108
|
+
|
109
|
+
# include parser behaviour
|
110
|
+
include @@parser.const_get( _module )
|
111
|
+
|
112
|
+
rescue NameError
|
113
|
+
|
114
|
+
# raise proper exception if behaviour module not found
|
115
|
+
raise NotImplementedError, "Required behaviour module #{ @@parser.name }::#{ _module } not found"
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
}
|
65
120
|
|
66
121
|
end
|
67
122
|
|
@@ -77,21 +132,78 @@ module MobyUtil
|
|
77
132
|
#
|
78
133
|
# == params
|
79
134
|
# xml_string:: String containing XML
|
135
|
+
# crc:: Optional CRC16 checksum - used for cache/buffering if given
|
80
136
|
# == return
|
81
137
|
# Document:: XML document object
|
138
|
+
# Array:: Array containing XML document object and status was it already found from cache
|
82
139
|
# == raises
|
83
|
-
def self.parse_string( xml_string )
|
140
|
+
def self.parse_string( xml_string, crc = nil )
|
84
141
|
|
85
142
|
begin
|
86
143
|
|
87
|
-
|
144
|
+
unless crc.nil?
|
88
145
|
|
89
|
-
|
90
|
-
document.xml = document.parse( xml_string )
|
146
|
+
[ Document.new( xml_string ), false ]
|
91
147
|
|
92
|
-
|
148
|
+
else
|
93
149
|
|
94
|
-
|
150
|
+
Document.new( xml_string )
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
# JKo: disable xml caching for now, need more investigation why tests starts to fail
|
155
|
+
=begin
|
156
|
+
unless crc.nil?
|
157
|
+
|
158
|
+
if @document_cache[ :cache ].include?( crc )
|
159
|
+
|
160
|
+
# return cached object and status that object was found from cache
|
161
|
+
[ @document_cache[ :objects ][ crc ], true ]
|
162
|
+
|
163
|
+
else
|
164
|
+
|
165
|
+
cache_enabled = ( @document_cache_buffer_size > 0 )
|
166
|
+
|
167
|
+
# create new document object with given xml string
|
168
|
+
document = Document.new( xml_string, { :cache_enabled => cache_enabled } )
|
169
|
+
|
170
|
+
# verify that xml caching is enabled
|
171
|
+
if cache_enabled
|
172
|
+
|
173
|
+
# drop olders cached xml object
|
174
|
+
if @document_cache[ :cache ].count == @document_cache_buffer_size
|
175
|
+
|
176
|
+
# remove data object from cache
|
177
|
+
@document_cache[ :objects ].delete(
|
178
|
+
|
179
|
+
# take (oldest) first from cache buffer
|
180
|
+
@document_cache[ :cache ].shift
|
181
|
+
|
182
|
+
)
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
# add new xml data object to cache
|
187
|
+
@document_cache[ :cache ] << crc
|
188
|
+
|
189
|
+
# add new xml data object to cache
|
190
|
+
@document_cache[ :objects ][ crc ] = document
|
191
|
+
|
192
|
+
end
|
193
|
+
|
194
|
+
# return document object and status that object was not found from cache
|
195
|
+
[ document, false ]
|
196
|
+
|
197
|
+
end
|
198
|
+
|
199
|
+
else
|
200
|
+
|
201
|
+
# create new document object with given xml string - no caching used
|
202
|
+
Document.new( xml_string )
|
203
|
+
|
204
|
+
end
|
205
|
+
=end
|
206
|
+
rescue
|
95
207
|
|
96
208
|
if $TDRIVER_INITIALIZED == true
|
97
209
|
|
@@ -133,14 +245,12 @@ module MobyUtil
|
|
133
245
|
end
|
134
246
|
|
135
247
|
# raise exception
|
136
|
-
|
137
|
-
Kernel::raise MobyUtil::XML::ParseError, "#{ exception.message.gsub("\n", '') } (#{ exception.class }). #{ dump_location }"
|
248
|
+
Kernel::raise MobyUtil::XML::ParseError, "#{ $!.message.gsub("\n", '') } (#{ $!.class }). #{ dump_location }"
|
138
249
|
|
139
250
|
else
|
140
251
|
|
141
252
|
# raise exception
|
142
|
-
|
143
|
-
Kernel::raise MobyUtil::XML::ParseError, "#{ exception.message.gsub("\n", '') } (#{ exception.class })"
|
253
|
+
Kernel::raise MobyUtil::XML::ParseError, "#{ $!.message.gsub("\n", '') } (#{ $!.class })"
|
144
254
|
|
145
255
|
end
|
146
256
|
|
@@ -160,11 +270,16 @@ module MobyUtil
|
|
160
270
|
# == raises
|
161
271
|
# IOError:: File '%s' not found
|
162
272
|
def self.parse_file( filename )
|
163
|
-
|
273
|
+
|
164
274
|
# raise exception if file not found
|
165
275
|
Kernel::raise IOError, "File #{ filename.inspect } not found" unless File.exist?( filename )
|
166
276
|
|
167
|
-
|
277
|
+
# parse file content
|
278
|
+
parse_string(
|
279
|
+
|
280
|
+
IO.read( filename )
|
281
|
+
|
282
|
+
)
|
168
283
|
|
169
284
|
end
|
170
285
|
|
@@ -190,15 +305,15 @@ module MobyUtil
|
|
190
305
|
|
191
306
|
begin
|
192
307
|
|
193
|
-
|
308
|
+
Builder.new.tap{ | builder |
|
194
309
|
|
195
310
|
builder.build( &block )
|
196
311
|
|
197
312
|
}
|
198
313
|
|
199
|
-
rescue
|
314
|
+
rescue
|
200
315
|
|
201
|
-
Kernel::raise MobyUtil::XML::BuilderError, "#{
|
316
|
+
Kernel::raise MobyUtil::XML::BuilderError, "#{ $!.message } (#{ $!.class })"
|
202
317
|
|
203
318
|
end
|
204
319
|
|
@@ -207,9 +322,9 @@ module MobyUtil
|
|
207
322
|
# enable hooking for performance measurement & debug logging
|
208
323
|
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
209
324
|
|
325
|
+
# initialize class
|
326
|
+
initialize_class
|
327
|
+
|
210
328
|
end # XML
|
211
329
|
|
212
330
|
end # MobyUtil
|
213
|
-
|
214
|
-
# set used parser module
|
215
|
-
MobyUtil::XML.current_parser = MobyUtil::XML::Nokogiri
|
@@ -45,15 +45,15 @@ module TDriverVerify
|
|
45
45
|
|
46
46
|
@@on_error_verify_block.call
|
47
47
|
|
48
|
-
rescue Exception
|
48
|
+
rescue Exception
|
49
49
|
|
50
|
-
raise exception.class
|
50
|
+
raise exception.class, "Exception was raised while executing on_error_verify_block. Reason: #{ $!.message.to_s }"
|
51
51
|
|
52
52
|
end
|
53
53
|
|
54
54
|
else
|
55
55
|
|
56
|
-
raise ArgumentError
|
56
|
+
raise ArgumentError, 'No verify block defined with on_error_verify_block method'
|
57
57
|
|
58
58
|
end
|
59
59
|
|
@@ -70,103 +70,993 @@ module TDriverVerify
|
|
70
70
|
# === raises
|
71
71
|
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
72
72
|
# VerificationError:: The verification failed.
|
73
|
+
def verify( timeout = nil, message = nil, &block )
|
74
|
+
|
75
|
+
begin
|
76
|
+
|
77
|
+
# determine name of caller method
|
78
|
+
verify_caller = caller( 1 ).first.to_s
|
79
|
+
|
80
|
+
# store orignal logging state
|
81
|
+
logging_enabled = $logger.enabled
|
82
|
+
|
83
|
+
# disable behaviour logging
|
84
|
+
$logger.enabled = false
|
85
|
+
|
86
|
+
# ensure that code block was given
|
87
|
+
raise ArgumentError, "No block was given." unless block_given?
|
88
|
+
|
89
|
+
# ensure that timeout is either nil or type of integer
|
90
|
+
raise ArgumentError, "wrong argument type #{ timeout.class } for timeout (expected Fixnum or NilClass)" unless [ NilClass, Fixnum ].include?( timeout.class )
|
91
|
+
|
92
|
+
# ensure that message is either nil or type of string
|
93
|
+
raise ArgumentError, "Argument message was not a String" unless [ NilClass, String ].include?( message.class )
|
94
|
+
|
95
|
+
# convert timeout to integer, nil will be zero
|
96
|
+
timeout = get_timeout( timeout )
|
97
|
+
|
98
|
+
# calculate the time when timeout exceeds
|
99
|
+
timeout_end_time = Time.now + timeout
|
100
|
+
|
101
|
+
# convert message to string, nil will be empty string
|
102
|
+
message = message.to_s
|
103
|
+
|
104
|
+
# add double quotation and trailing whitespace if not empty string
|
105
|
+
message = "#{ message.inspect } " if message.length > 0
|
106
|
+
|
107
|
+
# store original timeout value
|
108
|
+
original_timeout_value = MobyBase::TestObjectFactory.instance.timeout
|
109
|
+
|
110
|
+
# set the testobject timeout to 0 for the duration of the verify call
|
111
|
+
MobyBase::TestObjectFactory.instance.timeout = 0
|
112
|
+
|
113
|
+
loop do
|
114
|
+
|
115
|
+
begin
|
116
|
+
|
117
|
+
counter = ref_counter
|
118
|
+
|
119
|
+
# execute code block
|
120
|
+
yield
|
121
|
+
|
122
|
+
# break loop if no exceptions thrown
|
123
|
+
break
|
124
|
+
|
125
|
+
rescue
|
126
|
+
|
127
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
128
|
+
|
129
|
+
# refresh and retry unless timeout exceeded
|
130
|
+
raise $! if Time.new > timeout_end_time
|
131
|
+
|
132
|
+
# retry interval
|
133
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
134
|
+
|
135
|
+
# refresh suts
|
136
|
+
refresh_suts if counter == ref_counter
|
137
|
+
|
138
|
+
end # begin
|
139
|
+
|
140
|
+
end # do loop
|
141
|
+
|
142
|
+
rescue
|
143
|
+
|
144
|
+
# restore logger state
|
145
|
+
$logger.enabled = logging_enabled
|
146
|
+
|
147
|
+
# execute on verification error code block
|
148
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
149
|
+
|
150
|
+
# process the exception
|
151
|
+
if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
152
|
+
|
153
|
+
raise
|
154
|
+
|
155
|
+
else
|
156
|
+
|
157
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed as an exception was thrown when the verification block was executed"
|
158
|
+
error_message << "#{ MobyUtil::KernelHelper.find_source( verify_caller ) }\nDetails: \n#{ $!.inspect }"
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
$logger.behaviour "FAIL;Verification #{ message }failed: #{ $!.to_s }.\n #{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify;"
|
163
|
+
|
164
|
+
# raise the exception
|
165
|
+
raise MobyBase::VerificationError, error_message
|
166
|
+
|
167
|
+
ensure
|
168
|
+
|
169
|
+
# restore original test object factory timeout value
|
170
|
+
MobyBase::TestObjectFactory.instance.timeout = original_timeout_value
|
171
|
+
|
172
|
+
# restore logger state
|
173
|
+
$logger.enabled = logging_enabled
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
$logger.behaviour "PASS;Verification #{ message }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify;"
|
178
|
+
|
179
|
+
nil
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
# Verifies that the block given to this method throws an exception while being evaluated. Verification is synchronized with all connected suts.
|
184
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
185
|
+
#
|
186
|
+
# === params
|
187
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
188
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
189
|
+
# === returns
|
190
|
+
# nil
|
191
|
+
# === raises
|
192
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
193
|
+
# VerificationError:: The verification failed.
|
194
|
+
def verify_not( timeout = nil, message = nil, &block )
|
195
|
+
|
196
|
+
begin
|
197
|
+
|
198
|
+
# determine name of caller method
|
199
|
+
verify_caller = caller( 1 ).first.to_s
|
200
|
+
|
201
|
+
# store orignal logging state
|
202
|
+
logging_enabled = $logger.enabled
|
203
|
+
|
204
|
+
# disable behaviour logging
|
205
|
+
$logger.enabled = false
|
206
|
+
|
207
|
+
# ensure that code block was given
|
208
|
+
raise ArgumentError, "No block was given." unless block_given?
|
209
|
+
|
210
|
+
# ensure that timeout is either nil or type of integer
|
211
|
+
raise ArgumentError, "wrong argument type #{ timeout.class } for timeout (expected Fixnum or NilClass)" unless [ NilClass, Fixnum ].include?( timeout.class )
|
212
|
+
|
213
|
+
# ensure that message is either nil or type of string
|
214
|
+
raise ArgumentError, "Argument message was not a String" unless [ NilClass, String ].include?( message.class )
|
215
|
+
|
216
|
+
# convert timeout to integer, nil will be zero
|
217
|
+
timeout = get_timeout( timeout )
|
218
|
+
|
219
|
+
# calculate the time when timeout exceeds
|
220
|
+
timeout_end_time = Time.now + timeout
|
221
|
+
|
222
|
+
# convert message to string, nil will be empty string
|
223
|
+
message = message.to_s
|
224
|
+
|
225
|
+
# add double quotation and trailing whitespace if not empty string
|
226
|
+
message = "#{ message.inspect } " if message.length > 0
|
227
|
+
|
228
|
+
# store original timeout value
|
229
|
+
original_timeout_value = MobyBase::TestObjectFactory.instance.timeout
|
230
|
+
|
231
|
+
# set the testobject timeout to 0 for the duration of the verify call
|
232
|
+
MobyBase::TestObjectFactory.instance.timeout = 0
|
233
|
+
|
234
|
+
# result container
|
235
|
+
result = nil
|
236
|
+
|
237
|
+
loop do
|
238
|
+
|
239
|
+
counter = ref_counter
|
240
|
+
|
241
|
+
begin
|
242
|
+
|
243
|
+
# execute code block
|
244
|
+
result = yield
|
245
|
+
|
246
|
+
rescue
|
247
|
+
|
248
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
249
|
+
|
250
|
+
# break loop if exceptions thrown
|
251
|
+
break
|
252
|
+
|
253
|
+
end
|
254
|
+
|
255
|
+
# refresh and retry unless timeout exceeded
|
256
|
+
raise $! if Time.new > timeout_end_time
|
257
|
+
|
258
|
+
# retry interval
|
259
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
260
|
+
|
261
|
+
# refresh suts
|
262
|
+
refresh_suts if counter == ref_counter
|
263
|
+
|
264
|
+
end # do loop
|
265
|
+
|
266
|
+
rescue
|
267
|
+
|
268
|
+
# restore logger state
|
269
|
+
$logger.enabled = logging_enabled
|
270
|
+
|
271
|
+
# execute on verification error code block
|
272
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
273
|
+
|
274
|
+
# process the exception
|
275
|
+
if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
276
|
+
|
277
|
+
raise
|
278
|
+
|
279
|
+
elsif $!.kind_of?( MobyBase::VerificationError )
|
280
|
+
|
281
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed: #{ MobyUtil::KernelHelper.find_source( verify_caller ) }"
|
282
|
+
error_message << "The block did not raise exception. It returned: #{ result.inspect }"
|
283
|
+
|
284
|
+
else
|
285
|
+
|
286
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed as an exception was thrown when the verification block was executed"
|
287
|
+
error_message << "#{ MobyUtil::KernelHelper.find_source( verify_caller ) }\nDetails: \n#{ $!.inspect }"
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
$logger.behaviour "FAIL;Verification #{ message }failed: #{ $!.to_s }.\n #{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_not;"
|
292
|
+
|
293
|
+
# raise the exception
|
294
|
+
raise MobyBase::VerificationError, error_message
|
295
|
+
|
296
|
+
ensure
|
297
|
+
|
298
|
+
# restore original test object factory timeout value
|
299
|
+
MobyBase::TestObjectFactory.instance.timeout = original_timeout_value
|
300
|
+
|
301
|
+
# restore logger state
|
302
|
+
$logger.enabled = logging_enabled
|
303
|
+
|
304
|
+
end
|
305
|
+
|
306
|
+
$logger.behaviour "PASS;Verification #{ message }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_not;"
|
307
|
+
|
308
|
+
nil
|
309
|
+
|
310
|
+
end
|
311
|
+
|
312
|
+
# Verifies that the block given to this method evaluates to true. Verification is synchronized with all connected suts.
|
313
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
314
|
+
#
|
315
|
+
# === params
|
316
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
317
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
318
|
+
# === returns
|
319
|
+
# nil
|
320
|
+
# === raises
|
321
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
322
|
+
# VerificationError:: The verification failed.
|
323
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
324
|
+
def verify_true( timeout = nil, message = nil, &block )
|
325
|
+
|
326
|
+
begin
|
327
|
+
|
328
|
+
# expected result
|
329
|
+
expected_value = true
|
330
|
+
|
331
|
+
# determine name of caller method
|
332
|
+
verify_caller = caller( 1 ).first.to_s
|
333
|
+
|
334
|
+
# store orignal logging state
|
335
|
+
logging_enabled = $logger.enabled
|
336
|
+
|
337
|
+
# disable behaviour logging
|
338
|
+
$logger.enabled = false
|
339
|
+
|
340
|
+
# ensure that code block was given
|
341
|
+
raise ArgumentError, "No block was given." unless block_given?
|
342
|
+
|
343
|
+
# ensure that timeout is either nil or type of integer
|
344
|
+
raise ArgumentError, "wrong argument type #{ timeout.class } for timeout (expected Fixnum or NilClass)" unless [ NilClass, Fixnum ].include?( timeout.class )
|
345
|
+
|
346
|
+
# ensure that message is either nil or type of string
|
347
|
+
raise ArgumentError, "Argument message was not a String" unless [ NilClass, String ].include?( message.class )
|
348
|
+
|
349
|
+
# convert timeout to integer, nil will be zero
|
350
|
+
timeout = get_timeout( timeout )
|
351
|
+
|
352
|
+
# calculate the time when timeout exceeds
|
353
|
+
timeout_end_time = Time.now + timeout
|
354
|
+
|
355
|
+
# convert message to string, nil will be empty string
|
356
|
+
message = message.to_s
|
357
|
+
|
358
|
+
# add double quotation and trailing whitespace if not empty string
|
359
|
+
message = "#{ message.inspect } " if message.length > 0
|
360
|
+
|
361
|
+
# store original timeout value
|
362
|
+
original_timeout_value = MobyBase::TestObjectFactory.instance.timeout
|
363
|
+
|
364
|
+
# set the testobject timeout to 0 for the duration of the verify call
|
365
|
+
MobyBase::TestObjectFactory.instance.timeout = 0
|
366
|
+
|
367
|
+
# result container
|
368
|
+
result = nil
|
369
|
+
|
370
|
+
loop do
|
371
|
+
|
372
|
+
begin
|
373
|
+
|
374
|
+
counter = ref_counter
|
375
|
+
|
376
|
+
# execute code block
|
377
|
+
result = yield
|
378
|
+
|
379
|
+
# raise exception if result of yield does not equal with expected value
|
380
|
+
raise MobyBase::VerificationError unless result == expected_value
|
381
|
+
|
382
|
+
# break loop if no exceptions thrown
|
383
|
+
break
|
384
|
+
|
385
|
+
rescue
|
386
|
+
|
387
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
388
|
+
|
389
|
+
# refresh and retry unless timeout exceeded
|
390
|
+
raise $! if Time.new > timeout_end_time
|
391
|
+
|
392
|
+
# retry interval
|
393
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
394
|
+
|
395
|
+
# refresh suts
|
396
|
+
refresh_suts if counter == ref_counter
|
397
|
+
|
398
|
+
end # begin
|
399
|
+
|
400
|
+
end # do loop
|
401
|
+
|
402
|
+
rescue
|
403
|
+
|
404
|
+
# restore logger state
|
405
|
+
$logger.enabled = logging_enabled
|
406
|
+
|
407
|
+
# execute on verification error code block
|
408
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
409
|
+
|
410
|
+
# process the exception
|
411
|
+
if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
412
|
+
|
413
|
+
raise
|
414
|
+
|
415
|
+
elsif $!.kind_of?( MobyBase::VerificationError )
|
416
|
+
|
417
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed: #{ MobyUtil::KernelHelper.find_source( verify_caller ) }"
|
418
|
+
error_message << "The block did not return #{ expected_value }. It returned: #{ result.inspect }"
|
419
|
+
|
420
|
+
else
|
421
|
+
|
422
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed as an exception was thrown when the verification block was executed"
|
423
|
+
error_message << "#{ MobyUtil::KernelHelper.find_source( verify_caller ) }\nDetails: \n#{ $!.inspect }"
|
424
|
+
|
425
|
+
end
|
426
|
+
|
427
|
+
$logger.behaviour "FAIL;Verification #{ message }failed: #{ $!.to_s }.\n #{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_true;"
|
428
|
+
|
429
|
+
# raise the exception
|
430
|
+
raise MobyBase::VerificationError, error_message
|
431
|
+
|
432
|
+
ensure
|
433
|
+
|
434
|
+
# restore original test object factory timeout value
|
435
|
+
MobyBase::TestObjectFactory.instance.timeout = original_timeout_value
|
436
|
+
|
437
|
+
# restore logger state
|
438
|
+
$logger.enabled = logging_enabled
|
439
|
+
|
440
|
+
end
|
441
|
+
|
442
|
+
$logger.behaviour "PASS;Verification #{ message }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_true;"
|
443
|
+
|
444
|
+
nil
|
445
|
+
|
446
|
+
end
|
447
|
+
|
448
|
+
# Verifies that the block given to this method evaluates to false. Verification is synchronized with all connected suts.
|
449
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
450
|
+
#
|
451
|
+
# === params
|
452
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
453
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
454
|
+
# === returns
|
455
|
+
# nil
|
456
|
+
# === raises
|
457
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
458
|
+
# VerificationError:: The verification failed.
|
459
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
460
|
+
def verify_false( timeout = nil, message = nil, &block )
|
461
|
+
|
462
|
+
begin
|
463
|
+
|
464
|
+
# expected result
|
465
|
+
expected_value = false
|
466
|
+
|
467
|
+
# determine name of caller method
|
468
|
+
verify_caller = caller( 1 ).first.to_s
|
469
|
+
|
470
|
+
# store orignal logging state
|
471
|
+
logging_enabled = $logger.enabled
|
472
|
+
|
473
|
+
# disable behaviour logging
|
474
|
+
$logger.enabled = false
|
475
|
+
|
476
|
+
# ensure that code block was given
|
477
|
+
raise ArgumentError, "No block was given." unless block_given?
|
478
|
+
|
479
|
+
# ensure that timeout is either nil or type of integer
|
480
|
+
raise ArgumentError, "wrong argument type #{ timeout.class } for timeout (expected Fixnum or NilClass)" unless [ NilClass, Fixnum ].include?( timeout.class )
|
481
|
+
|
482
|
+
# ensure that message is either nil or type of string
|
483
|
+
raise ArgumentError, "Argument message was not a String" unless [ NilClass, String ].include?( message.class )
|
484
|
+
|
485
|
+
# convert timeout to integer, nil will be zero
|
486
|
+
timeout = get_timeout( timeout )
|
487
|
+
|
488
|
+
# calculate the time when timeout exceeds
|
489
|
+
timeout_end_time = Time.now + timeout
|
490
|
+
|
491
|
+
# convert message to string, nil will be empty string
|
492
|
+
message = message.to_s
|
493
|
+
|
494
|
+
# add double quotation and trailing whitespace if not empty string
|
495
|
+
message = "#{ message.inspect } " if message.length > 0
|
496
|
+
|
497
|
+
# store original timeout value
|
498
|
+
original_timeout_value = MobyBase::TestObjectFactory.instance.timeout
|
499
|
+
|
500
|
+
# set the testobject timeout to 0 for the duration of the verify call
|
501
|
+
MobyBase::TestObjectFactory.instance.timeout = 0
|
502
|
+
|
503
|
+
# result container
|
504
|
+
result = nil
|
505
|
+
|
506
|
+
loop do
|
507
|
+
|
508
|
+
begin
|
509
|
+
|
510
|
+
counter = ref_counter
|
511
|
+
|
512
|
+
# execute code block
|
513
|
+
result = yield
|
514
|
+
|
515
|
+
# raise exception if result of yield does not equal with expected value
|
516
|
+
raise MobyBase::VerificationError unless result == expected_value
|
517
|
+
|
518
|
+
# break loop if no exceptions thrown
|
519
|
+
break
|
520
|
+
|
521
|
+
rescue
|
522
|
+
|
523
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
524
|
+
|
525
|
+
# refresh and retry unless timeout exceeded
|
526
|
+
raise $! if Time.new > timeout_end_time
|
527
|
+
|
528
|
+
# retry interval
|
529
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
530
|
+
|
531
|
+
# refresh suts
|
532
|
+
refresh_suts if counter == ref_counter
|
533
|
+
|
534
|
+
end # begin
|
535
|
+
|
536
|
+
end # do loop
|
537
|
+
|
538
|
+
rescue
|
539
|
+
|
540
|
+
# restore logger state
|
541
|
+
$logger.enabled = logging_enabled
|
542
|
+
|
543
|
+
# execute on verification error code block
|
544
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
545
|
+
|
546
|
+
# process the exception
|
547
|
+
if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
548
|
+
|
549
|
+
raise
|
550
|
+
|
551
|
+
elsif $!.kind_of?( MobyBase::VerificationError )
|
552
|
+
|
553
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed: #{ MobyUtil::KernelHelper.find_source( verify_caller ) }"
|
554
|
+
error_message << "The block did not return #{ expected_value }. It returned: #{ result.inspect }"
|
555
|
+
|
556
|
+
else
|
557
|
+
|
558
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed as an exception was thrown when the verification block was executed"
|
559
|
+
error_message << "#{ MobyUtil::KernelHelper.find_source( verify_caller ) }\nDetails: \n#{ $!.inspect }"
|
560
|
+
|
561
|
+
end
|
562
|
+
|
563
|
+
$logger.behaviour "FAIL;Verification #{ message }failed: #{ $!.to_s }.\n #{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_false;"
|
564
|
+
|
565
|
+
# raise the exception
|
566
|
+
raise MobyBase::VerificationError, error_message
|
567
|
+
|
568
|
+
ensure
|
569
|
+
|
570
|
+
# restore original test object factory timeout value
|
571
|
+
MobyBase::TestObjectFactory.instance.timeout = original_timeout_value
|
572
|
+
|
573
|
+
# restore logger state
|
574
|
+
$logger.enabled = logging_enabled
|
575
|
+
|
576
|
+
end
|
577
|
+
|
578
|
+
$logger.behaviour "PASS;Verification #{ message }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_false;"
|
579
|
+
|
580
|
+
nil
|
581
|
+
|
582
|
+
end
|
583
|
+
|
584
|
+
# Verifies that the block given to this method evaluates to the expected value. Verification is synchronized with all connected suts.
|
585
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
586
|
+
#
|
587
|
+
# === params
|
588
|
+
# expected:: Expected result value of the block
|
589
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
590
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
591
|
+
# === returns
|
592
|
+
# nil
|
593
|
+
# === raises
|
594
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
595
|
+
# VerificationError:: The verification failed.
|
596
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
597
|
+
def verify_equal( expected_value, timeout = nil, message = nil, &block )
|
598
|
+
|
599
|
+
begin
|
600
|
+
|
601
|
+
# determine name of caller method
|
602
|
+
verify_caller = caller( 1 ).first.to_s
|
603
|
+
|
604
|
+
# store orignal logging state
|
605
|
+
logging_enabled = $logger.enabled
|
606
|
+
|
607
|
+
# disable behaviour logging
|
608
|
+
$logger.enabled = false
|
609
|
+
|
610
|
+
# ensure that code block was given
|
611
|
+
raise ArgumentError, "No block was given." unless block_given?
|
612
|
+
|
613
|
+
# ensure that timeout is either nil or type of integer
|
614
|
+
raise ArgumentError, "wrong argument type #{ timeout.class } for timeout (expected Fixnum or NilClass)" unless [ NilClass, Fixnum ].include?( timeout.class )
|
615
|
+
|
616
|
+
# ensure that message is either nil or type of string
|
617
|
+
raise ArgumentError, "Argument message was not a String" unless [ NilClass, String ].include?( message.class )
|
618
|
+
|
619
|
+
# convert timeout to integer, nil will be zero
|
620
|
+
timeout = get_timeout( timeout )
|
621
|
+
|
622
|
+
# calculate the time when timeout exceeds
|
623
|
+
timeout_end_time = Time.now + timeout
|
624
|
+
|
625
|
+
# convert message to string, nil will be empty string
|
626
|
+
message = message.to_s
|
627
|
+
|
628
|
+
# add double quotation and trailing whitespace if not empty string
|
629
|
+
message = "#{ message.inspect } " if message.length > 0
|
630
|
+
|
631
|
+
# store original timeout value
|
632
|
+
original_timeout_value = MobyBase::TestObjectFactory.instance.timeout
|
633
|
+
|
634
|
+
# set the testobject timeout to 0 for the duration of the verify call
|
635
|
+
MobyBase::TestObjectFactory.instance.timeout = 0
|
636
|
+
|
637
|
+
# result container
|
638
|
+
result = nil
|
639
|
+
|
640
|
+
loop do
|
641
|
+
|
642
|
+
begin
|
643
|
+
|
644
|
+
counter = ref_counter
|
645
|
+
|
646
|
+
# execute code block
|
647
|
+
result = yield
|
648
|
+
|
649
|
+
# raise exception if result of yield does not equal with expected value
|
650
|
+
raise MobyBase::VerificationError unless result == expected_value
|
651
|
+
|
652
|
+
# break loop if no exceptions thrown
|
653
|
+
break
|
654
|
+
|
655
|
+
rescue
|
656
|
+
|
657
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
658
|
+
|
659
|
+
# refresh and retry unless timeout exceeded
|
660
|
+
raise $! if Time.new > timeout_end_time
|
661
|
+
|
662
|
+
# retry interval
|
663
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
664
|
+
|
665
|
+
# refresh suts
|
666
|
+
refresh_suts if counter == ref_counter
|
667
|
+
|
668
|
+
end # begin
|
669
|
+
|
670
|
+
end # do loop
|
671
|
+
|
672
|
+
rescue
|
673
|
+
|
674
|
+
# restore logger state
|
675
|
+
$logger.enabled = logging_enabled
|
676
|
+
|
677
|
+
# execute on verification error code block
|
678
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
679
|
+
|
680
|
+
# process the exception
|
681
|
+
if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
682
|
+
|
683
|
+
raise
|
684
|
+
|
685
|
+
elsif $!.kind_of?( MobyBase::VerificationError )
|
686
|
+
|
687
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed: #{ MobyUtil::KernelHelper.find_source( verify_caller ) }"
|
688
|
+
error_message << "The block did not return #{ expected_value }. It returned: #{ result.inspect }"
|
689
|
+
|
690
|
+
else
|
691
|
+
|
692
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed as an exception was thrown when the verification block was executed"
|
693
|
+
error_message << "#{ MobyUtil::KernelHelper.find_source( verify_caller ) }\nDetails: \n#{ $!.inspect }"
|
694
|
+
|
695
|
+
end
|
696
|
+
|
697
|
+
$logger.behaviour "FAIL;Verification #{ message }failed: #{ $!.to_s }.\n #{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_equal;"
|
698
|
+
|
699
|
+
# raise the exception
|
700
|
+
raise MobyBase::VerificationError, error_message
|
701
|
+
|
702
|
+
ensure
|
703
|
+
|
704
|
+
# restore original test object factory timeout value
|
705
|
+
MobyBase::TestObjectFactory.instance.timeout = original_timeout_value
|
706
|
+
|
707
|
+
# restore logger state
|
708
|
+
$logger.enabled = logging_enabled
|
709
|
+
|
710
|
+
end
|
711
|
+
|
712
|
+
$logger.behaviour "PASS;Verification #{ message }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_equal;"
|
713
|
+
|
714
|
+
nil
|
715
|
+
|
716
|
+
end
|
717
|
+
|
718
|
+
# Verifies that the block given to return value matches with expected regular expression pattern. Verification is synchronized with all connected suts.
|
719
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
720
|
+
#
|
721
|
+
# === params
|
722
|
+
# expected:: Regular expression
|
723
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
724
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
725
|
+
# === returns
|
726
|
+
# nil
|
727
|
+
# === raises
|
728
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
729
|
+
# TypeError:: if block result not type of String.
|
730
|
+
# VerificationError:: The verification failed.
|
731
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
732
|
+
def verify_regexp( expected_value, timeout = nil, message = nil, &block )
|
733
|
+
|
734
|
+
begin
|
735
|
+
|
736
|
+
# determine name of caller method
|
737
|
+
verify_caller = caller( 1 ).first.to_s
|
738
|
+
|
739
|
+
# store orignal logging state
|
740
|
+
logging_enabled = $logger.enabled
|
741
|
+
|
742
|
+
# disable behaviour logging
|
743
|
+
$logger.enabled = false
|
744
|
+
|
745
|
+
# ensure that code block was given
|
746
|
+
raise ArgumentError, "No block was given." unless block_given?
|
747
|
+
|
748
|
+
# ensure that timeout is either nil or type of integer
|
749
|
+
raise ArgumentError, "wrong argument type #{ timeout.class } for timeout (expected Fixnum or NilClass)" unless [ NilClass, Fixnum ].include?( timeout.class )
|
750
|
+
|
751
|
+
# ensure that message is either nil or type of string
|
752
|
+
raise ArgumentError, "Argument message was not a String" unless [ NilClass, String ].include?( message.class )
|
753
|
+
|
754
|
+
expected_value.check_type Regexp, "wrong argument type $1 for expected result (expected $2)"
|
755
|
+
|
756
|
+
# convert timeout to integer, nil will be zero
|
757
|
+
timeout = get_timeout( timeout )
|
758
|
+
|
759
|
+
# calculate the time when timeout exceeds
|
760
|
+
timeout_end_time = Time.now + timeout
|
761
|
+
|
762
|
+
# convert message to string, nil will be empty string
|
763
|
+
message = message.to_s
|
764
|
+
|
765
|
+
# add double quotation and trailing whitespace if not empty string
|
766
|
+
message = "#{ message.inspect } " if message.length > 0
|
767
|
+
|
768
|
+
# store original timeout value
|
769
|
+
original_timeout_value = MobyBase::TestObjectFactory.instance.timeout
|
770
|
+
|
771
|
+
# set the testobject timeout to 0 for the duration of the verify call
|
772
|
+
MobyBase::TestObjectFactory.instance.timeout = 0
|
773
|
+
|
774
|
+
# result container
|
775
|
+
result = nil
|
776
|
+
|
777
|
+
loop do
|
778
|
+
|
779
|
+
begin
|
780
|
+
|
781
|
+
counter = ref_counter
|
782
|
+
|
783
|
+
# execute code block
|
784
|
+
result = yield
|
785
|
+
|
786
|
+
# raise exception if result of yield does not match with expected value regexp
|
787
|
+
raise MobyBase::VerificationError unless result =~ expected_value
|
788
|
+
|
789
|
+
# break loop if no exceptions thrown
|
790
|
+
break
|
791
|
+
|
792
|
+
rescue
|
793
|
+
|
794
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
795
|
+
|
796
|
+
# refresh and retry unless timeout exceeded
|
797
|
+
raise $! if Time.new > timeout_end_time
|
798
|
+
|
799
|
+
# retry interval
|
800
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
801
|
+
|
802
|
+
# refresh suts
|
803
|
+
refresh_suts if counter == ref_counter
|
804
|
+
|
805
|
+
end # begin
|
806
|
+
|
807
|
+
end # do loop
|
808
|
+
|
809
|
+
rescue
|
810
|
+
|
811
|
+
# restore logger state
|
812
|
+
$logger.enabled = logging_enabled
|
813
|
+
|
814
|
+
# execute on verification error code block
|
815
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
816
|
+
|
817
|
+
# process the exception
|
818
|
+
if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
819
|
+
|
820
|
+
raise
|
821
|
+
|
822
|
+
elsif $!.kind_of?( MobyBase::VerificationError )
|
823
|
+
|
824
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed: #{ MobyUtil::KernelHelper.find_source( verify_caller ) }"
|
825
|
+
error_message << "The block did not return #{ expected_value.inspect } pattern. It returned: #{ result.inspect }"
|
826
|
+
|
827
|
+
else
|
828
|
+
|
829
|
+
error_message = "Verification #{ message }at #{ verify_caller } failed as an exception was thrown when the verification block was executed"
|
830
|
+
error_message << "#{ MobyUtil::KernelHelper.find_source( verify_caller ) }\nDetails: \n#{ $!.inspect }"
|
831
|
+
|
832
|
+
end
|
833
|
+
|
834
|
+
$logger.behaviour "FAIL;Verification #{ message }failed: #{ $!.to_s }.\n #{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_regexp;"
|
835
|
+
|
836
|
+
# raise the exception
|
837
|
+
raise MobyBase::VerificationError, error_message
|
838
|
+
|
839
|
+
ensure
|
840
|
+
|
841
|
+
# restore original test object factory timeout value
|
842
|
+
MobyBase::TestObjectFactory.instance.timeout = original_timeout_value
|
843
|
+
|
844
|
+
# restore logger state
|
845
|
+
$logger.enabled = logging_enabled
|
846
|
+
|
847
|
+
end
|
848
|
+
|
849
|
+
$logger.behaviour "PASS;Verification #{ message }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? self.id.to_s + ';sut' : ';' };{};verify_regexp;"
|
850
|
+
|
851
|
+
nil
|
852
|
+
|
853
|
+
end
|
854
|
+
|
855
|
+
# Verifies that the given signal is emitted.
|
856
|
+
#
|
857
|
+
# === params
|
858
|
+
# timeout:: Integer, defining the amount of seconds during which the verification must pass.
|
859
|
+
# signal_name:: String, name of the signal
|
860
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
861
|
+
# block:: code to execute while listening signals
|
862
|
+
# === returns
|
863
|
+
# nil
|
864
|
+
# === raises
|
865
|
+
# ArgumentError:: message or signal_name was not a String or timeout a non negative Integer
|
866
|
+
# VerificationError:: The verification failed.
|
867
|
+
def verify_signal( timeout, signal_name, message = nil, &block )
|
868
|
+
|
869
|
+
logging_enabled = $logger.enabled
|
870
|
+
verify_caller = caller(1).first.to_s
|
871
|
+
|
872
|
+
begin
|
873
|
+
|
874
|
+
$logger.enabled = false
|
875
|
+
|
876
|
+
raise ArgumentError, "Argument timeout was not a non negative Integer." unless (timeout.kind_of?(Integer) && timeout >= 0)
|
877
|
+
raise ArgumentError, "Argument message was not a non empty String." unless (message.nil? || (message.kind_of?(String) && !message.empty?))
|
878
|
+
|
879
|
+
# wait for the signal
|
880
|
+
begin
|
881
|
+
|
882
|
+
self.wait_for_signal( timeout, signal_name, &block )
|
883
|
+
|
884
|
+
rescue
|
885
|
+
|
886
|
+
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed:"
|
887
|
+
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
888
|
+
error_msg << "The signal #{signal_name} was not emitted in #{timeout} seconds.\nNested exception:\n" << $!.inspect
|
889
|
+
|
890
|
+
raise MobyBase::VerificationError, error_msg
|
891
|
+
|
892
|
+
end
|
893
|
+
|
894
|
+
rescue
|
895
|
+
|
896
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
897
|
+
|
898
|
+
$logger.enabled = logging_enabled
|
899
|
+
|
900
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{$!.to_s} using timeout '#{timeout}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_signal;#{signal_name}"
|
901
|
+
|
902
|
+
raise
|
73
903
|
|
74
|
-
|
904
|
+
ensure
|
905
|
+
|
906
|
+
$logger.enabled = logging_enabled
|
907
|
+
|
908
|
+
end
|
909
|
+
|
910
|
+
$logger.behaviour "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_signal;#{signal_name}"
|
911
|
+
|
912
|
+
nil
|
913
|
+
|
914
|
+
end
|
915
|
+
|
916
|
+
=begin
|
917
|
+
|
918
|
+
# old implementation:
|
919
|
+
|
920
|
+
# Verifies that the block given to return value matches with expected regular expression pattern. Verification is synchronized with all connected suts.
|
921
|
+
# If this method is called for a sut, synchronization is only done with that sut.
|
922
|
+
#
|
923
|
+
# === params
|
924
|
+
# expected:: Regular expression
|
925
|
+
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
926
|
+
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
927
|
+
# === returns
|
928
|
+
# nil
|
929
|
+
# === raises
|
930
|
+
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
931
|
+
# TypeError:: if block result not type of String.
|
932
|
+
# VerificationError:: The verification failed.
|
933
|
+
# RuntimeError:: An unexpected error was encountered during verification.
|
934
|
+
def verify_regexp( expected, timeout = nil, message = nil, &block )
|
75
935
|
|
76
936
|
logging_enabled = $logger.enabled
|
77
937
|
|
78
|
-
verify_caller = caller(1).first.to_s
|
938
|
+
verify_caller = caller( 1 ).first.to_s
|
79
939
|
|
80
940
|
begin
|
81
941
|
|
942
|
+
raise ArgumentError, "No block was given." unless block_given?
|
943
|
+
|
944
|
+
# verify argument types
|
945
|
+
timeout.check_type [ Integer, NilClass ], "wrong argument type $1 for timeout (expected $2)"
|
946
|
+
message.check_type [ String, NilClass ], "wrong argument type $1 for message (expected $2)"
|
947
|
+
expected.check_type Regexp, "wrong argument type $1 for expected result (expected $2)"
|
948
|
+
|
82
949
|
$logger.enabled = false
|
83
|
-
|
84
|
-
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
85
|
-
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
86
|
-
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
87
950
|
|
88
951
|
#Set the testobject timeout to 0 for the duration of the verify call
|
89
952
|
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
953
|
+
|
90
954
|
MobyBase::TestObjectFactory.instance.timeout = 0
|
91
955
|
|
92
|
-
timeout_time = get_end_time(timeout)
|
93
|
-
#TIMEOUT_CYCLE_SECONDS
|
956
|
+
timeout_time = get_end_time( timeout )
|
94
957
|
|
95
958
|
loop do
|
96
|
-
|
959
|
+
|
97
960
|
counter = ref_counter
|
961
|
+
|
962
|
+
# catch errors thrown due to verification results
|
963
|
+
begin
|
964
|
+
|
965
|
+
# catch errors thrown in the provided block
|
966
|
+
begin
|
967
|
+
|
968
|
+
# execute block
|
969
|
+
result = yield
|
98
970
|
|
99
|
-
|
971
|
+
rescue Exception
|
100
972
|
|
101
|
-
|
973
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
102
974
|
|
103
|
-
|
104
|
-
break
|
975
|
+
error_msg = "Verification #{ message.nil? ? '' : '"' << message.to_s << '" '}at #{ verify_caller } failed as an exception was thrown when the verification block was executed."
|
105
976
|
|
106
|
-
|
977
|
+
error_msg << MobyUtil::KernelHelper.find_source( verify_caller )
|
107
978
|
|
108
|
-
|
979
|
+
error_msg << "\nDetails: \n#{ $!.inspect }"
|
109
980
|
|
110
|
-
|
111
|
-
error_msg = ""
|
981
|
+
raise MobyBase::VerificationError, error_msg
|
112
982
|
|
113
|
-
|
983
|
+
end
|
114
984
|
|
115
|
-
|
985
|
+
# verify that result value is type of string
|
986
|
+
result.check_type String, "wrong variable type $1 for result (expected $2)"
|
987
|
+
|
988
|
+
# result verification
|
989
|
+
unless result =~ expected
|
116
990
|
|
117
|
-
|
991
|
+
error_msg = "Verification #{ message.nil? ? '' : '"' << message.to_s << '" '}at #{ verify_caller } failed:"
|
992
|
+
|
993
|
+
error_msg << MobyUtil::KernelHelper.find_source( verify_caller )
|
994
|
+
|
995
|
+
error_msg << "\nThe block did not match with pattern #{ expected.inspect }. It returned: #{ result.inspect }"
|
118
996
|
|
119
|
-
|
997
|
+
raise MobyBase::VerificationError, error_msg
|
120
998
|
|
121
|
-
|
122
|
-
# failed to load line from file, do nothing
|
123
|
-
$logger.enabled = logging_enabled
|
124
|
-
$logger.log "behaviour" , "WARNING;Failed to load source line: #{e.backtrace.inspect}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
125
|
-
end
|
999
|
+
end
|
126
1000
|
|
127
|
-
|
128
|
-
|
129
|
-
end
|
1001
|
+
# break loop if no exceptions thrown
|
1002
|
+
break
|
130
1003
|
|
131
|
-
|
1004
|
+
rescue MobyBase::VerificationError
|
132
1005
|
|
133
|
-
|
1006
|
+
# refresh and retry unless timeout reached
|
134
1007
|
|
135
|
-
|
1008
|
+
raise $! if Time.new > timeout_time
|
136
1009
|
|
137
|
-
|
1010
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
138
1011
|
|
139
|
-
|
1012
|
+
refresh_suts if counter == ref_counter
|
1013
|
+
|
1014
|
+
rescue MobyBase::ContinuousVerificationError
|
1015
|
+
|
1016
|
+
raise
|
140
1017
|
|
141
|
-
|
1018
|
+
rescue TypeError
|
1019
|
+
|
1020
|
+
raise $!
|
1021
|
+
|
1022
|
+
rescue Exception
|
1023
|
+
|
1024
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
1025
|
+
|
1026
|
+
# an unexpected error has occurred
|
1027
|
+
raise RuntimeError, "An unexpected error was encountered during verification:\n#{ $!.inspect }"
|
1028
|
+
|
1029
|
+
end # begin, catch any VerificationErrors
|
142
1030
|
|
143
1031
|
end # do
|
144
1032
|
|
145
|
-
rescue Exception
|
1033
|
+
rescue Exception
|
146
1034
|
|
147
1035
|
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
148
1036
|
|
149
|
-
raise if
|
1037
|
+
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
150
1038
|
|
151
1039
|
$logger.enabled = logging_enabled
|
152
|
-
|
153
|
-
|
1040
|
+
|
1041
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{ $!.to_s }.\n#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? "#{ self.id.to_s };sut" : ';' };{};verify_regexp;#{ expected.inspect }"
|
154
1042
|
|
155
|
-
|
1043
|
+
raise $!
|
156
1044
|
|
157
|
-
|
1045
|
+
ensure
|
1046
|
+
|
1047
|
+
MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout
|
158
1048
|
|
1049
|
+
$logger.enabled = logging_enabled
|
1050
|
+
|
159
1051
|
end
|
160
1052
|
|
161
|
-
$logger.
|
162
|
-
$logger.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
1053
|
+
$logger.behaviour "PASS;Verification #{ message.nil? ? '' : '\"' << message << '\" ' }at #{ verify_caller } was successful#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{ self.kind_of?( MobyBase::SUT ) ? "#{ self.id.to_s };sut" : ';'};{};verify_regexp;#{ expected.inspect }"
|
163
1054
|
|
164
|
-
|
1055
|
+
nil
|
165
1056
|
|
166
1057
|
end
|
167
1058
|
|
168
|
-
|
169
|
-
# Verifies that the block given to this method throws an exception while being evaluated. Verification is synchronized with all connected suts.
|
1059
|
+
# Verifies that the block given to this method evaluates without throwing any exceptions. Verification is synchronized with all connected suts.
|
170
1060
|
# If this method is called for a sut, synchronization is only done with that sut.
|
171
1061
|
#
|
172
1062
|
# === params
|
@@ -177,13 +1067,16 @@ module TDriverVerify
|
|
177
1067
|
# === raises
|
178
1068
|
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
179
1069
|
# VerificationError:: The verification failed.
|
180
|
-
def
|
1070
|
+
def verify( timeout = nil, message = nil, &block )
|
181
1071
|
|
182
1072
|
logging_enabled = $logger.enabled
|
1073
|
+
|
183
1074
|
verify_caller = caller(1).first.to_s
|
1075
|
+
|
184
1076
|
begin
|
185
1077
|
|
186
1078
|
$logger.enabled = false
|
1079
|
+
|
187
1080
|
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
188
1081
|
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
189
1082
|
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
@@ -196,47 +1089,55 @@ module TDriverVerify
|
|
196
1089
|
#TIMEOUT_CYCLE_SECONDS
|
197
1090
|
|
198
1091
|
loop do
|
1092
|
+
|
199
1093
|
counter = ref_counter
|
200
|
-
|
1094
|
+
|
201
1095
|
begin # catch errors thrown in the provided block
|
202
1096
|
|
203
1097
|
yield
|
204
|
-
|
205
|
-
|
1098
|
+
|
1099
|
+
# no error => verification ok
|
1100
|
+
break
|
1101
|
+
|
206
1102
|
rescue Exception => e
|
1103
|
+
|
207
1104
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
208
1105
|
|
209
1106
|
source_contents = ""
|
210
1107
|
error_msg = ""
|
211
1108
|
|
212
|
-
if (!artificial_exception_raised)
|
213
|
-
# an error was encountered => verification ok
|
214
|
-
break
|
215
|
-
end
|
216
|
-
|
217
1109
|
if Time.new > timeout_time
|
218
1110
|
|
219
1111
|
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed\n"
|
220
1112
|
|
221
|
-
|
1113
|
+
begin
|
1114
|
+
|
1115
|
+
source_contents = MobyUtil::KernelHelper.find_source(verify_caller)
|
1116
|
+
|
1117
|
+
rescue Exception
|
1118
|
+
# failed to load line from file, do nothing
|
1119
|
+
$logger.enabled = logging_enabled
|
1120
|
+
$logger.behaviour "WARNING;Failed to load source line: #{e.backtrace.inspect}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
1121
|
+
end
|
222
1122
|
|
223
1123
|
if !source_contents.empty?
|
224
1124
|
error_msg << source_contents
|
225
1125
|
end
|
226
1126
|
|
1127
|
+
error_msg << "\nNested exception:" << e.message << "\n"
|
1128
|
+
|
227
1129
|
Kernel::raise MobyBase::VerificationError.new(error_msg)
|
228
1130
|
|
229
1131
|
end
|
230
1132
|
|
231
|
-
|
1133
|
+
end
|
232
1134
|
|
233
|
-
|
1135
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
234
1136
|
|
235
|
-
|
1137
|
+
refresh_suts if counter == ref_counter
|
236
1138
|
|
237
1139
|
end # do
|
238
1140
|
|
239
|
-
|
240
1141
|
rescue Exception => e
|
241
1142
|
|
242
1143
|
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
@@ -244,7 +1145,7 @@ module TDriverVerify
|
|
244
1145
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
245
1146
|
|
246
1147
|
$logger.enabled = logging_enabled
|
247
|
-
$logger.
|
1148
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s}#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
248
1149
|
Kernel::raise e
|
249
1150
|
|
250
1151
|
ensure
|
@@ -254,12 +1155,13 @@ module TDriverVerify
|
|
254
1155
|
end
|
255
1156
|
|
256
1157
|
$logger.enabled = logging_enabled
|
257
|
-
$logger.
|
1158
|
+
$logger.behaviour "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
|
1159
|
+
|
258
1160
|
return nil
|
259
1161
|
|
260
1162
|
end
|
261
1163
|
|
262
|
-
# Verifies that the block given to this method
|
1164
|
+
# Verifies that the block given to this method throws an exception while being evaluated. Verification is synchronized with all connected suts.
|
263
1165
|
# If this method is called for a sut, synchronization is only done with that sut.
|
264
1166
|
#
|
265
1167
|
# === params
|
@@ -270,13 +1172,12 @@ module TDriverVerify
|
|
270
1172
|
# === raises
|
271
1173
|
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
272
1174
|
# VerificationError:: The verification failed.
|
273
|
-
|
274
|
-
def verify_true( timeout = nil, message = nil, &block )
|
1175
|
+
def verify_not( timeout = nil, message = nil, &block )
|
275
1176
|
|
276
1177
|
logging_enabled = $logger.enabled
|
277
1178
|
verify_caller = caller(1).first.to_s
|
278
|
-
|
279
1179
|
begin
|
1180
|
+
|
280
1181
|
$logger.enabled = false
|
281
1182
|
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
282
1183
|
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
@@ -290,93 +1191,74 @@ module TDriverVerify
|
|
290
1191
|
#TIMEOUT_CYCLE_SECONDS
|
291
1192
|
|
292
1193
|
loop do
|
293
|
-
|
294
1194
|
counter = ref_counter
|
1195
|
+
artificial_exception_raised = false
|
1196
|
+
begin # catch errors thrown in the provided block
|
295
1197
|
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
result = yield
|
302
|
-
|
303
|
-
rescue Exception => e
|
304
|
-
|
305
|
-
#@@on_error_verify_block.call unless @@on_error_verify_block.nil?
|
306
|
-
|
307
|
-
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
308
|
-
|
309
|
-
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
310
|
-
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
311
|
-
error_msg << "\nDetails: "
|
312
|
-
error_msg << "\n" << e.inspect
|
313
|
-
|
314
|
-
raise MobyBase::VerificationError.new( error_msg )
|
315
|
-
|
316
|
-
end
|
317
|
-
|
318
|
-
unless result == true
|
319
|
-
|
320
|
-
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed."
|
321
|
-
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
322
|
-
|
323
|
-
error_msg << "\nThe block did not return true. It returned: " << result.inspect
|
1198
|
+
yield
|
1199
|
+
artificial_exception_raised = true
|
1200
|
+
Kernel::raise "test"
|
1201
|
+
rescue Exception => e
|
1202
|
+
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
324
1203
|
|
325
|
-
|
1204
|
+
source_contents = ""
|
1205
|
+
error_msg = ""
|
326
1206
|
|
1207
|
+
if (!artificial_exception_raised)
|
1208
|
+
# an error was encountered => verification ok
|
1209
|
+
break
|
327
1210
|
end
|
328
1211
|
|
329
|
-
|
330
|
-
break
|
331
|
-
|
332
|
-
rescue MobyBase::VerificationError => ve
|
333
|
-
|
334
|
-
# refresh and retry unless timeout reached
|
335
|
-
|
336
|
-
if ( Time.new > timeout_time )
|
337
|
-
|
338
|
-
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
339
|
-
|
340
|
-
Kernel::raise ve
|
1212
|
+
if Time.new > timeout_time
|
341
1213
|
|
342
|
-
|
1214
|
+
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed\n"
|
343
1215
|
|
344
|
-
|
1216
|
+
source_contents = MobyUtil::KernelHelper.find_source(verify_caller)
|
345
1217
|
|
346
|
-
|
1218
|
+
if !source_contents.empty?
|
1219
|
+
error_msg << source_contents
|
1220
|
+
end
|
347
1221
|
|
348
|
-
|
1222
|
+
Kernel::raise MobyBase::VerificationError.new(error_msg)
|
349
1223
|
|
350
|
-
|
1224
|
+
end
|
351
1225
|
|
352
|
-
|
1226
|
+
sleep TIMEOUT_CYCLE_SECONDS
|
353
1227
|
|
354
|
-
|
355
|
-
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
1228
|
+
refresh_suts if counter == ref_counter
|
356
1229
|
|
357
|
-
end
|
1230
|
+
end
|
358
1231
|
|
359
1232
|
end # do
|
360
1233
|
|
1234
|
+
|
361
1235
|
rescue Exception => e
|
1236
|
+
|
1237
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
1238
|
+
|
362
1239
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
1240
|
+
|
363
1241
|
$logger.enabled = logging_enabled
|
364
|
-
$logger.
|
1242
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s}#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_not;"
|
365
1243
|
Kernel::raise e
|
1244
|
+
|
366
1245
|
ensure
|
1246
|
+
|
367
1247
|
MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
|
1248
|
+
|
368
1249
|
end
|
369
1250
|
|
370
1251
|
$logger.enabled = logging_enabled
|
371
|
-
$logger.
|
1252
|
+
$logger.behaviour "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_not;"
|
372
1253
|
return nil
|
373
1254
|
|
374
1255
|
end
|
375
1256
|
|
376
|
-
# Verifies that the block given to this method evaluates to
|
1257
|
+
# Verifies that the block given to this method evaluates to the expected value. Verification is synchronized with all connected suts.
|
377
1258
|
# If this method is called for a sut, synchronization is only done with that sut.
|
378
1259
|
#
|
379
1260
|
# === params
|
1261
|
+
# expected:: Expected result value of the block
|
380
1262
|
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
381
1263
|
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
382
1264
|
# === returns
|
@@ -385,18 +1267,12 @@ module TDriverVerify
|
|
385
1267
|
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
386
1268
|
# VerificationError:: The verification failed.
|
387
1269
|
# RuntimeError:: An unexpected error was encountered during verification.
|
388
|
-
def
|
389
|
-
|
1270
|
+
def verify_equal( expected, timeout = nil, message = nil, &block )
|
390
1271
|
logging_enabled = $logger.enabled
|
391
|
-
|
392
1272
|
verify_caller = caller(1).first.to_s
|
393
|
-
|
394
1273
|
begin
|
395
|
-
|
396
1274
|
$logger.enabled = false
|
397
|
-
|
398
1275
|
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
399
|
-
|
400
1276
|
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
401
1277
|
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
402
1278
|
|
@@ -405,6 +1281,7 @@ module TDriverVerify
|
|
405
1281
|
MobyBase::TestObjectFactory.instance.timeout = 0
|
406
1282
|
|
407
1283
|
timeout_time = get_end_time(timeout)
|
1284
|
+
|
408
1285
|
#TIMEOUT_CYCLE_SECONDS
|
409
1286
|
|
410
1287
|
loop do
|
@@ -413,6 +1290,7 @@ module TDriverVerify
|
|
413
1290
|
|
414
1291
|
begin # catch errors thrown in the provided block
|
415
1292
|
result = yield
|
1293
|
+
|
416
1294
|
rescue Exception => e
|
417
1295
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
418
1296
|
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
@@ -421,12 +1299,12 @@ module TDriverVerify
|
|
421
1299
|
error_msg << "\n" << e.inspect
|
422
1300
|
raise MobyBase::VerificationError.new(error_msg)
|
423
1301
|
end
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
1302
|
+
if result != expected
|
1303
|
+
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed:"
|
1304
|
+
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
1305
|
+
error_msg << "\nThe block did not return #{expected.inspect}. It returned: " << result.inspect
|
1306
|
+
raise MobyBase::VerificationError.new(error_msg)
|
1307
|
+
end
|
430
1308
|
# break loop if no exceptions thrown
|
431
1309
|
break
|
432
1310
|
|
@@ -441,12 +1319,11 @@ module TDriverVerify
|
|
441
1319
|
sleep TIMEOUT_CYCLE_SECONDS
|
442
1320
|
|
443
1321
|
refresh_suts if counter == ref_counter
|
444
|
-
|
445
|
-
|
1322
|
+
rescue MobyBase::ContinuousVerificationError
|
1323
|
+
raise
|
446
1324
|
rescue Exception => e
|
447
1325
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
448
1326
|
# an unexpected error has occurred
|
449
|
-
$logger.enabled = logging_enabled
|
450
1327
|
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
451
1328
|
|
452
1329
|
end # begin, catch any VerificationErrors
|
@@ -460,25 +1337,22 @@ module TDriverVerify
|
|
460
1337
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
461
1338
|
|
462
1339
|
$logger.enabled = logging_enabled
|
463
|
-
$logger.
|
464
|
-
|
1340
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_equal;" << expected.to_s
|
465
1341
|
Kernel::raise e
|
466
|
-
|
467
1342
|
ensure
|
468
1343
|
MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
|
469
1344
|
end
|
470
1345
|
|
471
1346
|
$logger.enabled = logging_enabled
|
472
|
-
$logger.
|
1347
|
+
$logger.behaviour "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_equal;" << expected.to_s
|
473
1348
|
return nil
|
474
1349
|
|
475
1350
|
end
|
476
1351
|
|
477
|
-
# Verifies that the block given to this method evaluates to
|
1352
|
+
# Verifies that the block given to this method evaluates to true. Verification is synchronized with all connected suts.
|
478
1353
|
# If this method is called for a sut, synchronization is only done with that sut.
|
479
1354
|
#
|
480
1355
|
# === params
|
481
|
-
# expected:: Expected result value of the block
|
482
1356
|
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
483
1357
|
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
484
1358
|
# === returns
|
@@ -487,9 +1361,11 @@ module TDriverVerify
|
|
487
1361
|
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
488
1362
|
# VerificationError:: The verification failed.
|
489
1363
|
# RuntimeError:: An unexpected error was encountered during verification.
|
490
|
-
def
|
1364
|
+
def verify_true( timeout = nil, message = nil, &block )
|
1365
|
+
|
491
1366
|
logging_enabled = $logger.enabled
|
492
1367
|
verify_caller = caller(1).first.to_s
|
1368
|
+
|
493
1369
|
begin
|
494
1370
|
$logger.enabled = false
|
495
1371
|
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
@@ -501,30 +1377,45 @@ module TDriverVerify
|
|
501
1377
|
MobyBase::TestObjectFactory.instance.timeout = 0
|
502
1378
|
|
503
1379
|
timeout_time = get_end_time(timeout)
|
504
|
-
|
505
1380
|
#TIMEOUT_CYCLE_SECONDS
|
506
1381
|
|
507
1382
|
loop do
|
1383
|
+
|
508
1384
|
counter = ref_counter
|
1385
|
+
|
509
1386
|
begin # catch errors thrown due to verification results
|
510
1387
|
|
1388
|
+
|
511
1389
|
begin # catch errors thrown in the provided block
|
1390
|
+
|
512
1391
|
result = yield
|
513
1392
|
|
514
1393
|
rescue Exception => e
|
1394
|
+
|
1395
|
+
#@@on_error_verify_block.call unless @@on_error_verify_block.nil?
|
1396
|
+
|
515
1397
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
1398
|
+
|
516
1399
|
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
517
1400
|
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
518
1401
|
error_msg << "\nDetails: "
|
519
1402
|
error_msg << "\n" << e.inspect
|
520
|
-
|
1403
|
+
|
1404
|
+
raise MobyBase::VerificationError.new( error_msg )
|
1405
|
+
|
521
1406
|
end
|
522
|
-
|
523
|
-
|
1407
|
+
|
1408
|
+
unless result == true
|
1409
|
+
|
1410
|
+
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed."
|
524
1411
|
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
525
|
-
|
526
|
-
|
1412
|
+
|
1413
|
+
error_msg << "\nThe block did not return true. It returned: " << result.inspect
|
1414
|
+
|
1415
|
+
raise MobyBase::VerificationError.new( error_msg )
|
1416
|
+
|
527
1417
|
end
|
1418
|
+
|
528
1419
|
# break loop if no exceptions thrown
|
529
1420
|
break
|
530
1421
|
|
@@ -532,17 +1423,24 @@ module TDriverVerify
|
|
532
1423
|
|
533
1424
|
# refresh and retry unless timeout reached
|
534
1425
|
|
535
|
-
if Time.new > timeout_time
|
1426
|
+
if ( Time.new > timeout_time )
|
1427
|
+
|
1428
|
+
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
1429
|
+
|
536
1430
|
Kernel::raise ve
|
1431
|
+
|
537
1432
|
end
|
538
1433
|
|
539
1434
|
sleep TIMEOUT_CYCLE_SECONDS
|
540
1435
|
|
541
1436
|
refresh_suts if counter == ref_counter
|
542
|
-
|
543
|
-
raise
|
1437
|
+
|
544
1438
|
rescue Exception => e
|
1439
|
+
|
545
1440
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
1441
|
+
|
1442
|
+
$logger.enabled = logging_enabled
|
1443
|
+
|
546
1444
|
# an unexpected error has occurred
|
547
1445
|
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
548
1446
|
|
@@ -551,228 +1449,153 @@ module TDriverVerify
|
|
551
1449
|
end # do
|
552
1450
|
|
553
1451
|
rescue Exception => e
|
554
|
-
|
555
|
-
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
556
|
-
|
557
1452
|
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
558
|
-
|
559
1453
|
$logger.enabled = logging_enabled
|
560
|
-
$logger.
|
1454
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_true;"
|
561
1455
|
Kernel::raise e
|
562
1456
|
ensure
|
563
1457
|
MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
|
564
1458
|
end
|
565
1459
|
|
566
1460
|
$logger.enabled = logging_enabled
|
567
|
-
$logger.
|
1461
|
+
$logger.behaviour "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_true;"
|
568
1462
|
return nil
|
569
1463
|
|
570
1464
|
end
|
571
1465
|
|
572
|
-
# Verifies that the block given to
|
1466
|
+
# Verifies that the block given to this method evaluates to false. Verification is synchronized with all connected suts.
|
573
1467
|
# If this method is called for a sut, synchronization is only done with that sut.
|
574
1468
|
#
|
575
1469
|
# === params
|
576
|
-
# expected:: Regular expression
|
577
1470
|
# timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
|
578
1471
|
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
579
1472
|
# === returns
|
580
1473
|
# nil
|
581
1474
|
# === raises
|
582
1475
|
# ArgumentError:: message was not a String or timeout an integer, or no block was given.
|
583
|
-
# TypeError:: if block result not type of String.
|
584
1476
|
# VerificationError:: The verification failed.
|
585
1477
|
# RuntimeError:: An unexpected error was encountered during verification.
|
586
|
-
def
|
1478
|
+
def verify_false( timeout = nil, message = nil, &block )
|
587
1479
|
|
588
1480
|
logging_enabled = $logger.enabled
|
589
1481
|
|
590
|
-
verify_caller = caller(
|
1482
|
+
verify_caller = caller(1).first.to_s
|
591
1483
|
|
592
1484
|
begin
|
593
1485
|
|
594
|
-
|
1486
|
+
$logger.enabled = false
|
595
1487
|
|
596
|
-
|
597
|
-
timeout.check_type [ Integer, NilClass ], "wrong argument type $1 for timeout (expected $2)"
|
598
|
-
message.check_type [ String, NilClass ], "wrong argument type $1 for message (expected $2)"
|
599
|
-
expected.check_type Regexp, "wrong argument type $1 for expected result (expected $2)"
|
1488
|
+
Kernel::raise ArgumentError.new("No block was given.") unless block_given?
|
600
1489
|
|
601
|
-
|
1490
|
+
Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
|
1491
|
+
Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
|
602
1492
|
|
603
1493
|
#Set the testobject timeout to 0 for the duration of the verify call
|
604
1494
|
original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
|
605
|
-
|
606
1495
|
MobyBase::TestObjectFactory.instance.timeout = 0
|
607
1496
|
|
608
|
-
timeout_time = get_end_time(
|
1497
|
+
timeout_time = get_end_time(timeout)
|
1498
|
+
#TIMEOUT_CYCLE_SECONDS
|
609
1499
|
|
610
1500
|
loop do
|
611
|
-
|
612
1501
|
counter = ref_counter
|
613
|
-
|
614
|
-
# catch errors thrown due to verification results
|
615
|
-
begin
|
616
|
-
|
617
|
-
# catch errors thrown in the provided block
|
618
|
-
begin
|
619
|
-
|
620
|
-
# execute block
|
621
|
-
result = yield
|
622
|
-
|
623
|
-
rescue Exception
|
624
|
-
|
625
|
-
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
626
|
-
|
627
|
-
error_msg = "Verification #{ message.nil? ? '' : '"' << message.to_s << '" '}at #{ verify_caller } failed as an exception was thrown when the verification block was executed."
|
628
|
-
|
629
|
-
error_msg << MobyUtil::KernelHelper.find_source( verify_caller )
|
630
|
-
|
631
|
-
error_msg << "\nDetails: \n#{ $!.inspect }"
|
632
|
-
|
633
|
-
raise MobyBase::VerificationError, error_msg
|
1502
|
+
begin # catch errors thrown due to verification results
|
634
1503
|
|
1504
|
+
begin # catch errors thrown in the provided block
|
1505
|
+
result = yield
|
1506
|
+
rescue Exception => e
|
1507
|
+
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
1508
|
+
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
|
1509
|
+
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
1510
|
+
error_msg << "\nDetails: "
|
1511
|
+
error_msg << "\n" << e.inspect
|
1512
|
+
raise MobyBase::VerificationError.new(error_msg)
|
635
1513
|
end
|
636
1514
|
|
637
|
-
#
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
unless result =~ expected
|
642
|
-
|
643
|
-
error_msg = "Verification #{ message.nil? ? '' : '"' << message.to_s << '" '}at #{ verify_caller } failed:"
|
644
|
-
|
645
|
-
error_msg << MobyUtil::KernelHelper.find_source( verify_caller )
|
646
|
-
|
647
|
-
error_msg << "\nThe block did not match with pattern #{ expected.inspect }. It returned: #{ result.inspect }"
|
648
|
-
|
649
|
-
raise MobyBase::VerificationError, error_msg
|
650
|
-
|
651
|
-
end
|
1515
|
+
error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed:"
|
1516
|
+
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
1517
|
+
error_msg << "The block did not return false. It returned: " << result.inspect
|
1518
|
+
raise MobyBase::VerificationError.new(error_msg) unless result == false
|
652
1519
|
|
653
1520
|
# break loop if no exceptions thrown
|
654
1521
|
break
|
655
1522
|
|
656
|
-
rescue MobyBase::VerificationError
|
1523
|
+
rescue MobyBase::VerificationError => ve
|
657
1524
|
|
658
1525
|
# refresh and retry unless timeout reached
|
659
1526
|
|
660
|
-
|
1527
|
+
if Time.new > timeout_time
|
1528
|
+
Kernel::raise ve
|
1529
|
+
end
|
661
1530
|
|
662
1531
|
sleep TIMEOUT_CYCLE_SECONDS
|
663
1532
|
|
664
1533
|
refresh_suts if counter == ref_counter
|
665
|
-
|
666
|
-
rescue MobyBase::ContinuousVerificationError
|
667
|
-
|
668
|
-
raise
|
669
1534
|
|
670
|
-
rescue TypeError
|
671
|
-
|
672
|
-
raise $!
|
673
|
-
|
674
|
-
rescue Exception
|
675
|
-
|
676
|
-
raise if $!.kind_of?( MobyBase::ContinuousVerificationError )
|
677
1535
|
|
1536
|
+
rescue Exception => e
|
1537
|
+
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
678
1538
|
# an unexpected error has occurred
|
679
|
-
|
1539
|
+
$logger.enabled = logging_enabled
|
1540
|
+
Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
|
680
1541
|
|
681
1542
|
end # begin, catch any VerificationErrors
|
682
1543
|
|
683
1544
|
end # do
|
684
1545
|
|
685
|
-
rescue Exception
|
1546
|
+
rescue Exception => e
|
686
1547
|
|
687
1548
|
execute_on_error_verify_block unless @@on_error_verify_block.nil?
|
688
1549
|
|
689
|
-
raise if
|
1550
|
+
raise if e.kind_of? MobyBase::ContinuousVerificationError
|
690
1551
|
|
691
1552
|
$logger.enabled = logging_enabled
|
692
|
-
|
693
|
-
$logger.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{ $!.to_s }.\n#{ timeout.nil? ? '' : ' using timeout ' + timeout.to_s }.;#{ self.kind_of?( MobyBase::SUT ) ? "#{ self.id.to_s };sut" : ';' };{};verify_regexp;#{ expected.inspect }"
|
1553
|
+
$logger.behaviour "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n #{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_false;"
|
694
1554
|
|
695
|
-
raise
|
1555
|
+
Kernel::raise e
|
696
1556
|
|
697
1557
|
ensure
|
698
|
-
|
699
|
-
MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout
|
700
|
-
|
701
|
-
$logger.enabled = logging_enabled
|
702
|
-
|
1558
|
+
MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
|
703
1559
|
end
|
704
1560
|
|
705
|
-
$logger.
|
706
|
-
|
707
|
-
nil
|
1561
|
+
$logger.enabled = logging_enabled
|
1562
|
+
$logger.behaviour "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_false;"
|
1563
|
+
return nil
|
708
1564
|
|
709
1565
|
end
|
1566
|
+
|
1567
|
+
=end
|
710
1568
|
|
1569
|
+
private
|
711
1570
|
|
712
|
-
|
713
|
-
#
|
714
|
-
# === params
|
715
|
-
# timeout:: Integer, defining the amount of seconds during which the verification must pass.
|
716
|
-
# signal_name:: String, name of the signal
|
717
|
-
# message:: (optional) A String that is displayed as additional information if the verification fails.
|
718
|
-
# block:: code to execute while listening signals
|
719
|
-
# === returns
|
720
|
-
# nil
|
721
|
-
# === raises
|
722
|
-
# ArgumentError:: message or signal_name was not a String or timeout a non negative Integer
|
723
|
-
# VerificationError:: The verification failed.
|
724
|
-
def verify_signal( timeout, signal_name, message = nil, &block )
|
725
|
-
|
726
|
-
logging_enabled = $logger.enabled
|
727
|
-
verify_caller = caller(1).first.to_s
|
728
|
-
|
729
|
-
begin
|
730
|
-
|
731
|
-
$logger.enabled = false
|
732
|
-
|
733
|
-
Kernel::raise ArgumentError.new("Argument timeout was not a non negative Integer.") unless (timeout.kind_of?(Integer) && timeout >= 0)
|
734
|
-
Kernel::raise ArgumentError.new("Argument message was not a non empty String.") unless (message.nil? || (message.kind_of?(String) && !message.empty?))
|
735
|
-
|
736
|
-
# wait for the signal
|
737
|
-
begin
|
738
|
-
|
739
|
-
self.wait_for_signal( timeout, signal_name, &block )
|
740
|
-
|
741
|
-
rescue Exception => e
|
1571
|
+
def get_end_time( timeout )
|
742
1572
|
|
743
|
-
|
744
|
-
error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
|
745
|
-
error_msg << "The signal #{signal_name} was not emitted in #{timeout} seconds."
|
746
|
-
error_msg << "\nNested exception:\n" << e.inspect
|
747
|
-
Kernel::raise MobyBase::VerificationError.new(error_msg)
|
1573
|
+
if self.kind_of?( MobyBase::SUT )
|
748
1574
|
|
749
|
-
|
1575
|
+
Time.new + ( timeout.nil? ? $parameters[ self.sut ][ :synchronization_timeout, '10' ].to_i : timeout.to_i )
|
750
1576
|
|
751
|
-
|
1577
|
+
else
|
752
1578
|
|
753
|
-
|
1579
|
+
Time.new + ( timeout.nil? ? $parameters[ :synchronization_timeout, '10' ].to_i : timeout.to_i )
|
754
1580
|
|
755
|
-
$logger.enabled = logging_enabled
|
756
|
-
$logger.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s} using timeout '#{timeout}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_signal;#{signal_name}"
|
757
|
-
Kernel::raise e
|
758
1581
|
end
|
759
1582
|
|
760
|
-
$logger.enabled = logging_enabled
|
761
|
-
$logger.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_signal;#{signal_name}"
|
762
|
-
return nil
|
763
|
-
|
764
1583
|
end
|
765
1584
|
|
766
|
-
|
767
|
-
|
1585
|
+
def get_timeout( timeout )
|
1586
|
+
|
1587
|
+
if self.kind_of?( MobyBase::SUT )
|
768
1588
|
|
769
|
-
|
1589
|
+
timeout = $parameters[ self.sut ][ :synchronization_timeout, '10' ].to_i if timeout.nil?
|
770
1590
|
|
771
|
-
if self.kind_of?(MobyBase::SUT)
|
772
|
-
Time.new + (timeout.nil? ? MobyUtil::Parameter[self.sut][ :synchronization_timeout].to_i : timeout.to_i)
|
773
1591
|
else
|
774
|
-
|
1592
|
+
|
1593
|
+
timeout = $parameters[ :synchronization_timeout, '10' ].to_i if timeout.nil?
|
1594
|
+
|
775
1595
|
end
|
1596
|
+
|
1597
|
+
timeout.to_i
|
1598
|
+
|
776
1599
|
end
|
777
1600
|
|
778
1601
|
# Current count of combined sut refresh calls to all suts
|