Module: MobyController::QT::KeySequence

Includes:
Abstraction
Defined in:
lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb

Instance Method Summary collapse

Instance Method Details

#make_messageObject

Creates service command message which will be sent to @sut_adapter by execute method

params

returns

raises



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/testability-driver-plugins/testability-driver-qt-sut-plugin/controllers/key_sequence.rb', line 32

def make_message

  press_types = { :KeyDown => 'KeyPress', :KeyUp => 'KeyRelease' }

  sut = @_sut

  keymap = $parameters[ sut.id ][ :keymap ]

  sequence = @sequence
  
  message = Nokogiri::XML::Builder.new{

    TasCommands( :id => sut.application.id, :transitions => 'true', :service => 'uiCommand' ){

      Target( :TasId => 'FOCUSWIDGET', :type => 'Standard' ){

        sequence.each{ | key_press |

          key_press[ :value ].tap{ | key |

            # raise exception if value type other than Fixnum or Symbol
            raise ArgumentError, "Wrong argument type #{ key.class } for key (expected: Symbol or Fixnum)" unless [ Fixnum, Symbol ].include?( key.class ) 

            # verify that keymap is defined for sut if symbol used. 
            raise ArgumentError, "Symbol #{ key.inspect } cannot be used due to no keymap defined for #{ sut.id } in TDriver configuration file." if key.kind_of?( Symbol ) && keymap.nil?

            # fetch keycode from keymap
            key = TDriver::KeymapUtilities.fetch_keycode( key, keymap )

            # retrieve corresponding scan code (type of string, convert to fixnum) for symbol from keymap if available 
            key = key.hex if key.kind_of?( String )

            # raise exception if value is other than fixnum
            raise ArgumentError, "Scan code for #{ key.inspect } not defined in keymap" unless key.kind_of?( Fixnum )
    
            # determine keypress type
            press_type = press_types.fetch( key_press[ :type ], 'KeyClick' )

            Command( key.to_s, "name" => press_type.to_s, "modifiers" => "0", "delay" => "0")

          }

        }

      }
      
    }
    
  }.to_xml

  Comms::MessageGenerator.generate( message )

end