testability-driver 1.1.0 → 1.1.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.
@@ -679,6 +679,7 @@ module MobyBehaviour
679
679
 
680
680
  else
681
681
 
682
+ =begin
682
683
  # execute the application control service request
683
684
  execute_command(
684
685
 
@@ -689,11 +690,30 @@ module MobyBehaviour
689
690
  self,
690
691
  target[ :arguments ],
691
692
  target[ :environment ],
693
+ target[ :working_directory ],
692
694
  target[ :events_to_listen ],
693
695
  target[ :signals_to_listen ]
694
696
  )
695
697
 
696
698
  )
699
+ =end
700
+
701
+ # execute the application control service request
702
+ execute_command(
703
+ MobyCommand::Application.new(
704
+ :Run,
705
+ {
706
+ :application_name => target[ :name ],
707
+ :application_uid => target[ :uid ],
708
+ :sut => self,
709
+ :arguments => target[ :arguments ],
710
+ :environment => target[ :environment ],
711
+ :working_directory => target[ :working_directory ],
712
+ :events_to_listen => target[ :events_to_listen ],
713
+ :signals_to_listen => target[ :signals_to_listen ]
714
+ }
715
+ )
716
+ )
697
717
 
698
718
  end
699
719
 
@@ -1374,12 +1394,23 @@ module MobyBehaviour
1374
1394
 
1375
1395
  else
1376
1396
 
1397
+ =begin
1377
1398
  app_command = MobyCommand::Application.new(
1378
1399
  :State,
1379
1400
  refresh_args[ :FullName ] || refresh_args[ :name ],
1380
1401
  refresh_args[ :id ],
1381
1402
  self
1382
1403
  )
1404
+ =end
1405
+
1406
+ app_command = MobyCommand::Application.new(
1407
+ :State,
1408
+ {
1409
+ :application_name => refresh_args[ :FullName ] || refresh_args[ :name ],
1410
+ :application_uid => refresh_args[ :id ],
1411
+ :sut => self
1412
+ }
1413
+ )
1383
1414
 
1384
1415
  # store in case needed
1385
1416
  app_command.refresh_args( refresh_args )
@@ -1410,11 +1441,12 @@ module MobyBehaviour
1410
1441
 
1411
1442
  end
1412
1443
 
1413
- fetch_references( @xml_data )
1414
-
1444
+ # fetch_references( @xml_data )
1445
+ @xml_data
1415
1446
  end
1416
1447
 
1417
1448
  # TODO: document me
1449
+ # Usage disable for now.
1418
1450
  def fetch_references( xml )
1419
1451
 
1420
1452
  pids = []
@@ -1456,6 +1488,7 @@ module MobyBehaviour
1456
1488
 
1457
1489
  begin
1458
1490
 
1491
+ =begin
1459
1492
  subdata =
1460
1493
  MobyUtil::XML.parse_string(
1461
1494
  execute_command(
@@ -1468,6 +1501,7 @@ module MobyBehaviour
1468
1501
  nil,
1469
1502
  nil,
1470
1503
  nil,
1504
+ nil,
1471
1505
  {
1472
1506
  'x_parent_absolute' => x_prev,
1473
1507
  'y_parent_absolute' => y_prev,
@@ -1477,6 +1511,26 @@ module MobyBehaviour
1477
1511
  )
1478
1512
  )[ 0 ]
1479
1513
  )
1514
+ =end
1515
+
1516
+ subdata =
1517
+ MobyUtil::XML.parse_string(
1518
+ execute_command(
1519
+ MobyCommand::Application.new(
1520
+ :State,
1521
+ {
1522
+ :application_uid => pid,
1523
+ :sut => self,
1524
+ :flags => {
1525
+ 'x_parent_absolute' => x_prev,
1526
+ 'y_parent_absolute' => y_prev,
1527
+ 'embedded' => 'true',
1528
+ 'parent_size' => winSize
1529
+ }
1530
+ }
1531
+ )
1532
+ )[ 0 ]
1533
+ )
1480
1534
 
1481
1535
  child = subdata.root.xpath('//object')[0]
1482
1536
 
@@ -17,12 +17,244 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
-
21
20
  module MobyCommand
22
21
 
22
+ class Application < MobyCommand::CommandData
23
+
24
+ =begin
25
+ attr_reader(
26
+
27
+ :command_type,
28
+ :application_name,
29
+ :application_uid,
30
+ :sut,
31
+ :application_arguments,
32
+ :events_to_listen,
33
+ :signals_to_listen,
34
+ :working_directory,
35
+ :flags,
36
+ :start_command,
37
+
38
+ :refresh_arguments,
39
+ :attribute_csv_string
40
+
41
+
42
+ :_arguments,
43
+ :_environment,
44
+ :_working_directory,
45
+ :_events_to_listen,
46
+ :_start_command,
47
+ :_application_uid,
48
+ :_application_name,
49
+ :_command,
50
+ :_application_name,
51
+ :_application_uid,
52
+ :_flags,
53
+ :_attribute_csv_string,
54
+ :_signals_to_listen,
55
+ :_sut,
56
+ :_refresh_args
57
+
58
+ )
59
+ =end
60
+
61
+ attr_reader :command_arguments
62
+
63
+ # TODO: document me
64
+ def initialize( command, arguments = {} )
65
+
66
+ arguments.check_type Hash, "wrong argument type $1 for #{ self.class } arguments (expected $2)"
67
+
68
+ # default values
69
+ arguments.default = nil
70
+
71
+ @command_arguments = arguments
72
+
73
+ self.command( command )
74
+
75
+ # store values from arguments
76
+ self.name( arguments[ :application_name ] )
77
+ self.uid( arguments[ :application_uid ] )
78
+ self.sut( arguments[ :sut ] )
79
+ self.arguments( arguments[ :arguments ] )
80
+ self.events_to_listen( arguments[ :events_to_listen ] )
81
+ self.signals_to_listen( arguments[ :signals_to_listen ] )
82
+ self.environment( arguments[ :environment ] )
83
+ self.working_directory( arguments[ :working_directory ] )
84
+ self.flags( arguments[ :flags ] )
85
+ self.start_command( arguments[ :start_command ] )
86
+ self.refresh_args( arguments[ :refresh_arguments ] )
87
+ self.attribute_filter( arguments[ :attribute_filter ] )
88
+
89
+ self
90
+
91
+ end
92
+
93
+ # Store the args for possible future use
94
+ def refresh_args(refresh_args={})
95
+ @_refresh_args = refresh_args
96
+ end
97
+
98
+ def get_refresh_args
99
+ @_refresh_args
100
+ end
101
+
102
+
103
+ # Defines the type of command this Application CommandData object represents
104
+ # == params
105
+ # command_type:: Symbol, defines the command to perform on the application
106
+ # == returns
107
+ # Application:: This CommandData object
108
+ # == raises
109
+ # ArgumentError:: When the supplied command_type is invalid.
110
+ def command( command_type )
111
+
112
+ @_command = command_type
113
+
114
+ self
115
+
116
+ end
117
+
118
+ # Defines the used SUT to be able to access parameters when creating messages
119
+ # == params
120
+ # sut:: SUT, creator of the command.
121
+ # == returns
122
+ # Application:: This CommandData object
123
+ # == raises
124
+ # ArgumentError:: When sut is not nil or a SUT
125
+ def sut( sut )
126
+
127
+ raise ArgumentError.new( "The given sut must be nil or a SUT." ) unless sut == nil || sut.kind_of?( MobyBase::SUT )
128
+ @_sut = sut
129
+ self
130
+
131
+ end
132
+
133
+ # Defines the name of the application this Application CommandData object is associated with
134
+ # == params
135
+ # app_name:: String, name of application to perform this command on
136
+ # == returns
137
+ # Application:: This CommandData object
138
+ # == raises
139
+ # ArgumentError:: When app_name is not nil or a String
140
+ def name( app_name )
141
+
142
+ raise ArgumentError.new( "The given application name must be nil or a String." ) unless app_name == nil || app_name.kind_of?( String )
143
+ @_application_name = app_name
144
+ self
145
+
146
+ end
147
+
148
+ def arguments( arguments )
149
+
150
+ raise ArgumentError.new( "The given application arguments must be nil or a String." ) unless arguments == nil || arguments.kind_of?( String )
151
+ @_arguments = arguments
152
+
153
+ end
154
+
155
+ def flags( flags )
156
+
157
+ raise ArgumentError.new( "The given application flags must be nil or a Hash." ) unless flags == nil || flags.kind_of?( Hash )
158
+ @_flags = flags
159
+
160
+ end
161
+
162
+ def environment( environment )
163
+
164
+ raise ArgumentError.new( "The given application environment must be nil or a String." ) unless environment == nil || environment.kind_of?( String )
165
+ @_environment = environment
166
+
167
+ end
168
+
169
+ def working_directory( working_directory )
170
+
171
+ raise ArgumentError.new( "The given application working directory must be nil or a String." ) unless working_directory == nil || working_directory.kind_of?( String )
172
+ @_working_directory = working_directory
173
+
174
+ end
175
+
176
+ def events_to_listen( events )
177
+
178
+ raise ArgumentError.new( "The events to listen must be nil or a String." ) unless events == nil || events.kind_of?( String )
179
+ @_events_to_listen = events
180
+
181
+ end
182
+
183
+ def signals_to_listen( signals )
184
+
185
+ raise ArgumentError.new( "The signals to listen must be nil or a String." ) unless signals == nil || signals.kind_of?( String )
186
+ @_signals_to_listen = signals
187
+
188
+ end
189
+
190
+ def start_command( start_command )
191
+
192
+ raise ArgumentError.new( "The start_command must be nil or a String." ) unless start_command == nil || start_command.kind_of?( String )
193
+ @_start_command = start_command
194
+
195
+ end
196
+
197
+ # Defines the uid of the application this Application CommandData object is associated with
198
+ # == params
199
+ # app_uid:: FixNum, uid of application to perform this command on
200
+ # == returns
201
+ # Application:: This CommandData object
202
+ # == raises
203
+ # ArgumentError:: When app_name is not nil or a String
204
+ def uid( app_uid )
205
+
206
+ raise ArgumentError.new( "The given application uid must be nil, a String or an Integer." ) unless app_uid == nil || app_uid.kind_of?( String ) || app_uid.kind_of?( Fixnum )
207
+ @_application_uid = app_uid
208
+ @_application_uid = @_application_uid.to_i unless @_application_uid == nil
209
+ self
210
+
211
+ end
212
+
213
+ def get_command
214
+
215
+ @_command
216
+
217
+ end
218
+
219
+ def get_application
220
+
221
+ @_application_name
222
+
223
+ end
224
+
225
+ def get_uid
226
+
227
+ @_application_uid
228
+
229
+ end
230
+
231
+ def get_flags
232
+
233
+ @_flags
234
+
235
+ end
236
+
237
+ def attribute_filter(attribute_string)
238
+
239
+ @_attribute_csv_string = attribute_string
240
+
241
+ end
242
+
243
+ def get_attribute_filter
244
+
245
+ @_attribute_csv_string
246
+
247
+ end
248
+
249
+ # enable hooking for performance measurement & debug logging
250
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
251
+
252
+ end
253
+
254
+ =begin
255
+
23
256
  class Application < MobyCommand::CommandData
24
257
 
25
- #TODO: Team TE review @ Wheels
26
258
  #Application command types
27
259
  #Launch application = :Run
28
260
  #Close application = :Close
@@ -38,11 +270,13 @@ module MobyCommand
38
270
  # app_uid::
39
271
  # sut:: (optional) SUT, creator of the command. Can be used to access parameters when creating messages.
40
272
  # arguments:: (optional) Arguments given to the application on start up. Comma separated list if more the one.
273
+ # environment:: (optional) Environment given to the application on start up. Comma separated list if more the one.
274
+ # working_directory:: (optional) Working directory for the application (not used on Symbian)
41
275
  # == returns
42
276
  # Application:: New CommandData object
43
277
  # == raises
44
278
  # ArgumentError:: When the supplied command_type is invalid.
45
- def initialize( command_type = nil, app_name = nil, app_uid = nil, sut = nil, arguments = nil, environment = nil, events_to_listen = nil, signals_to_listen = nil, flags = nil, start_command = nil)
279
+ def initialize( command_type = nil, app_name = nil, app_uid = nil, sut = nil, arguments = nil, environment = nil, working_directory = nil, events_to_listen = nil, signals_to_listen = nil, flags = nil, start_command = nil)
46
280
  # Set status value to nil (not executed)
47
281
 
48
282
  self.command( command_type )
@@ -53,9 +287,10 @@ module MobyCommand
53
287
  self.events_to_listen( events_to_listen )
54
288
  self.signals_to_listen( signals_to_listen )
55
289
  self.environment( environment )
290
+ self.working_directory( working_directory )
56
291
  self.flags( flags )
57
292
  self.start_command( start_command )
58
- self.refresh_args
293
+ self.refresh_args
59
294
 
60
295
  @_attribute_csv_string = nil
61
296
 
@@ -138,6 +373,13 @@ module MobyCommand
138
373
 
139
374
  end
140
375
 
376
+ def working_directory( working_directory )
377
+
378
+ raise ArgumentError.new( "The given application working directory must be nil or a String." ) unless working_directory == nil || working_directory.kind_of?( String )
379
+ @_working_directory = working_directory
380
+
381
+ end
382
+
141
383
  def events_to_listen( events )
142
384
 
143
385
  raise ArgumentError.new( "The events to listen must be nil or a String." ) unless events == nil || events.kind_of?( String )
@@ -215,5 +457,7 @@ module MobyCommand
215
457
  TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
216
458
 
217
459
  end # Application
460
+ =end
218
461
 
219
462
  end # MobyCommand
463
+
@@ -93,7 +93,7 @@ module MobyPlugin
93
93
  TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
94
94
 
95
95
  # register plugin
96
- MobyUtil::PluginService.instance.register_plugin( self ) # Note: self is MobyPlugin::Generic::SUT
96
+ TDriver::PluginService.register_plugin( self )
97
97
 
98
98
  end # SUT
99
99
 
@@ -26,12 +26,9 @@ module TDriver
26
26
 
27
27
  private
28
28
 
29
- # special cases: allow partial match when value of type and attribute name matches
30
- @@partial_match_allowed = [ 'list_item', 'text' ], [ 'application', 'fullname' ]
31
-
32
29
  # TODO: document me
33
30
  def xpath_attributes( attributes, element_attributes, object_type )
34
-
31
+
35
32
  # collect attributes
36
33
  attributes = attributes.collect{ | key, values |
37
34
 
@@ -41,20 +38,35 @@ module TDriver
41
38
  # concatenate string if it contains single and double quotes, otherwise return as is
42
39
  value = xpath_literal_string( value )
43
40
 
44
- if @@partial_match_allowed.include?( [ object_type, key ] )
41
+ prefix_key = "@#{ key }"
42
+
43
+ if @partial_match_allowed.include?( [ object_type, key ] )
44
+
45
+ # regexp support is needed also here
45
46
 
46
47
  prefix_value = "[contains(.,#{ value })]"
47
48
  attribute_value = "contains(value/.,#{ value })"
48
49
 
49
50
  else
50
51
 
51
- prefix_value = "=#{ value }"
52
- attribute_value = "value/.=#{ value }"
52
+ if value.kind_of?( Regexp )
53
+
54
+ prefix_value = "regexp_compare(#{ prefix_key },'#{ value.source }',#{ value.options })"
55
+ attribute_value = "regexp_compare(value/.,'#{ value.source }',#{ value.options })"
56
+
57
+ prefix_key = ""
58
+
59
+ else
60
+
61
+ prefix_value = "=#{ value }"
62
+ attribute_value = "value/.=#{ value }"
53
63
 
64
+ end
65
+
54
66
  end
55
67
 
56
68
  # construct xpath
57
- "(#{ element_attributes ? "@#{ key }#{ prefix_value } or " : "" }attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ key }' and #{ attribute_value }])"
69
+ "(#{ element_attributes ? "#{ prefix_key }#{ prefix_value } or " : "" }attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ key }' and #{ attribute_value }])"
58
70
 
59
71
  }.join( ' or ' ) # join attribute alternative values
60
72
 
@@ -74,14 +86,37 @@ module TDriver
74
86
  end
75
87
 
76
88
  end # xpath_attributes
89
+
90
+ # TODO: document me
91
+ def initialize_class
92
+
93
+ # special cases: allow partial match when value of type and attribute name matches
94
+ @partial_match_allowed = [ 'list_item', 'text' ], [ 'application', 'fullname' ]
95
+
96
+ end
77
97
 
78
98
  end # static
79
99
 
100
+ # TODO: document me
101
+ def self.regexp_compare( nodeset, source, options )
102
+
103
+ # rebuild defined regexp, used while matching element content
104
+ regexp_object = Regexp.new( source.to_s, options.to_i )
105
+
106
+ # collect all nodes matching with regexp
107
+ nodeset.find_all{ | node | node.content =~ regexp_object }
108
+
109
+ end
110
+
80
111
  # TODO: document me
81
112
  def self.xpath_to_object( rules, find_all_children )
82
113
 
83
114
  # convert hash keys to downcased string
84
- rules = Hash[ rules.collect{ | key, value | [ key.to_s.downcase, value.to_s ] } ]
115
+ rules = Hash[
116
+ rules.collect{ | key, value |
117
+ [ key.to_s.downcase, value.kind_of?( Regexp ) ? value : value.to_s ]
118
+ }
119
+ ]
85
120
 
86
121
  # xpath container array
87
122
  test_object_xpath_array = []
@@ -116,6 +151,8 @@ module TDriver
116
151
  # TODO: document me
117
152
  def self.xpath_literal_string( string )
118
153
 
154
+ return string if string.kind_of?( Regexp )
155
+
119
156
  # make sure that argument is type of string
120
157
  string = string.to_s
121
158
 
@@ -176,9 +213,11 @@ module TDriver
176
213
  # TODO: document me
177
214
  def self.get_objects( source_data, rules, find_all_children )
178
215
 
216
+ rule = xpath_to_object( rules, find_all_children )
217
+
179
218
  [
180
219
  # perform xpath to source xml data
181
- source_data.xpath( rule = xpath_to_object( rules, find_all_children ) ),
220
+ source_data.xpath( rule, self ),
182
221
 
183
222
  # return also created xpath
184
223
  rule
@@ -311,7 +350,7 @@ module TDriver
311
350
  # retrieve attribute(s) from xml
312
351
  nodeset = source_data.xpath(
313
352
 
314
- "attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ attribute_name.downcase }']"
353
+ "attributes/attribute[translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='#{ attribute_name.downcase }']/value"
315
354
 
316
355
  )
317
356
 
@@ -347,7 +386,7 @@ module TDriver
347
386
  # Kernel::raise MobyBase::MultipleAttributesFoundError.new( "Multiple attributes found with name '%s'" % name ) if nodeset.count > 1
348
387
 
349
388
  # return found attribute
350
- nodeset.first.content.strip
389
+ nodeset.first.content
351
390
 
352
391
  end
353
392
 
@@ -420,12 +459,21 @@ module TDriver
420
459
  # skip if child accessor is already created
421
460
  next if test_object.respond_to?( object_type )
422
461
 
423
- # create child accessor method to test object unless already exists
424
- test_object.instance_eval(
462
+ begin
463
+
464
+ # create child accessor method to test object unless already exists
465
+ test_object.instance_eval(
425
466
 
426
- "def #{ object_type }( rules = {} ); raise TypeError,'parameter <rules> should be hash' unless rules.kind_of?( Hash ); rules[ :type ]=:#{ object_type }; child( rules ); end;"
467
+ "def #{ object_type }( rules = {} ); raise TypeError,'parameter <rules> should be hash' unless rules.kind_of?( Hash ); rules[ :type ]=:#{ object_type }; child( rules ); end;"
427
468
 
428
- ) unless object_type.empty?
469
+ ) unless object_type.empty?
470
+
471
+ # in case if object type has some invalid characters, e.g. type is "ns:object"
472
+ rescue SyntaxError
473
+
474
+ warn "warning: unable to create accessor to child test object whose type is #{ object_type.inspect }"
475
+
476
+ end
429
477
 
430
478
  }
431
479
 
@@ -605,6 +653,9 @@ module TDriver
605
653
  # enable hooking for performance measurement & debug logging
606
654
  TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
607
655
 
656
+ # initialize TDriver::TestObjectAdapter
657
+ initialize_class
658
+
608
659
  end # TestObjectAdapter
609
660
 
610
661
  end # TDriver