testability-driver 0.9.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +1 -1
  2. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +11 -7
  3. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +8 -0
  4. data/lib/tdriver/base/behaviour/factory.rb +229 -209
  5. data/lib/tdriver/base/errors.rb +3 -0
  6. data/lib/tdriver/base/state_object.rb +11 -20
  7. data/lib/tdriver/base/sut/controller.rb +4 -4
  8. data/lib/tdriver/base/sut/factory.rb +205 -170
  9. data/lib/tdriver/base/sut/generic/behaviours/application.rb +256 -174
  10. data/lib/tdriver/base/sut/generic/behaviours/find.rb +17 -11
  11. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +57 -66
  12. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +578 -497
  13. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +41 -15
  14. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +48 -19
  15. data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
  16. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +25 -13
  17. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +16 -10
  18. data/lib/tdriver/base/sut/generic/plugin.rb +9 -3
  19. data/lib/tdriver/base/sut/sut.rb +41 -33
  20. data/lib/tdriver/base/test_object/abstract.rb +26 -3
  21. data/lib/tdriver/base/test_object/adapter.rb +399 -0
  22. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +56 -14
  23. data/lib/tdriver/base/test_object/behaviours/test_object.rb +663 -197
  24. data/lib/tdriver/base/test_object/cache.rb +132 -0
  25. data/lib/tdriver/base/test_object/factory.rb +677 -426
  26. data/lib/tdriver/base/test_object/factory_new.rb +202 -0
  27. data/lib/tdriver/base/test_object/identificator.rb +24 -17
  28. data/lib/tdriver/base/test_object/loader.rb +9 -3
  29. data/lib/tdriver/base/test_object/verification.rb +181 -0
  30. data/lib/tdriver/loader.rb +1 -1
  31. data/lib/tdriver/report/report.rb +2 -0
  32. data/lib/tdriver/report/report_api.rb +4 -4
  33. data/lib/tdriver/report/report_creator.rb +29 -3
  34. data/lib/tdriver/report/report_data_presentation.rb +7 -3
  35. data/lib/tdriver/report/report_execution_statistics.rb +80 -21
  36. data/lib/tdriver/report/report_javascript.rb +192 -0
  37. data/lib/tdriver/report/report_test_case_run.rb +22 -0
  38. data/lib/tdriver/report/report_test_run.rb +62 -55
  39. data/lib/tdriver/report/report_writer.rb +57 -56
  40. data/lib/tdriver/tdriver.rb +14 -41
  41. data/lib/tdriver/util/common/error.rb +1 -0
  42. data/lib/tdriver/util/common/exceptions.rb +12 -0
  43. data/lib/tdriver/util/common/file.rb +12 -6
  44. data/lib/tdriver/util/common/gem.rb +2 -1
  45. data/lib/tdriver/util/common/hash.rb +152 -0
  46. data/lib/tdriver/util/common/kernel.rb +49 -34
  47. data/lib/tdriver/util/common/loader.rb +21 -17
  48. data/lib/tdriver/util/common/numeric.rb +39 -0
  49. data/lib/tdriver/util/common/object.rb +115 -0
  50. data/lib/tdriver/util/common/string.rb +55 -2
  51. data/lib/tdriver/util/dbaccess/dbaccess.rb +194 -161
  52. data/lib/tdriver/util/dynamic_attribute_filter.rb +6 -0
  53. data/lib/tdriver/util/hooking.rb +2 -2
  54. data/lib/tdriver/util/loader.rb +2 -2
  55. data/lib/tdriver/util/localisation/localisation.rb +277 -18
  56. data/lib/tdriver/util/logger.rb +142 -13
  57. data/lib/tdriver/util/parameter/parameter_hash.rb +8 -5
  58. data/lib/tdriver/util/parameter/parameter_xml.rb +18 -2
  59. data/lib/tdriver/util/recorder.rb +17 -12
  60. data/lib/tdriver/util/user_data/user_data.rb +3 -2
  61. data/lib/tdriver/util/{video_rec.rb → video_utils.rb} +136 -16
  62. data/lib/tdriver/util/xml/abstraction.rb +7 -0
  63. data/lib/tdriver/util/xml/attribute.rb +32 -0
  64. data/lib/tdriver/util/xml/loader.rb +8 -2
  65. data/lib/tdriver/util/xml/nil_node.rb +95 -0
  66. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +46 -7
  67. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +19 -9
  68. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +1 -1
  69. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +13 -1
  70. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +6 -0
  71. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +27 -15
  72. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +57 -0
  73. data/lib/tdriver/util/xml/text.rb +32 -0
  74. data/lib/tdriver/util/xml/xml.rb +35 -22
  75. data/lib/tdriver/version.rb +1 -1
  76. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +41 -34
  77. data/lib/tdriver-devtools/doc/generate.rb +31 -6
  78. data/lib/tdriver-devtools/doc/xslt/template.xsl +46 -25
  79. data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
  80. data/lib/tdriver-devtools/tests/feature_tests/update +1 -1
  81. data/lib/tdriver.rb +0 -3
  82. data/xml/behaviours/generic.xml +1 -1
  83. data/xml/defaults/generic.xml +4 -90
  84. data/xml/templates/generic.xml +33 -25
  85. metadata +21 -29
  86. data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +0 -245
  87. data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +0 -964
  88. data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +0 -68
  89. data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +0 -1865
  90. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +0 -1
  91. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +0 -3
  92. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +0 -4
  93. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +0 -4
  94. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +0 -4
  95. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +0 -3
  96. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +0 -3
  97. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +0 -1
  98. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +0 -3
  99. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +0 -3
  100. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +0 -12
  101. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +0 -5
  102. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +0 -1
  103. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +0 -2
  104. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +0 -7
  105. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +0 -14
  106. data/lib/tdriver-devtools/behaviour/xml_generator/update +0 -3
  107. data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +0 -233
  108. data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +0 -194
@@ -128,4 +128,7 @@ module MobyBase
128
128
  end
129
129
  end
130
130
 
131
+ # TODO: document
132
+ class ApplicationNotAvailableError < MobyStandardError; end;
133
+
131
134
  end # MobyBase
@@ -64,15 +64,18 @@ module MobyBase
64
64
 
65
65
  end
66
66
 
67
- @parent = nil
68
- add_parent( parent ) unless parent.nil?
67
+ #@parent = nil
68
+ #add_parent( parent ) unless parent.nil?
69
+ #@parent = parent unless parent.nil?
70
+
71
+ @parent = parent
69
72
 
70
73
  self.xml_data= xml_element
71
74
 
72
- @_child_object_cache = {}
75
+ @child_object_cache = TDriver::TestObjectCache.new
73
76
 
74
77
  # Create accessor methods for any child state objects.
75
- TestObjectFactory.instance.create_child_accessors!( self )
78
+ TDriver::TestObjectAdapter.create_child_accessors!( xml_element, self )
76
79
 
77
80
  end
78
81
 
@@ -81,18 +84,8 @@ module MobyBase
81
84
 
82
85
  hash_rule = method_arguments.first
83
86
 
84
- # method mapping/aliases
85
- case method_id
86
-
87
- when :Button;
88
- method_id = [ :Button, :QToolButton, :DuiButton, :HbPushButton, :softkey ]
89
-
90
- when :List;
91
- method_id = [ :QList, :HbListWidgetView, :DuiList ]
92
-
93
- end
94
-
95
87
  hash_rule = Hash.new unless hash_rule.kind_of? Hash
88
+
96
89
  hash_rule[ :type ] = method_id
97
90
 
98
91
  begin
@@ -211,11 +204,9 @@ module MobyBase
211
204
 
212
205
  def get_cached_test_object!( object )
213
206
 
214
- object_hash = object.hash
215
-
216
- if @_child_object_cache.has_key?( object_hash )
207
+ if @child_object_cache.has_object?( object )
217
208
 
218
- object = @_child_object_cache[ object_hash ]
209
+ object = @child_object_cache[ object ]
219
210
 
220
211
  true
221
212
 
@@ -247,7 +238,7 @@ module MobyBase
247
238
  get_cached_test_object!( child_object ).tap{ | found_in_cache |
248
239
 
249
240
  # add child to objects cache
250
- add_child( child_object ) unless found_in_cache
241
+ @child_object_cache.add_object( child_object ) unless found_in_cache
251
242
 
252
243
  }
253
244
 
@@ -17,7 +17,6 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
20
  module MobyBase
22
21
 
23
22
  class SutController
@@ -28,10 +27,11 @@ module MobyBase
28
27
  # == params
29
28
  # sut_adapter:: MobyController::SutAdapter descendant, e.g. MobyController::QT::SutAdapter
30
29
  # == raises
30
+ # TypeError:: Wrong argument type $1 for SUT controller (expected $2)
31
31
  # NameError:: No SUT controller found for %s (%s)
32
32
  def initialize( sut_controllers, sut_adapter )
33
33
 
34
- Kernel::raise ArgumentError.new( "SUT Controller(s) must be given in String format, got #{ sut_controllers.class }" ) unless sut_controllers.kind_of? String
34
+ sut_controllers.check_type( String, "Wrong argument type $1 for SUT controller (expected $2)" )
35
35
 
36
36
  @sut_adapter = sut_adapter
37
37
 
@@ -81,11 +81,11 @@ module MobyBase
81
81
  # == returns
82
82
  # command_data implementation specific return value
83
83
  # == raises
84
- # ArgumentError:: if command_data is not kind of MobyController::CommandData
84
+ # TypeError:: Wrong argument type $1 for command_data (expected $2)
85
85
  # MobyBase::CommandNotFoundError:: if no implementation is found for the CommandData object
86
86
  def execute_command( command_data )
87
87
 
88
- Kernel::raise ArgumentError.new( 'Data not of type MobyController::CommandData' ) unless command_data.kind_of?( MobyCommand::CommandData )
88
+ command_data.check_type( MobyCommand::CommandData, "Wrong argument type $1 for command_data (expected $2)" )
89
89
 
90
90
  @execution_order.each{ | controller |
91
91
 
@@ -17,271 +17,306 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
20
  module MobyBase
22
21
 
23
- # Class to create SUT objects
24
- # Hides actual SUT object from the clients -> clients should be able to use the instantiated SUT object as if it was any SUT
25
- class SUTFactory
22
+ # Class to create SUT objects
23
+ # Hides actual SUT object from the clients -> clients should be able to use the instantiated SUT object as if it was any SUT
24
+ class SUTFactory
26
25
 
27
- include Singleton
26
+ include Singleton
28
27
 
29
- # Initialize the singleton
30
- def initialize()
28
+ # Initialize the singleton
29
+ def initialize()
31
30
 
32
- reset
31
+ reset
33
32
 
34
- end
33
+ end
35
34
 
36
- # Create/reset hash to store sut ids for all current suts
37
- def reset
35
+ # Create/reset hash to store sut ids for all current suts
36
+ def reset
38
37
 
39
- @_sut_list = {}
38
+ @_sut_list = {}
40
39
 
41
- end
40
+ end
42
41
 
43
- def mapped_sut?( sut_id )
42
+ def mapped_sut?( sut_id )
44
43
 
45
- MobyUtil::Parameter[ :mappings, {} ].has_key?( sut_id.to_sym )
46
- end
44
+ MobyUtil::Parameter[ :mappings, {} ].has_key?( sut_id.to_sym )
47
45
 
46
+ end
48
47
 
49
- def get_mapped_sut( sut_id )
50
48
 
51
- MobyUtil::Parameter[ :mappings ][ sut_id.to_sym ].to_sym
49
+ def get_mapped_sut( sut_id )
52
50
 
53
- end
51
+ MobyUtil::Parameter[ :mappings ][ sut_id.to_sym ].to_sym
54
52
 
55
- # Function to create the actual SUT objects based on the 'sut' attribute.
56
- # === params
57
- # sut_type:: sut_type - sut type, supportes all types defined by SUTFactory constants
58
- # id:: id - unique identifier for identifying particular SUT from each other. Is propagated to proper initializers.
59
- # === returns
60
- # return:: SUT object
61
- # raise::
62
- # ArgumentError:: SUT ID '%s' not found from tdriver_parameters.xml
63
- def make( sut_id )
53
+ end
64
54
 
65
- # cast into symbol just in case string was passed
66
- sut_id = sut_id.to_sym
55
+ # Function to create the actual SUT objects based on the 'sut' attribute.
56
+ # === params
57
+ # sut_type:: sut_type - sut type, supportes all types defined by SUTFactory constants
58
+ # id:: id - unique identifier for identifying particular SUT from each other. Is propagated to proper initializers.
59
+ # === returns
60
+ # return:: SUT object
61
+ # raise::
62
+ # ArgumentError:: SUT ID '%s' not found from tdriver_parameters.xml
63
+ def make( sut_attributes )
67
64
 
68
- sut_id = get_mapped_sut( sut_id ) if mapped_sut?( sut_id )
65
+ sut_id = retrieve_sut_id_from_hash( sut_attributes )
69
66
 
70
- # if sut is already connected, return existing sut
71
- return get_sut_from_list( sut_id ) if sut_exists?( sut_id )
67
+ sut_id = get_mapped_sut( sut_id ) if mapped_sut?( sut_id )
72
68
 
73
- #mapped_id = MobyUtil::Parameter[ sut_id, nil ].to_sym
69
+ # if sut is already connected, return existing sut
70
+ return get_sut_from_list( sut_id ) if sut_exists?( sut_id )
74
71
 
75
- # check if the sut or an alias exists in tdriver_parameters.xml
76
- #mapped_id = find_sut_or_mapping( sut_id )
77
72
 
78
- # if sut is already connected, return existing sut
79
- #return get_sut_from_list( mapped_id ) if (mapped_id != sut_id and sut_exists?( mapped_id ))
73
+ # retrieve sut from parameters
74
+ sut = MobyUtil::Parameter[ sut_id, nil ]
80
75
 
81
- Kernel::raise ArgumentError.new( "The SUT '#{ sut_id }' was not defined in TDriver parameters XML" ) if MobyUtil::Parameter[ sut_id, nil ].nil?
76
+ # raise exception if sut was not found
77
+ Kernel::raise ArgumentError.new( "%s not defined in TDriver parameters XML" % [ sut_id ]) if sut.nil?
78
+
79
+ # retrieve sut type from parameters
80
+ sut_type = sut[ :type, nil ]
81
+
82
+ # raise exception if sut type was not found
83
+ Kernel::raise RuntimeError.new( "SUT parameter 'type' not defined for %s in TDriver parameters/templates XML" % [ sut_id ] ) if sut_type.nil?
82
84
 
83
- # retrieve sut type from parameters, raise exception if sut type was not found
84
- Kernel::raise RuntimeError.new( "SUT type not defined for #{ sut_id } in TDriver parameters/templates XML" ) if ( sut_type = MobyUtil::Parameter[ sut_id ][ :type, nil ] ).nil?
85
+ sut_type_symbol = sut_type.downcase.to_sym
85
86
 
86
- sut_type_symbol = sut_type.downcase.to_sym
87
+ # retrieve plugin name that implements given sut
88
+ sut_plugin = sut[ :sut_plugin, nil ]
87
89
 
88
- # retrieve plugin name that implements given sut
89
- sut_plugin = MobyUtil::Parameter[ sut_id ][ :sut_plugin, nil ]
90
+ sut_env = sut[ :env, '*' ]
90
91
 
91
- # verify that sut plugin is defined in sut configuration
92
- Kernel::raise RuntimeError.new( "SUT plugin not defined for %s (%s)" % [ sut_id, sut_type ] ) if sut_plugin.nil?
92
+ # verify that sut plugin is defined in sut configuration
93
+ Kernel::raise RuntimeError.new( "SUT parameter 'sut_plugin' not defined for %s (%s)" % [ sut_id, sut_type ] ) if sut_plugin.nil?
94
+
95
+ # flag to determine that should exception be raised; allow one retry, then set flag to true if error still occures
96
+ raise_exception = false
93
97
 
94
- # flag to determine that should exception be raised; allow one retry, then set flag to true if error still occures
95
- raise_exception = false
98
+ begin
96
99
 
97
- begin
100
+ # verify that sut plugin is registered
101
+ if MobyUtil::PluginService.instance.plugin_registered?( sut_plugin, :sut )
102
+
103
+ # create sut object
104
+ created_sut = MobyUtil::PluginService.instance.call_plugin_method( sut_plugin, :make_sut, sut_id )
98
105
 
99
- # verify that sut plugin is registered
100
- if MobyUtil::PluginService.instance.plugin_registered?( sut_plugin, :sut )
101
-
102
- # create sut object
103
- created_sut = MobyUtil::PluginService.instance.call_plugin_method( sut_plugin, :make_sut, sut_id )
106
+ else
104
107
 
105
- else
108
+ # raise error if sut was not registered
109
+ Kernel::raise NotImplementedError.new( "No plugin implementation found for SUT type: %s" % [ sut_type ] )
106
110
 
107
- # raise error if sut was not registered
108
- Kernel::raise NotImplementedError.new( "No plugin/implementation for SUT type: %s" % [ sut_type ] )
111
+ end
109
112
 
110
- end
113
+ rescue Exception => exception
111
114
 
112
- rescue Exception => exception
115
+ # if sut was not registered, try to load it
116
+ MobyUtil::PluginService.instance.load_plugin( sut_plugin ) if exception.kind_of?( NotImplementedError )
113
117
 
114
- # if sut was not registered, try to load it
115
- MobyUtil::PluginService.instance.load_plugin( sut_plugin ) if exception.kind_of?( NotImplementedError )
118
+ if !raise_exception
116
119
 
117
- if !raise_exception
120
+ raise_exception = true
121
+ retry
122
+
123
+ else
118
124
 
119
- raise_exception = true
120
- retry
121
- else
125
+ # still errors, raise original exception
126
+ Kernel::raise exception
122
127
 
123
- # still errors, raise original exception
124
- Kernel::raise exception
128
+ end
125
129
 
126
- end
130
+ end
127
131
 
128
- end
132
+ # sut type version, default: nil
133
+ created_sut.instance_eval {
134
+ @ui_type = sut_type;
135
+ @ui_version = MobyUtil::Parameter[ sut_id ][ :version, nil ];
136
+ @input = MobyUtil::Parameter[ sut_id ][ :input_type, nil ];
137
+ }
138
+
139
+ # add behaviours to sut
140
+ created_sut.extend( MobyBehaviour::ObjectBehaviourComposition )
129
141
 
130
- # sut type version, default: nil
131
- created_sut.instance_eval {
132
- @ui_type = sut_type;
133
- @ui_version = MobyUtil::Parameter[ sut_id ][ :version, nil ];
134
- @input = MobyUtil::Parameter[ sut_id ][ :input_type, nil ];
135
- }
136
-
137
- # add behaviours to sut
138
- created_sut.extend( MobyBehaviour::ObjectBehaviourComposition )
142
+ # retrieve list of optional extension plugins
143
+ @extension_plugins = MobyUtil::Parameter[ sut_id ][ :extension_plugins, "" ].split( ";" )
139
144
 
140
- # retrieve list of optional extension plugins
141
- @extension_plugins = MobyUtil::Parameter[ sut_id ][ :extension_plugins, "" ].split( ";" )
145
+ # load optional extension plugins
146
+ if @extension_plugins.count > 0
142
147
 
143
- # load optional extension plugins
144
- if @extension_plugins.count > 0
148
+ @extension_plugins.each{ | plugin_name |
145
149
 
146
- @extension_plugins.each{ | plugin_name |
150
+ raise_exception = false
147
151
 
148
- raise_exception = false
152
+ begin
149
153
 
150
- begin
154
+ # verify that extension plugin is registered
155
+ unless MobyUtil::PluginService.instance.plugin_registered?( plugin_name, :extension )
151
156
 
152
- # verify that extension plugin is registered
153
- unless MobyUtil::PluginService.instance.plugin_registered?( plugin_name, :extension )
157
+ # raise error if sut was not registered
158
+ Kernel::raise NotImplementedError.new( "Extension plugin not found %s" % [ plugin_name ] )
154
159
 
155
- # raise error if sut was not registered
156
- Kernel::raise NotImplementedError.new( "Extension plugin not found %s" % [ plugin_name ] )
160
+ end
157
161
 
158
- end
162
+ rescue Exception => exception
159
163
 
160
- rescue Exception => exception
164
+ # if sut was not registered, try to load it
165
+ MobyUtil::PluginService.instance.load_plugin( plugin_name ) if exception.kind_of?( NotImplementedError )
161
166
 
162
- # if sut was not registered, try to load it
163
- MobyUtil::PluginService.instance.load_plugin( plugin_name ) if exception.kind_of?( NotImplementedError )
167
+ if !raise_exception
164
168
 
165
- if !raise_exception
169
+ raise_exception = true
170
+ retry
171
+ else
166
172
 
167
- raise_exception = true
168
- retry
169
- else
173
+ # still errors, raise original exception
174
+ Kernel::raise exception
170
175
 
171
- # still errors, raise original exception
172
- Kernel::raise exception
176
+ end
173
177
 
174
- end
178
+ end
175
179
 
176
- end
180
+ }
177
181
 
178
- }
182
+ end
179
183
 
180
- end
184
+ # apply sut generic behaviours
185
+ created_sut.apply_behaviour!(
186
+ :object_type => [ 'sut' ],
187
+ # :sut_type => [ '*', sut_type.upcase ],
188
+ # :sut_type => [ '*', sut_type ],
189
+ :input_type => [ '*', created_sut.input.to_s ],
190
+ :env => [ '*', *sut_env.to_s.split(";") ],
191
+ :version => [ '*', created_sut.ui_version.to_s ]
192
+ )
181
193
 
182
- # apply sut generic behaviours
183
- created_sut.apply_behaviour!(
184
- :object_type => [ 'sut' ],
185
- :sut_type => [ '*', sut_type.upcase ],
186
- :input_type => [ '*', created_sut.input.to_s ],
187
- :version => [ '*', created_sut.ui_version.to_s ]
188
- )
194
+ @_sut_list[ sut_id ] = { :sut => created_sut, :is_connected => true }
189
195
 
190
- @_sut_list[ sut_id ] = { :sut => created_sut, :is_connected => true }
196
+ created_sut
191
197
 
192
- created_sut
198
+ end
193
199
 
194
- end
200
+ def disconnect_sut( sut_attributes )
195
201
 
196
- def disconnect_sut( id )
202
+ sut_id = retrieve_sut_id_from_hash( sut_attributes )
197
203
 
198
- #cast into symbol just in case string was passed
199
- id = id.to_sym
200
- Kernel::raise RuntimeError.new( "Not connected to device: #{ id }" ) unless sut_exists?( id ) && @_sut_list[ id ][ :is_connected ]
204
+ Kernel::raise RuntimeError.new(
205
+
206
+ "Unable disconnect SUT due to %s is not connected" % [ sut_id ]
207
+
208
+ ) unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ]
209
+
210
+ @_sut_list[ sut_id ][ :sut ].disconnect
211
+
212
+ @_sut_list[ sut_id ][ :is_connected ] = false
201
213
 
202
- @_sut_list[ id ][ :sut ].disconnect
203
- @_sut_list[ id ][ :is_connected ] = false
214
+ end
204
215
 
205
- end
216
+ def reboot_sut( sut_attributes )
206
217
 
207
- def reboot_sut( id )
218
+ sut_id = retrieve_sut_id_from_hash( sut_attributes )
208
219
 
209
- id = id.to_sym
210
- Kernel::raise RuntimeError.new( "Not connected to device: #{ id }" ) unless sut_exists?( id ) && @_sut_list[ id ][ :is_connected ]
211
-
212
- @_sut_list[ id ][ :sut ].reboot
213
- disconnect_sut( id )
214
- end
220
+ Kernel::raise RuntimeError.new(
221
+
222
+ "Unable to reboot SUT due to %s is not connected" % [ sut_id ]
223
+
224
+ ) unless sut_exists?( sut_id ) && @_sut_list[ sut_id ][ :is_connected ]
225
+
226
+ @_sut_list[ sut_id ][ :sut ].reboot
215
227
 
216
- def connected_suts
228
+ disconnect_sut( sut_id )
217
229
 
218
- @_sut_list
230
+ end
219
231
 
220
- end
232
+ def connected_suts
233
+
234
+ @_sut_list
235
+
236
+ end
221
237
 
222
238
  private
223
239
 
224
- # gets sut from sut-factorys list - if not connected tries to reconnect first
225
- def get_sut_from_list( id )
240
+ def retrieve_sut_id_from_hash( sut_attributes )
226
241
 
227
- if !@_sut_list[ id ][ :is_connected ]
242
+ # usability improvement: threat sut_attribute as SUT id if it is type of Symbol or String
243
+ sut_attributes = { :id => sut_attributes.to_sym } if [ String, Symbol ].include?( sut_attributes.class )
228
244
 
229
- @_sut_list[ id ][ :sut ].connect( id )
230
- @_sut_list[ id ][ :is_connected ] = true
245
+ # verify that sut_attributes is type of Hash
246
+ sut_attributes.check_type( [ Hash, Symbol, String ], "Wrong argument type $1 for 'sut_attributes' (expected $2)" )
231
247
 
232
- end
248
+ # legacy support: support also :Id
249
+ sut_attributes[ :id ] = sut_attributes.delete( :Id ) if sut_attributes.has_key?( :Id )
233
250
 
234
- @_sut_list[ id ][ :sut ]
235
- end
251
+ sut_attributes.require_key( :id, "Required SUT identification key $1 not defined in 'sut_attributes'" )
252
+
253
+ sut_attributes[ :id ].to_sym
236
254
 
237
- def sut_exists?( sut_id )
255
+ end
238
256
 
239
- @_sut_list.has_key?( sut_id )
257
+ # gets sut from sut-factorys list - if not connected tries to reconnect first
258
+ def get_sut_from_list( id )
240
259
 
241
- end
260
+ if !@_sut_list[ id ][ :is_connected ]
242
261
 
243
- # Finds the sut definition matching the id, either directly or via a mapping
244
- #
245
- # === params
246
- # id:: Symbol defining the id of the sut to search for
247
- # === returns
248
- # Symbol:: Either id if it was found in the parameter file or the id of a sut mapped to this id, or nil if no direct or mapped match was found
249
- # === raises
250
- # ArgumentError:: The id argument was not a Symbol
251
- def find_sut_or_mapping( id )
262
+ @_sut_list[ id ][ :sut ].connect( id )
263
+ @_sut_list[ id ][ :is_connected ] = true
252
264
 
253
- Kernel::raise ArgumentError.new( "The id argument was not a Symbol." ) unless id.kind_of?( Symbol )
265
+ end
254
266
 
255
- begin
267
+ @_sut_list[ id ][ :sut ]
268
+ end
256
269
 
257
- # check if direct match exists
258
- return id if MobyUtil::Parameter[ id ]
270
+ def sut_exists?( sut_id )
259
271
 
260
- rescue MobyUtil::ParameterNotFoundError
272
+ @_sut_list.has_key?( sut_id )
261
273
 
262
- # check if a mapping is defined for the id
263
- begin
274
+ end
264
275
 
265
- # return nil if no mapping exists
266
- return nil if ( mapped_id = MobyUtil::Parameter[ :mappings ][ id ] ).nil?
276
+ # Finds the sut definition matching the id, either directly or via a mapping
277
+ #
278
+ # === params
279
+ # sut_id:: Symbol defining the id of the sut to search for
280
+ # === returns
281
+ # Symbol:: Either id if it was found in the parameter file or the id of a sut mapped to this id, or nil if no direct or mapped match was found
282
+ # === raises
283
+ # ArgumentError:: The id argument was not a Symbol
284
+ def find_sut_or_mapping( sut_id )
267
285
 
268
- # check if the mapped to sut id exists
269
- return mapped_id if MobyUtil::Parameter[ ( mapped_id = mapped_id.to_sym ) ]
286
+ sut_id.check_type( Symbol, "Wrong argument type $1 for SUT id (expected $2)" )
287
+
288
+ #Kernel::raise ArgumentError.new( "The id argument was not a Symbol." ) unless sut_id.kind_of?( Symbol )
270
289
 
271
- rescue MobyUtil::ParameterNotFoundError
290
+ begin
272
291
 
273
- # no mappings defined in tdriver_parameters.xml or the mapped to sut was not found
274
- return nil
292
+ # check if direct match exists
293
+ return sut_id if MobyUtil::Parameter[ sut_id ]
275
294
 
276
- end # check if mapping exists
295
+ rescue MobyUtil::ParameterNotFoundError
277
296
 
278
- end # check if direct match exists
297
+ # check if a mapping is defined for the id
298
+ begin
279
299
 
280
- end
300
+ # return nil if no mapping exists
301
+ return nil if ( mapped_id = MobyUtil::Parameter[ :mappings ][ sut_id ] ).nil?
302
+
303
+ # check if the mapped to sut id exists
304
+ return mapped_id if MobyUtil::Parameter[ ( mapped_id = mapped_id.to_sym ) ]
305
+
306
+ rescue MobyUtil::ParameterNotFoundError
307
+
308
+ # no mappings defined in tdriver_parameters.xml or the mapped to sut was not found
309
+ return nil
310
+
311
+ end # check if mapping exists
312
+
313
+ end # check if direct match exists
314
+
315
+ end
281
316
 
282
- # enable hooking for performance measurement & debug logging
283
- MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
317
+ # enable hooking for performance measurement & debug logging
318
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
284
319
 
285
- end # SUTFactory
320
+ end # SUTFactory
286
321
 
287
322
  end # MobyBase