testability-driver 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -19,6 +19,7 @@
19
19
  # Generic configuration file for sut data.
20
20
  # Can be used to provide ruby code for sut configurations.
21
21
  module SutParameters
22
+
22
23
  # Verify blocks define the verify_always blocks that are automatically added to given sut.
23
24
  # Takes an array of VerifyBlock objects
24
25
  # VerifyBlock parameters:
@@ -27,13 +28,25 @@ module SutParameters
27
28
  # - Error message
28
29
  # Configured verify_always blocks will not return the failed error block code in the error message.
29
30
  VERIFY_BLOCKS = [
30
- # Example block
31
- MobyUtil::VerifyBlock.new(
32
- Proc.new { |sut|
33
- # Verifies that some application is always running
34
- sut.application.name != "qttasserver"
35
- },
36
- true, "Top most application is qttas, no application is running")
37
- ]
31
+
32
+ # Example block
33
+ MobyUtil::VerifyBlock.new(
34
+
35
+ # proc block to execute
36
+ Proc.new{ |sut|
37
+ # Verifies that some application is always running
38
+ sut.application.name != "qttasserver"
39
+ },
40
+
41
+ # expected return value
42
+ true,
43
+
44
+ # error message
45
+ "Top most application is qttas, no application is running"
46
+
47
+ )
48
+
49
+ ]
50
+
38
51
  end
39
52
 
@@ -0,0 +1,83 @@
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 TDriverCustomErrorRecovery
21
+
22
+ # This method is called by TDriver Reporter when error is detected in connection
23
+ # === params
24
+ # === returns
25
+ # === raises
26
+ def error_in_connection()
27
+
28
+ end
29
+
30
+ # This method is called by TDriver Reporter when test set execution is starting
31
+ # === params
32
+ # === returns
33
+ # === raises
34
+ def starting_test_set_run()
35
+
36
+ end
37
+
38
+ # This method is called by TDriver Reporter when test case execution is starting
39
+ # === params
40
+ # test_case: the test case name
41
+ # connected_suts: All the connected TDriver suts
42
+ # === returns
43
+ # === raises
44
+ def starting_test_case(test_case,connected_suts)
45
+
46
+ end
47
+
48
+ # This method is called by TDriver Reporter when a error is detected in test case execution
49
+ # === params
50
+ # connected_suts: All the connected TDriver suts
51
+ # === returns
52
+ # === raises
53
+ def error_in_test_case(connected_suts)
54
+
55
+ end
56
+
57
+ # This method is called by TDriver Reporter when test case details are updated
58
+ # === params
59
+ # details: Execution details recived from the current test case
60
+ # === returns
61
+ # === raises
62
+ def updating_test_case_details(details)
63
+
64
+ end
65
+
66
+ # This method is called by TDriver Reporter when test case execution is ended
67
+ # === params
68
+ # connected_suts: All the connected TDriver suts
69
+ # === returns
70
+ # === raises
71
+ def ending_test_case(status,connected_suts)
72
+
73
+ end
74
+
75
+ # This method is called by TDriver Reporter when test set execution is ending
76
+ # === params
77
+ # === returns
78
+ # === raises
79
+ def ending_test_set_run()
80
+
81
+ end
82
+
83
+ end
data/ext/extconf.rb CHANGED
@@ -29,8 +29,9 @@ MobyUtil::GemHelper.install( MobyUtil::FileHelper.tdriver_home ){ | tdriver_home
29
29
  [ "../xml/parameters/tdriver_parameters.xml", "tdriver_parameters.xml", false ],
30
30
  [ "../xml/parameters/tdriver_parameters.xml", "default/tdriver_parameters.xml", true ],
31
31
  [ "../config/sut_parameters.rb", "sut_parameters.rb", true ],
32
- [ "../config/sut_setup.rb", "sut_setup.rb", true ],
33
- [ "../config/sut_teardown.rb", "sut_teardown.rb", true ],
32
+ [ "../config/sut_setup.rb", "sut_setup.rb", false ],
33
+ [ "../config/sut_teardown.rb", "sut_teardown.rb", false ],
34
+ [ "../config/tdriver_custom_error_recovery.rb", "tdriver_custom_error_recovery.rb", false ],
34
35
 
35
36
  # templates
36
37
  [ "../xml/templates/*.xml", "templates/", true ],
@@ -30,6 +30,7 @@ static const CRC_16[ 16 ] = {
30
30
 
31
31
  };
32
32
 
33
+ /*
33
34
  static VALUE crc16_ibm( VALUE self, VALUE string ) {
34
35
 
35
36
  // verify argument type
@@ -55,16 +56,73 @@ static VALUE crc16_ibm( VALUE self, VALUE string ) {
55
56
 
56
57
  return INT2FIX( ~crc & 0xffff );
57
58
 
59
+ }
60
+ */
61
+
62
+ //static VALUE crc16_ibm( VALUE self, VALUE string, VALUE unused_crc ) {
63
+ static VALUE crc16_ibm( int argc, VALUE* argv, VALUE self ) {
64
+ //klass VALUE self, VALUE string, VALUE unused_crc ) {
65
+
66
+ // variables for arguments
67
+ VALUE string, initial_crc;
68
+
69
+ // retrieve arguments
70
+ rb_scan_args(argc, argv, "11", &string, &initial_crc);
71
+
72
+ int crc; // = 0xffff;
73
+
74
+ if (NIL_P(initial_crc)){
75
+
76
+ crc = 0xffff;
77
+
78
+ } else {
79
+
80
+ // verify initial crc value
81
+ Check_Type( initial_crc, T_FIXNUM );
82
+
83
+ crc = NUM2INT( initial_crc );
84
+
85
+ }
86
+
87
+ // verify argument type
88
+ Check_Type( string, T_STRING );
89
+
90
+ const char* data = RSTRING_PTR( string );
91
+
92
+ int len = RSTRING_LEN( string );
93
+
94
+ int c = 0;
95
+
96
+ while( len-- ){
97
+
98
+ c = *data++;
99
+
100
+ crc = ( crc >> 4 ) ^ CRC_16[ ( crc ^ c ) & 15 ];
101
+
102
+ crc = ( crc >> 4 ) ^ CRC_16[ ( crc ^ ( c >> 4 ) ) & 15 ];
103
+
104
+ }
105
+
106
+ return INT2FIX( ~crc & 0xffff );
107
+
108
+
58
109
  }
59
110
 
60
111
  void Init_native_extensions() {
61
112
 
113
+ // main tdriver module
62
114
  VALUE mTDriver = rb_define_module( "TDriver" );
63
115
 
64
- VALUE mNativeExtensions = rb_define_module_under( mTDriver, "NativeExtensions" );
116
+ // checksum module
117
+ VALUE cChecksum = rb_define_class_under( mTDriver, "Checksum", rb_cObject );
118
+
119
+ // checksum methods
120
+ rb_define_singleton_method( cChecksum, "crc16_ibm", crc16_ibm, -1 );
65
121
 
122
+ // deprecated - for backwards compatibility
123
+ VALUE mNativeExtensions = rb_define_module_under( mTDriver, "NativeExtensions" );
66
124
  VALUE mCRC = rb_define_module_under( mNativeExtensions, "CRC" );
125
+ rb_define_singleton_method( mCRC, "crc16_ibm", crc16_ibm, -1 );
67
126
 
68
- rb_define_singleton_method( mCRC, "crc16_ibm", crc16_ibm, 1 );
69
127
 
70
128
  }
@@ -92,31 +92,7 @@ module MobyBehaviour
92
92
  # app.QPushButton( :text => "Close" ).flick :Left
93
93
  #
94
94
  def flick( direction, button = :Left, optional_params = {} )
95
-
96
- begin
97
- use_tap_screen = optional_params[:use_tap_screen].nil? ? MobyUtil::Parameter[ @sut.id][ :use_tap_screen, 'false'] :
98
- optional_params[:use_tap_screen].to_s
99
- optional_params[:useTapScreen] = use_tap_screen
100
-
101
- speed = calculate_speed(@sut.parameter(:gesture_flick_distance), @sut.parameter(:gesture_flick_speed))
102
- distance = @sut.parameter(:gesture_flick_distance).to_i
103
- params = {:gesture_type => :MouseGesture, :direction => direction, :speed => speed, :distance => distance, :isDrag => false, :button => button, :useTapScreen => use_tap_screen}
104
- params.merge!(optional_params)
105
-
106
- do_gesture(params)
107
- do_sleep(speed)
108
-
109
- rescue Exception => e
110
-
111
- MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed flick with direction \"#{direction}\", button \"#{button.to_s}\".;#{identity};flick;"
112
- Kernel::raise e
113
- end
114
-
115
- MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation flick executed successfully with direction \"#{direction}\", button \"#{button.to_s}\".;#{identity};flick;"
116
-
117
- nil
118
- end
119
-
95
+ end
120
96
 
121
97
  private
122
98
 
@@ -126,98 +102,19 @@ module MobyBehaviour
126
102
  # gesture_type: :MouseGesture, :MouseGestureTo, :MouseGestureToCoordinates
127
103
  # params = {:direction => :Up, duration => 2, :distance =>100, :isDrag =>false, :isMove =>false }
128
104
  def do_gesture(params)
129
- validate_gesture_params!(params)
130
-
131
- if attribute('objectType') == 'Embedded'
132
- params['x'] = center_x
133
- params['y'] = center_y
134
- params['useCoordinates'] = 'true'
135
- end
136
-
137
- command = command_params #in qt_behaviour
138
- command.command_name(params[:gesture_type].to_s)
139
- command.command_params( params )
140
- @sut.execute_command( command )
141
105
  end
142
106
 
143
- def validate_gesture_params!(params)
144
- #direction
145
- if params[:gesture_type] == :MouseGesture
146
- if params[:direction].kind_of?(Integer)
147
- raise ArgumentError.new( "Invalid direction." ) unless 0 <= params[:direction].to_i and params[:direction].to_i <= 360
148
- else
149
- raise ArgumentError.new( "Invalid direction." ) unless @@_valid_directions.include?(params[:direction])
150
- params[:direction] = @@_direction_map[params[:direction]]
151
- end
152
- #distance
153
- params[:distance] = params[:distance].to_i unless params[:distance].kind_of?(Integer)
154
- raise ArgumentError.new( "Distance must be an integer and greater than zero." ) unless params[:distance] > 0
155
- elsif params[:gesture_type] == :MouseGestureToCoordinates
156
- raise ArgumentError.new("X and Y must be integers.") unless params[:x].kind_of?(Integer) and params[:y].kind_of?(Integer)
157
- elsif params[:gesture_type] == :MouseGestureTo
158
- raise ArgumentError.new("targetId and targetType must be defined.") unless params[:targetId] and params[:targetType]
159
- end
160
-
161
- #duration/speed
162
- params[:speed] = params[:speed].to_f unless params[:speed].kind_of?(Numeric)
163
- raise ArgumentError.new( "Duration must be a number and greated than zero, was:" + params[:speed].to_s) unless params[:speed] > 0
164
- duration_secs = params[:speed].to_f
165
- duration_secs = duration_secs*1000
166
- params[:speed] = duration_secs.to_i
167
-
168
- #mouseMove true always
169
- params[:mouseMove] = true
170
-
171
- params[:button] = :Left unless params[:button]
172
- raise ArgumentError.new( "Invalid button." ) unless @@_valid_buttons.include?(params[:button])
173
- params[:button] = @@_buttons_map[params[:button]]
174
-
175
- if params[:isMove] == true
176
- params[:press] = 'false'
177
- params[:release] = 'false'
178
- end
179
-
180
- end
181
-
182
-
183
107
  def do_sleep(time)
184
-
185
- if MobyUtil::Parameter[ @sut.id ][ :sleep_disabled, nil ] != 'true'
186
- time = time.to_f
187
- time = time * 1.3
188
- #for flicks the duration of the gesture is short but animation (scroll etc..) may not
189
- #so wait at least one second
190
- time = 1 if time < 1
191
- sleep time
192
- end
193
-
194
108
  end
195
109
 
196
110
  def calculate_speed(distance, speed)
197
-
198
- distance = distance.to_f
199
- speed = speed.to_f
200
- duration = distance/speed
201
- duration
202
-
203
111
  end
204
112
 
205
113
  def distance_to_point(x, y)
206
-
207
- x = x.to_i
208
- y = y.to_i
209
- dist_x = x - center_x.to_i
210
- dist_y = y - center_y.to_i
211
-
212
- return 0 if dist_y == 0 and dist_x == 0
213
- distance = Math.hypot( dist_x, dist_y )
214
- distance
215
-
216
114
  end
217
115
 
218
116
  end
219
117
 
220
118
  end
221
- end
222
119
 
223
- MobyUtil::Logger.instance.hook_methods( MobyBehaviour::QT::Gesture )
120
+ end
@@ -199,19 +199,19 @@ module MobyBase
199
199
 
200
200
  rescue MobyUtil::EmptyFilenameError
201
201
 
202
- Kernel::raise EmptyFilenameError.new( "Unable to load behaviours xml file due to filename is empty or nil" )
202
+ raise EmptyFilenameError, "Unable to load behaviours xml file due to filename is empty or nil"
203
203
 
204
- rescue MobyUtil::FileNotFoundError => ex
204
+ rescue MobyUtil::FileNotFoundError
205
205
 
206
- Kernel::raise ex
206
+ raise
207
207
 
208
- rescue IOError => ex
208
+ rescue IOError
209
209
 
210
- Kernel::raise IOError.new("Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, ex.message ] )
210
+ raise IOError, "Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, $!.message ]
211
211
 
212
- rescue => ex
212
+ rescue
213
213
 
214
- Kernel::raise RuntimeError.new( "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, ex.message, ex.class ] )
214
+ raise RuntimeError, "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, $!.message, $!.class ]
215
215
 
216
216
  end
217
217
 
@@ -223,111 +223,175 @@ module MobyBase
223
223
 
224
224
  behaviour_files.each{ | behaviours |
225
225
 
226
- begin
226
+ begin
227
227
 
228
- # skip parsing the xml if string is empty
229
- next if behaviours[ :xml ].empty?
228
+ # skip parsing the xml if string is empty
229
+ next if behaviours[ :xml ].empty?
230
230
 
231
- # parse behaviour xml
232
- document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
231
+ # parse behaviour xml
232
+ document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
233
233
 
234
- rescue => exception
234
+ rescue
235
235
 
236
- Kernel::raise MobyUtil::XML::ParseError.new(
237
- "Error occured while parsing behaviour XML file %s. Error: %s " % [ behaviours[ :filename ], exception.message ]
238
- )
236
+ raise MobyUtil::XML::ParseError, "Error occured while parsing behaviour XML file #{ behaviours[ :filename ] }. Error: #{ $!.message }"
239
237
 
240
- end
238
+ end
241
239
 
242
- # retrieve root attributes
243
- root_attributes = document.root.xpath( "/behaviours" ).first.attributes
240
+ # process each behaviours element
241
+ document.root.xpath( "/behaviours" ).each{ | behaviours_element |
242
+
243
+ # retrieve root attributes
244
+ root_attributes = behaviours_element.attributes
244
245
 
245
- # parse retrieve behaviour definitions
246
- document.root.xpath( "/behaviours/behaviour" ).each{ | node |
246
+ # process each behaviour element
247
+ behaviours_element.xpath( "behaviour" ).each{ | node |
247
248
 
248
- # retrieve behaviour attributes & module node
249
- attributes = node.attributes
249
+ # retrieve behaviour attributes & module node
250
+ attributes = node.attributes
250
251
 
251
- name = attributes[ "name" ].to_s
252
- object_type = attributes[ "object_type" ].to_s
253
- input_type = attributes[ "input_type" ].to_s
254
- sut_type = attributes[ "sut_type" ].to_s
255
- version = attributes[ "version" ].to_s
252
+ name = attributes[ "name" ].to_s
253
+ object_type = attributes[ "object_type" ].to_s
254
+ input_type = attributes[ "input_type" ].to_s
255
+ sut_type = attributes[ "sut_type" ].to_s
256
+ version = attributes[ "version" ].to_s
256
257
 
257
- env = ( attributes[ "env" ] || '*' ).to_s
258
+ env = ( attributes[ "env" ] || '*' ).to_s
258
259
 
259
- module_node = node.xpath( 'module' ).first
260
-
261
- name = attributes[ "name" ].to_s
262
- object_type = attributes[ "object_type" ].to_s
263
- input_type = attributes[ "input_type" ].to_s
264
- sut_type = attributes[ "sut_type" ].to_s
265
- version = attributes[ "version" ].to_s
266
-
267
- # verify that all required attributes and nodes are found in behaviour xml node
268
- #Kernel::raise RuntimeError.new("Behaviour does not have a name, please see behaviour XML files") if name.empty?
269
- name.not_empty("Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError)
270
-
271
- #Kernel::raise RuntimeError.new("Behaviour target object type not defined for #{ name } in XML") if object_type.empty?
272
- object_type.not_empty("Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
260
+ module_node = node.xpath( 'module' ).first
261
+
262
+ # verify that all required attributes and nodes are found in behaviour xml node
263
+ name.not_empty "Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError
264
+
265
+ object_type.not_empty "Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
273
266
 
274
- #Kernel::raise RuntimeError.new("Behaviour target object input type not defined for #{ name } in XML") if input_type.empty?
275
- input_type.not_empty("Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
267
+ input_type.not_empty "Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
276
268
 
277
- #Kernel::raise RuntimeError.new("Behaviour target object sut type not defined for #{ name } in XML") if sut_type.empty?
278
- sut_type.not_empty("Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
269
+ sut_type.not_empty "Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
279
270
 
280
- #Kernel::raise RuntimeError.new("Behaviour target object sut version not defined for #{ name } in XML") if version.empty?
281
- version.not_empty("Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
271
+ version.not_empty "Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
282
272
 
283
- #Kernel::raise RuntimeError.new("Behaviour implementation module not defined for #{ name } in XML") if module_node.nil?
284
- module_node.not_nil("Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError)
285
-
286
- # retrieve module name & implementation filename
287
- module_attributes = module_node.attributes
288
- module_file = module_attributes[ "file" ].to_s # optional
289
- module_name = module_attributes[ "name" ].to_s
290
-
291
- #Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
292
- module_name.not_empty("Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError)
273
+ module_node.not_nil "Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError
274
+
275
+ # retrieve module name & implementation filename
276
+ module_attributes = module_node.attributes
277
+ module_file = module_attributes[ "file" ].to_s # optional
278
+ module_name = module_attributes[ "name" ].to_s
279
+
280
+ module_name.not_empty "Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError
293
281
 
294
- methods_hash = {}
282
+ methods_hash = {}
295
283
 
296
- # create hash of methods
297
- node.xpath( 'methods/method' ).each{ | method |
284
+ # create hash of methods
285
+ node.xpath( 'methods/method' ).each{ | method |
298
286
 
299
- # retrieve method description & example and store to methods hash
300
- methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
287
+ # retrieve method description & example and store to methods hash
288
+ methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
289
+ :description => method.at_xpath( 'description/text()' ).to_s,
290
+ :example => method.at_xpath( 'example/text()' ).to_s
291
+ }
301
292
 
302
- :description => method.at_xpath( 'description/text()' ).to_s,
293
+ }
294
+
295
+ # create and store beahaviour hash
296
+ @@behaviours << {
297
+
298
+ :name => name,
299
+ :requires => root_attributes[ "plugin" ].to_s.split(";"),
300
+ :object_type => object_type.split(";"),
301
+ :input_type => input_type.split(";"),
302
+ #:sut_type => sut_type.split(";"),
303
+ :version => version.split(";"),
304
+ :env => env.split(";"),
305
+
306
+ :module => {
307
+ :file => module_file,
308
+ :name => module_name
309
+ },
310
+
311
+ :methods => methods_hash
312
+
313
+ }
303
314
 
304
- :example => method.at_xpath( 'example/text()' ).to_s
305
315
 
306
316
  }
307
317
 
308
318
  }
309
319
 
310
- # create and store beahaviour hash
311
- @@behaviours << {
320
+ =begin
312
321
 
313
- :name => name,
314
- :requires => root_attributes[ "plugin" ].to_s.split(";"),
315
- :object_type => object_type.split(";"),
316
- :input_type => input_type.split(";"),
317
- # :sut_type => sut_type.split(";"),
318
- :version => version.split(";"),
319
- :env => env.split(";"),
322
+ # parse retrieve behaviour definitions
323
+ document.root.xpath( "/behaviours/behaviour" ).each{ | node |
320
324
 
321
- :module => {
322
- :file => module_file,
323
- :name => module_name
324
- },
325
+ # retrieve behaviour attributes & module node
326
+ attributes = node.attributes
325
327
 
326
- :methods => methods_hash
328
+ name = attributes[ "name" ].to_s
329
+ object_type = attributes[ "object_type" ].to_s
330
+ input_type = attributes[ "input_type" ].to_s
331
+ sut_type = attributes[ "sut_type" ].to_s
332
+ version = attributes[ "version" ].to_s
327
333
 
328
- }
334
+ env = ( attributes[ "env" ] || '*' ).to_s
329
335
 
330
- }
336
+ module_node = node.xpath( 'module' ).first
337
+
338
+ # verify that all required attributes and nodes are found in behaviour xml node
339
+ name.not_empty("Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError)
340
+
341
+ object_type.not_empty("Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
342
+
343
+ input_type.not_empty("Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
344
+
345
+ sut_type.not_empty("Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
346
+
347
+ version.not_empty("Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
348
+
349
+ module_node.not_nil("Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError)
350
+
351
+ # retrieve module name & implementation filename
352
+ module_attributes = module_node.attributes
353
+ module_file = module_attributes[ "file" ].to_s # optional
354
+ module_name = module_attributes[ "name" ].to_s
355
+
356
+ #Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
357
+ module_name.not_empty("Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError)
358
+
359
+ methods_hash = {}
360
+
361
+ # create hash of methods
362
+ node.xpath( 'methods/method' ).each{ | method |
363
+
364
+ # retrieve method description & example and store to methods hash
365
+ methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
366
+ :description => method.at_xpath( 'description/text()' ).to_s,
367
+ :example => method.at_xpath( 'example/text()' ).to_s
368
+ }
369
+
370
+ }
371
+
372
+ # create and store beahaviour hash
373
+ @@behaviours << {
374
+
375
+ :name => name,
376
+ :requires => root_attributes[ "plugin" ].to_s.split(";"),
377
+ :object_type => object_type.split(";"),
378
+ :input_type => input_type.split(";"),
379
+ #:sut_type => sut_type.split(";"),
380
+ :version => version.split(";"),
381
+ :env => env.split(";"),
382
+
383
+ :module => {
384
+ :file => module_file,
385
+ :name => module_name
386
+ },
387
+
388
+ :methods => methods_hash
389
+
390
+ }
391
+
392
+ }
393
+
394
+ =end
331
395
 
332
396
  }
333
397
 
@@ -413,20 +477,21 @@ module MobyBase
413
477
 
414
478
  end
415
479
 
416
-
417
480
  def get_behaviour_from_cache( target, sut_type, object_type, sut_version, input_type )
418
481
 
419
482
  if @_behaviour_cache.has_key?( object_type )
420
483
 
421
- # apply modules to target object
422
- @_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
484
+ # apply modules to target object
485
+ @_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
423
486
 
424
- # return true
425
- true
487
+ # return true
488
+ true
426
489
 
427
490
  else
428
- # return false
429
- false
491
+
492
+ # return false
493
+ false
494
+
430
495
  end
431
496
 
432
497
  end