testability-driver 0.9.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +1 -1
  2. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +11 -7
  3. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +8 -0
  4. data/lib/tdriver/base/behaviour/factory.rb +229 -209
  5. data/lib/tdriver/base/errors.rb +3 -0
  6. data/lib/tdriver/base/state_object.rb +11 -20
  7. data/lib/tdriver/base/sut/controller.rb +4 -4
  8. data/lib/tdriver/base/sut/factory.rb +205 -170
  9. data/lib/tdriver/base/sut/generic/behaviours/application.rb +256 -174
  10. data/lib/tdriver/base/sut/generic/behaviours/find.rb +17 -11
  11. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +57 -66
  12. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +578 -497
  13. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +41 -15
  14. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +48 -19
  15. data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
  16. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +25 -13
  17. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +16 -10
  18. data/lib/tdriver/base/sut/generic/plugin.rb +9 -3
  19. data/lib/tdriver/base/sut/sut.rb +41 -33
  20. data/lib/tdriver/base/test_object/abstract.rb +26 -3
  21. data/lib/tdriver/base/test_object/adapter.rb +399 -0
  22. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +56 -14
  23. data/lib/tdriver/base/test_object/behaviours/test_object.rb +663 -197
  24. data/lib/tdriver/base/test_object/cache.rb +132 -0
  25. data/lib/tdriver/base/test_object/factory.rb +677 -426
  26. data/lib/tdriver/base/test_object/factory_new.rb +202 -0
  27. data/lib/tdriver/base/test_object/identificator.rb +24 -17
  28. data/lib/tdriver/base/test_object/loader.rb +9 -3
  29. data/lib/tdriver/base/test_object/verification.rb +181 -0
  30. data/lib/tdriver/loader.rb +1 -1
  31. data/lib/tdriver/report/report.rb +2 -0
  32. data/lib/tdriver/report/report_api.rb +4 -4
  33. data/lib/tdriver/report/report_creator.rb +29 -3
  34. data/lib/tdriver/report/report_data_presentation.rb +7 -3
  35. data/lib/tdriver/report/report_execution_statistics.rb +80 -21
  36. data/lib/tdriver/report/report_javascript.rb +192 -0
  37. data/lib/tdriver/report/report_test_case_run.rb +22 -0
  38. data/lib/tdriver/report/report_test_run.rb +62 -55
  39. data/lib/tdriver/report/report_writer.rb +57 -56
  40. data/lib/tdriver/tdriver.rb +14 -41
  41. data/lib/tdriver/util/common/error.rb +1 -0
  42. data/lib/tdriver/util/common/exceptions.rb +12 -0
  43. data/lib/tdriver/util/common/file.rb +12 -6
  44. data/lib/tdriver/util/common/gem.rb +2 -1
  45. data/lib/tdriver/util/common/hash.rb +152 -0
  46. data/lib/tdriver/util/common/kernel.rb +49 -34
  47. data/lib/tdriver/util/common/loader.rb +21 -17
  48. data/lib/tdriver/util/common/numeric.rb +39 -0
  49. data/lib/tdriver/util/common/object.rb +115 -0
  50. data/lib/tdriver/util/common/string.rb +55 -2
  51. data/lib/tdriver/util/dbaccess/dbaccess.rb +194 -161
  52. data/lib/tdriver/util/dynamic_attribute_filter.rb +6 -0
  53. data/lib/tdriver/util/hooking.rb +2 -2
  54. data/lib/tdriver/util/loader.rb +2 -2
  55. data/lib/tdriver/util/localisation/localisation.rb +277 -18
  56. data/lib/tdriver/util/logger.rb +142 -13
  57. data/lib/tdriver/util/parameter/parameter_hash.rb +8 -5
  58. data/lib/tdriver/util/parameter/parameter_xml.rb +18 -2
  59. data/lib/tdriver/util/recorder.rb +17 -12
  60. data/lib/tdriver/util/user_data/user_data.rb +3 -2
  61. data/lib/tdriver/util/{video_rec.rb → video_utils.rb} +136 -16
  62. data/lib/tdriver/util/xml/abstraction.rb +7 -0
  63. data/lib/tdriver/util/xml/attribute.rb +32 -0
  64. data/lib/tdriver/util/xml/loader.rb +8 -2
  65. data/lib/tdriver/util/xml/nil_node.rb +95 -0
  66. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +46 -7
  67. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +19 -9
  68. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +1 -1
  69. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +13 -1
  70. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +6 -0
  71. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +27 -15
  72. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +57 -0
  73. data/lib/tdriver/util/xml/text.rb +32 -0
  74. data/lib/tdriver/util/xml/xml.rb +35 -22
  75. data/lib/tdriver/version.rb +1 -1
  76. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +41 -34
  77. data/lib/tdriver-devtools/doc/generate.rb +31 -6
  78. data/lib/tdriver-devtools/doc/xslt/template.xsl +46 -25
  79. data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
  80. data/lib/tdriver-devtools/tests/feature_tests/update +1 -1
  81. data/lib/tdriver.rb +0 -3
  82. data/xml/behaviours/generic.xml +1 -1
  83. data/xml/defaults/generic.xml +4 -90
  84. data/xml/templates/generic.xml +33 -25
  85. metadata +21 -29
  86. data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +0 -245
  87. data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +0 -964
  88. data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +0 -68
  89. data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +0 -1865
  90. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +0 -1
  91. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +0 -3
  92. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +0 -4
  93. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +0 -4
  94. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +0 -4
  95. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +0 -3
  96. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +0 -3
  97. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +0 -1
  98. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +0 -3
  99. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +0 -3
  100. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +0 -12
  101. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +0 -5
  102. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +0 -1
  103. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +0 -2
  104. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +0 -7
  105. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +0 -14
  106. data/lib/tdriver-devtools/behaviour/xml_generator/update +0 -3
  107. data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +0 -233
  108. data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +0 -194
@@ -75,6 +75,12 @@ module MobyUtil
75
75
 
76
76
  end
77
77
 
78
+ def has_attribute?( symbol )
79
+
80
+ @attributes.include?( symbol.to_s )
81
+
82
+ end
83
+
78
84
  def add_attribute( symbol )
79
85
 
80
86
  # update filter if new symbols added
@@ -380,7 +380,7 @@ module MobyUtil
380
380
  begin
381
381
 
382
382
  # call original method
383
- result = method(:#{ original_method_name }).call( *args, &block )
383
+ result = send(:#{ original_method_name }, *args, &block )
384
384
 
385
385
  rescue Exception => exception
386
386
 
@@ -408,7 +408,7 @@ module MobyUtil
408
408
  else
409
409
 
410
410
  "# call original method
411
- result = self.method(:#{ original_method_name }).call( *args, &block )"
411
+ result = send(:#{ original_method_name }, *args, &block )"
412
412
 
413
413
  end
414
414
 
@@ -60,6 +60,6 @@ require File.expand_path( File.join( File.dirname( __FILE__ ), 'operator_data/lo
60
60
  # Recorder module
61
61
  require File.expand_path( File.join( File.dirname( __FILE__ ), 'recorder.rb' ) )
62
62
 
63
- # Video rec module
64
- require File.expand_path( File.join( File.dirname( __FILE__ ), 'video_rec.rb' ) )
63
+ # Video utils module
64
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'video_utils.rb' ) )
65
65
 
@@ -24,7 +24,222 @@ require 'nokogiri'
24
24
  module MobyUtil
25
25
 
26
26
  class Localisation
27
-
27
+
28
+ # == Language maping cross-referenced from Nokia Shared Lancuage Codes and Symbian
29
+ # http://developer.symbian.org/main/documentation/reference/s3/pdk/GUID-31C133DE-F245-5992-9A41-20A99291E72A.html
30
+ # http://www2.connecting.nokia.com/nokia/terminology/terms.nsf/document/ES346PMF37?OpenDocument&ExpandSection=1#_Section1
31
+ # Its also enumerated by TLanguage in e32lang.h in the Symbian code.
32
+ # The ones only on e32lang.h are commented out
33
+ @language_code_map = {
34
+ "English" => ["en", "01"],
35
+ "French" => ["fr", "02"],
36
+ "German" => ["de", "03"],
37
+ "Spanish" => ["es", "04"],
38
+ "Italian" => ["it", "05"],
39
+ "Swedish" => ["sv", "06"],
40
+ "Danish" => ["da", "07"],
41
+ "Norwegian" => ["no", "08"],
42
+ "Finish" => ["fi", "09"],
43
+ "English US" => ["en_US", "10"],
44
+ # "Swiss French" => ["SF", "11"],
45
+ # "Swiss German" => ["SG", "12"],
46
+ "Portuguese" => ["pt", "13"],
47
+ "Turkish" => ["tr", "14"],
48
+ "Icelandic" => ["is", "15"],
49
+ "Russian" => ["ru", "16"],
50
+ "Hungarian" => ["hu", "17"],
51
+ "Dutch" => ["nl", "18"],
52
+ # "Belgian Flemish" => ["BL", "19"],
53
+ # "Australian" => ["AU", "20"],
54
+ # "Belgian French" => ["BF", "21"],
55
+ # "Austrian" => ["AS", "22"],
56
+ # "New Zealand" => ["NZ", "23"],
57
+ # "International French" => ["IR", "24"],
58
+ "Czech" => ["cs", "25"],
59
+ "Slovak" => ["sk", "26"],
60
+ "Polish" => ["pl", "27"],
61
+ "Slovenian" => ["sl", "28"],
62
+ "Chinese TW" => ["zh_TW", "29"],
63
+ "Chinese HK" => ["zh_HK", "30"],
64
+ "Chinese" => ["zh", "31"],
65
+ "Japanese" => ["ja", "32"],
66
+ "Thai" => ["th", "33"],
67
+ "Afrikaans" => ["af", "34"],
68
+ "Albanian" => ["sq", "35"],
69
+ "Amharic" => ["am", "36"],
70
+ "Arabic" => ["ar", "37"],
71
+ "Armenian" => ["hy", "38"],
72
+ "Filipino" => ["tl", "39"],
73
+ "Belarusian" => ["be", "40"],
74
+ "Bengali" => ["bn", "41"],
75
+ "Bulgarian" => ["bg", "42"],
76
+ # "Burmese" => ["MY", "43"],
77
+ "Catalan" => ["ca", "44"],
78
+ "Croatian" => ["hr", "45"],
79
+ # "Canadian English" => ["CE", "46"],
80
+ # "International English" => ["IE", "47"],
81
+ # "South African English" => ["SA", "48"],
82
+ "Estonian" => ["et", "49"],
83
+ "Persian" => ["fa", "50"],
84
+ "French CA" => ["fr_CA", "51"],
85
+ # "Scots Gaelic" => ["GD", "52"],
86
+ "Georgian" => ["ka", "53"],
87
+ "Greek" => ["el", "54"],
88
+ # "Cyprus Greek" => ["CG", "55"],
89
+ "Gujarati" => ["gu", "56"],
90
+ "Hebrew" => ["he", "57"],
91
+ "Hindi" => ["hi", "58"],
92
+ "Indonesian" => ["id", "59"],
93
+ # "Irish" => ["GA", "60"],
94
+ # "Swiss Italian" => ["SZ", "61"],
95
+ "Kannada" => ["kn", "62"],
96
+ "Kazakh" => ["kk", "63"],
97
+ "Khmer" => ["km", "64"],
98
+ "Korean" => ["ko", "65"],
99
+ # "Lao" => ["lo", "66"],
100
+ "Latvian" => ["lv", "67"],
101
+ "Lithuanian" => ["lt", "68"],
102
+ "Macedonian" => ["mk", "69"],
103
+ "Malay" => ["ms", "70"],
104
+ "Malayalam" => ["ml", "71"],
105
+ "Marathi" => ["mr", "72"],
106
+ # "Moldavian" => ["MO", "73"],
107
+ "Mongolian" => ["mn", "74"],
108
+ # "Norwegian Nynorsk" => ["nn", "75"],
109
+ "Portuguese BR" => ["pt_BP", "76"],
110
+ "Punjabi" => ["pa", "77"],
111
+ "Romanian" => ["ro", "78"],
112
+ "Servian" => ["sr", "79"],
113
+ "Sinhala" => ["si", "80"],
114
+ # "Somali" => ["SO", "81"],
115
+ # "International Spanish" => ["OS", "82"],
116
+ "Spanish AM" => ["es_419", "83"],
117
+ "Swahili" => ["sw", "84"],
118
+ # "Finland Swedish" => ["FS", "85"],
119
+ "Tamil" => ["ta", "87"],
120
+ "Telugu" => ["te", "88"],
121
+ # "Tibetan" => ["BO", "89"],
122
+ # "Tigrinya" => ["TI", "90"],
123
+ # "Cyprus Turkish" => ["CT", "91"],
124
+ "Turkem" => ["tk", "92"],
125
+ "Ukranian" => ["uk", "93"],
126
+ "Urdu" => ["ur", "94"],
127
+ "Vietnamese" => ["vi", "96"],
128
+ # "Welsh" => ["CY", "97"],
129
+ "Zulu" => ["zu", "98"],
130
+ # "Manufacturer English" => ["ME", "100"],
131
+ "Sesotho" => ["st", "101"],
132
+ "Basque" => ["eu", "102"],
133
+ "Galician" => ["gl", "103"],
134
+ # "Javanese" => ["", "104"],
135
+ # "Maithili" => ["", "105"],
136
+ # "Azerbaijani Latin" => ["", "106"],
137
+ "Azerbaijani Cyrillic" => ["az", "107"],
138
+ "Oriya" => ["or", "108"],
139
+ # "Bhojpuri" => ["", "109"],
140
+ # "Sundanese" => ["", "110"],
141
+ # "Kurdish Latin" => ["", "111"],
142
+ # "Kurdish Arabic" => ["", "112"],
143
+ "Pashto" => ["ps", "113"],
144
+ "Hausa" => ["ha", "114"],
145
+ #"Oromo" => ["", "115"],
146
+ # "Uzbek Latin" => [", "116"],
147
+ "Uzbek Cyrillic" => ["uz", "117"],
148
+ # "Sindhi Arabic" => ["", "118"],
149
+ # "Sindhi Devanagari" => ["", "119"],
150
+ "Yoruba" => ["yo", "120"],
151
+ # "Cebuano" => ["", "121"],
152
+ "Igbo" => ["ig", "122"],
153
+ "Malagasy" => ["mg", "123"],
154
+ # "Nepali" => ["", "124"],
155
+ "Assamese" => ["as", "125"],
156
+ # "Shona" => ["", "126"],
157
+ # "Zhuang" => ["", "127"],
158
+ # "Madurese" => ["", "127"],
159
+ "English Apac" => ["EA", "129"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
160
+ "English Taiwan" => ["YW", "157"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
161
+ "English Hong Kong" => ["YH", "158"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
162
+ "English PRC" => ["YP", "159"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
163
+ "English Japan" => ["YJ", "160"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
164
+ "English Thailand" => ["YT", "161"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
165
+ # "Fulfulde" => ["", "162"],
166
+ # "Tamazight" => ["", "163"],
167
+ # "BolivianQuechua" => ["", "164"],
168
+ # "PeruQuechua" => ["", "165"],
169
+ # "EcuadorQuechua" => ["", "166"],
170
+ "Tajik_Cyrillic" => ["tg", "167"],
171
+ # "Tajik_PersoArabic" => ["", "168"],
172
+ # "Nyanja" => ["", "169"],
173
+ # "HaitianCreole" => ["", "170"],
174
+ # "Lombard" => ["", "171"],
175
+ # "Koongo" => ["", "172"],
176
+ # "Akan" => ["", "173"],
177
+ # "Hmong" => ["", "174"],
178
+ # "Yi" => ["", "175"],
179
+ # "Tshiluba" => ["", "176"],
180
+ # "Ilocano" => ["", "177"],
181
+ # "Uyghur" => ["", "178"],
182
+ # "Neapolitan" => ["", "179"],
183
+ # "Rwanda" => ["", "180"],
184
+ "Xhosa" => ["xh", "181"],
185
+ # "Balochi" => ["", "182"],
186
+ # "Hiligaynon" => {"", "183"],
187
+ # "Minangkabau" => ["", "184"],
188
+ # "Makhuwa" => ["", "185"],
189
+ # "Santali" => ["", "186"],
190
+ # "Gikuyu" => ["", "187"],
191
+ # "Moore" => ["", "188"],
192
+ # "Guarani" => ["", "189"],
193
+ # "Rundi" => ["", "190"],
194
+ # "Romani_Latin" => ["", "191"],
195
+ # "Romani_Cyrillic" => ["", "192"],
196
+ # "Tswana" => ["", "193"],
197
+ # "Kanuri" => ["", "194"],
198
+ # "Kashmiri Devanagari" => ["", "195"],
199
+ "Kashmiri Perso Arabic" => ["ks", "196"],
200
+ # "Umbundu" => ["", "197"],
201
+ # "Konkani" => ["", "198"],
202
+ # "Balinese" => ["", "199"],
203
+ # "Northern Sotho" => ["", "200"],
204
+ # "Wolof" => ["", "201"],
205
+ # "Bemba" => ["", "202"],
206
+ # "Tsonga" => ["", "203"],
207
+ # "Yiddish" => ["", "204"],
208
+ "Kirghiz" => ["ky", "205"],
209
+ # "Ganda" => ["", "206"],
210
+ # "Soga" => ["", "207"],
211
+ # "Mbundu" => ["", "208"],
212
+ # "Bambara" => ["", "209"],
213
+ # "Central Aymara" => ["", "210"],
214
+ # "Zarma" => ["", "211"],
215
+ "Lingala" => ["ln", "212"],
216
+ # "Bashkir" => ["", "213"],
217
+ # "Chuvash" => ["", "214"],
218
+ # "Swati" => ["", "215"],
219
+ # "Tatar" => ["", "216"],
220
+ # "Southern Ndebele" => ["", "217"],
221
+ # "Sardinian" => ["", "218"],
222
+ # "Scots" => ["", "219"],
223
+ # "Meitei" => ["", "220"],
224
+ # "Walloon" => ["", "221"],
225
+ # "Kabardian" => ["", "222"],
226
+ # "Mazanderani" => ["", "223"],
227
+ # "Gilaki" => ["", "224"],
228
+ # "Shan" => ["", "225"],
229
+ # "Luyia" => ["", "226"],
230
+ # "Luo" => ["", "227"],
231
+ # "Sukuma" => ["", "228"],
232
+ # "Aceh" => ["", "229"],
233
+ #"English_India" => ["", "230"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
234
+ "Malay Apac" => ["MA", "326"], # In e32long.h, Pearl script, but not in Nokia Language Codes Standard
235
+ # "Indonesian Apac" =>["", "327"],
236
+ # "Bengali IN" => ["bn_IN", ""],
237
+ # "Bosnian" => ["bs", ""],
238
+ }
239
+
240
+
241
+
242
+
28
243
  # == description
29
244
  # Function to fetch a translation for a given logical name from the localisation DB
30
245
  #
@@ -39,8 +254,8 @@ module MobyUtil
39
254
  #
40
255
  # language
41
256
  # String
42
- # description: Name of the language column to be used. This is normally the language code found on the .ts or .qm translation files
43
- # example: "en"
257
+ # description: Name of the language column to be used. This is normally the language postfix found on the .ts, .qm translation files. On .loc file postfix numbers are mapped to similar language codes according to standards in Symbian literature and others, check the localization.db implementation file for the full mapping.
258
+ # example: "en" or "es_416" or "en_us"
44
259
  #
45
260
  # table_name
46
261
  # String
@@ -155,7 +370,7 @@ module MobyUtil
155
370
  #
156
371
  # column_names_map
157
372
  # Hash
158
- # description: Hash with the language codes from the translation files as keys and the desired column names as values
373
+ # description: Use this parameter to change the default language names. The default language postfix translation files (.ts, .qm or .loc) as keys and the desired column names as values
159
374
  # example: {"en" => "en_GB"}
160
375
  #
161
376
  # record_sql
@@ -186,14 +401,19 @@ module MobyUtil
186
401
 
187
402
  db_connection = DBConnection.new( db_type, host, database_name, username, password )
188
403
  end
189
- # Check File and convert to TS File if needed
190
- tsFile = MobyUtil::Localisation.convert_to_ts( file )
191
- Kernel::raise Exception.new("Failed to convert #{file} to .ts") if tsFile == nil
192
- # Collect data for INSERT query from TS File
193
- language, data = MobyUtil::Localisation.parse_ts_file( tsFile, column_names_map )
194
- Kernel::raise Exception.new("Error while parsing #{file}.") if language == nil or data == ""
195
- # Upload language data to DB for current language file
196
- MobyUtil::Localisation.upload_ts_data( language, data, table_name, db_connection, record_sql )
404
+ if file.match(/.*\.ts/) or file.match(/.*\.qm/)
405
+ # Check File and convert to TS File if needed
406
+ tsFile = MobyUtil::Localisation.convert_to_ts( file )
407
+ Kernel::raise Exception.new("Failed to convert #{file} to .ts") if tsFile == nil
408
+ # Collect data for INSERT query from TS File
409
+ language, data = MobyUtil::Localisation.parse_ts_file( tsFile, column_names_map )
410
+ Kernel::raise Exception.new("Error while parsing #{file}.") if language == nil or data == ""
411
+ elsif file.match(/.*\.loc/)
412
+ language, data = MobyUtil::Localisation.parse_loc_file( file, column_names_map )
413
+ Kernel::raise Exception.new("Error while parsing #{file}. The file might have no translations.") if language.nil? or language.empty? or data.nil? or data.empty?
414
+ end
415
+ # Upload language data to DB for current language file
416
+ MobyUtil::Localisation.upload_data( language, data, table_name, db_connection, record_sql )
197
417
  end
198
418
 
199
419
 
@@ -261,9 +481,9 @@ module MobyUtil
261
481
  # Read TS file
262
482
  open_file = File.new( file )
263
483
  doc = Nokogiri.XML( open_file )
264
- language = doc.xpath('.//TS').attribute("language")
484
+ # language = doc.xpath('.//TS').attribute("language")
265
485
  # IF filename-to-columnname mapping is provided update language
266
- fname = parseFName(file)
486
+ fname, language = parseFName(file)
267
487
  if (!column_names_map.empty?)
268
488
  language_code = file.split('/').last.gsub(fname + "_" ){|s| ""}.gsub(".ts"){|s| ""}
269
489
  language = column_names_map[ language_code ] if column_names_map.key?( language_code )
@@ -290,18 +510,24 @@ module MobyUtil
290
510
  # Parse Numerus(LengthVar), or Numerus or LengthVar or translation direclty
291
511
  if ! node.xpath('.//translation/numerusform').empty?
292
512
  # puts ">>> Numerusform"
513
+ plurality = 1
293
514
  node.xpath('.//translation/numerusform').each do |numerus|
294
515
  nodePlurality = numerus.xpath('@plurality').inner_text()
516
+ nodePlurality = plurality.to_s if nodePlurality.empty?
295
517
  if ! numerus.xpath('.//lengthvariant').empty?
296
518
  # puts " >>> Lengthvar"
519
+ priority = 1
297
520
  numerus.xpath('.//lengthvariant').each do |lenghtvar|
298
521
  nodeLengthVar = lenghtvar.xpath('@priority').inner_text()
522
+ nodeLengthVar = priority.to_s if nodeLengthVar.empty?
299
523
  nodeTranslation = lenghtvar.inner_text()
300
524
  data << [ fname, nodeId, nodeTranslation, nodePlurality, nodeLengthVar ]
525
+ priority += 1
301
526
  end
302
527
  else
303
528
  nodeTranslation = numerus.inner_text()
304
529
  data << [ fname, nodeId, nodeTranslation, nodePlurality, nodeLengthVar ]
530
+ plurality += 1
305
531
  end
306
532
  end
307
533
  elsif ! node.xpath('.//translation/lengthvariant').empty?
@@ -326,11 +552,43 @@ module MobyUtil
326
552
  return language, data
327
553
  end
328
554
 
555
+ #
556
+ # Note: for .loc files the colum mapping is done with the Language code number on the filenames
557
+ #
558
+ def self.parse_loc_file(file, column_names_map = {})
559
+ begin
560
+
561
+ data = []
562
+ file.split('/').last.match(/(.*)_(\w{2,3}).loc/)
563
+ fname = $1
564
+ language_number = $2
565
+ # select returns an array of [language, codes] that suite the conditional
566
+ # codes is the array ["NokiaCode(2-leter)", "SymbianCode(number)"]
567
+ language = @language_code_map.select{|lang,codes| codes[1] == language_number}[0][1][0]
568
+ language = column_names_map[ language_number ] if !column_names_map.empty? and column_names_map.key?( language_number )
569
+
570
+ io = open(file)
571
+ while line = io.gets
572
+ if line.match(/#define ([a-zA-Z1-9\_]*) \"(.*)\"/)
573
+ lname = $1
574
+ translation = $2
575
+ data << [ fname, lname, translation, plurality = "", lengthvariant = "0" ]
576
+ end
577
+ end
578
+ io.close
579
+ #puts language
580
+ #p data
581
+ return language, data
582
+ rescue Exception => e
583
+ puts e.message
584
+ puts e.backtrace
585
+ end
586
+ end
329
587
 
330
588
  # == description
331
589
  # Uploads language data to Localisation DB and optionally records the sql queries on a file
332
590
  #
333
- def self.upload_ts_data( language, data, table_name, db_connection, record_sql = false )
591
+ def self.upload_data( language, data, table_name, db_connection, record_sql = false )
334
592
 
335
593
  raise Exception.new("Language not provided.") if language.nil? or language.to_s.empty?
336
594
  raise Exception.new("No data povided. Please make sure the source of your data is valid.") if data.nil? or data.empty?
@@ -383,7 +641,7 @@ module MobyUtil
383
641
  case db_connection.db_type
384
642
  when "mysql"
385
643
  begin
386
- query_string = "ALTER TABLE `" + table_name + "` ADD `" + language + "` VARCHAR(350) NULL DEFAULT NULL COLLATE utf8_general_ci;"
644
+ query_string = "ALTER TABLE `" + table_name + "` ADD `" + language + "` TEXT NULL DEFAULT NULL COLLATE utf8_general_ci;"
387
645
  MobyUtil::DBAccess.query( db_connection, query_string )
388
646
  sql_file.write( query_string + "\n" ) if record_sql
389
647
  rescue Mysql::Error # catch if language column already exists
@@ -458,7 +716,7 @@ module MobyUtil
458
716
 
459
717
  # == description
460
718
  # Extracs application name used for FNAME from a given filename (removes language tags and file extension)
461
- #
719
+ # Used only on .ts files
462
720
  def self.parseFName(file)
463
721
  fname = file.split('/').last
464
722
  #(wordlist matching)
@@ -470,7 +728,8 @@ module MobyUtil
470
728
  end
471
729
  end
472
730
  fname.gsub!(".ts"){|s| ""}
473
- return fname #gsub! will return nil if now subs are performed
731
+ language = file.split('/').last.gsub( fname + "_" ){|s| ""}.gsub(".ts"){|s| ""}
732
+ return fname, language #gsub! will return nil if now subs are performed
474
733
  end
475
734
 
476
735
  end # class
@@ -198,7 +198,6 @@ module MobyUtil
198
198
  # do not add caller info if called from self
199
199
  include_behaviour_info = false
200
200
 
201
-
202
201
  else
203
202
 
204
203
  # normal logging, e.g. behaviour logging from method etc
@@ -209,8 +208,6 @@ module MobyUtil
209
208
  # log text to given level if logging enabled
210
209
  text_array.each{ | text |
211
210
 
212
-
213
-
214
211
  @logger_instance.send( level, ( include_behaviour_info && !text.empty? ) ? ( "%s in %s" % [ text, log_caller ] ) : ( "%s" % text ) )
215
212
 
216
213
  }
@@ -221,21 +218,22 @@ module MobyUtil
221
218
 
222
219
  def enable_raise_hooking
223
220
 
224
- def Kernel::raise( exception )
221
+ # hook Kernel.raise
222
+ def Kernel::raise( *exception )
225
223
 
226
224
  begin
227
225
 
228
- super( exception )
226
+ super( *exception )
229
227
 
230
- rescue => ex
228
+ rescue => raised_exception
231
229
 
232
- ex.backtrace.slice!( 0 )
230
+ raised_exception.backtrace.slice!( 0 )
233
231
 
234
- warn_array = [ '', "(%s) %s" % [ ex.class, ex.message.split("\n") ], '', ex.backtrace, '' ].flatten
232
+ warn_array = [ '', "(%s) %s" % [ raised_exception.class, raised_exception.message.split("\n") ], '', raised_exception.backtrace, '' ].flatten
235
233
 
236
234
  MobyUtil::Logger.instance.log( 'warning', *warn_array )
237
235
 
238
- super( ex )
236
+ super( raised_exception )
239
237
 
240
238
  end
241
239
 
@@ -243,24 +241,155 @@ module MobyUtil
243
241
 
244
242
  end
245
243
 
244
+ def set_debug_exceptions
245
+
246
+ if ARGV.include?( '--debug_exceptions' ) || TDriver.parameter[ :debug_exceptions, 'false' ].to_s.downcase == 'true'
247
+
248
+ ARGV.delete('--debug_exceptions')
249
+ # for debugging to see every occured exception
250
+ def Kernel.raise( *args )
251
+ #begin
252
+ # raise and catch exception
253
+ super( *args )
254
+ #rescue
255
+ # remove wrapper call from backtrace
256
+ # $!.backtrace.shift
257
+ #puts "%s: %s\nBacktrace: \n%s\n\n" % [ $!.class, $!.message, $!.backtrace.collect{ | line | " %s" % line }.join("\n") ]
258
+ # raise exception again
259
+ # super $!
260
+ #end
261
+ end
262
+
263
+ # hook Object(Kernel)#raise
264
+ ::Object.class_exec{
265
+
266
+ ::Kernel.module_exec{
267
+
268
+ alias_method :original_raise, :raise
269
+
270
+ def raise( *args )
271
+
272
+ begin
273
+
274
+ # raise and catch exception
275
+ original_raise( *args )
276
+
277
+ rescue
278
+
279
+ # remove wrapper calls from backtrace
280
+ while $!.backtrace.first =~ /(logger\.rb).*(raise)/
281
+
282
+ $!.backtrace.shift
283
+
284
+ end
285
+
286
+ puts "[debug] %s: %s\n[debug] Backtrace: \n[debug] %s\n\n" % [
287
+ $!.class,
288
+ $!.message,
289
+ $!.backtrace.collect{ | line | " ... from %s" % line }.join("\n[debug] ")
290
+ ]
291
+
292
+ # raise exception again
293
+ original_raise $!
294
+
295
+ end
296
+
297
+ end
298
+
299
+ }
300
+ }
301
+
302
+ end
303
+
304
+ end
305
+
246
306
  # TODO: add documentation
247
307
  def enable_logging
248
308
 
309
+ set_debug_exceptions # if enabled
310
+
311
+ # returns logging level as string
249
312
  logging_level = Parameter[ :logging_level, nil ]
250
313
 
314
+ # do not enable logging if no logging level is not defined
251
315
  return nil if logging_level.nil?
252
316
 
253
- Kernel::raise RuntimeError.new( "Wrong logging level format '%s' (Expected: %s)" % [ logging_level, "Numeric string"] ) unless MobyUtil::StringHelper.numeric?( logging_level )
317
+ # raise exception if wrong format for logging level
318
+ Kernel::raise RuntimeError.new(
319
+
320
+ "Wrong logging level format '%s' defined in TDriver parameter/template XML (expected %s)" % [ logging_level, "numeric string"]
321
+
322
+ ) unless logging_level.numeric? #MobyUtil::StringHelper.numeric?( logging_level )
254
323
 
324
+ # convert to integer
255
325
  logging_level = logging_level.to_i
256
326
 
257
- Kernel::raise RuntimeError.new( "Invalid logging level '%s' (Expected: %s)" % [ logging_level, "0..5"] ) unless (0..5).include?( logging_level.to_i )
327
+ # raise exception if unsupported logging level
328
+ Kernel::raise RuntimeError.new(
329
+
330
+ "Unsupported logging level '%s' defined in TDriver parameter/template XML (expected %s)" % [ logging_level, "0..5"]
331
+
332
+ ) unless (0..5).include?( logging_level )
258
333
 
259
334
  @include_behaviour_info = ( MobyUtil::Parameter[ :logging_include_behaviour_info, 'false' ].downcase == 'true' )
260
335
 
261
- # create error dump folder if not exist, used e.g. when xml parse error
262
- MobyUtil::FileHelper.mkdir_path( MobyUtil::FileHelper.expand_path( MobyUtil::Parameter[ :logging_xml_parse_error_dump_path ] ) )
336
+ # UI state XML parse error logging - verify that all required parameters are configured and output folder is created succesfully
337
+ if MobyUtil::KernelHelper.to_boolean( MobyUtil::Parameter[ :logging_xml_parse_error_dump, 'false' ] ) == true
338
+
339
+ begin
340
+
341
+ if MobyUtil::Parameter[ :logging_xml_parse_error_dump_path, nil ].nil?
342
+
343
+ warn("Warning: Configuration parameter :logging_xml_parse_error_dump_path missing, disabling the feature...")
344
+
345
+ # disable feature
346
+ raise ArgumentError
347
+
348
+ else
349
+
350
+ begin
351
+
352
+ # create error dump folder if not exist, used e.g. when xml parse error
353
+ MobyUtil::FileHelper.mkdir_path( MobyUtil::FileHelper.expand_path( $last_parameter ) )
354
+
355
+ rescue Exception
356
+
357
+ warn("Warning: Unable to create log folder %s for corrupted XML UI state files" % [ MobyUtil::Parameter[ :logging_xml_parse_error_dump_path ] ] )
358
+
359
+ # disable feature
360
+ raise ArgumentError
361
+
362
+ end
363
+
364
+ end
365
+
366
+ if MobyUtil::Parameter[ :logging_xml_parse_error_dump_overwrite, nil ].nil?
367
+
368
+ warn("Warning: Configuration parameter :logging_xml_parse_error_dump_overwrite missing, using 'false' as default value")
369
+
370
+ MobyUtil::Parameter[ :logging_xml_parse_error_dump_overwrite ] = 'false'
371
+
372
+ end
373
+
374
+ rescue ArgumentError => exception
375
+
376
+ MobyUtil::Parameter[ :logging_xml_parse_error_dump ] = 'false'
377
+
378
+ rescue Exception => exception
379
+
380
+ warn("Warning: Disabling logging due to failure (%s: %s)" % [ exception.class, exception.message ] )
381
+
382
+ MobyUtil::Parameter[ :logging_xml_parse_error_dump ] = 'false'
383
+
384
+ end
385
+
386
+ else
387
+
388
+ warn("Warning: Configuration parameter :logging_xml_parse_error_dump missing, disabling the feature...")
389
+ MobyUtil::Parameter[ :logging_xml_parse_error_dump ] = 'false'
263
390
 
391
+ end
392
+
264
393
  unless logging_level.zero?
265
394
 
266
395
  # create new logger instance