testability-driver-qt-sut-plugin 1.1.1 → 1.2.0

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 (40) hide show
  1. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/action.rb +7 -6
  2. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/application.rb +190 -182
  3. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/attribute.rb +2 -2
  4. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/behaviour.rb +17 -17
  5. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/configure_behaviour.rb +6 -6
  6. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/events.rb +6 -6
  7. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/find.rb +2 -2
  8. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fixture.rb +10 -14
  9. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fps.rb +7 -7
  10. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/gesture.rb +387 -338
  11. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/infologger.rb +177 -5
  12. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/key_press.rb +5 -5
  13. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/locale_db.rb +2 -1
  14. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/method.rb +34 -7
  15. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/multitouch.rb +4 -4
  16. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/os.rb +4 -4
  17. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/record.rb +6 -6
  18. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/screen_capture.rb +8 -12
  19. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/settings.rb +8 -8
  20. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/sut.rb +171 -115
  21. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/synchronization.rb +2 -2
  22. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/treewidgetitemcolumn.rb +11 -7
  23. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/type_text.rb +2 -2
  24. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/view_item.rb +5 -5
  25. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/webkit.rb +13 -13
  26. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/widget.rb +54 -63
  27. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/find_object.rb +45 -28
  28. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/version.rb +34 -0
  29. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/widget.rb +2 -2
  30. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/application.rb +174 -121
  31. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb +35 -26
  32. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/version.rb +56 -0
  33. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/plugin.rb +64 -16
  34. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/adapter.rb +138 -40
  35. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb +91 -83
  36. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/find_object_generator.rb +222 -44
  37. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/message_composer.rb +176 -10
  38. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/widget.rb +2 -2
  39. data/xml/behaviour/qt.xml +12 -0
  40. metadata +7 -5
@@ -0,0 +1,56 @@
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 TDriver.
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 MobyController
21
+
22
+ module QT
23
+
24
+ module VersionCommand
25
+
26
+ # Execute the command
27
+ # Sends the message to the device using the @sut_adapter (see base class)
28
+ # == params
29
+ # == returns
30
+ # == raises
31
+ # NotImplementedError: raised if unsupported command type
32
+ def execute
33
+
34
+ # TODO: message contructed with builder
35
+ @sut_adapter.send_service_request(
36
+
37
+ MobyController::QT::Comms::MessageGenerator.generate( "<TasCommands service=\"versionService\" />" ), false
38
+
39
+ )
40
+
41
+ end
42
+
43
+ def set_adapter( adapter )
44
+
45
+ @sut_adapter = adapter
46
+
47
+ end
48
+
49
+ # enable hooking for performance measurement & debug logging
50
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
51
+
52
+ end # VersionCommand
53
+
54
+ end # QT
55
+
56
+ end # MobyController
@@ -100,29 +100,37 @@ module MobyPlugin
100
100
  # returns SUT object - this method will be called from MobyBase::SUTFactory
101
101
  def self.make_sut( sut_id )
102
102
 
103
- # create sut object
104
- MobyBase::SUT.new(
103
+ # retrieve sut specific parameters
104
+ sut_parameters = $parameters[ sut_id ]
105
105
 
106
- # create controller for sut
107
- MobyBase::SutController.new(
106
+ # create sut adapter
107
+ adapter = MobyController::QT::SutAdapter.new(
108
+
109
+ # sut id
110
+ sut_id,
111
+
112
+ # tcp/ip read timeouts, default: 15 (seconds)
113
+ $parameters[ sut_id ][ :socket_read_timeout, "15" ].to_i,
114
+
115
+ # tcp/ip write timeouts, default: 15 (seconds)
116
+ $parameters[ sut_id ][ :socket_write_timeout, "15" ].to_i
117
+
118
+ )
108
119
 
109
- # controller id
110
- "QT",
120
+ # create controller for sut
121
+ sut_controller = MobyBase::SutController.new(
111
122
 
112
- # create sut adapter
113
- MobyController::QT::SutAdapter.new(
123
+ # controller id
124
+ "QT",
114
125
 
115
- # sut id
116
- sut_id,
126
+ adapter
117
127
 
118
- # tcp/ip read timeouts, default: 15 (seconds)
119
- $parameters[ sut_id ][ :socket_read_timeout, "15" ].to_i,
128
+ )
120
129
 
121
- # tcp/ip write timeouts, default: 15 (seconds)
122
- $parameters[ sut_id ][ :socket_write_timeout, "15" ].to_i
123
- )
130
+ # create sut object
131
+ sut = MobyBase::SUT.new(
124
132
 
125
- ),
133
+ sut_controller,
126
134
 
127
135
  # pass test object factory class
128
136
  MobyBase::TestObjectFactory.instance,
@@ -131,6 +139,46 @@ module MobyPlugin
131
139
  sut_id
132
140
  )
133
141
 
142
+ # hook connect method
143
+ adapter.add_hook( 'before_connect' ){}
144
+
145
+ # hook connect method
146
+ adapter.add_hook( 'after_connect' ){
147
+
148
+ begin
149
+
150
+ # send service request for agent version number
151
+ agent_version = sut_controller.__send__( :execute_command, MobyCommand::VersionCommand.new )
152
+
153
+ case agent_version
154
+
155
+ when "1.3"
156
+
157
+ # use optimized XML format; if adapter is not found we're going through rescue block
158
+ adapter = TDriver::OptimizedXML::TestObjectAdapter
159
+
160
+ else
161
+
162
+ # didn't recognize the version number use old TDriver::TestObjectAdapter
163
+ raise
164
+
165
+ end
166
+
167
+ rescue
168
+
169
+ # in case of any exceptions use TDriver::TestObjectAdapter with old XML format
170
+ adapter = TDriver::TestObjectAdapter
171
+
172
+ end
173
+
174
+ #sut_controller.test_object_adapter = adapter
175
+ sut.instance_variable_set( :@test_object_adapter, adapter )
176
+
177
+ }
178
+
179
+ # return sut object as result
180
+ sut
181
+
134
182
  end
135
183
 
136
184
  # enable hooking for performance measurement & debug logging
@@ -62,14 +62,31 @@ module MobyController
62
62
  @socket_read_timeout = receive_timeout
63
63
  @socket_write_timeout = send_timeout
64
64
 
65
-
66
65
  @counter = rand( 1000 )
67
66
 
68
- # connect socket
69
- #connect( @sut_id )
67
+ # determine which inflate method to use
68
+ if $parameters[ @sut_id ][ :win_native, false ].to_s == "true"
69
+
70
+ @inflate_method = method( :inflate_windows_native )
71
+
72
+ else
73
+
74
+ @inflate_method = method( :inflate )
75
+
76
+ end
77
+
78
+ @hooks = {}
70
79
 
71
80
  end
72
81
 
82
+ def add_hook( id, &block )
83
+
84
+ raise ArgumentError, 'Unable to add hook due to no block was given' unless block_given?
85
+
86
+ @hooks[ id ] = block
87
+
88
+ end
89
+
73
90
  # TODO: document me
74
91
  def disconnect
75
92
 
@@ -84,19 +101,37 @@ module MobyController
84
101
 
85
102
  id ||= @sut_id
86
103
 
104
+ sut_parameters = $parameters[ id, {} ]
105
+
87
106
  begin
88
107
 
89
- @socket = TCPSocket.open( $parameters[ id ][ :qttas_server_ip ], $parameters[ id ][ :qttas_server_port ].to_i )
108
+ # retrieve ip and verify that value is not empty or nil
109
+ ip = sut_parameters[ :qttas_server_ip, nil ].not_blank( 'Connection failure; QTTAS server IP not defined in SUT configuration' ).to_s
110
+
111
+ # retrieve port and verify that value is not empty or nil
112
+ port = sut_parameters[ :qttas_server_port, nil ].not_blank( 'Connection failure; QTTAS server port not defined in SUT configuration' ).to_i
113
+
114
+ # executes the code block before openning the connection
115
+ execute_hook( 'before_connect', id, ip, port ) if hooked?( 'before_connect' )
116
+
117
+ # open tcp/ip connection
118
+ @socket = TCPSocket.open( ip, port )
119
+
120
+ # set connected status to true
121
+ @connected = true
122
+
123
+ # communication authentication etc can be done here
124
+ execute_hook( 'after_connect', id, ip, port, @socket ) if hooked?( 'after_connect' )
90
125
 
91
- rescue => ex
126
+ rescue
92
127
 
93
- ip = "no ip" if ( ip = $parameters[ id ][ :qttas_server_ip, "" ] ).empty?
94
- port = "no port" if ( port = $parameters[ id ][ :qttas_server_port, "" ] ).empty?
128
+ execute_hook( 'connection_failed', id, ip, port, $! ) if hooked?( 'connection_failed' )
129
+
130
+ raise IOError, "Connection failure; verify that QTTAS server is up and running at #{ ip }:#{ port }.\n Nested exception: #{ $!.message }"
95
131
 
96
- Kernel::raise IOError.new("Unable to connect QTTAS server, verify that it is running properly (#{ ip }:#{ port }): .\nException: #{ ex.message }")
97
132
  end
98
133
 
99
- @connected = true
134
+ true
100
135
 
101
136
  end
102
137
 
@@ -108,7 +143,7 @@ module MobyController
108
143
  end
109
144
 
110
145
  # Set the document builder for the grouped behaviour message.
111
- def set_message_builder(builder)
146
+ def set_message_builder( builder )
112
147
 
113
148
  @_group = true
114
149
 
@@ -119,7 +154,11 @@ module MobyController
119
154
  # TODO: document me
120
155
  def append_command(node_list)
121
156
 
122
- node_list.each {|ch| @_builder.doc.root.add_child(ch)}
157
+ node_list.each { | ch |
158
+
159
+ @_builder.doc.root.add_child( ch )
160
+
161
+ }
123
162
 
124
163
  end
125
164
 
@@ -133,7 +172,11 @@ module MobyController
133
172
 
134
173
  size = @_builder.doc.root.children.size
135
174
 
136
- send_service_request(Comms::MessageGenerator.generate(@_builder.to_xml))
175
+ send_service_request(
176
+
177
+ Comms::MessageGenerator.generate( @_builder.to_xml )
178
+
179
+ )
137
180
 
138
181
  @_builder = nil
139
182
 
@@ -141,6 +184,12 @@ module MobyController
141
184
 
142
185
  end
143
186
 
187
+ def connected?
188
+
189
+ @connected
190
+
191
+ end
192
+
144
193
  # Send the message to the qt server
145
194
  # If there is no exception propagated the send to the device was successful
146
195
  # == params
@@ -149,13 +198,19 @@ module MobyController
149
198
  # the response body
150
199
  def send_service_request( message, return_crc = false )
151
200
 
152
- connect if !@connected
201
+ connect if !@connected
202
+
203
+ # increase message count
204
+ @counter += 1
153
205
 
154
206
  # set request message id
155
- message.message_id = ( @counter += 1 )
207
+ message.message_id = @counter
208
+
209
+ # generate binary message to be sent to socket
210
+ binary_message = message.make_binary_message( @counter )
156
211
 
157
212
  # write request message to socket
158
- write_socket( message.make_binary_message( @counter ) )
213
+ write_socket( binary_message )
159
214
 
160
215
  # read response to determine was the message handled properly and parse the header
161
216
  # header[ 0 ] = command_flag
@@ -164,20 +219,25 @@ module MobyController
164
219
  # header[ 3 ] = compression_flag
165
220
  # header[ 4 ] = message_id
166
221
 
222
+ read_message_id = 0
223
+
167
224
  header = nil
168
225
 
169
226
  body = nil
170
227
 
171
- read_message_id = 0
172
-
173
228
  until read_message_id == @counter
174
229
 
230
+ # read message header from socket, unpack string to array
175
231
  header = read_socket( 12 ).unpack( 'CISCI' )
176
232
 
233
+ # read message body from socket
177
234
  body = read_socket( header[ 1 ] )
178
235
 
236
+ # calculate body crc16 checksum
237
+ crc = TDriver::Checksum.crc16_ibm( body )
238
+
179
239
  # read the message body and compare crc checksum
180
- Kernel::raise IOError, "CRC do not match, response message body may be corrupted!" if CRC::Crc16.crc16_ibm( body, 0xffff ) != header[ 2 ]
240
+ raise IOError, "CRC checksum did not match, response message body is corrupted! (#{ crc } != #{ header[ 2 ] })" if crc != header[ 2 ]
181
241
 
182
242
  # validate response message; check that response message id matches the request
183
243
  # if smaller than expected try to read the next message but if bigger raise error
@@ -185,34 +245,23 @@ module MobyController
185
245
 
186
246
  if read_message_id < @counter
187
247
 
188
- $logger.log "warning", "Response to request did not match: \"#{ header[ 4 ].to_s }\"<\"#{ @counter.to_s }\""
248
+ $logger.warning "Response to request did not match: \"#{ header[ 4 ].to_s }\"<\"#{ @counter.to_s }\""
189
249
 
190
250
  elsif read_message_id > @counter
191
251
 
192
- $logger.log "fatal", "Response to request did not match: \"#{ header[ 4 ].to_s }\">\"#{ @counter.to_s }\""
252
+ $logger.fatal "Response to request did not match: \"#{ header[ 4 ].to_s }\">\"#{ @counter.to_s }\""
193
253
 
194
254
  # save to file?
195
- $logger.log "fatal", body
255
+ $logger.fatal body
196
256
 
197
- Kernel::raise RuntimeError.new( "Response to request did not match: \"#{ header[ 4 ].to_s }\"!=\"#{ @counter.to_s }\"" )
257
+ raise RuntimeError, "Response to request did not match: \"#{ header[ 4 ].to_s }\"!=\"#{ @counter.to_s }\""
198
258
 
199
259
  end
200
260
 
201
261
  end
202
262
 
203
263
  # inflate the message body if compressed
204
- if ( header[ 3 ] == 2 )
205
-
206
- if $parameters[ @sut_id ][ :win_native, false ] == "true"
207
- zstream = Zlib::Inflate.new(-Zlib::MAX_WBITS)
208
- body = zstream.inflate(body) unless body.empty?
209
- else
210
- # remove leading 4 bytes
211
- body = body[ 4 .. -1 ]
212
- body = Zlib::Inflate.inflate( body ) unless body.empty?
213
- end
214
-
215
- end
264
+ body = @inflate_method.call( body ) if ( header[ 3 ] == 2 )
216
265
 
217
266
  # raise exception if messages error flag is set
218
267
  # Flag statuses:
@@ -223,11 +272,11 @@ module MobyController
223
272
 
224
273
  if body =~ /The application with Id \d+ is no longer available/
225
274
 
226
- Kernel::raise MobyBase::ApplicationNotAvailableError, body
275
+ raise MobyBase::ApplicationNotAvailableError, body
227
276
 
228
277
  else
229
278
 
230
- Kernel::raise RuntimeError, body
279
+ raise RuntimeError, body
231
280
 
232
281
  end
233
282
 
@@ -240,6 +289,20 @@ module MobyController
240
289
 
241
290
  private
242
291
 
292
+ # TODO: document me
293
+ def execute_hook( id, *arguments )
294
+
295
+ @hooks[ id ].call( *arguments )
296
+
297
+ end
298
+
299
+ # TODO: document me
300
+ def hooked? ( id )
301
+
302
+ @hooks.has_key?( id )
303
+
304
+ end
305
+
243
306
  # TODO: document me
244
307
  def read_socket( bytes_count )
245
308
 
@@ -247,17 +310,17 @@ module MobyController
247
310
  start_time = Time.now
248
311
 
249
312
  # verify that there is data available to be read
250
- Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] ) if TCPSocket::select( [ @socket ], nil, nil, @socket_read_timeout ).nil?
313
+ raise IOError, "Socket reading timeout (#{ @socket_read_timeout.to_i }) exceeded for #{ bytes_count.to_i } bytes" if TCPSocket::select( [ @socket ], nil, nil, @socket_read_timeout ).nil?
251
314
 
252
315
  # read data from socket
253
316
  read_buffer = @socket.read( bytes_count ){
254
317
 
255
- Kernel::raise IOError.new( "Socket reading timeout (%i) exceeded for %i bytes" % [ @socket_read_timeout, bytes_count ] ) if ( Time.now - start_time ) > @socket_read_timeout
318
+ raise IOError, "Socket reading timeout (#{ @socket_read_timeout.to_i }) exceeded for #{ bytes_count.to_i } bytes" if ( Time.now - start_time ) > @socket_read_timeout
256
319
 
257
320
  }
258
321
 
259
322
  # useless?
260
- Kernel::raise IOError.new( "Socket reading error for %i bytes - No data retrieved" % [ bytes_count ] ) if read_buffer.nil?
323
+ raise IOError, "Socket reading error for #{ bytes_count.to_i } bytes - No data retrieved" if read_buffer.nil?
261
324
 
262
325
  @socket_received_bytes += read_buffer.size
263
326
 
@@ -331,7 +394,7 @@ module MobyController
331
394
  @socket.write( data )
332
395
 
333
396
  # verify that there is no data in writing buffer
334
- Kernel::raise IOError.new( "Socket writing timeout (%i) exceeded for %i bytes" % [ @socket_write_timeout, data.length ] ) if TCPSocket::select( nil, [ @socket ], nil, @socket_write_timeout ).nil?
397
+ raise IOError, "Socket writing timeout (#{ @socket_write_timeout.to_i }) exceeded for #{ data.length.to_i } bytes" if TCPSocket::select( nil, [ @socket ], nil, @socket_write_timeout ).nil?
335
398
 
336
399
  =begin
337
400
 
@@ -367,6 +430,41 @@ module MobyController
367
430
 
368
431
  end
369
432
 
433
+ private
434
+
435
+ # inflate to be used in native windows env.
436
+ def inflate_windows_native( body )
437
+
438
+ unless body.empty?
439
+
440
+ Zlib::Inflate.new( -Zlib::MAX_WBITS ).inflate( body )
441
+
442
+ else
443
+
444
+ body
445
+
446
+ end
447
+
448
+ end
449
+
450
+ # inflate to be used by default
451
+ def inflate( body )
452
+
453
+ # remove leading 4 bytes
454
+ tmp = body[ 4 .. -1 ]
455
+
456
+ unless tmp.empty?
457
+
458
+ Zlib::Inflate.inflate( tmp )
459
+
460
+ else
461
+
462
+ tmp
463
+
464
+ end
465
+
466
+ end
467
+
370
468
  # enable hooking for performance measurement & debug logging
371
469
  TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
372
470