testability-driver 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -22,14 +22,14 @@ class Hash
|
|
22
22
|
|
23
23
|
def not_empty( message = "Hash must not be empty", exception = ArgumentError )
|
24
24
|
|
25
|
-
raise exception, message if empty?
|
25
|
+
raise exception, message, caller if empty?
|
26
26
|
|
27
27
|
self
|
28
28
|
|
29
29
|
end
|
30
30
|
|
31
|
-
#
|
32
|
-
def
|
31
|
+
# verify that receiver object contains one of given keys. Raises exception is key not found.
|
32
|
+
def require_one( keys, message = "None of key(s) $1 found from hash" )
|
33
33
|
|
34
34
|
# create array of types
|
35
35
|
keys_array = Array( keys )
|
@@ -55,7 +55,7 @@ class Hash
|
|
55
55
|
[ verbose_keys_list.join ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
56
56
|
|
57
57
|
# raise the exception
|
58
|
-
raise ArgumentError, message
|
58
|
+
raise ArgumentError, message, caller
|
59
59
|
|
60
60
|
end
|
61
61
|
|
@@ -63,7 +63,18 @@ class Hash
|
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
|
-
#
|
66
|
+
# verify that receiver object contains all of given keys. Raises exception is key not found.
|
67
|
+
def require_key( key, message = 'required key $1 not found from hash' )
|
68
|
+
|
69
|
+
fetch( key ){
|
70
|
+
|
71
|
+
raise ArgumentError, message.gsub!( "$1", key.inspect ), caller
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# verify that receiver object contains all of given keys. Raises exception is key not found.
|
67
78
|
def require_keys( keys, message = "Required key(s) $1 not found from hash" )
|
68
79
|
|
69
80
|
# create array of types
|
@@ -87,7 +98,7 @@ class Hash
|
|
87
98
|
[ verbose_keys_list.join ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
88
99
|
|
89
100
|
# raise the exception
|
90
|
-
raise ArgumentError, message
|
101
|
+
raise ArgumentError, message, caller
|
91
102
|
|
92
103
|
end
|
93
104
|
|
@@ -187,6 +198,17 @@ class Hash
|
|
187
198
|
|
188
199
|
end # strip_dynamic_attributes!
|
189
200
|
|
201
|
+
# TODO: document me
|
202
|
+
def to_attributes
|
203
|
+
|
204
|
+
self.collect{ | key, value |
|
205
|
+
|
206
|
+
"#{ key.to_s }=\"#{ value.to_s.encode_to_xml }\""
|
207
|
+
|
208
|
+
}.join(" ")
|
209
|
+
|
210
|
+
end
|
211
|
+
|
190
212
|
# TODO: document me
|
191
213
|
def recursive_merge( other )
|
192
214
|
|
@@ -226,4 +248,38 @@ class Hash
|
|
226
248
|
|
227
249
|
end # recursive_merge!
|
228
250
|
|
229
|
-
|
251
|
+
# TODO: document me
|
252
|
+
def if_found( key )
|
253
|
+
|
254
|
+
if has_key?( key )
|
255
|
+
|
256
|
+
yield( key, self[ key ] )
|
257
|
+
|
258
|
+
end
|
259
|
+
|
260
|
+
end # if_found
|
261
|
+
|
262
|
+
# TODO: document me
|
263
|
+
def rename_key!( key, new )
|
264
|
+
|
265
|
+
if has_key?( key )
|
266
|
+
|
267
|
+
self[ new ] = delete( key )
|
268
|
+
|
269
|
+
else
|
270
|
+
|
271
|
+
if block_given?
|
272
|
+
|
273
|
+
yield( key, new )
|
274
|
+
|
275
|
+
else
|
276
|
+
|
277
|
+
raise IndexError, "key #{ key.inspect } not found", caller
|
278
|
+
|
279
|
+
end
|
280
|
+
|
281
|
+
end # has_key?
|
282
|
+
|
283
|
+
end # rename_key!
|
284
|
+
|
285
|
+
end # Hash
|
@@ -17,9 +17,54 @@
|
|
17
17
|
##
|
18
18
|
############################################################################
|
19
19
|
|
20
|
+
module Kernel
|
21
|
+
|
22
|
+
# TODO: document me
|
23
|
+
def require_relative( file )
|
24
|
+
|
25
|
+
# require with full expanded path
|
26
|
+
require File.expand_path( File.join( File.dirname( caller.first.scan( /(.*?):/ ).to_s ), file ) )
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# TODO: document me
|
31
|
+
def warn_caller( message, remove_eval = true )
|
32
|
+
|
33
|
+
# verify that message argument type is correct
|
34
|
+
raise TypeError, "wrong argument type #{ message.class } for message (expected String)" unless message.kind_of?( String )
|
35
|
+
|
36
|
+
# verify that remove_eval argument type is correct
|
37
|
+
raise TypeError, "wrong argument type #{ remove_eval.class } for remove evaluate calls value (expected TrueClass or FalseClass)" unless [ TrueClass, FalseClass ].include?( remove_eval.class )
|
38
|
+
|
39
|
+
# retrieve caller method, file and line number
|
40
|
+
begin
|
41
|
+
|
42
|
+
# remove evals if required
|
43
|
+
caller_stack = ( remove_eval == true ? caller.select{ | str | str !~ /^\(eval\)\:/ and str !~ /`eval'$/ } : caller )
|
44
|
+
|
45
|
+
# retrieve filename, line number and method name
|
46
|
+
/^(.+?):(\d+)(?::in `(.*)')?/.match( caller_stack.reverse[ -2 ].to_s )
|
47
|
+
|
48
|
+
# store matches
|
49
|
+
file, line, method = $1, $2, $3
|
50
|
+
|
51
|
+
rescue
|
52
|
+
|
53
|
+
# could not retrieve filename, line number and method name
|
54
|
+
file, line, method = [ '##', '##', 'unknown' ]
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
# print warning to STDOUT
|
59
|
+
warn message.gsub( '$1', file.to_s ).gsub( '$2', line.to_s ).gsub( '$3', method.to_s )
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
20
65
|
module MobyUtil
|
21
66
|
|
22
|
-
# Helper class to store
|
67
|
+
# Helper class to store verify block for
|
23
68
|
# constant verifications for sut state
|
24
69
|
class VerifyBlock
|
25
70
|
|
@@ -27,9 +27,21 @@ class Object
|
|
27
27
|
|
28
28
|
end
|
29
29
|
|
30
|
+
def true?
|
31
|
+
|
32
|
+
false
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def false?
|
37
|
+
|
38
|
+
false
|
39
|
+
|
40
|
+
end
|
41
|
+
|
30
42
|
def not_blank( message = "Object must not be blank", exception = ArgumentError )
|
31
43
|
|
32
|
-
raise exception, message if blank?
|
44
|
+
raise exception, message, caller if blank?
|
33
45
|
|
34
46
|
self
|
35
47
|
|
@@ -46,7 +58,7 @@ class Object
|
|
46
58
|
def check_type( types, message = "wrong argument type $1 (expected $2)" )
|
47
59
|
|
48
60
|
# raise exception if message is not type of String
|
49
|
-
raise TypeError, "wrong argument type #{ message.class } for message (expected String)" unless message.kind_of?( String )
|
61
|
+
raise TypeError, "wrong argument type #{ message.class } for message (expected String)", caller unless message.kind_of?( String )
|
50
62
|
|
51
63
|
# create array of types
|
52
64
|
type_array = Array( types )
|
@@ -57,7 +69,7 @@ class Object
|
|
57
69
|
# collect verbose type list
|
58
70
|
verbose_type_list = type_array.each_with_index.collect{ | type, index |
|
59
71
|
|
60
|
-
raise TypeError, "invalid argument type #{ type } for check_type. Did you mean #{ type.class }?" unless type.kind_of?( Class )
|
72
|
+
raise TypeError, "invalid argument type #{ type } for check_type. Did you mean #{ type.class }?", caller unless type.kind_of?( Class )
|
61
73
|
|
62
74
|
if self.kind_of?( type )
|
63
75
|
|
@@ -79,7 +91,7 @@ class Object
|
|
79
91
|
[ self.class, verbose_type_list.join, self.inspect ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
80
92
|
|
81
93
|
# raise the exception
|
82
|
-
raise TypeError, message
|
94
|
+
raise TypeError, message, caller
|
83
95
|
|
84
96
|
end
|
85
97
|
|
@@ -90,7 +102,7 @@ class Object
|
|
90
102
|
|
91
103
|
def not_nil( message = "Value must not be nil", exception = ArgumentError )
|
92
104
|
|
93
|
-
raise exception, message unless self
|
105
|
+
raise exception, message, caller unless self
|
94
106
|
|
95
107
|
self
|
96
108
|
|
@@ -99,7 +111,7 @@ class Object
|
|
99
111
|
def validate( values, message = "Unexpected value $3 for $1 (expected $2)" )
|
100
112
|
|
101
113
|
# raise exception if message is not type of String
|
102
|
-
raise TypeError, "wrong argument type #{ message.class } for message (expected String)" unless message.kind_of?( String )
|
114
|
+
raise TypeError, "wrong argument type #{ message.class } for message (expected String)", caller unless message.kind_of?( String )
|
103
115
|
|
104
116
|
# create array of values
|
105
117
|
values_array = Array( values )
|
@@ -110,7 +122,7 @@ class Object
|
|
110
122
|
# collect verbose type list
|
111
123
|
verbose_values_list = values_array.each_with_index.collect{ | value, index |
|
112
124
|
|
113
|
-
raise TypeError
|
125
|
+
raise TypeError, "Invalid argument type #{ value.class } for value (expected #{ self.class })", caller unless value.kind_of?( self.class )
|
114
126
|
|
115
127
|
if self == value
|
116
128
|
|
@@ -132,7 +144,7 @@ class Object
|
|
132
144
|
[ self.class, verbose_values_list.join, self.inspect ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
133
145
|
|
134
146
|
# raise the exception
|
135
|
-
raise ArgumentError, message
|
147
|
+
raise ArgumentError, message, caller
|
136
148
|
|
137
149
|
end
|
138
150
|
|
@@ -20,14 +20,33 @@
|
|
20
20
|
# extend Ruby String class functionality
|
21
21
|
class String
|
22
22
|
|
23
|
+
def true?
|
24
|
+
|
25
|
+
/^true$/i.match( self.to_s ) != nil
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def false?
|
30
|
+
|
31
|
+
/^false$/i.match( self.to_s ) != nil
|
32
|
+
|
33
|
+
end
|
34
|
+
|
23
35
|
def not_empty( message = "String must not be empty", exception = ArgumentError )
|
24
36
|
|
25
|
-
raise exception, message if empty?
|
37
|
+
raise exception, message, caller if empty?
|
26
38
|
|
27
39
|
self
|
28
40
|
|
29
41
|
end
|
30
42
|
|
43
|
+
# TODO: document me
|
44
|
+
def encode_to_xml
|
45
|
+
|
46
|
+
gsub('&', '&').gsub('<', '<').gsub('>', '>').gsub( '"', '"' ).gsub( '\'', ''' )
|
47
|
+
|
48
|
+
end
|
49
|
+
|
31
50
|
# Function determines if string is "true" or "false"
|
32
51
|
# == params
|
33
52
|
# string:: String
|
@@ -78,7 +97,7 @@ class String
|
|
78
97
|
else
|
79
98
|
|
80
99
|
# raise exception if no default given
|
81
|
-
|
100
|
+
raise TypeError, "Unable to convert string \"#{ self }\" to boolean (Expected \"true\" or \"false\")", caller
|
82
101
|
|
83
102
|
end
|
84
103
|
|
@@ -349,7 +349,7 @@ module MobyUtil
|
|
349
349
|
set_debug_exceptions # if enabled
|
350
350
|
|
351
351
|
# returns logging level as string
|
352
|
-
logging_level =
|
352
|
+
logging_level = $parameters[ :logging_level, nil ]
|
353
353
|
|
354
354
|
# do not enable logging if no logging level is not defined
|
355
355
|
return nil if logging_level.nil?
|
@@ -384,7 +384,7 @@ module MobyUtil
|
|
384
384
|
# create error dump folder if not exist, used e.g. when xml parse error
|
385
385
|
MobyUtil::FileHelper.mkdir_path( MobyUtil::FileHelper.expand_path( $last_parameter ) )
|
386
386
|
|
387
|
-
rescue
|
387
|
+
rescue
|
388
388
|
|
389
389
|
warn("warning: Unable to create log folder #{ $parameters[ :logging_xml_parse_error_dump_path ] } for corrupted XML UI state files")
|
390
390
|
|
@@ -403,12 +403,12 @@ module MobyUtil
|
|
403
403
|
|
404
404
|
end
|
405
405
|
|
406
|
-
rescue ArgumentError
|
406
|
+
rescue ArgumentError
|
407
407
|
|
408
408
|
# disable xml logging
|
409
409
|
$parameters[ :logging_xml_parse_error_dump ] = 'false'
|
410
410
|
|
411
|
-
rescue
|
411
|
+
rescue
|
412
412
|
|
413
413
|
# disable xml logging
|
414
414
|
warn( "warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })" )
|
@@ -20,23 +20,6 @@
|
|
20
20
|
# Parameter related errors
|
21
21
|
require File.expand_path( File.join( File.dirname( __FILE__ ), 'error.rb' ) )
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_new.rb' ) )
|
26
|
-
|
27
|
-
=begin
|
28
|
-
# Parameter hash class
|
29
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_hash.rb' ) )
|
30
|
-
|
31
|
-
# Parameter API etc
|
32
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_template.rb' ) )
|
33
|
-
|
34
|
-
# Parameter API etc
|
35
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_xml.rb' ) )
|
36
|
-
|
37
|
-
# Parameter end user API etc
|
38
|
-
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_user_api.rb' ) )
|
39
|
-
|
40
|
-
# Parameter API etc
|
23
|
+
# parameters related classes
|
41
24
|
require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter.rb' ) )
|
42
|
-
|
25
|
+
|
@@ -17,348 +17,1045 @@
|
|
17
17
|
##
|
18
18
|
############################################################################
|
19
19
|
|
20
|
-
module
|
20
|
+
module TDriver
|
21
21
|
|
22
|
-
class
|
22
|
+
class ParameterUserAPI
|
23
23
|
|
24
|
-
|
24
|
+
class << self
|
25
25
|
|
26
|
-
|
26
|
+
def new
|
27
|
+
|
28
|
+
warn_caller "$1:$2 warning: #{ self.to_s } is static class; unable initialize new instance of it"
|
29
|
+
|
30
|
+
nil
|
31
|
+
|
32
|
+
end
|
27
33
|
|
28
|
-
|
34
|
+
# TODO: document me
|
35
|
+
def []=( key, value )
|
29
36
|
|
30
|
-
|
37
|
+
$parameters[ key ] = value
|
31
38
|
|
32
|
-
|
33
|
-
parse_command_line_arguments
|
39
|
+
end
|
34
40
|
|
35
|
-
#
|
36
|
-
|
41
|
+
# TODO: document me
|
42
|
+
def []( *args )
|
37
43
|
|
38
|
-
|
39
|
-
@@initialized = true
|
44
|
+
$parameters[ *args ]
|
40
45
|
|
41
|
-
|
46
|
+
end
|
42
47
|
|
43
|
-
|
48
|
+
# TODO: document me
|
49
|
+
def fetch( *args, &block )
|
44
50
|
|
45
|
-
|
46
|
-
@@user_defined_parameters_file_defined_in_command_line_arguments = false
|
51
|
+
$parameters.fetch( *args, &block )
|
47
52
|
|
48
|
-
|
53
|
+
end
|
49
54
|
|
50
|
-
|
55
|
+
# TODO: document me
|
56
|
+
def files
|
51
57
|
|
52
|
-
|
53
|
-
ARGV.each_index do | index |
|
58
|
+
$parameters.files
|
54
59
|
|
55
|
-
|
56
|
-
puts "--matti_parameters is deprecated, use -tdriver_parameters instead"
|
57
|
-
Kernel::raise ArgumentError.new( "TDriver parameters command line argument given without a filename" ) if ARGV.count == index + 1
|
58
|
-
delete_values << ARGV[ index ].to_s
|
59
|
-
end
|
60
|
+
end
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
delete_values << ARGV[ index ].to_s
|
64
|
-
end
|
62
|
+
# TODO: document me
|
63
|
+
def clear
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
65
|
+
$parameters.clear
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
# TODO: document me
|
70
|
+
def load_xml( filename )
|
71
|
+
|
72
|
+
$parameters.parse_file( filename )
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
# TODO: document me
|
77
|
+
def reset( *keys )
|
78
|
+
|
79
|
+
$parameters.reset
|
73
80
|
|
74
81
|
end
|
75
82
|
|
76
|
-
#
|
77
|
-
|
78
|
-
|
79
|
-
|
83
|
+
# TODO: document me
|
84
|
+
def inspect
|
85
|
+
|
86
|
+
$parameters.inspect
|
87
|
+
|
80
88
|
end
|
81
89
|
|
82
|
-
|
90
|
+
# TODO: document me
|
91
|
+
def to_s
|
92
|
+
|
93
|
+
$parameters.to_s
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
# TODO: document me
|
98
|
+
def keys
|
99
|
+
|
100
|
+
$parameters.keys
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
# TODO: document me
|
105
|
+
def values
|
106
|
+
|
107
|
+
$parameters.values
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
# TODO: document me
|
112
|
+
def configured_suts
|
113
|
+
|
114
|
+
$parameters.configured_suts
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end # self
|
119
|
+
|
120
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
121
|
+
|
122
|
+
end # ParameterUserAPI
|
123
|
+
|
124
|
+
class ParameterHash < Hash
|
125
|
+
|
126
|
+
# TODO: document me
|
127
|
+
def []( key, *default, &block )
|
128
|
+
|
129
|
+
$last_parameter = fetch( key ){
|
130
|
+
|
131
|
+
if default.empty?
|
132
|
+
|
133
|
+
raise MobyUtil::ParameterNotFoundError, "Parameter #{ key } not found" unless block_given?
|
83
134
|
|
84
|
-
|
135
|
+
# yield with key if block given
|
136
|
+
yield key
|
137
|
+
|
138
|
+
else
|
139
|
+
|
140
|
+
raise ArgumentError, "Only one default value allowed for parameter (#{ default.join(', ') })" unless default.size == 1
|
141
|
+
|
142
|
+
#result = default.first
|
143
|
+
|
144
|
+
#result.kind_of?( Hash ) ? convert_hash( result ) : result
|
145
|
+
|
146
|
+
convert_hash( default.first )
|
85
147
|
|
86
|
-
raise MobyUtil::FileNotFoundError, "User defined TDriver parameters file #{ parameter_file } does not exist" unless File.exist?( parameter_file )
|
87
148
|
|
88
149
|
end
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
# TODO: document me
|
156
|
+
def []=( key, value )
|
157
|
+
|
158
|
+
raise MobyUtil::ParameterNotFoundError, 'Parameter key nil is not valid' unless key
|
159
|
+
|
160
|
+
super key, convert_hash( value ) # value.kind_of?( Hash ) ? convert_hash( value ) : value
|
161
|
+
|
162
|
+
end
|
163
|
+
|
164
|
+
# for backwards compatibility
|
165
|
+
def kind_of?( klass )
|
166
|
+
|
167
|
+
if klass == MobyUtil::ParameterHash
|
168
|
+
|
169
|
+
warn_caller '$1:$2 warning: deprecated class MobyUtil::ParameterHash, use TDriver::ParameterHash instead'
|
170
|
+
|
171
|
+
true
|
172
|
+
|
173
|
+
else
|
89
174
|
|
175
|
+
super klass
|
176
|
+
|
90
177
|
end
|
178
|
+
|
179
|
+
end
|
180
|
+
|
181
|
+
private
|
91
182
|
|
92
|
-
|
183
|
+
# TODO: document me
|
184
|
+
def convert_hash( value )
|
185
|
+
|
186
|
+
value.kind_of?( Hash ) ? ParameterHash[ value.collect{ | key, value | [ key, value.kind_of?( Hash ) ? convert_hash( value ) : value ] } ] : value
|
93
187
|
|
94
|
-
|
188
|
+
#value.class == Hash ? ParameterHash[ value.collect{ | key, value | [ key, value.class == Hash ? convert_hash( value ) : value ] } ] : value
|
95
189
|
|
96
190
|
end
|
191
|
+
|
192
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
193
|
+
|
194
|
+
end # ParameterHash
|
97
195
|
|
98
|
-
|
196
|
+
class Parameter
|
197
|
+
|
198
|
+
# singleton and private methods
|
199
|
+
class << self
|
99
200
|
|
100
|
-
|
201
|
+
def new
|
202
|
+
|
203
|
+
warn_caller "$1:$2 warning: #{ self.to_s } is static class; unable initialize new instance of it"
|
204
|
+
|
205
|
+
nil
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
# TODO: document me
|
210
|
+
def init
|
101
211
|
|
102
|
-
|
103
|
-
|
212
|
+
# initialize only once
|
213
|
+
return if defined?( @initalized )
|
104
214
|
|
105
|
-
|
106
|
-
|
215
|
+
# retrieve platform name
|
216
|
+
@platform = MobyUtil::EnvironmentHelper.platform
|
107
217
|
|
108
|
-
|
109
|
-
|
218
|
+
# detect is posix platform
|
219
|
+
@is_posix = MobyUtil::EnvironmentHelper.posix?
|
110
220
|
|
111
|
-
|
221
|
+
# retrieve parameter filenames from command line arguments
|
222
|
+
parse_command_line_arguments
|
223
|
+
|
224
|
+
# reset templates and parameters
|
225
|
+
reset_hashes
|
226
|
+
|
227
|
+
# indicates that class is already initialized - templates and parameters will not reset
|
228
|
+
@initialized = true
|
229
|
+
|
230
|
+
end
|
231
|
+
|
232
|
+
private
|
233
|
+
|
234
|
+
def parse_command_line_arguments
|
235
|
+
|
236
|
+
# reset command line argument files list
|
237
|
+
@command_line_argument_files = []
|
238
|
+
|
239
|
+
capture_elements = false
|
240
|
+
|
241
|
+
ARGV.each_with_index do | value, index |
|
242
|
+
|
243
|
+
value = value.to_s
|
244
|
+
|
245
|
+
case value
|
246
|
+
|
247
|
+
when '--tdriver_parameters', '--matti_parameters'
|
248
|
+
|
249
|
+
warn "warning: #{ value } is deprecated, use -tdriver_parameters instead" if value == '--matti_parameters'
|
250
|
+
|
251
|
+
# capture following xml filenames
|
252
|
+
capture_elements = true
|
253
|
+
|
254
|
+
# mark element to be removed
|
255
|
+
ARGV[ index ] = nil
|
256
|
+
|
257
|
+
else
|
258
|
+
|
259
|
+
# process the string if capturing arguments
|
260
|
+
if capture_elements
|
261
|
+
|
262
|
+
# stop capturing if is a option (e.g. --version)
|
263
|
+
if [ '-' ].include?( value[ 0 ].chr )
|
264
|
+
|
265
|
+
capture_elements = false
|
266
|
+
|
267
|
+
# add argument to parameters list if meets the regexp and capture_element is true
|
268
|
+
elsif /\.xml$/i.match( value )
|
269
|
+
|
270
|
+
# expand filename
|
271
|
+
value = File.expand_path( value )
|
272
|
+
|
273
|
+
# raise exception if given file does not found
|
274
|
+
raise MobyUtil::FileNotFoundError, "User defined TDriver parameters file #{ value } does not exist" unless File.exist?( value )
|
275
|
+
|
276
|
+
# add file to command line arguments files
|
277
|
+
@command_line_argument_files << value
|
278
|
+
|
279
|
+
# mark element to be removed
|
280
|
+
ARGV[ index ] = nil
|
281
|
+
|
282
|
+
end # if
|
283
|
+
|
284
|
+
end # else
|
285
|
+
|
286
|
+
end # case
|
287
|
+
|
288
|
+
end # each_with_index
|
112
289
|
|
113
|
-
|
290
|
+
# raise exception if "--tdriver_parameters" option found but no filenames defined
|
291
|
+
if capture_elements && @command_line_argument_files.empty?
|
292
|
+
|
293
|
+
raise ArgumentError, 'TDriver parameters command line argument given without a filename'
|
294
|
+
|
295
|
+
end
|
296
|
+
|
297
|
+
# remove nil elements from array
|
298
|
+
ARGV.compact!
|
299
|
+
|
300
|
+
# return collected filenames
|
301
|
+
@command_line_argument_files
|
302
|
+
|
303
|
+
end
|
114
304
|
|
115
|
-
|
305
|
+
# TODO: document me
|
306
|
+
def initialize_class
|
307
|
+
|
308
|
+
# initialize only once
|
309
|
+
return if defined?( @parameters )
|
310
|
+
|
311
|
+
# class variables not used; read below article:
|
312
|
+
# http://www.oreillynet.com/ruby/blog/2007/01/nubygems_dont_use_class_variab_1.html
|
313
|
+
|
314
|
+
# parameters container
|
315
|
+
@parameters = ParameterHash.new
|
116
316
|
|
117
|
-
|
118
|
-
|
317
|
+
# templates container
|
318
|
+
@templates = ParameterHash.new
|
119
319
|
|
120
|
-
|
121
|
-
|
320
|
+
# platform enum
|
321
|
+
@platform = nil
|
322
|
+
|
323
|
+
# determine if platform is type of posix
|
324
|
+
@is_posix = nil
|
325
|
+
|
326
|
+
# list of loaded SUT's
|
327
|
+
@sut_list = []
|
328
|
+
|
329
|
+
# list of loaded parameter filenames
|
330
|
+
@parameter_files = []
|
331
|
+
|
332
|
+
# list of loaded template filenames
|
333
|
+
@template_files = []
|
334
|
+
|
335
|
+
# files defined in command line arguments
|
336
|
+
@command_line_argument_files = []
|
337
|
+
|
338
|
+
# templates cache
|
339
|
+
@cache = {}
|
122
340
|
|
123
|
-
|
124
|
-
@@parameters.merge_with_hash!( load_default_parameter_files ) if load_parameter_defaults
|
341
|
+
end
|
125
342
|
|
126
|
-
#
|
127
|
-
|
343
|
+
# TODO: document me
|
344
|
+
def load_default_parameters
|
345
|
+
|
346
|
+
# collect all templates
|
347
|
+
Dir.glob( MobyUtil::FileHelper.expand_path( 'defaults/*.xml' ) ).each { | filename |
|
128
348
|
|
129
|
-
|
130
|
-
|
349
|
+
file_content = load_file( filename )
|
350
|
+
|
351
|
+
MobyUtil::XML.parse_string( file_content ).xpath( '*' ).each{ | element |
|
352
|
+
|
353
|
+
# merge new hash to parameters hash
|
354
|
+
@parameters.recursive_merge!(
|
355
|
+
|
356
|
+
# parse element and convert it to hash
|
357
|
+
process_element( element )
|
358
|
+
|
359
|
+
)
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
# add file to loaded parameter files list
|
364
|
+
@parameter_files << filename
|
131
365
|
|
132
|
-
|
133
|
-
if filename
|
366
|
+
}
|
134
367
|
|
135
|
-
|
368
|
+
end
|
369
|
+
|
370
|
+
# TODO: document me
|
371
|
+
def load_file( filename )
|
136
372
|
|
137
|
-
|
373
|
+
filename = MobyUtil::FileHelper.expand_path( filename )
|
374
|
+
|
375
|
+
begin
|
376
|
+
|
377
|
+
MobyUtil::FileHelper.get_file( filename )
|
378
|
+
|
379
|
+
rescue MobyUtil::EmptyFilenameError
|
380
|
+
|
381
|
+
raise $!, 'Unable to load parameters XML file due to filename is empty or nil'
|
382
|
+
|
383
|
+
rescue MobyUtil::FileNotFoundError
|
384
|
+
|
385
|
+
raise
|
386
|
+
|
387
|
+
rescue IOError
|
388
|
+
|
389
|
+
raise $!, "Error occured while loading xml file. Reason: #{ $!.message }"
|
390
|
+
|
391
|
+
rescue
|
392
|
+
|
393
|
+
raise MobyUtil::ParameterFileParseError, "Error occured while parsing parameters xml file #{ filename }\nDescription: #{ $!.message }"
|
138
394
|
|
139
395
|
end
|
396
|
+
|
397
|
+
end
|
398
|
+
|
399
|
+
# TODO: document me
|
400
|
+
def process_element( xml )
|
401
|
+
|
402
|
+
# calculate xml hash
|
403
|
+
xml_hash = xml.to_s.hash
|
140
404
|
|
405
|
+
return @cache[ xml_hash ] if @cache.has_key?( xml_hash )
|
406
|
+
|
407
|
+
# default results
|
408
|
+
results = ParameterHash.new
|
409
|
+
|
410
|
+
# go through each element in xml
|
411
|
+
xml.xpath( "*" ).each{ | element |
|
412
|
+
|
413
|
+
# retrieve element attributes as hash
|
414
|
+
attributes = element.attributes
|
415
|
+
|
416
|
+
# default value
|
417
|
+
value = attributes[ 'value' ]
|
418
|
+
|
419
|
+
# generic posix value - overwrites attribute["value"] if found
|
420
|
+
value = attributes[ 'posix' ] unless attributes[ 'posix' ].nil? if @is_posix
|
421
|
+
|
422
|
+
# platform specific value - overwrites existing value
|
423
|
+
value = attributes[ @platform.to_s ] unless attributes[ @platform.to_s ].nil?
|
424
|
+
|
425
|
+
# retrieve name attribute
|
426
|
+
name = attributes[ 'name' ]
|
427
|
+
|
428
|
+
case element.name
|
429
|
+
|
430
|
+
when 'keymap'
|
431
|
+
|
432
|
+
# use element name as parameter name ("keymap")
|
433
|
+
name = element.name
|
434
|
+
|
435
|
+
# read xml file from given location if defined - otherwise pass content as is
|
436
|
+
if attributes[ 'xml_file' ]
|
437
|
+
|
438
|
+
# merge hash values (value type of hash)
|
439
|
+
value = process_file( attributes[ 'xml_file' ] )
|
440
|
+
|
441
|
+
else
|
442
|
+
|
443
|
+
# use element content as value
|
444
|
+
value = process_element( element )
|
445
|
+
|
446
|
+
end
|
447
|
+
|
448
|
+
# retrieve environment attribute from xml
|
449
|
+
env = attributes[ 'env' ].to_s
|
450
|
+
|
451
|
+
# set environment to 'default' unless defined in xml element
|
452
|
+
env = 'default' if env.empty?
|
453
|
+
|
454
|
+
# store keymap as hash
|
455
|
+
value = { env.to_sym => value, :all => value, :default_keymap => env.to_sym }
|
456
|
+
|
457
|
+
when 'fixture'
|
458
|
+
|
459
|
+
name.not_blank( "No name defined for fixture \"#{ element.to_s }\"", SyntaxError )
|
460
|
+
|
461
|
+
value = {
|
462
|
+
|
463
|
+
:plugin => attributes[ 'plugin' ].not_blank( "No name defined for fixture with value #{ name }", SyntaxError ),
|
464
|
+
|
465
|
+
:env => attributes[ 'env' ]
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
when 'parameter'
|
470
|
+
|
471
|
+
# verify that name attribute is defined
|
472
|
+
name.not_blank( "No name defined for parameter with value #{ value }", SyntaxError )
|
473
|
+
|
474
|
+
# return value as is
|
475
|
+
#value.not_nil( "No value defined for parameter with name #{ name }", SyntaxError )
|
476
|
+
|
477
|
+
value = '' if value.nil?
|
478
|
+
|
479
|
+
when 'method'
|
480
|
+
|
481
|
+
# verify that name attribute is defined
|
482
|
+
name.not_blank( "No name defined for parameter with value #{ value }", SyntaxError )
|
483
|
+
|
484
|
+
# return value as is
|
485
|
+
#value.not_nil( "No value defined for parameter with name #{ name }", SyntaxError )
|
486
|
+
|
487
|
+
value = attributes[ 'args' ]
|
488
|
+
|
489
|
+
when 'sut'
|
490
|
+
|
491
|
+
# use id as parameter name
|
492
|
+
name = attributes[ 'id' ]
|
493
|
+
|
494
|
+
# verify that name attribute is defined
|
495
|
+
name.not_blank( "No name defined for SUT \"#{ element.to_s }\"", SyntaxError )
|
496
|
+
|
497
|
+
# add SUT to found sut list
|
498
|
+
@sut_list << name unless @sut_list.include?( name )
|
499
|
+
|
500
|
+
# retrieve names of used templates
|
501
|
+
templates = attributes[ 'template' ]
|
502
|
+
|
503
|
+
# empty value by default
|
504
|
+
value = ParameterHash.new
|
505
|
+
|
506
|
+
unless templates.blank?
|
507
|
+
|
508
|
+
# retrieve each defined template
|
509
|
+
templates.split( ';' ).each{ | template |
|
510
|
+
|
511
|
+
# merge template with current value hash
|
512
|
+
value.recursive_merge!(
|
513
|
+
|
514
|
+
# retrieve template
|
515
|
+
get_template( template )
|
516
|
+
|
517
|
+
)
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
end
|
522
|
+
|
523
|
+
# merge sut content with template values
|
524
|
+
value.recursive_merge!( process_element( element ) )
|
525
|
+
|
526
|
+
else
|
527
|
+
|
528
|
+
# use element name as parameter name (e.g. fixture, keymap etc)
|
529
|
+
name = element.name
|
530
|
+
|
531
|
+
# read xml file from given location if defined - otherwise pass content as is
|
532
|
+
if attributes[ 'xml_file' ]
|
533
|
+
|
534
|
+
# merge hash values (value type of hash)
|
535
|
+
value = process_file( attributes[ 'xml_file' ] )
|
536
|
+
|
537
|
+
else
|
538
|
+
|
539
|
+
# use element content as value
|
540
|
+
value = process_element( element )
|
541
|
+
|
542
|
+
end
|
543
|
+
|
544
|
+
end
|
545
|
+
|
546
|
+
# store values to parameters
|
547
|
+
results[ name.to_sym ] = value
|
548
|
+
|
549
|
+
}
|
550
|
+
|
551
|
+
# store to cache and return hash as result
|
552
|
+
@cache[ xml_hash ] = results
|
553
|
+
|
554
|
+
end
|
555
|
+
|
556
|
+
# TODO: document me
|
557
|
+
def parse_template( name )
|
558
|
+
|
559
|
+
template = @templates[ name ]
|
560
|
+
|
561
|
+
unless template.kind_of?( Hash )
|
562
|
+
|
563
|
+
result = ParameterHash.new
|
564
|
+
|
565
|
+
# retrieve each inherited template
|
566
|
+
template[ 'inherits' ].to_s.split(";").each{ | inherited_template |
|
567
|
+
|
568
|
+
result.recursive_merge!(
|
569
|
+
|
570
|
+
parse_template( inherited_template )
|
571
|
+
|
572
|
+
)
|
573
|
+
|
574
|
+
}
|
575
|
+
|
576
|
+
# merge template content with inherited templates and store to templates hash table
|
577
|
+
@templates[ name ] = result.recursive_merge!(
|
578
|
+
|
579
|
+
process_element( template )
|
580
|
+
|
581
|
+
)
|
582
|
+
|
583
|
+
else
|
584
|
+
|
585
|
+
# template is already parsed, pass template hash as is
|
586
|
+
template
|
587
|
+
|
588
|
+
end
|
589
|
+
|
141
590
|
end
|
142
591
|
|
592
|
+
# TODO: document me
|
593
|
+
def load_templates
|
143
594
|
|
144
|
-
|
595
|
+
# collect all templates
|
596
|
+
Dir.glob( MobyUtil::FileHelper.expand_path( 'templates/*.xml' ) ).each { | filename |
|
145
597
|
|
146
|
-
|
598
|
+
unless @template_files.include?( filename )
|
147
599
|
|
148
|
-
|
600
|
+
# read file content
|
601
|
+
file_content = load_file( filename )
|
149
602
|
|
150
|
-
|
603
|
+
MobyUtil::XML.parse_string( file_content ).root.xpath( 'template' ).each{ | template |
|
151
604
|
|
152
|
-
|
605
|
+
# store template element to hash
|
606
|
+
@templates[ template[ 'name' ] ] = template
|
607
|
+
|
608
|
+
}
|
153
609
|
|
154
|
-
|
610
|
+
# add file to loaded templates files list
|
611
|
+
@template_files << filename
|
155
612
|
|
156
|
-
|
613
|
+
end
|
157
614
|
|
158
|
-
|
159
|
-
|
615
|
+
}
|
616
|
+
|
617
|
+
# parse templates hash; convert elements to hash
|
618
|
+
@templates.each_pair{ | name, template |
|
619
|
+
|
620
|
+
# convert element to hash
|
621
|
+
parse_template( name )
|
622
|
+
|
623
|
+
}
|
624
|
+
|
625
|
+
end
|
160
626
|
|
161
|
-
|
627
|
+
# TODO: document me
|
628
|
+
def get_template( name )
|
629
|
+
|
630
|
+
@templates.fetch( name ){
|
162
631
|
|
163
|
-
|
632
|
+
# return empty hash if template not found
|
633
|
+
ParameterHash.new
|
164
634
|
|
165
635
|
}
|
636
|
+
|
637
|
+
end
|
166
638
|
|
167
|
-
|
639
|
+
# TODO: document me
|
640
|
+
def reset_hashes( options = {} )
|
641
|
+
|
642
|
+
# default options
|
643
|
+
options.default_values(
|
644
|
+
|
645
|
+
:reset_templates => true,
|
646
|
+
:reset_parameters => true,
|
647
|
+
|
648
|
+
:load_default_parameters => true,
|
649
|
+
:load_user_parameters => true,
|
650
|
+
:load_command_line_parameters => true
|
651
|
+
|
652
|
+
)
|
653
|
+
|
654
|
+
# empty parameters hash
|
655
|
+
if options[ :reset_parameters ] == true
|
168
656
|
|
169
|
-
|
657
|
+
@parameter_files.clear
|
170
658
|
|
171
|
-
|
659
|
+
@parameters.clear
|
172
660
|
|
173
|
-
|
174
|
-
def reset_parameters
|
661
|
+
end
|
175
662
|
|
176
|
-
|
663
|
+
if options[ :reset_templates ] == true
|
664
|
+
|
665
|
+
@template_files.clear
|
666
|
+
|
667
|
+
# empty templates hash
|
668
|
+
@templates.clear
|
177
669
|
|
178
|
-
|
670
|
+
# load parameter templates
|
671
|
+
load_templates
|
179
672
|
|
180
|
-
|
673
|
+
end
|
181
674
|
|
182
|
-
|
183
|
-
|
675
|
+
# apply global parameters to root level (e.g. MobyUtil::Parameter[ :logging_outputter_enabled ])
|
676
|
+
@parameters.recursive_merge!( get_template( 'global' ) )
|
184
677
|
|
185
|
-
|
678
|
+
# load and apply default parameter values
|
679
|
+
load_default_parameters if options[ :load_default_parameters ] == true
|
186
680
|
|
187
|
-
|
681
|
+
# load main parameter configuraion file
|
682
|
+
load_parameters_file( 'tdriver_parameters.xml' ) if options[ :load_user_parameters ] == true
|
188
683
|
|
189
|
-
|
684
|
+
if options[ :load_command_line_parameters ] == true
|
190
685
|
|
191
|
-
|
686
|
+
@command_line_argument_files.each{ | filename |
|
687
|
+
|
688
|
+
load_parameters_file( filename )
|
689
|
+
|
690
|
+
}
|
192
691
|
|
193
|
-
|
692
|
+
end
|
194
693
|
|
195
|
-
|
694
|
+
end
|
196
695
|
|
197
|
-
|
696
|
+
# TODO: document me
|
697
|
+
def process_file( filename )
|
198
698
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
699
|
+
begin
|
700
|
+
|
701
|
+
# load content from file
|
702
|
+
file_content = load_file( filename )
|
703
|
+
|
704
|
+
# parse file content and retrieve root element
|
705
|
+
root_element = MobyUtil::XML.parse_string( file_content ).root
|
706
|
+
|
707
|
+
# parse root element
|
708
|
+
process_element( root_element )
|
203
709
|
|
204
|
-
|
710
|
+
rescue MobyUtil::FileNotFoundError
|
205
711
|
|
206
|
-
|
712
|
+
raise $!, "Parameters file #{ MobyUtil::FileHelper.expand_path( filename ) } does not exist"
|
207
713
|
|
208
|
-
|
714
|
+
rescue
|
209
715
|
|
210
|
-
|
716
|
+
raise MobyUtil::ParameterFileParseError, "Error occured while parsing parameters XML file #{ filename }. Reason: #{ $!.message } (#{ $!.class })"
|
717
|
+
|
718
|
+
end
|
719
|
+
|
720
|
+
end
|
721
|
+
|
722
|
+
def process_string( source )
|
723
|
+
|
724
|
+
begin
|
725
|
+
|
726
|
+
# parse file content and retrieve root element
|
727
|
+
root_element = MobyUtil::XML.parse_string( source ).root
|
728
|
+
|
729
|
+
# parse root element
|
730
|
+
process_element( root_element )
|
731
|
+
|
732
|
+
rescue
|
733
|
+
|
734
|
+
raise MobyUtil::ParameterXmlParseError, "Error occured while parsing parameters XML string. Reason: #{ $!.message } (#{ $!.class })"
|
735
|
+
|
736
|
+
end
|
737
|
+
|
738
|
+
end
|
739
|
+
|
740
|
+
def load_parameters_file( filename )
|
211
741
|
|
212
|
-
|
742
|
+
filename = MobyUtil::FileHelper.expand_path( filename )
|
743
|
+
|
744
|
+
unless @parameter_files.include?( filename )
|
213
745
|
|
746
|
+
begin
|
747
|
+
|
748
|
+
@parameters.recursive_merge!(
|
749
|
+
|
750
|
+
process_file( filename )
|
751
|
+
|
752
|
+
)
|
753
|
+
|
754
|
+
rescue MobyUtil::FileNotFoundError
|
755
|
+
|
756
|
+
raise $!, "Parameters file #{ filename } does not exist"
|
757
|
+
|
758
|
+
end
|
759
|
+
|
760
|
+
# add file to loaded parameter files list
|
761
|
+
@parameter_files << filename
|
762
|
+
|
763
|
+
end # unless
|
764
|
+
|
765
|
+
end # def
|
766
|
+
|
767
|
+
end # self
|
768
|
+
|
214
769
|
# TODO: document me
|
215
|
-
def self.parse_file(
|
770
|
+
def self.parse_file( filename, reset_parameters = false )
|
771
|
+
|
772
|
+
# check argument type for filename
|
773
|
+
filename.check_type [ String ], 'wrong argument type $1 for filename argument (expected $2)'
|
774
|
+
|
775
|
+
# check argument type for filename
|
776
|
+
reset_parameters.check_type [ TrueClass, FalseClass ], 'wrong argument type $1 for reset_parameters boolean argument (expected $2)'
|
777
|
+
|
778
|
+
# reset parameter hash if requested
|
779
|
+
@parameters.clear if reset_parameters == true
|
216
780
|
|
217
|
-
|
781
|
+
# load and parse given file
|
782
|
+
load_parameters_file( filename )
|
218
783
|
|
219
784
|
end
|
220
|
-
|
785
|
+
|
221
786
|
# TODO: document me
|
222
787
|
def self.parse_string( source, merge_hashes = true )
|
223
|
-
|
224
|
-
self.instance unless @@initialized
|
225
788
|
|
226
|
-
|
789
|
+
# check argument type for source
|
790
|
+
source.check_type [ String ], 'wrong argument type $1 for source XML argument (expected $2)'
|
227
791
|
|
228
|
-
|
792
|
+
# check argument type for merge_hashes
|
793
|
+
merge_hashes.check_type [ TrueClass, FalseClass ], 'wrong argument type $1 for merge_hashes argument (expected $2)'
|
229
794
|
|
230
|
-
|
795
|
+
# process xml string, returns hash as result
|
796
|
+
hash = process_string( source )
|
231
797
|
|
232
|
-
|
798
|
+
if merge_hashes
|
799
|
+
|
800
|
+
@parameters.recursive_merge!( hash )
|
233
801
|
|
234
802
|
else
|
235
803
|
|
236
|
-
|
237
|
-
|
238
|
-
MobyUtil::ParameterXml.parse( source )
|
239
|
-
|
240
|
-
)
|
804
|
+
@parameters.merge!( hash )
|
241
805
|
|
242
806
|
end
|
243
807
|
|
244
808
|
end
|
245
|
-
|
809
|
+
|
246
810
|
# TODO: document me
|
247
811
|
def self.clear
|
248
812
|
|
249
|
-
|
813
|
+
@parameter_files.clear
|
250
814
|
|
251
|
-
|
815
|
+
@parameters.clear
|
252
816
|
|
817
|
+
end
|
818
|
+
|
253
819
|
# TODO: document me
|
254
|
-
def self.
|
820
|
+
def self.files
|
255
821
|
|
256
|
-
|
822
|
+
# return loaded parameter files list
|
823
|
+
@parameter_files
|
257
824
|
|
258
825
|
end
|
259
826
|
|
260
|
-
#
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
self.instance unless @@initialized
|
269
|
-
|
270
|
-
@@parameters[ key, *default ]
|
827
|
+
# TODO: document me
|
828
|
+
def self.template_files
|
829
|
+
|
830
|
+
# return loaded parameter files list
|
831
|
+
@template_files
|
832
|
+
|
833
|
+
end
|
271
834
|
|
835
|
+
# TODO: document me
|
836
|
+
def self.has_key?( key )
|
837
|
+
|
838
|
+
@parameters.has_key?( key )
|
839
|
+
|
272
840
|
end
|
273
841
|
|
274
|
-
|
842
|
+
# TODO: document me
|
843
|
+
def self.has_value?( key )
|
844
|
+
|
845
|
+
@parameters.has_value?( key )
|
846
|
+
|
847
|
+
end
|
275
848
|
|
276
|
-
|
849
|
+
# TODO: document me
|
850
|
+
def self.keys
|
851
|
+
|
852
|
+
@parameters.keys
|
853
|
+
|
854
|
+
end
|
277
855
|
|
278
|
-
|
856
|
+
# TODO: document me
|
857
|
+
def self.values
|
858
|
+
|
859
|
+
@parameters.values
|
860
|
+
|
861
|
+
end
|
279
862
|
|
863
|
+
# TODO: document me
|
864
|
+
def self.[]( key, *default )
|
865
|
+
|
866
|
+
@parameters[ key, *default ]
|
867
|
+
|
280
868
|
end
|
281
869
|
|
282
|
-
|
870
|
+
# TODO: document me
|
871
|
+
def self.[]=( key, value )
|
283
872
|
|
284
|
-
|
873
|
+
@parameters[ key ] = value
|
285
874
|
|
286
875
|
end
|
287
876
|
|
288
|
-
#
|
289
|
-
|
290
|
-
# == params
|
291
|
-
# key:: Symbol containing the name of the parameter to be modified
|
292
|
-
# == returns
|
293
|
-
# String:: new value of the parameter, or nil if not found
|
294
|
-
def self.[]=( key, value )
|
877
|
+
# TODO: document me
|
878
|
+
def self.fetch( key, *default, &block )
|
295
879
|
|
296
|
-
|
880
|
+
@parameters.__send__( :[], key, *default, &block )
|
297
881
|
|
298
|
-
|
882
|
+
end
|
883
|
+
|
884
|
+
# TODO: document me
|
885
|
+
def self.if_found( key, &block )
|
299
886
|
|
300
|
-
|
887
|
+
@parameters.__send__( :if_found, key, &block )
|
301
888
|
|
302
889
|
end
|
303
890
|
|
891
|
+
# TODO: document me
|
892
|
+
def self.delete( key )
|
893
|
+
|
894
|
+
@parameters.delete( key )
|
895
|
+
|
896
|
+
end
|
897
|
+
|
898
|
+
# TODO: document me
|
304
899
|
def self.inspect
|
900
|
+
|
901
|
+
@parameters.inspect
|
902
|
+
|
903
|
+
end
|
305
904
|
|
306
|
-
|
905
|
+
# TODO: document me
|
906
|
+
def self.templates
|
907
|
+
|
908
|
+
@templates
|
909
|
+
|
910
|
+
end
|
307
911
|
|
308
|
-
|
912
|
+
def self.parameters
|
309
913
|
|
914
|
+
warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#hash instead"
|
915
|
+
|
916
|
+
hash
|
917
|
+
|
310
918
|
end
|
311
919
|
|
312
|
-
def self.
|
920
|
+
def self.hash
|
921
|
+
|
922
|
+
@parameters
|
923
|
+
|
924
|
+
end
|
313
925
|
|
314
|
-
|
926
|
+
# TODO: document me
|
927
|
+
def self.reset
|
315
928
|
|
316
|
-
|
929
|
+
reset_hashes
|
930
|
+
|
931
|
+
end
|
317
932
|
|
933
|
+
# TODO: document me
|
934
|
+
def self.configured_suts
|
935
|
+
|
936
|
+
@sut_list
|
937
|
+
|
938
|
+
end
|
939
|
+
|
940
|
+
# deprecated methods
|
941
|
+
def self.reset_parameters
|
942
|
+
|
943
|
+
warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#reset instead"
|
944
|
+
|
945
|
+
reset
|
946
|
+
|
318
947
|
end
|
319
948
|
|
320
|
-
|
949
|
+
# load parameter xml files
|
950
|
+
def self.load_parameters_xml( filename, reset = false )
|
321
951
|
|
322
|
-
self.
|
952
|
+
warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#parse_file instead"
|
323
953
|
|
324
|
-
|
954
|
+
parse_file( filename, reset )
|
325
955
|
|
326
956
|
end
|
957
|
+
|
958
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
327
959
|
|
328
|
-
|
960
|
+
# initialize parameters class
|
961
|
+
initialize_class
|
329
962
|
|
330
|
-
|
963
|
+
end # Parameter
|
331
964
|
|
332
|
-
|
965
|
+
end
|
333
966
|
|
334
|
-
|
967
|
+
module MobyUtil
|
335
968
|
|
336
|
-
|
969
|
+
class ParameterHash
|
337
970
|
|
338
|
-
|
971
|
+
class << self
|
972
|
+
|
973
|
+
def new
|
974
|
+
|
975
|
+
warn_caller "$1:$2 warning: #{ self.to_s } is deprecated; use TDriver::ParameterHash instead"
|
976
|
+
|
977
|
+
TDriver::ParameterHash.new
|
978
|
+
|
979
|
+
end
|
339
980
|
|
340
|
-
|
981
|
+
end # self
|
982
|
+
|
983
|
+
end # ParameterHash
|
341
984
|
|
342
|
-
|
985
|
+
class Parameter
|
986
|
+
|
987
|
+
class << self
|
988
|
+
|
989
|
+
undef :inspect
|
990
|
+
|
991
|
+
def new
|
992
|
+
|
993
|
+
warn_caller "$1:$2 warning: #{ self.to_s } is static class; unable initialize new instance of it"
|
994
|
+
|
995
|
+
nil
|
996
|
+
|
997
|
+
end
|
998
|
+
|
999
|
+
def method_missing( id, *args )
|
1000
|
+
|
1001
|
+
warn_caller "$1:$2 warning: deprecated method; use TDriver::Parameter##{ id.to_s } instead of MobyUtil::Parameter##{ id.to_s }"
|
1002
|
+
|
1003
|
+
TDriver::Parameter.__send__( id, *args )
|
1004
|
+
|
1005
|
+
end
|
343
1006
|
|
344
|
-
|
1007
|
+
# TODO: document me
|
1008
|
+
def instance
|
1009
|
+
|
1010
|
+
warn_caller "$1:$2 warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name } class static methods instead"
|
1011
|
+
|
1012
|
+
TDriver::Parameter
|
1013
|
+
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
end # self
|
1017
|
+
|
1018
|
+
end # Parameter
|
1019
|
+
|
1020
|
+
class ParameterUserAPI
|
1021
|
+
|
1022
|
+
class << self
|
345
1023
|
|
346
|
-
|
1024
|
+
undef :inspect
|
347
1025
|
|
348
|
-
|
1026
|
+
def new
|
1027
|
+
|
1028
|
+
warn_caller "$1:$2 warning: #{ self.to_s } is static class; unable initialize new instance of it"
|
1029
|
+
|
1030
|
+
nil
|
1031
|
+
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
def method_missing( id, *args )
|
1035
|
+
|
1036
|
+
warn_caller "$1:$2 warning: deprecated method; use TDriver::ParameterUserAPI##{ id.to_s } instead of MobyUtil::ParameterUserAPI##{ id.to_s }"
|
1037
|
+
|
1038
|
+
TDriver::ParameterUserAPI.__send__( id, *args )
|
1039
|
+
|
1040
|
+
end
|
349
1041
|
|
350
|
-
|
1042
|
+
# TODO: document me
|
1043
|
+
def instance
|
351
1044
|
|
352
|
-
|
1045
|
+
warn_caller "$1:$2 warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name } class static methods instead"
|
353
1046
|
|
354
|
-
|
1047
|
+
TDriver::ParameterUserAPI
|
355
1048
|
|
356
|
-
|
1049
|
+
end
|
1050
|
+
|
1051
|
+
end # self
|
1052
|
+
|
1053
|
+
end # ParameterUserAPI
|
357
1054
|
|
358
1055
|
end # MobyUtil
|
359
1056
|
|
360
1057
|
# set global variable pointing to parameter class
|
361
|
-
$parameters = MobyUtil::Parameter
|
1058
|
+
$parameters = TDriver::Parameter #MobyUtil::Parameter
|
362
1059
|
|
363
1060
|
# set global variable pointing to parameter API class
|
364
|
-
$parameters_api =
|
1061
|
+
$parameters_api = TDriver::ParameterUserAPI
|