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.
Files changed (71) hide show
  1. data/config/sut_parameters.rb +21 -8
  2. data/config/tdriver_custom_error_recovery.rb +83 -0
  3. data/ext/extconf.rb +3 -2
  4. data/ext/native_extensions.c +60 -2
  5. data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +2 -105
  6. data/lib/tdriver/base/behaviour/factory.rb +154 -89
  7. data/lib/tdriver/base/behaviour/factory_new.rb +409 -0
  8. data/lib/tdriver/base/errors.rb +3 -3
  9. data/lib/tdriver/base/state_object.rb +85 -22
  10. data/lib/tdriver/base/sut/adapter.rb +26 -0
  11. data/lib/tdriver/base/sut/controller.rb +1 -1
  12. data/lib/tdriver/base/sut/generic/behaviours/application.rb +89 -118
  13. data/lib/tdriver/base/sut/generic/behaviours/find.rb +67 -62
  14. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +296 -187
  15. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +7 -7
  16. data/lib/tdriver/base/sut/generic/commands/application.rb +366 -295
  17. data/lib/tdriver/base/sut/sut.rb +19 -3
  18. data/lib/tdriver/base/test_object/abstract.rb +41 -21
  19. data/lib/tdriver/base/test_object/adapter.rb +62 -9
  20. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +10 -6
  21. data/lib/tdriver/base/test_object/behaviours/test_object.rb +84 -47
  22. data/lib/tdriver/base/test_object/factory.rb +124 -68
  23. data/lib/tdriver/base/test_object/loader.rb +3 -4
  24. data/lib/tdriver/base/test_object/verification.rb +3 -3
  25. data/lib/tdriver/base/test_object/xml/adapter.rb +734 -0
  26. data/lib/tdriver/loader.rb +12 -0
  27. data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +3 -2
  28. data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +14 -14
  29. data/lib/tdriver/report/report.rb +4 -8
  30. data/lib/tdriver/report/report_api.rb +9 -0
  31. data/lib/tdriver/report/report_crash_file_capture.rb +4 -4
  32. data/lib/tdriver/report/report_creator.rb +57 -35
  33. data/lib/tdriver/report/report_cucumber.rb +1 -1
  34. data/lib/tdriver/report/report_cucumber_listener.rb +5 -158
  35. data/lib/tdriver/report/report_cucumber_reporter.rb +7 -161
  36. data/lib/tdriver/report/report_execution_statistics.rb +4 -4
  37. data/lib/tdriver/report/report_file_capture.rb +5 -5
  38. data/lib/tdriver/report/report_grouping.rb +24 -22
  39. data/lib/tdriver/report/report_junit_xml.rb +5 -5
  40. data/lib/tdriver/report/report_test_case_run.rb +31 -22
  41. data/lib/tdriver/report/report_test_run.rb +107 -104
  42. data/lib/tdriver/report/report_writer.rb +150 -83
  43. data/lib/tdriver/tdriver.rb +147 -103
  44. data/lib/tdriver/util/common/boolean.rb +51 -0
  45. data/lib/tdriver/util/common/crc16.rb +110 -68
  46. data/lib/tdriver/util/common/hash.rb +63 -7
  47. data/lib/tdriver/util/common/kernel.rb +46 -1
  48. data/lib/tdriver/util/common/loader.rb +1 -0
  49. data/lib/tdriver/util/common/object.rb +20 -8
  50. data/lib/tdriver/util/common/string.rb +21 -2
  51. data/lib/tdriver/util/logger/logger.rb +4 -4
  52. data/lib/tdriver/util/parameter/loader.rb +2 -19
  53. data/lib/tdriver/util/parameter/parameter.rb +874 -177
  54. data/lib/tdriver/util/plugin/service.rb +1 -1
  55. data/lib/tdriver/util/recorder/recorder.rb +7 -1
  56. data/lib/tdriver/util/xml/abstraction.rb +13 -1
  57. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +63 -10
  58. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +8 -2
  59. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +16 -3
  60. data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +36 -32
  61. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +19 -22
  62. data/lib/tdriver/util/xml/xml.rb +147 -32
  63. data/lib/tdriver/verify/verify.rb +1112 -289
  64. data/lib/tdriver/version.rb +1 -1
  65. data/xml/templates/generic.xml +14 -2
  66. metadata +51 -24
  67. data/lib/tdriver/util/parameter/parameter_hash.rb +0 -104
  68. data/lib/tdriver/util/parameter/parameter_new.rb +0 -869
  69. data/lib/tdriver/util/parameter/parameter_template.rb +0 -120
  70. data/lib/tdriver/util/parameter/parameter_user_api.rb +0 -116
  71. data/lib/tdriver/util/parameter/parameter_xml.rb +0 -261
@@ -18,4 +18,4 @@
18
18
  ############################################################################
19
19
 
20
20
 
21
- ENV['TDRIVER_VERSION'] = '1.1.1'
21
+ ENV['TDRIVER_VERSION'] = '1.2.1'
@@ -24,6 +24,9 @@
24
24
 
25
25
  <!-- synchronization timeout for verify when used as a global method -->
26
26
  <parameter name="synchronization_timeout" value="10" />
27
+
28
+ <!-- xml cache settings -->
29
+ <parameter name="xml_cache_buffer_size" value="10" />
27
30
 
28
31
  </template>
29
32
 
@@ -58,6 +61,7 @@
58
61
  <parameter name="application_start_arguments" value="" /> <!-- start, e.g. value="-style, testability" -->
59
62
  <parameter name="application_close_kill" value="true" /> <!-- stop -->
60
63
  <parameter name="application_close_wait" value="10" /> <!-- time in seconds -->
64
+ <parameter name="application_check_pid" value="true" /> <!-- use pid for application object identification -->
61
65
 
62
66
  <parameter name="application_synchronization_timeout" value="20" />
63
67
  <parameter name="application_synchronization_retry_interval" value="0.25" />
@@ -78,6 +82,11 @@
78
82
  <parameter name="verify_blocks" value="" />
79
83
 
80
84
  <parameter name="use_find_object" value="true" />
85
+
86
+ <!-- if no objects are found by a given text, a new search will be attempted to try and find an ellided version of the text -->
87
+ <!-- the new search will try to match the first 4 chars of the original text and optionally a trailing ellipsis char ... (not 3 dots, but \u2026 unicode char) -->
88
+ <parameter name="elided_search" value="false" />
89
+ <parameter name="elided_search_with_ellipsis" value="false" />
81
90
 
82
91
  </template>
83
92
 
@@ -161,12 +170,14 @@
161
170
  <parameter name="report_crash_file_locations" value="C:,c:\data,E:,F:" /> <!-- posix="..." -->
162
171
  <parameter name="report_crash_file_names" value="MobileCrash" />
163
172
  <parameter name="report_disconnect_connected_devices" value="false" />
164
-
173
+ <parameter name="report_generate_rdoc" value="false" />
174
+ <parameter name="custom_error_recovery_module" value="/etc/tdriver/tdriver_custom_error_recovery.rb" windows="/tdriver/tdriver_custom_error_recovery.rb" />
165
175
 
166
176
  <!-- Parameters for report details -->
167
177
  <parameter name="report_outputter_path" value="tdriver_reports/" />
168
178
  <parameter name="behaviour_logging" value="true" />
169
179
  <parameter name="realtime_status_page_update" value="false" />
180
+ <parameter name="report_exclude_passed_cases" value="false" />
170
181
 
171
182
  <parameter name="report_passed_statuses" value="passed" /> <!-- Different statuses can be separated with | -->
172
183
  <parameter name="report_failed_statuses" value="failed" /> <!-- Different statuses can be separated with | -->
@@ -186,7 +197,8 @@
186
197
  <parameter name="report_file_locations" value="C:\logs,E:\logs" /> <!-- posix="..." -->
187
198
  <parameter name="report_file_names" value="*.log" />
188
199
  <parameter name="report_clean_files_from_sut_after_capture" value="true" />
189
- <parameter name="report_fail_test_if_files_found" value="true" />
200
+ <parameter name="report_fail_test_if_files_found" value="true" />
201
+
190
202
 
191
203
  </template>
192
204
 
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testability-driver
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 1
10
+ version: 1.2.1
5
11
  platform: ruby
6
12
  authors:
7
13
  - Testability Driver team
@@ -9,39 +15,56 @@ autorequire:
9
15
  bindir: bin/
10
16
  cert_chain: []
11
17
 
12
- date: 2011-04-12 00:00:00 +03:00
13
- default_executable:
18
+ date: 2011-06-13 00:00:00 Z
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: log4r
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 29
29
+ segments:
30
+ - 1
31
+ - 1
32
+ - 7
23
33
  version: 1.1.7
24
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: nokogiri
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 5
45
+ segments:
46
+ - 1
47
+ - 4
48
+ - 1
33
49
  version: 1.4.1
34
- version:
50
+ type: :runtime
51
+ version_requirements: *id002
35
52
  - !ruby/object:Gem::Dependency
36
53
  name: builder
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
40
57
  requirements:
41
58
  - - ">="
42
59
  - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 2
63
+ - 1
64
+ - 2
43
65
  version: 2.1.2
44
- version:
66
+ type: :runtime
67
+ version_requirements: *id003
45
68
  description:
46
69
  email: testabilitydriver@nokia.com
47
70
  executables:
@@ -65,6 +88,7 @@ files:
65
88
  - lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb
66
89
  - lib/tdriver/base/behaviour/behaviours/object_composition.rb
67
90
  - lib/tdriver/base/behaviour/factory.rb
91
+ - lib/tdriver/base/behaviour/factory_new.rb
68
92
  - lib/tdriver/base/behaviour/loader.rb
69
93
  - lib/tdriver/base/command_data/command_data.rb
70
94
  - lib/tdriver/base/command_data/loader.rb
@@ -97,6 +121,7 @@ files:
97
121
  - lib/tdriver/base/test_object/identificator.rb
98
122
  - lib/tdriver/base/test_object/loader.rb
99
123
  - lib/tdriver/base/test_object/verification.rb
124
+ - lib/tdriver/base/test_object/xml/adapter.rb
100
125
  - lib/tdriver/verify/verify.rb
101
126
  - lib/tdriver/verify/verify.rb_org
102
127
  - lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb
@@ -123,6 +148,7 @@ files:
123
148
  - lib/tdriver/report/report_test_unit.rb
124
149
  - lib/tdriver/report/report_writer.rb
125
150
  - lib/tdriver/util/common/array.rb
151
+ - lib/tdriver/util/common/boolean.rb
126
152
  - lib/tdriver/util/common/crc16.rb
127
153
  - lib/tdriver/util/common/environment.rb
128
154
  - lib/tdriver/util/common/error.rb
@@ -158,11 +184,6 @@ files:
158
184
  - lib/tdriver/util/parameter/error.rb
159
185
  - lib/tdriver/util/parameter/loader.rb
160
186
  - lib/tdriver/util/parameter/parameter.rb
161
- - lib/tdriver/util/parameter/parameter_hash.rb
162
- - lib/tdriver/util/parameter/parameter_new.rb
163
- - lib/tdriver/util/parameter/parameter_template.rb
164
- - lib/tdriver/util/parameter/parameter_user_api.rb
165
- - lib/tdriver/util/parameter/parameter_xml.rb
166
187
  - lib/tdriver/util/plugin/abstract.rb
167
188
  - lib/tdriver/util/plugin/error.rb
168
189
  - lib/tdriver/util/plugin/loader.rb
@@ -321,7 +342,7 @@ files:
321
342
  - config/sut_parameters.rb
322
343
  - config/sut_setup.rb
323
344
  - config/sut_teardown.rb
324
- has_rdoc: true
345
+ - config/tdriver_custom_error_recovery.rb
325
346
  homepage: http://code.nokia.com
326
347
  licenses: []
327
348
 
@@ -331,21 +352,27 @@ rdoc_options: []
331
352
  require_paths:
332
353
  - lib/.
333
354
  required_ruby_version: !ruby/object:Gem::Requirement
355
+ none: false
334
356
  requirements:
335
357
  - - ">="
336
358
  - !ruby/object:Gem::Version
359
+ hash: 3
360
+ segments:
361
+ - 0
337
362
  version: "0"
338
- version:
339
363
  required_rubygems_version: !ruby/object:Gem::Requirement
364
+ none: false
340
365
  requirements:
341
366
  - - ">="
342
367
  - !ruby/object:Gem::Version
368
+ hash: 3
369
+ segments:
370
+ - 0
343
371
  version: "0"
344
- version:
345
372
  requirements: []
346
373
 
347
374
  rubyforge_project:
348
- rubygems_version: 1.3.5
375
+ rubygems_version: 1.7.2
349
376
  signing_key:
350
377
  specification_version: 3
351
378
  summary: Testability Driver
@@ -1,104 +0,0 @@
1
- ############################################################################
2
- ##
3
- ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
- ## All rights reserved.
5
- ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
- ##
7
- ## This file is part of Testability Driver.
8
- ##
9
- ## If you have questions regarding the use of this file, please contact
10
- ## Nokia at testabilitydriver@nokia.com .
11
- ##
12
- ## This library is free software; you can redistribute it and/or
13
- ## modify it under the terms of the GNU Lesser General Public
14
- ## License version 2.1 as published by the Free Software Foundation
15
- ## and appearing in the file LICENSE.LGPL included in the packaging
16
- ## of this file.
17
- ##
18
- ############################################################################
19
-
20
- module MobyUtil
21
-
22
- class ParameterHash < Hash
23
-
24
- def initialize( hash = {} )
25
-
26
- #Kernel::raise ArgumentError.new( "Unexpected argument type %s, expecting Hash or ParameterHash" % [ hash.class ] ) unless [ Hash, ParameterHash ].include?( hash.class )
27
- hash.check_type( [ Hash, ParameterHash ], "Wrong argument type $1 for hash (expected $2)" )
28
-
29
- merge!(
30
-
31
- hash.empty? ? hash : convert_hash( hash )
32
-
33
- )
34
-
35
- end
36
-
37
- def convert_hash( hash )
38
-
39
- hash.kind_of?( ParameterHash ) ? hash : ParameterHash[ hash.collect{ | key, value | [ key, value.kind_of?( Hash ) ? convert_hash( value ) : value ] } ]
40
-
41
- end
42
-
43
- def []( key, *default, &block )
44
-
45
- $last_parameter = fetch( key ){
46
-
47
- if default.empty?
48
-
49
- Kernel::raise ParameterNotFoundError.new( "Parameter %s not found." % [ key ] ) unless block_given?
50
-
51
- # yield with key if block given
52
- result = yield( key )
53
-
54
- else
55
- Kernel::raise ArgumentError.new( "Only one default value allowed for parameter (%s)" % [ default.join(", ") ] ) unless default.size == 1
56
-
57
- result = default[ 0 ]
58
-
59
- end
60
-
61
- result.kind_of?( Hash ) ? convert_hash( result ) : result
62
-
63
- }
64
-
65
- end
66
-
67
- def []=( key, value )
68
-
69
- Kernel::raise ParameterNotFoundError.new( "Parameter key nil is not valid." ) unless key
70
-
71
- store( key, ( value.kind_of?( Hash ) ? convert_hash( value ) : value ) )
72
-
73
- end
74
-
75
- # Merge this Hash with another, primary Hash. Any values found in the other hash will overwrite local values and any Hash values will be recursively merged.
76
- def merge_with_hash!( other_hash )
77
-
78
- #raise ArgumentError.new( "Unable to merge, the other Hash was not a Hash, it was of type \"" + other_hash.class.to_s + "\"." ) unless other_hash.kind_of?( Hash )
79
-
80
- other_hash.check_type( Hash, "Wrong argument type $1 for hash (expected $2)" )
81
-
82
- other_hash.each_pair do | key, value |
83
-
84
- if ( self.has_key?( key ) && self[ key ].kind_of?( Hash ) ) and other_hash[ key ].kind_of?( Hash )
85
-
86
- self[ key ].merge_with_hash!( value )
87
-
88
- else
89
-
90
- self[ key ] = value
91
-
92
- end
93
-
94
- end
95
-
96
- self
97
-
98
- end
99
-
100
- TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
101
-
102
- end # ParameterHash
103
-
104
- end # MobyUtil
@@ -1,869 +0,0 @@
1
- ############################################################################
2
- ##
3
- ## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
- ## All rights reserved.
5
- ## Contact: Nokia Corporation (testabilitydriver@nokia.com)
6
- ##
7
- ## This file is part of Testability Driver.
8
- ##
9
- ## If you have questions regarding the use of this file, please contact
10
- ## Nokia at testabilitydriver@nokia.com .
11
- ##
12
- ## This library is free software; you can redistribute it and/or
13
- ## modify it under the terms of the GNU Lesser General Public
14
- ## License version 2.1 as published by the Free Software Foundation
15
- ## and appearing in the file LICENSE.LGPL included in the packaging
16
- ## of this file.
17
- ##
18
- ############################################################################
19
-
20
- module MobyUtil
21
-
22
- class ParameterHash < Hash
23
-
24
- =begin
25
- # TODO: document me
26
- def initialize #( hash = {} )
27
-
28
- hash.check_type( [ Hash, ParameterHash ], "Wrong argument type $1 for hash (expected $2)" )
29
-
30
- merge!(
31
-
32
- convert_hash( hash )
33
-
34
- ) unless hash.empty?
35
-
36
- end
37
- =end
38
-
39
- # TODO: document me
40
- def convert_hash( value )
41
-
42
- =begin
43
- if value.kind_of?( Hash )
44
-
45
- # convert hash to parameter hash
46
- ParameterHash[
47
-
48
- value.collect{ | key, value |
49
-
50
- [ key, value.kind_of?( Hash ) ? convert_hash( value ) : value ]
51
-
52
- }
53
-
54
- ]
55
-
56
- else
57
-
58
- # return as is
59
- value
60
-
61
- end
62
- =end
63
-
64
- value.kind_of?( Hash ) ? ParameterHash[ value.collect{ | key, value | [ key, value.kind_of?( Hash ) ? convert_hash( value ) : value ] } ] : value
65
-
66
- end
67
-
68
- # TODO: document me
69
- def []( key, *default, &block )
70
-
71
- $last_parameter = fetch( key ){
72
-
73
- if default.empty?
74
-
75
- raise ParameterNotFoundError, "Parameter #{ key } not found" unless block_given?
76
-
77
- # yield with key if block given
78
- yield( key )
79
-
80
- else
81
-
82
- raise ArgumentError, "Only one default value allowed for parameter (#{ default.join(", ") })" unless default.size == 1
83
-
84
- # convert_hash( default.first )
85
-
86
- result = default.first
87
-
88
- result.kind_of?( Hash ) ? convert_hash( result ) : result
89
-
90
- end
91
-
92
- }
93
-
94
- end
95
-
96
- # TODO: document me
97
- def []=( key, value )
98
-
99
- raise ParameterNotFoundError, "Parameter key nil is not valid" unless key
100
-
101
- super key, value.kind_of?( Hash ) ? convert_hash( value ) : value
102
-
103
- end
104
-
105
- TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
106
-
107
- end # ParameterHash
108
-
109
- class Parameter
110
-
111
- # private methods
112
- class << self
113
-
114
- public
115
-
116
- # TODO: document me
117
- def instance
118
-
119
- # get caller methods file name and line number
120
- file, line = caller.first.split(":")
121
-
122
- warn "#{ file }:#{ line } warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name } class static methods instead"
123
-
124
- self
125
-
126
- end
127
-
128
- # TODO: document me
129
- def init
130
-
131
- # initialize only once
132
- return if defined?( @initalized )
133
-
134
- # retrieve platform name
135
- @platform = MobyUtil::EnvironmentHelper.platform
136
-
137
- # detect is posix platform
138
- @is_posix = MobyUtil::EnvironmentHelper.posix?
139
-
140
- # retrieve parameter filenames from command line arguments
141
- parse_command_line_arguments
142
-
143
- # reset templates and parameters
144
- reset_hashes
145
-
146
- # indicates that class is already initialized - templates and parameters will not reset
147
- @initialized = true
148
-
149
- end
150
-
151
- private
152
-
153
- def parse_command_line_arguments
154
-
155
- # reset command line argument files list
156
- @command_line_argument_files = []
157
-
158
- capture_elements = false
159
-
160
- ARGV.each_with_index do | value, index |
161
-
162
- value = value.to_s
163
-
164
- case value
165
-
166
- when '--tdriver_parameters', '--matti_parameters'
167
-
168
- warn "warning: #{ value } is deprecated, use -tdriver_parameters instead" if value == '--matti_parameters'
169
-
170
- # capture following xml filenames
171
- capture_elements = true
172
-
173
- # mark element to be removed
174
- ARGV[ index ] = nil
175
-
176
- else
177
-
178
- # process the string if capturing arguments
179
- if capture_elements
180
-
181
- # stop capturing if is a option (e.g. --version)
182
- if [ '-' ].include?( value[ 0 ].chr )
183
-
184
- capture_elements = false
185
-
186
- # add argument to parameters list if meets the regexp and capture_element is true
187
- elsif /\.xml$/i.match( value )
188
-
189
- # expand filename
190
- value = File.expand_path( value )
191
-
192
- # raise exception if given file does not found
193
- raise MobyUtil::FileNotFoundError, "User defined TDriver parameters file #{ value } does not exist" unless File.exist?( value )
194
-
195
- # add file to command line arguments files
196
- @command_line_argument_files << value
197
-
198
- # mark element to be removed
199
- ARGV[ index ] = nil
200
-
201
- end # if
202
-
203
- end # else
204
-
205
- end # case
206
-
207
- end # each_with_index
208
-
209
- # raise exception if "--tdriver_parameters" option found but no filenames defined
210
- if capture_elements && @command_line_argument_files.empty?
211
-
212
- raise ArgumentError, "TDriver parameters command line argument given without a filename"
213
-
214
- end
215
-
216
- # remove nil elements from array
217
- ARGV.compact!
218
-
219
- # return collected filenames
220
- @command_line_argument_files
221
-
222
- end
223
-
224
- # TODO: document me
225
- def initialize_class
226
-
227
- # initialize only once
228
- return if defined?( @parameters )
229
-
230
- # class variables not used; read below article:
231
- # http://www.oreillynet.com/ruby/blog/2007/01/nubygems_dont_use_class_variab_1.html
232
-
233
- # parameters container
234
- @parameters = ParameterHash.new
235
-
236
- # templates container
237
- @templates = ParameterHash.new
238
-
239
- # platform enum
240
- @platform = nil
241
-
242
- # determine if platform is type of posix
243
- @is_posix = nil
244
-
245
- # list of loaded SUT's
246
- @sut_list = []
247
-
248
- # list of loaded parameter filenames
249
- @parameter_files = []
250
-
251
- # list of loaded template filenames
252
- @template_files = []
253
-
254
- # files defined in command line arguments
255
- @command_line_argument_files = []
256
-
257
- # templates cache
258
- @cache = {}
259
-
260
- end
261
-
262
- # TODO: document me
263
- def load_default_parameters
264
-
265
- # collect all templates
266
- Dir.glob( MobyUtil::FileHelper.expand_path( 'defaults/*.xml' ) ).each { | filename |
267
-
268
- file_content = load_file( filename )
269
-
270
- MobyUtil::XML.parse_string( file_content ).xpath( '*' ).each{ | element |
271
-
272
- # merge new hash to parameters hash
273
- @parameters.recursive_merge!(
274
-
275
- # parse element and convert it to hash
276
- process_element( element )
277
-
278
- )
279
-
280
- }
281
-
282
- # add file to loaded parameter files list
283
- @parameter_files << filename
284
-
285
- }
286
-
287
- end
288
-
289
- # TODO: document me
290
- def load_file( filename )
291
-
292
- filename = MobyUtil::FileHelper.expand_path( filename )
293
-
294
- begin
295
-
296
- MobyUtil::FileHelper.get_file( filename )
297
-
298
- rescue MobyUtil::EmptyFilenameError
299
-
300
- raise $!, "Unable to load parameters XML file due to filename is empty or nil"
301
-
302
- rescue MobyUtil::FileNotFoundError
303
-
304
- raise $!
305
-
306
- rescue IOError
307
-
308
- raise $!, "Error occured while loading xml file. Reason: #{ $!.message }"
309
-
310
- rescue
311
-
312
- raise MobyUtil::ParameterFileParseError, "Error occured while parsing parameters xml file #{ filename }\nDescription: #{ $!.message }"
313
-
314
- end
315
-
316
- end
317
-
318
- # TODO: document me
319
- def process_element( xml )
320
-
321
- # calculate xml hash
322
- xml_hash = xml.to_s.hash
323
-
324
- return @cache[ xml_hash ] if @cache.has_key?( xml_hash )
325
-
326
- # default results
327
- results = MobyUtil::ParameterHash.new
328
-
329
- # go through each element in xml
330
- xml.xpath( "*" ).each{ | element |
331
-
332
- # retrieve element attributes as hash
333
- attributes = element.attributes
334
-
335
- # default value
336
- value = attributes[ "value" ]
337
-
338
- # generic posix value - overwrites attribute["value"] if found
339
- value = attributes[ "posix" ] unless attributes[ "posix" ].nil? if @is_posix
340
-
341
- # platform specific value - overwrites existing value
342
- value = attributes[ @platform.to_s ] unless attributes[ @platform.to_s ].nil?
343
-
344
- # retrieve name attribute
345
- name = attributes[ "name" ]
346
-
347
- case element.name
348
-
349
- when 'keymap'
350
-
351
- # use element name as parameter name ("keymap")
352
- name = element.name
353
-
354
- # read xml file from given location if defined - otherwise pass content as is
355
- if attributes[ "xml_file" ]
356
-
357
- # merge hash values (value type of hash)
358
- value = process_file( attributes[ "xml_file" ] )
359
-
360
- else
361
-
362
- # use element content as value
363
- value = process_element( element )
364
-
365
- end
366
-
367
- # retrieve environment attribute from xml
368
- env = attributes[ 'env' ].to_s
369
-
370
- # set environment to 'default' unless defined in xml element
371
- env = 'default' if env.empty?
372
-
373
- # store keymap as hash
374
- value = { env.to_sym => value, :all => value, :default_keymap => env.to_sym }
375
-
376
- when 'fixture'
377
-
378
- name.not_blank( "No name defined for fixture \"#{ element.to_s }\"", SyntaxError )
379
-
380
- value = {
381
-
382
- :plugin => attributes[ "plugin" ].not_blank( "No name defined for fixture with value #{ name }", SyntaxError ),
383
-
384
- :env => attributes[ "env" ]
385
-
386
- }
387
-
388
- when 'parameter'
389
-
390
- # verify that name attribute is defined
391
- name.not_blank( "No name defined for parameter with value #{ value }", SyntaxError )
392
-
393
- # return value as is
394
- #value.not_nil( "No value defined for parameter with name #{ name }", SyntaxError )
395
-
396
- value = "" if value.nil?
397
-
398
- when 'method'
399
-
400
- # verify that name attribute is defined
401
- name.not_blank( "No name defined for parameter with value #{ value }", SyntaxError )
402
-
403
- # return value as is
404
- #value.not_nil( "No value defined for parameter with name #{ name }", SyntaxError )
405
-
406
- value = attributes[ "args" ]
407
-
408
- when 'sut'
409
-
410
- # use id as parameter name
411
- name = attributes[ 'id' ]
412
-
413
- # verify that name attribute is defined
414
- name.not_blank( "No name defined for SUT \"#{ element.to_s }\"", SyntaxError )
415
-
416
- # add SUT to found sut list
417
- @sut_list << name unless @sut_list.include?( name )
418
-
419
- # retrieve names of used templates
420
- templates = attributes[ "template" ]
421
-
422
- # empty value by default
423
- value = ParameterHash.new
424
-
425
- unless templates.blank?
426
-
427
- # retrieve each defined template
428
- templates.split(";").each{ | template |
429
-
430
- # merge template with current value hash
431
- value.recursive_merge!(
432
-
433
- # retrieve template
434
- get_template( template )
435
-
436
- )
437
-
438
- }
439
-
440
- end
441
-
442
- # merge sut content with template values
443
- value.recursive_merge!( process_element( element ) )
444
-
445
- else
446
-
447
- # use element name as parameter name (e.g. fixture, keymap etc)
448
- name = element.name
449
-
450
- # read xml file from given location if defined - otherwise pass content as is
451
- if attributes[ "xml_file" ]
452
-
453
- # merge hash values (value type of hash)
454
- value = process_file( attributes[ "xml_file" ] )
455
-
456
- else
457
-
458
- # use element content as value
459
- value = process_element( element )
460
-
461
- end
462
-
463
- end
464
-
465
- # store values to parameters
466
- results[ name.to_sym ] = value
467
-
468
- }
469
-
470
- # store to cache and return hash as result
471
- @cache[ xml_hash ] = results
472
-
473
- end
474
-
475
- # TODO: document me
476
- def parse_template( name )
477
-
478
- template = @templates[ name ]
479
-
480
- unless template.kind_of?( Hash )
481
-
482
- result = ParameterHash.new
483
-
484
- # retrieve each inherited template
485
- template[ 'inherits' ].to_s.split(";").each{ | inherited_template |
486
-
487
- result.recursive_merge!(
488
-
489
- parse_template( inherited_template )
490
-
491
- )
492
-
493
- }
494
-
495
- # merge template content with inherited templates and store to templates hash table
496
- @templates[ name ] = result.recursive_merge!(
497
-
498
- process_element( template )
499
-
500
- )
501
-
502
- else
503
-
504
- # template is already parsed, pass template hash as is
505
- template
506
-
507
- end
508
-
509
- end
510
-
511
- # TODO: document me
512
- def load_templates
513
-
514
- # collect all templates
515
- Dir.glob( MobyUtil::FileHelper.expand_path( 'templates/*.xml' ) ).each { | filename |
516
-
517
- unless @template_files.include?( filename )
518
-
519
- # read file content
520
- file_content = load_file( filename )
521
-
522
- MobyUtil::XML.parse_string( file_content ).root.xpath( 'template' ).each{ | template |
523
-
524
- # store template element to hash
525
- @templates[ template[ 'name' ] ] = template
526
-
527
- }
528
-
529
- # add file to loaded templates files list
530
- @template_files << filename
531
-
532
- end
533
-
534
- }
535
-
536
- # parse templates hash; convert elements to hash
537
- @templates.each_pair{ | name, template |
538
-
539
- # convert element to hash
540
- parse_template( name )
541
-
542
- }
543
-
544
- end
545
-
546
- # TODO: document me
547
- def get_template( name )
548
-
549
- @templates.fetch( name ){
550
-
551
- # return empty hash if template not found
552
- ParameterHash.new
553
-
554
- }
555
-
556
- end
557
-
558
- # TODO: document me
559
- def reset_hashes( options = {} )
560
-
561
- # default options
562
- options.default_values(
563
-
564
- :reset_templates => true,
565
- :reset_parameters => true,
566
-
567
- :load_default_parameters => true,
568
- :load_user_parameters => true,
569
- :load_command_line_parameters => true
570
-
571
- )
572
-
573
- # empty parameters hash
574
- if options[ :reset_parameters ] == true
575
-
576
- @parameter_files.clear
577
-
578
- @parameters.clear
579
-
580
- end
581
-
582
- if options[ :reset_templates ] == true
583
-
584
- @template_files.clear
585
-
586
- # empty templates hash
587
- @templates.clear
588
-
589
- # load parameter templates
590
- load_templates
591
-
592
- end
593
-
594
- # apply global parameters to root level (e.g. MobyUtil::Parameter[ :logging_outputter_enabled ])
595
- @parameters.recursive_merge!( get_template( 'global' ) )
596
-
597
- # load and apply default parameter values
598
- load_default_parameters if options[ :load_default_parameters ] == true
599
-
600
- # load main parameter configuraion file
601
- load_parameters_file( 'tdriver_parameters.xml' ) if options[ :load_user_parameters ] == true
602
-
603
- if options[ :load_command_line_parameters ] == true
604
-
605
- @command_line_argument_files.each{ | filename |
606
-
607
- load_parameters_file( filename )
608
-
609
- }
610
-
611
- end
612
-
613
- end
614
-
615
- # TODO: document me
616
- def process_file( filename )
617
-
618
- begin
619
-
620
- # load content from file
621
- file_content = load_file( filename )
622
-
623
- # parse file content and retrieve root element
624
- root_element = MobyUtil::XML.parse_string( file_content ).root
625
-
626
- # parse root element
627
- process_element( root_element )
628
-
629
- rescue MobyUtil::FileNotFoundError
630
-
631
- raise $!, "Parameters file #{ MobyUtil::FileHelper.expand_path( filename ) } does not exist"
632
-
633
- rescue
634
-
635
- raise MobyUtil::ParameterFileParseError, "Error occured while parsing parameters XML file #{ filename }. Reason: #{ $!.message } (#{ $!.class })"
636
-
637
- end
638
-
639
- end
640
-
641
- def process_string( source )
642
-
643
- begin
644
-
645
- # parse file content and retrieve root element
646
- root_element = MobyUtil::XML.parse_string( source ).root
647
-
648
- # parse root element
649
- process_element( root_element )
650
-
651
- rescue
652
-
653
- raise MobyUtil::ParameterXmlParseError, "Error occured while parsing parameters XML string. Reason: #{ $!.message } (#{ $!.class })"
654
-
655
- end
656
-
657
- end
658
-
659
- def load_parameters_file( filename )
660
-
661
- filename = MobyUtil::FileHelper.expand_path( filename )
662
-
663
- unless @parameter_files.include?( filename )
664
-
665
- begin
666
-
667
- @parameters.recursive_merge!(
668
-
669
- process_file( filename )
670
-
671
- )
672
-
673
- rescue MobyUtil::FileNotFoundError
674
-
675
- raise $!, "Parameters file #{ filename } does not exist"
676
-
677
- end
678
-
679
- # add file to loaded parameter files list
680
- @parameter_files << filename
681
-
682
- end # unless
683
-
684
- end # def
685
-
686
- end # self
687
-
688
- # TODO: document me
689
- def self.parse_file( filename, reset_parameters = false )
690
-
691
- # check argument type for filename
692
- filename.check_type [ String ], 'wrong argument type $1 for filename argument (expected $2)'
693
-
694
- # check argument type for filename
695
- reset_parameters.check_type [ TrueClass, FalseClass ], 'wrong argument type $1 for reset_parameters boolean argument (expected $2)'
696
-
697
- # reset parameter hash if requested
698
- @parameters.clear if reset_parameters == true
699
-
700
- # load and parse given file
701
- load_parameters_file( filename )
702
-
703
- end
704
-
705
- # TODO: document me
706
- def self.parse_string( source, merge_hashes = true )
707
-
708
- # check argument type for source
709
- source.check_type [ String ], 'wrong argument type $1 for source XML argument (expected $2)'
710
-
711
- # check argument type for merge_hashes
712
- merge_hashes.check_type [ TrueClass, FalseClass ], 'wrong argument type $1 for merge_hashes argument (expected $2)'
713
-
714
- # process xml string, returns hash as result
715
- hash = process_string( source )
716
-
717
- if merge_hashes
718
-
719
- @parameters.recursive_merge!( hash )
720
-
721
- else
722
-
723
- @parameters.merge!( hash )
724
-
725
- end
726
-
727
- end
728
-
729
- # TODO: document me
730
- def self.clear
731
-
732
- @parameter_files.clear
733
-
734
- @parameters.clear
735
-
736
- end
737
-
738
- # TODO: document me
739
- def self.files
740
-
741
- # return loaded parameter files list
742
- @parameter_files
743
-
744
- end
745
-
746
- # TODO: document me
747
- def self.template_files
748
-
749
- # return loaded parameter files list
750
- @template_files
751
-
752
- end
753
-
754
- # TODO: document me
755
- def self.keys
756
-
757
- @parameters.keys
758
-
759
- end
760
-
761
- # TODO: document me
762
- def self.values
763
-
764
- @parameters.values
765
-
766
- end
767
-
768
- # TODO: document me
769
- def self.[]( key, *default )
770
-
771
- @parameters[ key, *default ]
772
-
773
- end
774
-
775
- # TODO: document me
776
- def self.[]=( key, value )
777
-
778
- @parameters[ key ] = value
779
-
780
- end
781
-
782
- # TODO: document me
783
- def self.fetch( key, *default, &block )
784
-
785
- @parameters.__send__( :[], key, *default, &block )
786
-
787
- end
788
-
789
- # TODO: document me
790
- def self.delete( key )
791
-
792
- @parameters.delete( key )
793
-
794
- end
795
-
796
- # TODO: document me
797
- def self.inspect
798
-
799
- @parameters.inspect
800
-
801
- end
802
-
803
- # TODO: document me
804
- def self.templates
805
-
806
- @templates
807
-
808
- end
809
-
810
- def self.parameters
811
-
812
- warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#hash instead"
813
-
814
- hash
815
-
816
- end
817
-
818
- def self.hash
819
-
820
- @parameters
821
-
822
- end
823
-
824
- # TODO: document me
825
- def self.reset
826
-
827
- reset_hashes
828
-
829
- end
830
-
831
- # TODO: document me
832
- def self.configured_suts
833
-
834
- @sut_list
835
-
836
- end
837
-
838
- # deprecated methods
839
- def self.reset_parameters
840
-
841
- warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#reset instead"
842
-
843
- reset
844
-
845
- end
846
-
847
- # load parameter xml files
848
- def self.load_parameters_xml( filename, reset = false )
849
-
850
- warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#parse_file instead"
851
-
852
- parse_file( filename, reset )
853
-
854
- end
855
-
856
- TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
857
-
858
- # initialize parameters class
859
- initialize_class
860
-
861
- end # Parameter
862
-
863
- end # MobyUtil
864
-
865
- # set global variable pointing to parameter class
866
- $parameters = MobyUtil::Parameter
867
-
868
- # set global variable pointing to parameter API class
869
- $parameters_api = MobyUtil::ParameterUserAPI