testability-driver-qt-sut-plugin 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/env.rb +26 -0
  2. data/installer/extconf.rb +62 -0
  3. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin.rb +23 -0
  4. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/action.rb +156 -0
  5. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/application.rb +318 -0
  6. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/attribute.rb +227 -0
  7. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/behaviour.rb +140 -0
  8. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/configure_behaviour.rb +317 -0
  9. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/events.rb +165 -0
  10. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/file_transfer.rb +333 -0
  11. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/find.rb +80 -0
  12. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/fixture.rb +178 -0
  13. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/gesture.rb +906 -0
  14. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/infologger.rb +604 -0
  15. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/key_press.rb +152 -0
  16. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/locale_db.rb +151 -0
  17. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/method.rb +85 -0
  18. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/multitouch.rb +455 -0
  19. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/os.rb +100 -0
  20. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/qt_api_method.rb +148 -0
  21. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/record.rb +124 -0
  22. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/screen_capture.rb +283 -0
  23. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/sut.rb +492 -0
  24. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/synchronization.rb +113 -0
  25. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/treewidgetitemcolumn.rb +93 -0
  26. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/type_text.rb +97 -0
  27. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/view_item.rb +97 -0
  28. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/webkit.rb +230 -0
  29. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/behaviours/widget.rb +663 -0
  30. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/action.rb +30 -0
  31. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/configure_command.rb +38 -0
  32. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/drag.rb +44 -0
  33. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/find_object.rb +50 -0
  34. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/fixture.rb +45 -0
  35. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/group.rb +48 -0
  36. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/infologger_command.rb +38 -0
  37. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/qt.rb +170 -0
  38. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/tap.rb +54 -0
  39. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/commands/widget.rb +226 -0
  40. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/application.rb +264 -0
  41. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/configure_command.rb +60 -0
  42. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/find_object.rb +114 -0
  43. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/fixture.rb +67 -0
  44. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/group.rb +52 -0
  45. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/infologger_command.rb +62 -0
  46. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb +99 -0
  47. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/screen_capture.rb +54 -0
  48. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/tap.rb +51 -0
  49. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/widget.rb +72 -0
  50. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/plugin.rb +119 -0
  51. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/adapter.rb +225 -0
  52. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/communication.rb +154 -0
  53. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/sut/controller.rb +58 -0
  54. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/fixture_parameter.rb +77 -0
  55. data/lib/testability-driver-plugins/testability-driver-qt-sut-plugin/util/widget.rb +82 -0
  56. data/lib/testability-driver-qt-sut-plugin.rb +24 -0
  57. data/xml/behaviour/qt.xml +717 -0
  58. data/xml/defaults/sut_qt.xml +9 -0
  59. data/xml/keymap/qt.xml +321 -0
  60. data/xml/template/qt.xml +124 -0
  61. metadata +141 -0
@@ -0,0 +1,152 @@
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ # == description
25
+ # KeyPress specific behaviours
26
+ #
27
+ # == behaviour
28
+ # QtKeyPress
29
+ #
30
+ # == requires
31
+ # testability-driver-qt-sut-plugin
32
+ #
33
+ # == input_type
34
+ # *
35
+ #
36
+ # == sut_type
37
+ # qt
38
+ #
39
+ # == sut_version
40
+ # *
41
+ #
42
+ # == objects
43
+ # *
44
+ #
45
+ module KeyPress
46
+
47
+ include MobyBehaviour::QT::Behaviour
48
+
49
+ # == description
50
+ # Perform key press event or a series of events on an object.
51
+ #
52
+ # == arguments
53
+ # key
54
+ # Symbol
55
+ # description: Symbol of key
56
+ # example: :kRight
57
+ # Integer
58
+ # description: Scan code of key
59
+ # example: 0x01000001
60
+ # MobyCommand::KeySequence
61
+ # description: Sequence of key and press types, see [link="#GenericSut:press_key"]KeySequence reference[/link].
62
+ # example: MobyCommand::KeySequence.new( :kTab, :KeyDown )
63
+ #
64
+ # == returns
65
+ # NilClass
66
+ # description: nil
67
+ # example: nil
68
+ #
69
+ # == exceptions
70
+ # ArgumentError
71
+ # description: Wrong argument type %s for key (Expected: %s)
72
+ # ArgumentError
73
+ # description: Scan code for :%s not defined in keymap
74
+ # ArgumentError
75
+ # description: Error occured during keypress (Response: %s)
76
+ def press_key( key )
77
+
78
+ begin
79
+
80
+ command = command_params
81
+ command.command_name('KeyPress')
82
+ command.set_require_response( true )
83
+
84
+ # raise exception if value type other than Fixnum or Symbol
85
+ Kernel::raise ArgumentError.new( "Wrong argument type %s for key (Expected: %s)" % [ key.class, "Symbol/Fixnum/KeySequence" ] ) unless [ Fixnum, Symbol, MobyCommand::KeySequence ].include?( key.class )
86
+
87
+ # verify that keymap is defined for sut if symbol used.
88
+ Kernel::raise ArgumentError.new(
89
+
90
+ "Symbol #{ key.inspect } cannot be used due to no keymap defined for #{ @sut.id } in TDriver configuration file."
91
+
92
+ ) if key.kind_of?( Symbol ) && !MobyUtil::Parameter[ @sut.id ].has_key?( :keymap )
93
+
94
+ @key_sequence = nil
95
+ if key.kind_of?( Symbol )
96
+
97
+ scancode = MobyUtil::Parameter[ @sut.id ][ :keymap ][ key, nil ]
98
+ scancode = scancode.hex if scancode.kind_of?( String )
99
+ # raise exception if value is other than fixnum
100
+ Kernel::raise ArgumentError.new( "Scan code for :%s not defined in keymap" % key ) unless scancode.kind_of?( Fixnum )
101
+
102
+ # add scancode for keypress event
103
+ command.command_value( scancode.to_s )
104
+
105
+ elsif key.kind_of?( MobyCommand::KeySequence )
106
+
107
+ @key_sequence = []
108
+ key.get_sequence.each do | key_event |
109
+
110
+ tempcode = MobyUtil::Parameter[ @sut.id ][ :keymap ][ key_event[ :value ], nil ]
111
+ tempcode = tempcode.hex if tempcode.kind_of?( String )
112
+
113
+ press_type = { :KeyDown => 'KeyPress', :KeyUp => 'KeyRelease' }.fetch( key_event[ :type ] ){ "KeyClick" }
114
+ @key_sequence << { :value => tempcode, :params => { :name => press_type, :modifiers => "0", :delay => "0" } }
115
+
116
+ end
117
+ command.command_value( @key_sequence )
118
+ else
119
+
120
+ scancode = key.to_i
121
+
122
+ # raise exception if value is other than fixnum
123
+ Kernel::raise ArgumentError.new( "Scan code for :%s not defined in keymap" % key ) unless scancode.kind_of?( Fixnum )
124
+
125
+ # add scancode for keypress event
126
+ command.command_value( scancode.to_s )
127
+ end
128
+
129
+ # execute command & verify that execution passed ("OK" expected as response)
130
+ @sut.execute_command(command)
131
+ #Kernel::raise RuntimeError.new("Error occured during keypress (Response: %s)" % @response ) unless ( @response = @sut.execute_command(command) ) == "OK"
132
+
133
+ rescue Exception => exception
134
+
135
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed press_key with key \"#{ key }\".;#{ identity };press_key;"
136
+ Kernel::raise exception
137
+
138
+ end
139
+
140
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation press_key executed successfully with key \"#{ key }\".;#{ identity };press_key;"
141
+
142
+ nil
143
+
144
+ end
145
+
146
+ # enable hooking for performance measurement & debug logging
147
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
148
+
149
+ end
150
+
151
+ end
152
+ end
@@ -0,0 +1,151 @@
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
+ require 'tmpdir'
21
+ require 'base64'
22
+
23
+ module MobyBehaviour
24
+
25
+ module QT
26
+
27
+ # == description
28
+ # LocalisationDB specific behaviours
29
+ #
30
+ # == behaviour
31
+ # QtLocalisationDB
32
+ #
33
+ # == requires
34
+ # testability-driver-qt-sut-plugin
35
+ #
36
+ # == input_type
37
+ # *
38
+ #
39
+ # == sut_type
40
+ # qt
41
+ #
42
+ # == sut_version
43
+ # *
44
+ #
45
+ # == objects
46
+ # sut
47
+ #
48
+ module LocalisationDB
49
+
50
+ include MobyBehaviour::QT::Behaviour
51
+
52
+ # == description
53
+ # Creates a new localisation able for translation using the tdriver_parameters to locate the Localization DB.
54
+ # It uses the temporary folder to store temporary translation files.
55
+ #
56
+ # == arguments
57
+ # path
58
+ # String
59
+ # description: Path where the translation files to upload to the database are found
60
+ # example: "/usr/me/tdriver/localization_files"
61
+ #
62
+ # file
63
+ # String
64
+ # description: File names of the translation files to be uploaded.
65
+ # example: "*.ts"
66
+ #
67
+ # database_file
68
+ # String
69
+ # description: If this is provided it will overwrite the value set in the parameter ':localisation_server_database_name'
70
+ # example: "mysqlitedb.sqlite"
71
+ #
72
+ # column_names_map
73
+ # Hash
74
+ # description: Hash with the language codes from the translation files as keys and the desired column names as values
75
+ # example: {"en" => "en_GB"}
76
+ #
77
+ # == returns
78
+ # NilClass
79
+ # description: -
80
+ # example: -
81
+ #
82
+ def create_locale_db(path = "/", file = "*.qm", database_file = nil, column_names_map = {} )
83
+
84
+ db_type = MobyUtil::Parameter[ :localisation_db_type ]
85
+ host = MobyUtil::Parameter[ :localisation_server_ip ]
86
+ database_file = MobyUtil::Parameter[ :localisation_server_database_name ] if database_file.nil?
87
+ username = MobyUtil::Parameter[ :localisation_server_username ]
88
+ password = MobyUtil::Parameter[ :localisation_server_password ]
89
+
90
+ db_connection = MobyUtil::DBConnection.new( db_type, host, database_file, username, password )
91
+ table_name = MobyUtil::Parameter[ :sut_qt ][ :localisation_server_database_tablename, "" ]
92
+
93
+ begin
94
+ tmp_path = MobyUtil::Parameter[:tmp_folder] + "/locale_db_tmp"
95
+ rescue MobyUtil::ParameterNotFoundError
96
+ tmp_path = Dir.tmpdir + "/locale_db_tmp"
97
+ end
98
+
99
+ if (File.directory? tmp_path)
100
+ FileUtils.rm_rf(tmp_path)
101
+ end
102
+
103
+ if (File.directory? tmp_path)
104
+ else
105
+ FileUtils.mkdir(tmp_path)
106
+ end
107
+
108
+ list_of_files = receive_files( path, file, tmp_path )
109
+
110
+ list_of_files.each do |e_file|
111
+ begin
112
+ MobyUtil::Localisation.upload_translation_file( e_file, table_name, db_connection, column_names_map)
113
+ rescue Exception => e
114
+ puts "Error while uploading #{e_file}."
115
+ puts e.message
116
+ end
117
+ end
118
+
119
+ nil
120
+
121
+ end
122
+
123
+ private
124
+
125
+ # == description
126
+ # Receives files from SUT
127
+ #
128
+ def receive_files( device_path, file, tmp_path )
129
+
130
+ list_of_files = fixture( "file", "list_files", {:file_name => file, :file_path => device_path} ).split(';')
131
+ new_list_of_files = Array.new
132
+
133
+ list_of_files.each do |name|
134
+ new_list_of_files.push( tmp_path + "/" + File.basename(name) )
135
+ file = File.open(tmp_path + "/" + File.basename(name), 'w')
136
+ file << Base64.decode64( fixture("file", "read_file", {:file_name => name}) )
137
+ file.close
138
+ end
139
+
140
+ return new_list_of_files
141
+
142
+ end
143
+
144
+ # enable hooking for performance measurement & debug logging
145
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
146
+
147
+ end # LocalisationDB
148
+
149
+ end # QT
150
+
151
+ end # MobyBehaviour
@@ -0,0 +1,85 @@
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ # == description
25
+ # Method specific behaviours
26
+ #
27
+ # == behaviour
28
+ # QtMethod
29
+ #
30
+ # == requires
31
+ # testability-driver-qt-sut-plugin
32
+ #
33
+ # == input_type
34
+ # *
35
+ #
36
+ # == sut_type
37
+ # qt
38
+ #
39
+ # == sut_version
40
+ # *
41
+ #
42
+ # == objects
43
+ # *
44
+ #
45
+ module Method
46
+
47
+ include MobyBehaviour::QT::Behaviour
48
+
49
+ # == description
50
+ # Calls an invokable method of the Qt test object.
51
+ # Slots and signals are automatically invokable, but other methods must be explicitly made invokable.
52
+ # This version does not support method arguments or return values.
53
+ #
54
+ # == arguments
55
+ # method_name
56
+ # String
57
+ # description: name of method to invoke, including empty parenthesis
58
+ # example: "clear()"
59
+ #
60
+ # == returns
61
+ # Undefined
62
+ # description: on success, returns unspecified value of unspecified type
63
+ # example: "OK"
64
+ #
65
+ # == exceptions
66
+ # RuntimeError
67
+ # description: invoking the method failed
68
+ def call_method( method_name )
69
+
70
+ Kernel::raise ArgumentError.new( "Method name was empty" ) if method_name.empty?
71
+ command = command_params #in qt_behaviour
72
+ command.transitions_off
73
+ command.command_name( 'CallMethod' )
74
+ command.command_params( 'method_name' => method_name.to_s )
75
+ command.service( 'objectManipulation' )
76
+ returnValue = @sut.execute_command( command )
77
+ Kernel::raise RuntimeError.new( "Calling method '%s' failed with error: %s" % [ method_name, returnValue ] ) if ( returnValue != "OK" )
78
+ end
79
+
80
+ # enable hooking for performance measurement & debug logging
81
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
82
+
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,455 @@
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 MobyBehaviour
21
+
22
+ module QT
23
+
24
+ # == description
25
+ # Behaviours for multitouch operations.
26
+ #
27
+ # == behaviour
28
+ # QtMultitouch
29
+ #
30
+ # == requires
31
+ # testability-driver-qt-sut-plugin
32
+ #
33
+ # == input_type
34
+ # touch
35
+ #
36
+ # == sut_type
37
+ # qt
38
+ #
39
+ # == sut_version
40
+ # *
41
+ #
42
+ # == objects
43
+ # *
44
+ #
45
+ module Multitouch
46
+
47
+ include MobyBehaviour::QT::Behaviour
48
+
49
+ # == description
50
+ # Performs a pinch zoom in operation. The distance of the operation is
51
+ # is for both fingers. So a distance of 100 will be performed by both
52
+ # end points (fingers).
53
+ #
54
+ # == arguments
55
+ # speed
56
+ # Integer
57
+ # description: Speed of the operation in seconds
58
+ # example: 3
59
+ #
60
+ # distance
61
+ # Integer
62
+ # description: Distance of the pinch zoom
63
+ # example: 100
64
+ #
65
+ # direction
66
+ # Integer
67
+ # description: Direction of the pinch zoom in degrees 0-180
68
+ # example: 90
69
+ # Symbol
70
+ # description: Direction of the pinch zoom either :Horizontal or :Vertical
71
+ # example: :Horizontal
72
+ #
73
+ # differential
74
+ # Integer
75
+ # description: The difference from where the zoom starts or ends (how far apart are the fingers when starting the zoom)
76
+ # example: 10
77
+ #
78
+ # == returns
79
+ # NilClass
80
+ # description: -
81
+ # example: -
82
+ #
83
+ # == exceptions
84
+ # ArgumentError
85
+ # description: In case the given parameters are not valid.
86
+ #
87
+ # == info
88
+ # See method pinch_zoom
89
+ #
90
+ def pinch_zoom_in(speed, distance, direction, differential = 10)
91
+ pinch_zoom({:type => :in, :speed => speed, :distance_1 => distance, :distance_2 => distance, :direction => direction, :differential => differential})
92
+ end
93
+
94
+ # == description
95
+ # Performs a pinch zoom out operation. The distance of the operation is
96
+ # is for both fingers. So a distance of 100 will be performed by both
97
+ # fingers.
98
+ #
99
+ # == arguments
100
+ # speed
101
+ # Integer
102
+ # description: Speed of the operation in seconds
103
+ # example: 3
104
+ #
105
+ # distance
106
+ # Integer
107
+ # description: Distance of the pinch zoom
108
+ # example: 100
109
+ #
110
+ # direction
111
+ # Integer
112
+ # description: Direction of the pinch zoom in degrees 0-180
113
+ # example: 90
114
+ # Symbol
115
+ # description: Direction of the pinch zoom either :Horizontal or :Vertical
116
+ # example: :Horizontal
117
+ #
118
+ # differential
119
+ # Integer
120
+ # description: The difference from where the zoom starts or ends (how far apart are the fingers when starting the zoom)
121
+ # example: 10
122
+ #
123
+ # == returns
124
+ # NilClass
125
+ # description: -
126
+ # example: -
127
+ #
128
+ # == exceptions
129
+ # ArgumentError
130
+ # description: In case the given parameters are not valid.
131
+ #
132
+ # == info
133
+ # See method pinch_zoom
134
+ #
135
+ def pinch_zoom_out(speed, distance, direction, differential = 10)
136
+ pinch_zoom({:type => :out, :speed => speed, :distance_1 => distance, :distance_2 => distance, :direction => direction, :differential => differential})
137
+ end
138
+
139
+ # == description
140
+ # Causes a pinch zoom gesture on the object. The type of the pinch is based on the given parameters.
141
+ # The parameters make it possible to define various kinds of pinch zoom operations.
142
+ #
143
+ # The image shows how the different parameters will be used to make the pinch gesture.
144
+ # The image show a zoom in type gesture (:type => :in). Direction is the angle of the
145
+ # first part of the pinch gesture against the y axel (0 degrees is up). Distance variables
146
+ # do not have to be the same. This means that you can set the gesture so that one finger
147
+ # moves a longer distance than the other (or even set one distance to 0).
148
+ # The :differential parameter determines the how close the nearest points
149
+ # in the pinch gesture are (:in start points and :out end points).
150
+ # The center points can be set using the :x and :y setting.
151
+ # The values are relative to the object and if not set then the center point of the object is used.
152
+ # \n
153
+ # [img="images/pinch.png"]Pinch zoom parameters[/img]
154
+ #
155
+ # == arguments
156
+ # params
157
+ # Hash
158
+ # description:
159
+ # A Hash table contains all of the parameters required to make the pinch zoom.
160
+ # See [link="#pinch_options_table"]Pinch options table[/link] for valid keys.
161
+ # example: pinch_zoom({:type => :in, :speed => 2, :distance_1 => 100, :distance_2 => 100, :direction => :Vertical, :differential => 10})
162
+ #
163
+ # == tables
164
+ # pinch_options_table
165
+ # title: Pinch options table
166
+ # |Key|Type|Description|Accepted values|Example|Required|
167
+ # |:type|Symbol|Zoom in or out|:in,:out|:type => :in|Yes|
168
+ # |:speed|Integer|Speed of the gesture in seconds|Positive Integer|:speed => 2|Yes|
169
+ # |:distance_1|Integer|Distance of the first finger zoom gesture|Positive integer|:distance_1 => 100|Yes|
170
+ # |:distance_2|Integer|Distance of the second finger zoom gesture|Positive integer|:distance_2 => 100|Yes|
171
+ # |:differential|Integer|The difference from where the zoom starts or ends|Positive integer|:differential => 10|Yes|
172
+ # |:x|Integer|X coordinate of the center point for the pinch (relative to the object). Optional defaults to center point but if set y must also be set.|Positive Integer| :x => 120|No|
173
+ # |:y|Integer|Y coordinate of the center point for the pinch (relative to the object). Optional defaults to center point but if set x must also be set.|Positive Integer|:y => 200|No|
174
+ #
175
+ # == returns
176
+ # NilClass
177
+ # description: -
178
+ # example: -
179
+ #
180
+ # == exceptions
181
+ # ArgumentError
182
+ # description: In case the given parameters are not valid.
183
+ #
184
+ def pinch_zoom(params)
185
+
186
+ begin
187
+ verify_pinch_params!(params)
188
+
189
+ #convert speed to millis
190
+ time = params[:speed].to_f
191
+ speed = time*1000
192
+ params[:speed] = speed.to_i
193
+ if params[:x].kind_of?(Integer) and params[:y].kind_of?(Integer)
194
+ params[:useCoordinates] = 'true'
195
+ params[:x] = attribute('x_absolute').to_i + params[:x]
196
+ params[:y] = attribute('y_absolute').to_i + params[:y]
197
+ end
198
+ command = command_params #in qt_behaviour
199
+ command.command_name('PinchZoom')
200
+ command.command_params(params)
201
+
202
+ @sut.execute_command( command )
203
+
204
+ #wait untill the pinch is finished
205
+ do_sleep(time)
206
+
207
+ rescue Exception => e
208
+ MobyUtil::Logger.instance.log "behaviour","FAIL;Failed pinch_zoom with params \"#{params.to_s}\".;#{identity};pinch_zoom;"
209
+ Kernel::raise e
210
+ end
211
+ MobyUtil::Logger.instance.log "behaviour","PASS;Operation pinch_zoom succeeded with params \"#{params.to_s}\".;#{identity};pinch_zoom;"
212
+ nil
213
+ end
214
+
215
+ # == description
216
+ # Causes rotation motion on the object. The rotation will be so that one point is stationary
217
+ # while other moves to create a rotation motion (like a hinge).
218
+ #
219
+ # == arguments
220
+ # radius
221
+ # Integer
222
+ # description: Radius of the of the rotation in degrees (distance between the points)
223
+ # example: 100
224
+ #
225
+ # start_angle
226
+ # Integer
227
+ # description: Starting angle of the rotation. Integer from 0-360
228
+ # example: 90
229
+ # Symbol
230
+ # description: Starting angle of the rotation. Symbol :Horizontal or :Vertical
231
+ # example: :Horizontal
232
+ #
233
+ # rotate_direction
234
+ # Symbol
235
+ # description: Rotation direction :Clockwise or :CounterClockwise.
236
+ # example: :CounterClockwise
237
+ #
238
+ # distance
239
+ # Integer
240
+ # description: Distance of the rotation in degrees
241
+ # example: 360
242
+ #
243
+ # speed
244
+ # Integer
245
+ # description: Speed in seconds
246
+ # example: 3
247
+ #
248
+ # center_point
249
+ # Hash
250
+ # description: Optional X and Y coordinates (relative to the object e.g. top left of the object is 0.0).
251
+ # In one point rotation the other end point will remain stationary (the rotation is done around that point)
252
+ # and that will be the given point. If not given the point will be the center of the object.
253
+ # example: {:x => 50, :y => 100}
254
+ #
255
+ # == returns
256
+ # NilClass
257
+ # description: -
258
+ # example: -
259
+ #
260
+ #
261
+ # == exceptions
262
+ # ArgumentError
263
+ # description: In case the given parameters are not valid.
264
+ #
265
+ # == info
266
+ # See method rotate
267
+ #
268
+ def one_point_rotate(radius, start_angle, rotate_direction, distance, speed, center_point = nil)
269
+ params = {:type => :one_point, :radius => radius, :rotate_direction => rotate_direction, :distance => distance, :speed => speed, :direction => start_angle}
270
+ params.merge!(center_point) if center_point
271
+ rotate(params)
272
+ end
273
+
274
+ # == description
275
+ # Causes ratation motion on the object. The rotation will be so that both ends move to create a rotation motion around a point.
276
+ #
277
+ # == arguments
278
+ # radius
279
+ # Integer
280
+ # description: Radius of the of the rotation in degrees (distance between the points)
281
+ # example: 100
282
+ #
283
+ # start_angle
284
+ # Integer
285
+ # description: Starting angle of the rotation. Integer from 0-360
286
+ # example: 90
287
+ # Symbol
288
+ # description: Starting angle of the rotation. Symbol :Horizontal or :Vertical
289
+ # example: :Horizontal
290
+ #
291
+ # rotate_direction
292
+ # Symbol
293
+ # description: Rotation direction :Clockwise or :CounterClockwise.
294
+ # example: :CounterClockwise
295
+ #
296
+ # distance
297
+ # Integer
298
+ # description: Distance of the rotation in degrees
299
+ # example: 360
300
+ #
301
+ # speed
302
+ # Integer
303
+ # description: Speed in seconds
304
+ # example: 3
305
+ #
306
+ # center_point
307
+ # Hash
308
+ # description: Optional X and Y coordinates (relative to the object e.g. top left of the object is 0.0).
309
+ # In two point rotation both end points will rotate around a center point which will be
310
+ # the given point. If not given the point will be the center of the object.
311
+ # example: {:x => 50, :y => 100}
312
+ #
313
+ # == returns
314
+ # NilClass
315
+ # description: -
316
+ # example: -
317
+ #
318
+ # == exceptions
319
+ #
320
+ # ArgumentError
321
+ # description: In case the given parameters are not valid.
322
+ #
323
+ # == info
324
+ # See method rotate
325
+ #
326
+ def two_point_rotate(radius, start_angle, rotate_direction, distance, speed, center_point = nil)
327
+ params = {:type => :two_point, :radius => radius, :rotate_direction => rotate_direction, :distance => distance, :speed => speed, :direction => start_angle}
328
+ params.merge!(center_point) if center_point
329
+ rotate(params)
330
+ end
331
+
332
+ # == description
333
+ # Causes a rotate motion on the screen using two fingers (e.g. like turning a knob). Similar gesture to pinch zooming except the angle changes.
334
+ # \n
335
+ # \n
336
+ # [img="images/rotate.png"]Rotation parameters[/img]
337
+ # \n
338
+ # The image shows how the different parameters will be used to make the rotation gestures in both
339
+ # one point and two point rotations. In one point rotation the other end remains stationary while
340
+ # the other moves around it based on the given radius. In two point rotation the movement is done
341
+ # by both ends. Note the direction paramters as the :direction parameter defines the starting angle
342
+ # for the gesture and :rotation_direction defines the actual rotation direction (clockwise or counter clockwise).
343
+ # When performing two point rotation note that the radius is in fact a radius not the diameter.
344
+ # Distance is given in degrees from 0-360. Center point can be set using :x and :y and if
345
+ # not set the center point of the object will be used.
346
+ #
347
+ # == arguments
348
+ # params
349
+ # Hash
350
+ # description: A hash of the parameters that define the rotation. See [link="#rotate_options_table"]Rotate options table[/link] for valid keys
351
+ #
352
+ # example: {:type => :one_point, :radius => 100, :rotate_direction => :Clockwise, :distance => 45, :speed => 2, :direction => 35, :x => 2, y => 35}
353
+ #
354
+ # == tables
355
+ # rotate_options_table
356
+ # title: Rotate options table
357
+ # |Key|Type|Description|Accepted values|Example|Required|
358
+ # |:type|Symbol|Rotation type|:one_point,:two_point|:type => :one_point|Yes|
359
+ # |:radius|Integer|Radius of the rotatation in pixels|Any positive Integer|:radius => 100|Yes|
360
+ # |:rotation_direction|Symbol|Rotation direction|:Clockwise, :CounterClockwise|:rotate_direction => :Clockwise|Yes|
361
+ # |:distance|Integer|Rotation distance in degrees|0-360|:distance => 90|Yes|
362
+ # |:speed|Integer|Speed of the gesture in seconds|Positive Integer|:speed => 2|Yes|
363
+ # |:direction|Integer/Symbol|The start angle of the rotation.|0-360 or :Horizontal, :Vertical|:direction => 35|Yes|
364
+ # |:x|Integer|X coordinate of the center point for the pinch (relative to the object). Optional defaults to center point but if set y must also be set.|Positive Integer|:x => 50|No|
365
+ # |:y|Integer|Y coordinate of the center point for the pinch (relative to the object). Optional defaults to center point but if set x must also be set.|Positive Integer|:y => 120|No|
366
+ #
367
+ #
368
+ # == returns
369
+ # NilClass
370
+ # description: -
371
+ # example: -
372
+ #
373
+ # == exceptions
374
+ #
375
+ # ArgumentError
376
+ # description: In case the given parameters are not valid.
377
+ #
378
+ def rotate(params)
379
+ begin
380
+ verify_rotate_params!(params)
381
+
382
+ time = params[:speed].to_f
383
+ speed = time*1000
384
+ params[:speed] = speed.to_i
385
+
386
+ if params[:x].kind_of?(Integer) and params[:y].kind_of?(Integer)
387
+ params[:useCoordinates] = 'true'
388
+ params[:x] = attribute('x_absolute').to_i + params[:x]
389
+ params[:y] = attribute('y_absolute').to_i + params[:y]
390
+ end
391
+
392
+ command = command_params #in qt_behaviour
393
+ command.command_name('Rotate')
394
+ command.command_params(params)
395
+
396
+ @sut.execute_command( command )
397
+
398
+ #wait untill the operation to finish
399
+ do_sleep(time)
400
+ rescue Exception => e
401
+ MobyUtil::Logger.instance.log "behaviour","FAIL;Failed rotate with params \"#{params.to_s}\".;#{identity};rotate;"
402
+ Kernel::raise e
403
+ end
404
+ MobyUtil::Logger.instance.log "behaviour","PASS;Operation rotate succeeded with params \"#{params.to_s}\".;#{identity};rotate;"
405
+ nil
406
+ end
407
+
408
+ private
409
+
410
+ def verify_rotate_params!(params)
411
+ raise ArgumentError.new( "Invalid type allowed valued(:sector, :acrs)." ) unless params[:type] == :one_point or params[:type] == :two_point
412
+ raise ArgumentError.new("Speed must be a number.") unless params[:speed].kind_of?(Numeric)
413
+
414
+ #direction
415
+ if params[:direction].kind_of?(Integer)
416
+ raise ArgumentError.new("Direction must be between 0 and 360.") unless params[:direction] >= 0 and params[:direction] < 360
417
+ else
418
+ raise ArgumentError.new( "Invalid direction." ) unless @@_pinch_directions.include?(params[:direction])
419
+ params[:direction] = @@_pinch_directions[params[:direction]]
420
+ end
421
+
422
+ raise ArgumentError.new("Distance must be an integer.") unless params[:distance].kind_of?(Integer)
423
+ raise ArgumentError.new("Distance must be between 0 and 360") unless params[:distance] > 0 and params[:distance] <= 360
424
+
425
+ raise ArgumentError.new("Invalid direction must be " + @@_rotate_direction.to_s) unless @@_rotate_direction.include?(params[:rotate_direction])
426
+ raise ArgumentError.new("Radius must be an integer.") unless params[:radius].kind_of?(Integer)
427
+ end
428
+
429
+ def verify_pinch_params!(params)
430
+ #type
431
+ raise ArgumentError.new( "Invalid type allowed valued(:in, :out)." ) unless params[:type] == :in or params[:type] == :out
432
+ #speed
433
+ raise ArgumentError.new("Speed must be a number.") unless params[:speed].kind_of?(Numeric)
434
+ #distance
435
+ raise ArgumentError.new("Distance 1 must be an integer.") unless params[:distance_1].kind_of?(Integer)
436
+ raise ArgumentError.new("Distance 2 must be an integer.") unless params[:distance_2].kind_of?(Integer)
437
+ #direction
438
+ if params[:direction].kind_of?(Integer)
439
+ raise ArgumentError.new( "Invalid direction." ) unless 0 <= params[:direction].to_i and params[:direction].to_i <= 180
440
+ else
441
+ raise ArgumentError.new( "Invalid direction." ) unless @@_pinch_directions.include?(params[:direction])
442
+ params[:direction] = @@_pinch_directions[params[:direction]]
443
+ end
444
+ #differential
445
+ raise ArgumentError.new("Differential must be an integer.") unless params[:differential].kind_of?(Integer)
446
+ end
447
+
448
+ # enable hooking for performance measurement & debug logging
449
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
450
+
451
+ end # Multitouch
452
+
453
+ end # QT
454
+
455
+ end # MobyBehaviour