testability-driver 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/bin/tdriver-devtools +0 -0
  2. data/config/sut_setup.rb +32 -0
  3. data/config/sut_teardown.rb +32 -0
  4. data/ext/extconf.rb +3 -1
  5. data/lib/tdriver-devtools/behaviour/old/xml/update +0 -0
  6. data/lib/tdriver-devtools/behaviour/xml/generate.rb +0 -0
  7. data/lib/tdriver-devtools/doc/update +0 -0
  8. data/lib/tdriver-devtools/doc/xslt/update +0 -0
  9. data/lib/tdriver-devtools/tdriver-devtools.rb +0 -0
  10. data/lib/tdriver-devtools/tests/feature_tests/output/application_closable_0x3f.feature +10 -0
  11. data/lib/tdriver-devtools/tests/feature_tests/output/application_close.feature +15 -0
  12. data/lib/tdriver-devtools/tests/feature_tests/output/application_environment.feature +10 -0
  13. data/lib/tdriver-devtools/tests/feature_tests/output/application_executable_name.feature +10 -0
  14. data/lib/tdriver-devtools/tests/feature_tests/output/application_uid.feature +10 -0
  15. data/lib/tdriver-devtools/tests/feature_tests/output/created.rid +1 -0
  16. data/lib/tdriver-devtools/tests/feature_tests/output/find_find.feature +15 -0
  17. data/lib/tdriver-devtools/tests/feature_tests/output/flash_behaviour_flash.feature +10 -0
  18. data/lib/tdriver-devtools/tests/feature_tests/output/flash_behaviour_flash_images.feature +15 -0
  19. data/lib/tdriver-devtools/tests/feature_tests/output/sut_application.feature +15 -0
  20. data/lib/tdriver-devtools/tests/feature_tests/output/sut_capture_screen.feature +10 -0
  21. data/lib/tdriver-devtools/tests/feature_tests/output/sut_child.feature +10 -0
  22. data/lib/tdriver-devtools/tests/feature_tests/output/sut_clear_verify_blocks.feature +10 -0
  23. data/lib/tdriver-devtools/tests/feature_tests/output/sut_connect.feature +10 -0
  24. data/lib/tdriver-devtools/tests/feature_tests/output/sut_controller_execution_order.feature +10 -0
  25. data/lib/tdriver-devtools/tests/feature_tests/output/sut_controller_execution_order_0x3d.feature +10 -0
  26. data/lib/tdriver-devtools/tests/feature_tests/output/sut_current_application_id.feature +15 -0
  27. data/lib/tdriver-devtools/tests/feature_tests/output/sut_disconnect.feature +10 -0
  28. data/lib/tdriver-devtools/tests/feature_tests/output/sut_dump_count.feature +15 -0
  29. data/lib/tdriver-devtools/tests/feature_tests/output/sut_freeze.feature +10 -0
  30. data/lib/tdriver-devtools/tests/feature_tests/output/sut_frozen.feature +10 -0
  31. data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_application_id.feature +10 -0
  32. data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_object.feature +10 -0
  33. data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_operator_data.feature +10 -0
  34. data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_ui_dump.feature +15 -0
  35. data/lib/tdriver-devtools/tests/feature_tests/output/sut_get_user_information.feature +10 -0
  36. data/lib/tdriver-devtools/tests/feature_tests/output/sut_input.feature +15 -0
  37. data/lib/tdriver-devtools/tests/feature_tests/output/sut_parameter.feature +15 -0
  38. data/lib/tdriver-devtools/tests/feature_tests/output/sut_press_key.feature +10 -0
  39. data/lib/tdriver-devtools/tests/feature_tests/output/sut_received_data.feature +10 -0
  40. data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh.feature +20 -0
  41. data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh_timeout.feature +15 -0
  42. data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh_tries.feature +15 -0
  43. data/lib/tdriver-devtools/tests/feature_tests/output/sut_refresh_ui_dump.feature +20 -0
  44. data/lib/tdriver-devtools/tests/feature_tests/output/sut_run.feature +10 -0
  45. data/lib/tdriver-devtools/tests/feature_tests/output/sut_sent_data.feature +10 -0
  46. data/lib/tdriver-devtools/tests/feature_tests/output/sut_state.feature +10 -0
  47. data/lib/tdriver-devtools/tests/feature_tests/output/sut_translate.feature +30 -0
  48. data/lib/tdriver-devtools/tests/feature_tests/output/sut_ui_type.feature +10 -0
  49. data/lib/tdriver-devtools/tests/feature_tests/output/sut_ui_version.feature +10 -0
  50. data/lib/tdriver-devtools/tests/feature_tests/output/sut_unfreeze.feature +10 -0
  51. data/lib/tdriver-devtools/tests/feature_tests/output/sut_update.feature +10 -0
  52. data/lib/tdriver-devtools/tests/feature_tests/output/sut_verify_always.feature +20 -0
  53. data/lib/tdriver-devtools/tests/feature_tests/output/sut_verify_blocks.feature +10 -0
  54. data/lib/tdriver-devtools/tests/feature_tests/output/sut_x_path.feature +10 -0
  55. data/lib/tdriver-devtools/tests/feature_tests/output/sut_xml_data.feature +10 -0
  56. data/lib/tdriver-devtools/tests/feature_tests/output/sut_xml_data_0x3d.feature +10 -0
  57. data/lib/tdriver-devtools/tests/feature_tests/output/sut_xml_data_crc.feature +10 -0
  58. data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_power_down.feature +10 -0
  59. data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_power_status.feature +10 -0
  60. data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_power_up.feature +10 -0
  61. data/lib/tdriver-devtools/tests/feature_tests/output/switchbox_behaviour_reset.feature +10 -0
  62. data/lib/tdriver-devtools/tests/feature_tests/output/verification_test_object_exists_0x3f.feature +15 -0
  63. data/lib/tdriver-devtools/tests/feature_tests/update +0 -0
  64. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +4 -4
  65. data/lib/tdriver/base/behaviour/factory.rb +8 -0
  66. data/lib/tdriver/base/sut/generic/behaviours/application.rb +24 -3
  67. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +465 -354
  68. data/lib/tdriver/base/test_object/adapter.rb +2 -2
  69. data/lib/tdriver/base/test_object/behaviours/test_object.rb +22 -5
  70. data/lib/tdriver/base/test_object/cache.rb +1 -1
  71. data/lib/tdriver/base/test_object/factory.rb +23 -3
  72. data/lib/tdriver/env.rb +0 -0
  73. data/lib/tdriver/loader.rb +0 -0
  74. data/lib/tdriver/matti.rb +0 -0
  75. data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +22 -24
  76. data/lib/tdriver/report/report.rb +8 -1
  77. data/lib/tdriver/report/report_api.rb +18 -0
  78. data/lib/tdriver/report/report_combine.rb +1 -1
  79. data/lib/tdriver/report/report_creator.rb +5 -1
  80. data/lib/tdriver/report/report_execution_statistics.rb +105 -78
  81. data/lib/tdriver/report/report_test_case_run.rb +2 -1
  82. data/lib/tdriver/report/report_test_run.rb +187 -116
  83. data/lib/tdriver/report/report_writer.rb +49 -29
  84. data/lib/tdriver/tdriver.rb +14 -3
  85. data/lib/tdriver/util/common/exception.rb +53 -0
  86. data/lib/tdriver/util/common/hash.rb +79 -23
  87. data/lib/tdriver/util/common/numeric.rb +26 -5
  88. data/lib/tdriver/util/common/object.rb +44 -15
  89. data/lib/tdriver/util/common/string.rb +4 -1
  90. data/lib/tdriver/util/filters/dynamic_attributes.rb +2 -1
  91. data/lib/tdriver/util/keymap/keymap.rb +81 -0
  92. data/lib/tdriver/util/loader.rb +4 -1
  93. data/lib/tdriver/util/logger/logger.rb +17 -9
  94. data/lib/tdriver/util/other/config.rb +0 -0
  95. data/lib/tdriver/util/parameter/error.rb +3 -0
  96. data/lib/tdriver/util/parameter/loader.rb +6 -1
  97. data/lib/tdriver/util/parameter/parameter.rb +87 -14
  98. data/lib/tdriver/util/parameter/parameter_new.rb +869 -0
  99. data/lib/tdriver/util/parameter/parameter_template.rb +2 -2
  100. data/lib/tdriver/util/parameter/parameter_user_api.rb +27 -3
  101. data/lib/tdriver/util/parameter/parameter_xml.rb +36 -38
  102. data/lib/tdriver/version.rb +1 -1
  103. data/xml/templates/generic.xml +4 -10
  104. metadata +196 -138
@@ -17,11 +17,14 @@
17
17
  ##
18
18
  ############################################################################
19
19
 
20
+ # extend Ruby String class functionality
20
21
  class String
21
22
 
22
23
  def not_empty( message = "String must not be empty", exception = ArgumentError )
23
24
 
24
- raise exception.new( message ) if self.empty?
25
+ raise exception, message if empty?
26
+
27
+ self
25
28
 
26
29
  end
27
30
 
@@ -68,7 +68,8 @@ module MobyUtil
68
68
  # app.Object.attribute(var)
69
69
  def add_hardcoded_symbol( symbol )
70
70
 
71
- $stderr.puts "warning: DynamicAttributeFilter#add_hardcoded_symbol is deprecated, please use DynamicAttributeFilter#add_attribute instead."
71
+ #$stderr.puts "warning: DynamicAttributeFilter#add_hardcoded_symbol is deprecated; please use DynamicAttributeFilter#add_attribute instead."
72
+ warn "warning: deprecated method DynamicAttributeFilter#add_hardcoded_symbol; please use DynamicAttributeFilter#add_attribute instead"
72
73
 
73
74
  # update filter if new symbols added
74
75
  update_filter_string if add_attribute_to_filter( symbol )
@@ -0,0 +1,81 @@
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 TDriver
21
+
22
+ class KeymapUtilities
23
+
24
+ def self.fetch_keycode( keycode, keymap_hash )
25
+
26
+ # retrieve default keymap name from hash
27
+ keymap = keymap_hash[ :default_keymap ]
28
+
29
+ # convert symbol to string representation for further processing
30
+ keycode_string = keycode.to_s
31
+
32
+ # collect all loaded keymaps, exclude :default_keymap key from hash
33
+ keymaps = keymap_hash.keys.select{ | item | ![ :default_keymap, :all ].include?( item ) }
34
+
35
+ begin
36
+
37
+ # check if environment defined in keycode, e.g. :qt_kDown
38
+ if keycode_string.include?( '_' )
39
+
40
+ if /(#{ keymaps.collect{ | env | "#{ env.to_s }_" }.join('|') })(.+)/i.match( keycode_string )
41
+
42
+ # set new keymap value and convert to symbol, e.g. :qt from :qt_kDown
43
+ keymap = $1.chop.to_sym
44
+
45
+ # set correct keycode value and convert to symbol, e.g. :kDown from :qt_kDown
46
+ keycode = $2.to_sym
47
+
48
+ end
49
+
50
+ # retrieve symbol from keymap
51
+ keymap_hash[ keymap ][ keycode ]
52
+
53
+ else
54
+
55
+ begin
56
+
57
+ # try to retrieve from default keymap; raises exception if key not found
58
+ keymap_hash[ keymap ][ keycode ]
59
+
60
+ rescue
61
+
62
+ # if we didn't find the key, let's try finding from mixed keymap; mixed keymap has all loaded keycodes
63
+ # keycodes are merged to existing hash when loading new keymap on top
64
+ # raises exception if key not found
65
+ keymap_hash[ :all ][ keycode ]
66
+
67
+ end
68
+
69
+ end
70
+
71
+ rescue
72
+
73
+ raise ArgumentError, "Scan code for #{ keycode.inspect } not defined in #{ keymap } keymap"
74
+
75
+ end
76
+
77
+ end
78
+
79
+ end # KeymapUtilities
80
+
81
+ end # TDriver
@@ -62,7 +62,10 @@ require 'rubygems'
62
62
  'recorder/loader.rb',
63
63
 
64
64
  # video capture/util modules
65
- 'video/loader.rb'
65
+ 'video/loader.rb',
66
+
67
+ # keymap utility modules
68
+ 'keymap/keymap.rb'
66
69
 
67
70
  ].each{ | filename |
68
71
 
@@ -178,9 +178,6 @@ module MobyUtil
178
178
 
179
179
  if @logger_engine_loaded
180
180
 
181
- # Allow only FileOutputter instances
182
- Kernel::raise ArgumentError, 'Outputter instance not valid' if ![ Log4r::FileOutputter ].include?( outputter_instance.class )
183
-
184
181
  # Allow only FileOutputter instances
185
182
  Kernel::raise ArgumentError, 'Outputter pattern not valid, %M required by minimum' if !/\%M/.match( pattern )
186
183
 
@@ -375,7 +372,7 @@ module MobyUtil
375
372
 
376
373
  if $parameters[ :logging_xml_parse_error_dump_path, nil ].nil?
377
374
 
378
- warn("Warning: Configuration parameter :logging_xml_parse_error_dump_path missing, disabling the feature...")
375
+ warn("warning: Configuration parameter :logging_xml_parse_error_dump_path missing, disabling the feature...")
379
376
 
380
377
  # disable feature
381
378
  raise ArgumentError
@@ -389,7 +386,7 @@ module MobyUtil
389
386
 
390
387
  rescue #Exception
391
388
 
392
- warn("Warning: Unable to create log folder #{ $parameters[ :logging_xml_parse_error_dump_path ] } for corrupted XML UI state files")
389
+ warn("warning: Unable to create log folder #{ $parameters[ :logging_xml_parse_error_dump_path ] } for corrupted XML UI state files")
393
390
 
394
391
  # disable feature
395
392
  raise ArgumentError
@@ -400,7 +397,7 @@ module MobyUtil
400
397
 
401
398
  if $parameters[ :logging_xml_parse_error_dump_overwrite, nil ].nil?
402
399
 
403
- warn("Warning: Configuration parameter :logging_xml_parse_error_dump_overwrite missing, using 'false' as default value")
400
+ warn("warning: Configuration parameter :logging_xml_parse_error_dump_overwrite missing, using 'false' as default value")
404
401
 
405
402
  $parameters[ :logging_xml_parse_error_dump_overwrite ] = 'false'
406
403
 
@@ -414,7 +411,7 @@ module MobyUtil
414
411
  rescue #Exception => exception
415
412
 
416
413
  # disable xml logging
417
- warn( "Warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })" )
414
+ warn( "warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })" )
418
415
 
419
416
  $parameters[ :logging_xml_parse_error_dump ] = 'false'
420
417
 
@@ -422,7 +419,7 @@ module MobyUtil
422
419
 
423
420
  else
424
421
 
425
- warn("Warning: Configuration parameter :logging_xml_parse_error_dump missing, disabling the feature...")
422
+ warn("warning: Configuration parameter :logging_xml_parse_error_dump missing, disabling the feature...")
426
423
  $parameters[ :logging_xml_parse_error_dump ] = 'false'
427
424
 
428
425
  end
@@ -487,6 +484,17 @@ module MobyUtil
487
484
  add_outputter( @logger_instance, outputter )
488
485
 
489
486
  end
487
+
488
+ # Add stdout outputter if set on configuration parameters
489
+ if MobyUtil::StringHelper.to_boolean( Parameter[ :logging_stdout_outputter_enabled ] )
490
+ stdout_outputter = create_outputter(
491
+ Log4r::StdoutOutputter, # outputter type
492
+ "TDriver_LOG_stdout", # outputter name
493
+ :level => logging_level # logging level
494
+ )
495
+ set_outputter_pattern( stdout_outputter, Parameter[ :logging_outputter_pattern ] )
496
+ add_outputter( @logger_instance, stdout_outputter )
497
+ end
490
498
 
491
499
  rescue
492
500
 
@@ -496,7 +504,7 @@ module MobyUtil
496
504
 
497
505
  @enabled_stack = [ false ]
498
506
 
499
- warn("Warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })")
507
+ warn("warning: Disabling logging due to failure (#{ $!.class }: #{ $!.message })")
500
508
 
501
509
  return nil
502
510
 
File without changes
@@ -36,6 +36,9 @@ module MobyUtil
36
36
  # This error should be raised when parameter file parsing fails
37
37
  class ParameterFileParseError < CustomError; end
38
38
 
39
+ # This error should be raised when parameter file parsing fails
40
+ class ParameterXmlParseError < CustomError; end
41
+
39
42
  # This error should be raised when desired template was not found
40
43
  class TemplateNotFoundError < CustomError; end
41
44
 
@@ -20,6 +20,11 @@
20
20
  # Parameter related errors
21
21
  require File.expand_path( File.join( File.dirname( __FILE__ ), 'error.rb' ) )
22
22
 
23
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_user_api.rb' ) )
24
+
25
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_new.rb' ) )
26
+
27
+ =begin
23
28
  # Parameter hash class
24
29
  require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_hash.rb' ) )
25
30
 
@@ -34,4 +39,4 @@ require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter_user_a
34
39
 
35
40
  # Parameter API etc
36
41
  require File.expand_path( File.join( File.dirname( __FILE__ ), 'parameter.rb' ) )
37
-
42
+ =end
@@ -30,7 +30,7 @@ module MobyUtil
30
30
  def initialize
31
31
 
32
32
  # this can be done only once due to following method removes --tdriver_parameters argument from ARGV
33
- @@filename_from_command_list_arguments = parse_command_line_arguments
33
+ parse_command_line_arguments
34
34
 
35
35
  # initialize and load templates, default parameters and user defined parameter file
36
36
  reset( true, true, true, true )
@@ -46,7 +46,8 @@ module MobyUtil
46
46
  @@user_defined_parameters_file_defined_in_command_line_arguments = false
47
47
 
48
48
  filename = Array.new
49
- delete_values=Array.new
49
+
50
+ delete_values = Array.new
50
51
 
51
52
  # use command line argument if one exists.
52
53
  ARGV.each_index do | index |
@@ -79,16 +80,22 @@ module MobyUtil
79
80
  end
80
81
 
81
82
  if filename
83
+
82
84
  filename.each do | parameter_file |
83
- Kernel::raise MobyUtil::FileNotFoundError.new( "User defined TDriver parameters file %s does not exist" % [ parameter_file ] ) if !File.exist?( parameter_file )
85
+
86
+ raise MobyUtil::FileNotFoundError, "User defined TDriver parameters file #{ parameter_file } does not exist" unless File.exist?( parameter_file )
87
+
84
88
  end
89
+
85
90
  end
86
91
 
92
+ @@filename_from_command_list_arguments = filename
93
+
87
94
  filename
88
95
 
89
96
  end
90
97
 
91
- protected
98
+ protected
92
99
 
93
100
  def reset_flags
94
101
 
@@ -124,11 +131,13 @@ module MobyUtil
124
131
 
125
132
  # load parameters files unless file does not exist
126
133
  if filename
127
- filename.each do |parameter_file|
134
+
135
+ filename.each do | parameter_file |
128
136
 
129
- load_parameters_xml( parameter_file ) if File.exist?( parameter_file )
137
+ load_parameters_xml( parameter_file ) #if File.exist?( parameter_file )
130
138
 
131
139
  end
140
+
132
141
  end
133
142
 
134
143
 
@@ -147,9 +156,9 @@ module MobyUtil
147
156
  @@default_parameters_loaded = true
148
157
 
149
158
  # load default parameter values
150
- MobyUtil::ParameterXml.instance.parse(
159
+ MobyUtil::ParameterXml.parse(
151
160
 
152
- MobyUtil::ParameterXml.instance.merge_files( 'defaults/', 'parameters', '/parameters/*' ){ | filename |
161
+ MobyUtil::ParameterXml.merge_files( 'defaults/', 'parameters', '/parameters/*' ){ | filename |
153
162
 
154
163
  @@loaded_parameter_files << filename unless @@loaded_parameter_files.include?( filename )
155
164
 
@@ -159,12 +168,12 @@ module MobyUtil
159
168
 
160
169
  end
161
170
 
162
- public
171
+ public
163
172
 
164
173
  # reset parameters class
165
174
  def reset_parameters
166
175
 
167
- MobyUtil::ParameterXml.instance.reset
176
+ MobyUtil::ParameterXml.reset
168
177
 
169
178
  reset( true, true, true, true )
170
179
 
@@ -181,7 +190,7 @@ module MobyUtil
181
190
 
182
191
  @@parameters.merge_with_hash!(
183
192
 
184
- MobyUtil::ParameterXml.instance.parse_file( filename )
193
+ MobyUtil::ParameterXml.parse_file( filename )
185
194
 
186
195
  )
187
196
 
@@ -192,7 +201,7 @@ module MobyUtil
192
201
  # empty parameters hash
193
202
  def clear
194
203
 
195
- MobyUtil::ParameterXml.instance.reset
204
+ MobyUtil::ParameterXml.reset
196
205
 
197
206
  reset_flags
198
207
 
@@ -200,7 +209,53 @@ module MobyUtil
200
209
 
201
210
  end
202
211
 
203
- public # singleton methods
212
+ public # singleton methods
213
+
214
+ # TODO: document me
215
+ def self.parse_file( *args )
216
+
217
+ self.instance.load_parameters_xml( *args )
218
+
219
+ end
220
+
221
+ # TODO: document me
222
+ def self.parse_string( source, merge_hashes = true )
223
+
224
+ self.instance unless @@initialized
225
+
226
+ if merge_hashes
227
+
228
+ @@parameters.merge_with_hash!(
229
+
230
+ MobyUtil::ParameterXml.parse( source )
231
+
232
+ )
233
+
234
+ else
235
+
236
+ @@parameters.merge!(
237
+
238
+ MobyUtil::ParameterXml.parse( source )
239
+
240
+ )
241
+
242
+ end
243
+
244
+ end
245
+
246
+ # TODO: document me
247
+ def self.clear
248
+
249
+ self.instance.clear
250
+
251
+ end
252
+
253
+ # TODO: document me
254
+ def self.reset
255
+
256
+ self.instance.reset_parameters
257
+
258
+ end
204
259
 
205
260
  # Function for returning the value of a parameter. If the parameters is not yet populated it populates
206
261
  # it with default file (tdriver_home/tdriver_parameters.xml)
@@ -224,6 +279,12 @@ module MobyUtil
224
279
 
225
280
  end
226
281
 
282
+ def self.delete( key )
283
+
284
+ @@parameters.delete( key )
285
+
286
+ end
287
+
227
288
  # Function for setting the value of a parameter. If the parameters is not yet populated it populates
228
289
  # it with default file (tdriver_home/tdriver_parameters.xml)
229
290
  # == params
@@ -264,11 +325,23 @@ module MobyUtil
264
325
 
265
326
  end
266
327
 
328
+ def self.keys
329
+
330
+ @@initialized ? @@parameters.keys : []
331
+
332
+ end
333
+
334
+ def self.values
335
+
336
+ @@initialized ? @@parameters.values : []
337
+
338
+ end
339
+
267
340
  def self.configured_suts
268
341
 
269
342
  self.instance unless @@initialized
270
343
 
271
- MobyUtil::ParameterXml.instance.sut_list
344
+ MobyUtil::ParameterXml.sut_list
272
345
 
273
346
  end
274
347
 
@@ -0,0 +1,869 @@
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 MobyUtil
21
+
22
+ class ParameterHash < Hash
23
+
24
+ =begin
25
+ # TODO: document me
26
+ def initialize #( hash = {} )
27
+
28
+ hash.check_type( [ Hash, ParameterHash ], "Wrong argument type $1 for hash (expected $2)" )
29
+
30
+ merge!(
31
+
32
+ convert_hash( hash )
33
+
34
+ ) unless hash.empty?
35
+
36
+ end
37
+ =end
38
+
39
+ # TODO: document me
40
+ def convert_hash( value )
41
+
42
+ =begin
43
+ if value.kind_of?( Hash )
44
+
45
+ # convert hash to parameter hash
46
+ ParameterHash[
47
+
48
+ value.collect{ | key, value |
49
+
50
+ [ key, value.kind_of?( Hash ) ? convert_hash( value ) : value ]
51
+
52
+ }
53
+
54
+ ]
55
+
56
+ else
57
+
58
+ # return as is
59
+ value
60
+
61
+ end
62
+ =end
63
+
64
+ value.kind_of?( Hash ) ? ParameterHash[ value.collect{ | key, value | [ key, value.kind_of?( Hash ) ? convert_hash( value ) : value ] } ] : value
65
+
66
+ end
67
+
68
+ # TODO: document me
69
+ def []( key, *default, &block )
70
+
71
+ $last_parameter = fetch( key ){
72
+
73
+ if default.empty?
74
+
75
+ raise ParameterNotFoundError, "Parameter #{ key } not found" unless block_given?
76
+
77
+ # yield with key if block given
78
+ yield( key )
79
+
80
+ else
81
+
82
+ raise ArgumentError, "Only one default value allowed for parameter (#{ default.join(", ") })" unless default.size == 1
83
+
84
+ # convert_hash( default.first )
85
+
86
+ result = default.first
87
+
88
+ result.kind_of?( Hash ) ? convert_hash( result ) : result
89
+
90
+ end
91
+
92
+ }
93
+
94
+ end
95
+
96
+ # TODO: document me
97
+ def []=( key, value )
98
+
99
+ raise ParameterNotFoundError, "Parameter key nil is not valid" unless key
100
+
101
+ super key, value.kind_of?( Hash ) ? convert_hash( value ) : value
102
+
103
+ end
104
+
105
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
106
+
107
+ end # ParameterHash
108
+
109
+ class Parameter
110
+
111
+ # private methods
112
+ class << self
113
+
114
+ public
115
+
116
+ # TODO: document me
117
+ def instance
118
+
119
+ # get caller methods file name and line number
120
+ file, line = caller.first.split(":")
121
+
122
+ warn "#{ file }:#{ line } warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name } class static methods instead"
123
+
124
+ self
125
+
126
+ end
127
+
128
+ # TODO: document me
129
+ def init
130
+
131
+ # initialize only once
132
+ return if defined?( @initalized )
133
+
134
+ # retrieve platform name
135
+ @platform = MobyUtil::EnvironmentHelper.platform
136
+
137
+ # detect is posix platform
138
+ @is_posix = MobyUtil::EnvironmentHelper.posix?
139
+
140
+ # retrieve parameter filenames from command line arguments
141
+ parse_command_line_arguments
142
+
143
+ # reset templates and parameters
144
+ reset_hashes
145
+
146
+ # indicates that class is already initialized - templates and parameters will not reset
147
+ @initialized = true
148
+
149
+ end
150
+
151
+ private
152
+
153
+ def parse_command_line_arguments
154
+
155
+ # reset command line argument files list
156
+ @command_line_argument_files = []
157
+
158
+ capture_elements = false
159
+
160
+ ARGV.each_with_index do | value, index |
161
+
162
+ value = value.to_s
163
+
164
+ case value
165
+
166
+ when '--tdriver_parameters', '--matti_parameters'
167
+
168
+ warn "warning: #{ value } is deprecated, use -tdriver_parameters instead" if value == '--matti_parameters'
169
+
170
+ # capture following xml filenames
171
+ capture_elements = true
172
+
173
+ # mark element to be removed
174
+ ARGV[ index ] = nil
175
+
176
+ else
177
+
178
+ # process the string if capturing arguments
179
+ if capture_elements
180
+
181
+ # stop capturing if is a option (e.g. --version)
182
+ if [ '-' ].include?( value[ 0 ].chr )
183
+
184
+ capture_elements = false
185
+
186
+ # add argument to parameters list if meets the regexp and capture_element is true
187
+ elsif /\.xml$/i.match( value )
188
+
189
+ # expand filename
190
+ value = File.expand_path( value )
191
+
192
+ # raise exception if given file does not found
193
+ raise MobyUtil::FileNotFoundError, "User defined TDriver parameters file #{ value } does not exist" unless File.exist?( value )
194
+
195
+ # add file to command line arguments files
196
+ @command_line_argument_files << value
197
+
198
+ # mark element to be removed
199
+ ARGV[ index ] = nil
200
+
201
+ end # if
202
+
203
+ end # else
204
+
205
+ end # case
206
+
207
+ end # each_with_index
208
+
209
+ # raise exception if "--tdriver_parameters" option found but no filenames defined
210
+ if capture_elements && @command_line_argument_files.empty?
211
+
212
+ raise ArgumentError, "TDriver parameters command line argument given without a filename"
213
+
214
+ end
215
+
216
+ # remove nil elements from array
217
+ ARGV.compact!
218
+
219
+ # return collected filenames
220
+ @command_line_argument_files
221
+
222
+ end
223
+
224
+ # TODO: document me
225
+ def initialize_class
226
+
227
+ # initialize only once
228
+ return if defined?( @parameters )
229
+
230
+ # class variables not used; read below article:
231
+ # http://www.oreillynet.com/ruby/blog/2007/01/nubygems_dont_use_class_variab_1.html
232
+
233
+ # parameters container
234
+ @parameters = ParameterHash.new
235
+
236
+ # templates container
237
+ @templates = ParameterHash.new
238
+
239
+ # platform enum
240
+ @platform = nil
241
+
242
+ # determine if platform is type of posix
243
+ @is_posix = nil
244
+
245
+ # list of loaded SUT's
246
+ @sut_list = []
247
+
248
+ # list of loaded parameter filenames
249
+ @parameter_files = []
250
+
251
+ # list of loaded template filenames
252
+ @template_files = []
253
+
254
+ # files defined in command line arguments
255
+ @command_line_argument_files = []
256
+
257
+ # templates cache
258
+ @cache = {}
259
+
260
+ end
261
+
262
+ # TODO: document me
263
+ def load_default_parameters
264
+
265
+ # collect all templates
266
+ Dir.glob( MobyUtil::FileHelper.expand_path( 'defaults/*.xml' ) ).each { | filename |
267
+
268
+ file_content = load_file( filename )
269
+
270
+ MobyUtil::XML.parse_string( file_content ).xpath( '*' ).each{ | element |
271
+
272
+ # merge new hash to parameters hash
273
+ @parameters.recursive_merge!(
274
+
275
+ # parse element and convert it to hash
276
+ process_element( element )
277
+
278
+ )
279
+
280
+ }
281
+
282
+ # add file to loaded parameter files list
283
+ @parameter_files << filename
284
+
285
+ }
286
+
287
+ end
288
+
289
+ # TODO: document me
290
+ def load_file( filename )
291
+
292
+ filename = MobyUtil::FileHelper.expand_path( filename )
293
+
294
+ begin
295
+
296
+ MobyUtil::FileHelper.get_file( filename )
297
+
298
+ rescue MobyUtil::EmptyFilenameError
299
+
300
+ raise $!, "Unable to load parameters XML file due to filename is empty or nil"
301
+
302
+ rescue MobyUtil::FileNotFoundError
303
+
304
+ raise $!
305
+
306
+ rescue IOError
307
+
308
+ raise $!, "Error occured while loading xml file. Reason: #{ $!.message }"
309
+
310
+ rescue
311
+
312
+ raise MobyUtil::ParameterFileParseError, "Error occured while parsing parameters xml file #{ filename }\nDescription: #{ $!.message }"
313
+
314
+ end
315
+
316
+ end
317
+
318
+ # TODO: document me
319
+ def process_element( xml )
320
+
321
+ # calculate xml hash
322
+ xml_hash = xml.to_s.hash
323
+
324
+ return @cache[ xml_hash ] if @cache.has_key?( xml_hash )
325
+
326
+ # default results
327
+ results = MobyUtil::ParameterHash.new
328
+
329
+ # go through each element in xml
330
+ xml.xpath( "*" ).each{ | element |
331
+
332
+ # retrieve element attributes as hash
333
+ attributes = element.attributes
334
+
335
+ # default value
336
+ value = attributes[ "value" ]
337
+
338
+ # generic posix value - overwrites attribute["value"] if found
339
+ value = attributes[ "posix" ] unless attributes[ "posix" ].nil? if @is_posix
340
+
341
+ # platform specific value - overwrites existing value
342
+ value = attributes[ @platform.to_s ] unless attributes[ @platform.to_s ].nil?
343
+
344
+ # retrieve name attribute
345
+ name = attributes[ "name" ]
346
+
347
+ case element.name
348
+
349
+ when 'keymap'
350
+
351
+ # use element name as parameter name ("keymap")
352
+ name = element.name
353
+
354
+ # read xml file from given location if defined - otherwise pass content as is
355
+ if attributes[ "xml_file" ]
356
+
357
+ # merge hash values (value type of hash)
358
+ value = process_file( attributes[ "xml_file" ] )
359
+
360
+ else
361
+
362
+ # use element content as value
363
+ value = process_element( element )
364
+
365
+ end
366
+
367
+ # retrieve environment attribute from xml
368
+ env = attributes[ 'env' ].to_s
369
+
370
+ # set environment to 'default' unless defined in xml element
371
+ env = 'default' if env.empty?
372
+
373
+ # store keymap as hash
374
+ value = { env.to_sym => value, :all => value, :default_keymap => env.to_sym }
375
+
376
+ when 'fixture'
377
+
378
+ name.not_blank( "No name defined for fixture \"#{ element.to_s }\"", SyntaxError )
379
+
380
+ value = {
381
+
382
+ :plugin => attributes[ "plugin" ].not_blank( "No name defined for fixture with value #{ name }", SyntaxError ),
383
+
384
+ :env => attributes[ "env" ]
385
+
386
+ }
387
+
388
+ when 'parameter'
389
+
390
+ # verify that name attribute is defined
391
+ name.not_blank( "No name defined for parameter with value #{ value }", SyntaxError )
392
+
393
+ # return value as is
394
+ #value.not_nil( "No value defined for parameter with name #{ name }", SyntaxError )
395
+
396
+ value = "" if value.nil?
397
+
398
+ when 'method'
399
+
400
+ # verify that name attribute is defined
401
+ name.not_blank( "No name defined for parameter with value #{ value }", SyntaxError )
402
+
403
+ # return value as is
404
+ #value.not_nil( "No value defined for parameter with name #{ name }", SyntaxError )
405
+
406
+ value = attributes[ "args" ]
407
+
408
+ when 'sut'
409
+
410
+ # use id as parameter name
411
+ name = attributes[ 'id' ]
412
+
413
+ # verify that name attribute is defined
414
+ name.not_blank( "No name defined for SUT \"#{ element.to_s }\"", SyntaxError )
415
+
416
+ # add SUT to found sut list
417
+ @sut_list << name unless @sut_list.include?( name )
418
+
419
+ # retrieve names of used templates
420
+ templates = attributes[ "template" ]
421
+
422
+ # empty value by default
423
+ value = ParameterHash.new
424
+
425
+ unless templates.blank?
426
+
427
+ # retrieve each defined template
428
+ templates.split(";").each{ | template |
429
+
430
+ # merge template with current value hash
431
+ value.recursive_merge!(
432
+
433
+ # retrieve template
434
+ get_template( template )
435
+
436
+ )
437
+
438
+ }
439
+
440
+ end
441
+
442
+ # merge sut content with template values
443
+ value.recursive_merge!( process_element( element ) )
444
+
445
+ else
446
+
447
+ # use element name as parameter name (e.g. fixture, keymap etc)
448
+ name = element.name
449
+
450
+ # read xml file from given location if defined - otherwise pass content as is
451
+ if attributes[ "xml_file" ]
452
+
453
+ # merge hash values (value type of hash)
454
+ value = process_file( attributes[ "xml_file" ] )
455
+
456
+ else
457
+
458
+ # use element content as value
459
+ value = process_element( element )
460
+
461
+ end
462
+
463
+ end
464
+
465
+ # store values to parameters
466
+ results[ name.to_sym ] = value
467
+
468
+ }
469
+
470
+ # store to cache and return hash as result
471
+ @cache[ xml_hash ] = results
472
+
473
+ end
474
+
475
+ # TODO: document me
476
+ def parse_template( name )
477
+
478
+ template = @templates[ name ]
479
+
480
+ unless template.kind_of?( Hash )
481
+
482
+ result = ParameterHash.new
483
+
484
+ # retrieve each inherited template
485
+ template[ 'inherits' ].to_s.split(";").each{ | inherited_template |
486
+
487
+ result.recursive_merge!(
488
+
489
+ parse_template( inherited_template )
490
+
491
+ )
492
+
493
+ }
494
+
495
+ # merge template content with inherited templates and store to templates hash table
496
+ @templates[ name ] = result.recursive_merge!(
497
+
498
+ process_element( template )
499
+
500
+ )
501
+
502
+ else
503
+
504
+ # template is already parsed, pass template hash as is
505
+ template
506
+
507
+ end
508
+
509
+ end
510
+
511
+ # TODO: document me
512
+ def load_templates
513
+
514
+ # collect all templates
515
+ Dir.glob( MobyUtil::FileHelper.expand_path( 'templates/*.xml' ) ).each { | filename |
516
+
517
+ unless @template_files.include?( filename )
518
+
519
+ # read file content
520
+ file_content = load_file( filename )
521
+
522
+ MobyUtil::XML.parse_string( file_content ).root.xpath( 'template' ).each{ | template |
523
+
524
+ # store template element to hash
525
+ @templates[ template[ 'name' ] ] = template
526
+
527
+ }
528
+
529
+ # add file to loaded templates files list
530
+ @template_files << filename
531
+
532
+ end
533
+
534
+ }
535
+
536
+ # parse templates hash; convert elements to hash
537
+ @templates.each_pair{ | name, template |
538
+
539
+ # convert element to hash
540
+ parse_template( name )
541
+
542
+ }
543
+
544
+ end
545
+
546
+ # TODO: document me
547
+ def get_template( name )
548
+
549
+ @templates.fetch( name ){
550
+
551
+ # return empty hash if template not found
552
+ ParameterHash.new
553
+
554
+ }
555
+
556
+ end
557
+
558
+ # TODO: document me
559
+ def reset_hashes( options = {} )
560
+
561
+ # default options
562
+ options.default_values(
563
+
564
+ :reset_templates => true,
565
+ :reset_parameters => true,
566
+
567
+ :load_default_parameters => true,
568
+ :load_user_parameters => true,
569
+ :load_command_line_parameters => true
570
+
571
+ )
572
+
573
+ # empty parameters hash
574
+ if options[ :reset_parameters ] == true
575
+
576
+ @parameter_files.clear
577
+
578
+ @parameters.clear
579
+
580
+ end
581
+
582
+ if options[ :reset_templates ] == true
583
+
584
+ @template_files.clear
585
+
586
+ # empty templates hash
587
+ @templates.clear
588
+
589
+ # load parameter templates
590
+ load_templates
591
+
592
+ end
593
+
594
+ # apply global parameters to root level (e.g. MobyUtil::Parameter[ :logging_outputter_enabled ])
595
+ @parameters.recursive_merge!( get_template( 'global' ) )
596
+
597
+ # load and apply default parameter values
598
+ load_default_parameters if options[ :load_default_parameters ] == true
599
+
600
+ # load main parameter configuraion file
601
+ load_parameters_file( 'tdriver_parameters.xml' ) if options[ :load_user_parameters ] == true
602
+
603
+ if options[ :load_command_line_parameters ] == true
604
+
605
+ @command_line_argument_files.each{ | filename |
606
+
607
+ load_parameters_file( filename )
608
+
609
+ }
610
+
611
+ end
612
+
613
+ end
614
+
615
+ # TODO: document me
616
+ def process_file( filename )
617
+
618
+ begin
619
+
620
+ # load content from file
621
+ file_content = load_file( filename )
622
+
623
+ # parse file content and retrieve root element
624
+ root_element = MobyUtil::XML.parse_string( file_content ).root
625
+
626
+ # parse root element
627
+ process_element( root_element )
628
+
629
+ rescue MobyUtil::FileNotFoundError
630
+
631
+ raise $!, "Parameters file #{ MobyUtil::FileHelper.expand_path( filename ) } does not exist"
632
+
633
+ rescue
634
+
635
+ raise MobyUtil::ParameterFileParseError, "Error occured while parsing parameters XML file #{ filename }. Reason: #{ $!.message } (#{ $!.class })"
636
+
637
+ end
638
+
639
+ end
640
+
641
+ def process_string( source )
642
+
643
+ begin
644
+
645
+ # parse file content and retrieve root element
646
+ root_element = MobyUtil::XML.parse_string( source ).root
647
+
648
+ # parse root element
649
+ process_element( root_element )
650
+
651
+ rescue
652
+
653
+ raise MobyUtil::ParameterXmlParseError, "Error occured while parsing parameters XML string. Reason: #{ $!.message } (#{ $!.class })"
654
+
655
+ end
656
+
657
+ end
658
+
659
+ def load_parameters_file( filename )
660
+
661
+ filename = MobyUtil::FileHelper.expand_path( filename )
662
+
663
+ unless @parameter_files.include?( filename )
664
+
665
+ begin
666
+
667
+ @parameters.recursive_merge!(
668
+
669
+ process_file( filename )
670
+
671
+ )
672
+
673
+ rescue MobyUtil::FileNotFoundError
674
+
675
+ raise $!, "Parameters file #{ filename } does not exist"
676
+
677
+ end
678
+
679
+ # add file to loaded parameter files list
680
+ @parameter_files << filename
681
+
682
+ end # unless
683
+
684
+ end # def
685
+
686
+ end # self
687
+
688
+ # TODO: document me
689
+ def self.parse_file( filename, reset_parameters = false )
690
+
691
+ # check argument type for filename
692
+ filename.check_type [ String ], 'wrong argument type $1 for filename argument (expected $2)'
693
+
694
+ # check argument type for filename
695
+ reset_parameters.check_type [ TrueClass, FalseClass ], 'wrong argument type $1 for reset_parameters boolean argument (expected $2)'
696
+
697
+ # reset parameter hash if requested
698
+ @parameters.clear if reset_parameters == true
699
+
700
+ # load and parse given file
701
+ load_parameters_file( filename )
702
+
703
+ end
704
+
705
+ # TODO: document me
706
+ def self.parse_string( source, merge_hashes = true )
707
+
708
+ # check argument type for source
709
+ source.check_type [ String ], 'wrong argument type $1 for source XML argument (expected $2)'
710
+
711
+ # check argument type for merge_hashes
712
+ merge_hashes.check_type [ TrueClass, FalseClass ], 'wrong argument type $1 for merge_hashes argument (expected $2)'
713
+
714
+ # process xml string, returns hash as result
715
+ hash = process_string( source )
716
+
717
+ if merge_hashes
718
+
719
+ @parameters.recursive_merge!( hash )
720
+
721
+ else
722
+
723
+ @parameters.merge!( hash )
724
+
725
+ end
726
+
727
+ end
728
+
729
+ # TODO: document me
730
+ def self.clear
731
+
732
+ @parameter_files.clear
733
+
734
+ @parameters.clear
735
+
736
+ end
737
+
738
+ # TODO: document me
739
+ def self.files
740
+
741
+ # return loaded parameter files list
742
+ @parameter_files
743
+
744
+ end
745
+
746
+ # TODO: document me
747
+ def self.template_files
748
+
749
+ # return loaded parameter files list
750
+ @template_files
751
+
752
+ end
753
+
754
+ # TODO: document me
755
+ def self.keys
756
+
757
+ @parameters.keys
758
+
759
+ end
760
+
761
+ # TODO: document me
762
+ def self.values
763
+
764
+ @parameters.values
765
+
766
+ end
767
+
768
+ # TODO: document me
769
+ def self.[]( key, *default )
770
+
771
+ @parameters[ key, *default ]
772
+
773
+ end
774
+
775
+ # TODO: document me
776
+ def self.[]=( key, value )
777
+
778
+ @parameters[ key ] = value
779
+
780
+ end
781
+
782
+ # TODO: document me
783
+ def self.fetch( key, *default, &block )
784
+
785
+ @parameters.__send__( :[], key, *default, &block )
786
+
787
+ end
788
+
789
+ # TODO: document me
790
+ def self.delete( key )
791
+
792
+ @parameters.delete( key )
793
+
794
+ end
795
+
796
+ # TODO: document me
797
+ def self.inspect
798
+
799
+ @parameters.inspect
800
+
801
+ end
802
+
803
+ # TODO: document me
804
+ def self.templates
805
+
806
+ @templates
807
+
808
+ end
809
+
810
+ def self.parameters
811
+
812
+ warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#hash instead"
813
+
814
+ hash
815
+
816
+ end
817
+
818
+ def self.hash
819
+
820
+ @parameters
821
+
822
+ end
823
+
824
+ # TODO: document me
825
+ def self.reset
826
+
827
+ reset_hashes
828
+
829
+ end
830
+
831
+ # TODO: document me
832
+ def self.configured_suts
833
+
834
+ @sut_list
835
+
836
+ end
837
+
838
+ # deprecated methods
839
+ def self.reset_parameters
840
+
841
+ warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#reset instead"
842
+
843
+ reset
844
+
845
+ end
846
+
847
+ # load parameter xml files
848
+ def self.load_parameters_xml( filename, reset = false )
849
+
850
+ warn "warning: deprecated method #{ self.name }##{ __method__ }; please use #{ self.name }#parse_file instead"
851
+
852
+ parse_file( filename, reset )
853
+
854
+ end
855
+
856
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
857
+
858
+ # initialize parameters class
859
+ initialize_class
860
+
861
+ end # Parameter
862
+
863
+ end # MobyUtil
864
+
865
+ # set global variable pointing to parameter class
866
+ $parameters = MobyUtil::Parameter
867
+
868
+ # set global variable pointing to parameter API class
869
+ $parameters_api = MobyUtil::ParameterUserAPI