testability-driver 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (214) hide show
  1. data/README +1 -0
  2. data/bin/start_app_perf +199 -0
  3. data/bin/tdriver-devtools +3 -0
  4. data/config/sut_parameters.rb +39 -0
  5. data/ext/extconf.rb +67 -0
  6. data/ext/native_extensions.c +70 -0
  7. data/lib/matti.rb +30 -0
  8. data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +223 -0
  9. data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
  10. data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
  11. data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
  12. data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
  13. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
  14. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
  15. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
  16. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
  17. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
  18. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
  19. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
  20. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
  21. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
  22. data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
  23. data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
  24. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1924 -0
  25. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
  26. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
  27. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
  28. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
  29. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
  30. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
  31. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
  32. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
  33. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
  34. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
  35. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
  36. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
  37. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
  38. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
  39. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
  40. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
  41. data/lib/tdriver-devtools/behaviour/xml_generator/example/flick-example.rb +245 -0
  42. data/lib/tdriver-devtools/behaviour/xml_generator/example/sut.rb +964 -0
  43. data/lib/tdriver-devtools/behaviour/xml_generator/generate.rb +68 -0
  44. data/lib/tdriver-devtools/behaviour/xml_generator/lib/custom_rdoc_generator.rb +1865 -0
  45. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.default.template +1 -0
  46. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument.template +3 -0
  47. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.argument_type.template +4 -0
  48. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.exception.template +4 -0
  49. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.arguments.template +4 -0
  50. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.deprecated.template +3 -0
  51. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.exceptions.template +3 -0
  52. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.info.template +1 -0
  53. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.returns.template +3 -0
  54. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.tables.template +3 -0
  55. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.method.template +12 -0
  56. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.returns.template +5 -0
  57. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.item.template +1 -0
  58. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.row.template +2 -0
  59. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.table.template +7 -0
  60. data/lib/tdriver-devtools/behaviour/xml_generator/templates/behaviour.xml.template +14 -0
  61. data/lib/tdriver-devtools/behaviour/xml_generator/update +3 -0
  62. data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
  63. data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
  64. data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
  65. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
  66. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
  67. data/lib/tdriver-devtools/doc/generate.rb +892 -0
  68. data/lib/tdriver-devtools/doc/update +1 -0
  69. data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
  70. data/lib/tdriver-devtools/doc/xslt/template.xsl +1861 -0
  71. data/lib/tdriver-devtools/doc/xslt/update +3 -0
  72. data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
  73. data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
  74. data/lib/tdriver-devtools/tests/feature_tests/example/flick-example.rb +233 -0
  75. data/lib/tdriver-devtools/tests/feature_tests/example/impl.rb +194 -0
  76. data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
  77. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
  78. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
  79. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
  80. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
  81. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
  82. data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
  83. data/lib/tdriver.rb +26 -0
  84. data/lib/tdriver/base/behaviour/behaviour.rb +32 -0
  85. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +94 -0
  86. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +262 -0
  87. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +111 -0
  88. data/lib/tdriver/base/behaviour/factory.rb +380 -0
  89. data/lib/tdriver/base/behaviour/loader.rb +28 -0
  90. data/lib/tdriver/base/command_data/command_data.rb +51 -0
  91. data/lib/tdriver/base/command_data/loader.rb +25 -0
  92. data/lib/tdriver/base/errors.rb +131 -0
  93. data/lib/tdriver/base/loader.rb +38 -0
  94. data/lib/tdriver/base/state_object.rb +270 -0
  95. data/lib/tdriver/base/sut/adapter.rb +28 -0
  96. data/lib/tdriver/base/sut/controller.rb +119 -0
  97. data/lib/tdriver/base/sut/factory.rb +287 -0
  98. data/lib/tdriver/base/sut/generic/behaviours/application.rb +243 -0
  99. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
  100. data/lib/tdriver/base/sut/generic/behaviours/find.rb +96 -0
  101. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +346 -0
  102. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1268 -0
  103. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +182 -0
  104. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +119 -0
  105. data/lib/tdriver/base/sut/generic/commands/application.rb +219 -0
  106. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +82 -0
  107. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +58 -0
  108. data/lib/tdriver/base/sut/generic/plugin.rb +96 -0
  109. data/lib/tdriver/base/sut/loader.rb +35 -0
  110. data/lib/tdriver/base/sut/sut.rb +67 -0
  111. data/lib/tdriver/base/test_object/abstract.rb +179 -0
  112. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +94 -0
  113. data/lib/tdriver/base/test_object/behaviours/test_object.rb +787 -0
  114. data/lib/tdriver/base/test_object/factory.rb +618 -0
  115. data/lib/tdriver/base/test_object/identificator.rb +511 -0
  116. data/lib/tdriver/base/test_object/loader.rb +37 -0
  117. data/lib/tdriver/env.rb +21 -0
  118. data/lib/tdriver/loader.rb +36 -0
  119. data/lib/tdriver/matti.rb +35 -0
  120. data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
  121. data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +158 -0
  122. data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +98 -0
  123. data/lib/tdriver/report/report.rb +47 -0
  124. data/lib/tdriver/report/report_api.rb +207 -0
  125. data/lib/tdriver/report/report_combine.rb +86 -0
  126. data/lib/tdriver/report/report_crash_file_capture.rb +167 -0
  127. data/lib/tdriver/report/report_creator.rb +571 -0
  128. data/lib/tdriver/report/report_cucumber.rb +158 -0
  129. data/lib/tdriver/report/report_cucumber_listener.rb +337 -0
  130. data/lib/tdriver/report/report_cucumber_reporter.rb +335 -0
  131. data/lib/tdriver/report/report_data_presentation.rb +152 -0
  132. data/lib/tdriver/report/report_data_table.rb +64 -0
  133. data/lib/tdriver/report/report_execution_statistics.rb +284 -0
  134. data/lib/tdriver/report/report_file_capture.rb +159 -0
  135. data/lib/tdriver/report/report_grouping.rb +539 -0
  136. data/lib/tdriver/report/report_junit_xml.rb +147 -0
  137. data/lib/tdriver/report/report_rspec.rb +108 -0
  138. data/lib/tdriver/report/report_test_case_run.rb +621 -0
  139. data/lib/tdriver/report/report_test_run.rb +1286 -0
  140. data/lib/tdriver/report/report_test_unit.rb +175 -0
  141. data/lib/tdriver/report/report_writer.rb +1405 -0
  142. data/lib/tdriver/tdriver.rb +158 -0
  143. data/lib/tdriver/util/common.rb +24 -0
  144. data/lib/tdriver/util/common/array.rb +39 -0
  145. data/lib/tdriver/util/common/crc16.rb +100 -0
  146. data/lib/tdriver/util/common/environment.rb +153 -0
  147. data/lib/tdriver/util/common/error.rb +39 -0
  148. data/lib/tdriver/util/common/file.rb +315 -0
  149. data/lib/tdriver/util/common/gem.rb +108 -0
  150. data/lib/tdriver/util/common/kernel.rb +189 -0
  151. data/lib/tdriver/util/common/loader.rb +39 -0
  152. data/lib/tdriver/util/common/retryable.rb +98 -0
  153. data/lib/tdriver/util/common/string.rb +77 -0
  154. data/lib/tdriver/util/dbaccess/dbaccess.rb +188 -0
  155. data/lib/tdriver/util/dbaccess/dbconnection.rb +41 -0
  156. data/lib/tdriver/util/dbaccess/error.rb +35 -0
  157. data/lib/tdriver/util/dbaccess/loader.rb +29 -0
  158. data/lib/tdriver/util/dynamic_attribute_filter.rb +182 -0
  159. data/lib/tdriver/util/hooking.rb +434 -0
  160. data/lib/tdriver/util/loader.rb +65 -0
  161. data/lib/tdriver/util/localisation.rb +24 -0
  162. data/lib/tdriver/util/localisation/error.rb +32 -0
  163. data/lib/tdriver/util/localisation/loader.rb +28 -0
  164. data/lib/tdriver/util/localisation/localisation.rb +479 -0
  165. data/lib/tdriver/util/logger.rb +377 -0
  166. data/lib/tdriver/util/operator_data/error.rb +29 -0
  167. data/lib/tdriver/util/operator_data/loader.rb +26 -0
  168. data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
  169. data/lib/tdriver/util/other/config.rb +221 -0
  170. data/lib/tdriver/util/parameter.rb +24 -0
  171. data/lib/tdriver/util/parameter/error.rb +45 -0
  172. data/lib/tdriver/util/parameter/loader.rb +37 -0
  173. data/lib/tdriver/util/parameter/parameter.rb +285 -0
  174. data/lib/tdriver/util/parameter/parameter_hash.rb +101 -0
  175. data/lib/tdriver/util/parameter/parameter_template.rb +120 -0
  176. data/lib/tdriver/util/parameter/parameter_user_api.rb +84 -0
  177. data/lib/tdriver/util/parameter/parameter_xml.rb +247 -0
  178. data/lib/tdriver/util/plugin/abstract.rb +60 -0
  179. data/lib/tdriver/util/plugin/error.rb +25 -0
  180. data/lib/tdriver/util/plugin/loader.rb +28 -0
  181. data/lib/tdriver/util/plugin/service.rb +200 -0
  182. data/lib/tdriver/util/recorder.rb +292 -0
  183. data/lib/tdriver/util/stats.rb +90 -0
  184. data/lib/tdriver/util/user_data/error.rb +29 -0
  185. data/lib/tdriver/util/user_data/loader.rb +26 -0
  186. data/lib/tdriver/util/user_data/user_data.rb +103 -0
  187. data/lib/tdriver/util/video_rec.rb +264 -0
  188. data/lib/tdriver/util/xml/abstraction.rb +47 -0
  189. data/lib/tdriver/util/xml/builder.rb +54 -0
  190. data/lib/tdriver/util/xml/document.rb +32 -0
  191. data/lib/tdriver/util/xml/element.rb +32 -0
  192. data/lib/tdriver/util/xml/error.rb +46 -0
  193. data/lib/tdriver/util/xml/loader.rb +46 -0
  194. data/lib/tdriver/util/xml/nil_element.rb +89 -0
  195. data/lib/tdriver/util/xml/nodeset.rb +32 -0
  196. data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
  197. data/lib/tdriver/util/xml/parsers/loader.rb +22 -0
  198. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +111 -0
  199. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +54 -0
  200. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +58 -0
  201. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +58 -0
  202. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +147 -0
  203. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +42 -0
  204. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +187 -0
  205. data/lib/tdriver/util/xml/xml.rb +170 -0
  206. data/lib/tdriver/verify/verify.rb +687 -0
  207. data/lib/tdriver/verify/verify.rb_org +630 -0
  208. data/lib/tdriver/version.rb +21 -0
  209. data/xml/behaviours/generic.xml +495 -0
  210. data/xml/defaults/generic.xml +97 -0
  211. data/xml/defaults/sut_generic.xml +36 -0
  212. data/xml/parameters/tdriver_parameters.xml +23 -0
  213. data/xml/templates/generic.xml +227 -0
  214. metadata +327 -0
@@ -0,0 +1,189 @@
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
+ # Helper class to store verifyblock for
23
+ # constant verifications for sut state
24
+ class VerifyBlock
25
+
26
+ attr_accessor :block,:expected, :message,:source, :timeout
27
+
28
+ def initialize(block, expected, message = nil, timeout = nil, source = "")
29
+
30
+ @block = block
31
+ @expected = expected
32
+ @message = message
33
+ @timeout = timeout
34
+ @source = source
35
+
36
+ end
37
+
38
+ end
39
+
40
+ class KernelHelper
41
+
42
+ # Function to determine if given value is boolean
43
+ # == params
44
+ # value:: String containing boolean
45
+ # == returns
46
+ # TrueClass::
47
+ # FalseClass::
48
+ def self.boolean?( value )
49
+
50
+ /^(true|false)$/i.match( value.to_s ).kind_of?( MatchData ) rescue false
51
+
52
+ end
53
+
54
+ # Function to return boolean of given value
55
+ # == params
56
+ # value:: String containing boolean
57
+ # == returns
58
+ # TrueClass::
59
+ # FalseClass::
60
+ def self.to_boolean( value, default = nil )
61
+
62
+ /^(true|false)$/i.match( value.to_s ) ? $1.downcase == 'true' : default
63
+
64
+ end
65
+
66
+ # Function to return class constant from a string
67
+ # == params
68
+ # constant_name:: String containing path
69
+ # == returns
70
+ # Class
71
+ def self.get_constant( constant_name )
72
+
73
+ begin
74
+
75
+ constant_name.split("::").inject( Kernel ){ | scope, const_name | scope.const_get( const_name ) }
76
+
77
+ rescue
78
+
79
+ Kernel::raise NameError.new( "Invalid constant %s" % constant_name )
80
+
81
+ end
82
+
83
+ end
84
+
85
+ def self.parse_caller( at )
86
+
87
+ if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
88
+
89
+ file = Regexp.last_match[ 1 ]
90
+ line = Regexp.last_match[ 2 ].to_i
91
+ method = Regexp.last_match[ 3 ]
92
+
93
+ [ file, line, method ]
94
+
95
+ end
96
+
97
+ end
98
+
99
+ def self.deprecated( deprecated_name, new_name = "" )
100
+
101
+ output = "warning: #{ deprecated_name } is deprecated"
102
+
103
+ output += "; use #{ new_name } instead" unless new_name.empty?
104
+
105
+ $stderr.puts output
106
+
107
+ end
108
+
109
+ # Searches for the given source file for a line
110
+ #
111
+ # === params
112
+ # from_file:: String defining the file to load. If at_line is nil, this argument can also contain a path and line number separated by : (eg. some_dir/some_file.rb:123).
113
+ # at_line:: (optional) Integer, number of the line (first line is 1).
114
+ # === returns
115
+ # String:: Contents of the line
116
+ # === throws
117
+ # RuntimeError:: from_file is not correctly formed, the file cannot be loaded or the line cannot be found.
118
+ def self.find_source( backtrace )
119
+
120
+ ret_str = "\n"
121
+
122
+ begin
123
+
124
+ call_stack = backtrace.to_s.split(':')
125
+ #puts "call_stack:" << backtrace.to_s
126
+
127
+ line_number = 0
128
+ if (call_stack.size() == 2)
129
+ line_number = call_stack[1].to_i
130
+
131
+ else
132
+ line_number = call_stack[call_stack.size()-2].to_i
133
+ end
134
+ #puts "line number: " << line_number.to_s
135
+
136
+ file_path = ""
137
+ if (call_stack.size() == 2)
138
+ file_path = call_stack[0]
139
+ else
140
+ (call_stack.size()-2).times do |index|
141
+ file_path << call_stack[index].to_s << ":"
142
+ end
143
+ file_path.slice!(file_path.size()-1) # remove the trailing colon
144
+ end
145
+ #puts "file path: " << file_path.to_s
146
+
147
+ lines_to_read = line_number >= 2 ? 3 : line_number
148
+ #puts "lines to read: " << lines_to_read.to_s
149
+
150
+ start_line = line_number #- (lines_to_read <= 1 ? 0 : 1)
151
+ #puts "start line:" << start_line.to_s
152
+
153
+ File.open(File.expand_path(file_path.to_s), "r") { |source|
154
+
155
+ lines = source.readlines
156
+ #puts "lines.size:" << lines.size
157
+ Kernel::raise RuntimeError.new("Only \"#{lines.size.to_s}\" lines exist in the source file.")if start_line > lines.size
158
+
159
+ lines_to_read = (lines.size - start_line + 1) < 3 ? (lines.size - start_line + 1) : lines_to_read
160
+
161
+ # the array is zero based, first line is at position 0
162
+ lines_to_read.times do |index|
163
+ if (line_number == (start_line + index))
164
+ ret_str << "=> "
165
+ else
166
+ ret_str << " "
167
+ end
168
+ ret_str << lines[start_line + index - 1]
169
+ end
170
+
171
+ }
172
+
173
+ rescue Exception => e
174
+
175
+ #puts "exception:" << e.inspect
176
+ ret_str << "Unable to load source lines.\n" << e.inspect
177
+
178
+ end
179
+
180
+ return ret_str
181
+
182
+ end
183
+
184
+ # enable hooking for performance measurement & debug logging
185
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
186
+
187
+ end # KernelHelper
188
+
189
+ end # MobyUtil
@@ -0,0 +1,39 @@
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
+ require 'rbconfig' # ??
21
+
22
+ # common modules - should be generic and runnable as standalone
23
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'error.rb' ) )
24
+
25
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'array.rb' ) )
26
+
27
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'crc16.rb' ) )
28
+
29
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'environment.rb' ) )
30
+
31
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'file.rb' ) )
32
+
33
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'gem.rb' ) )
34
+
35
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'kernel.rb' ) )
36
+
37
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'retryable.rb' ) )
38
+
39
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'string.rb' ) )
@@ -0,0 +1,98 @@
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 Retryable
23
+
24
+ # Function to retry code block for x times if exception raises
25
+ # == params
26
+ # options:: Hash of options
27
+ # :tries Number of tries to perform. Default is 1
28
+ # :interval Timeout between retry. Default is 0
29
+ # :exception Retry if given type of exception occures. Default is Exception (any error)
30
+ # == returns
31
+ def self.while( options = {}, &block )
32
+
33
+ options = { :tries => 1, :interval => 0, :exception => Exception }.merge( options )
34
+
35
+ attempt = 1
36
+
37
+ begin
38
+
39
+ # yield given block and pass attempt number as parameter
40
+ return yield( attempt )
41
+
42
+ rescue *options[ :exception ]
43
+
44
+ #if ( options[ :tries ] -= 1) > 0 && ![ *options[ :unless ] ].include?( $!.class )
45
+
46
+ if ( attempt < options[ :tries ] ) && ![ *options[ :unless ] ].include?( $!.class )
47
+
48
+ sleep( options[ :interval ] ) if options[ :interval ] > 0
49
+
50
+ attempt += 1
51
+
52
+ retry
53
+
54
+ end
55
+
56
+ # raise exception with correct exception backtrace
57
+ Kernel::raise $!
58
+
59
+ end
60
+
61
+ nil
62
+ end
63
+
64
+ # Function to retry code block until timeout expires if exception raises
65
+ # == params
66
+ # options:: Hash of options
67
+ # :timeout Timeout until fail. Default is 0
68
+ # :interval Timeout between retry. Default is 0
69
+ # :exception Retry if given type of exception occures. Default is Exception (any error)
70
+ # == returns
71
+ def self.until( options = {}, &block )
72
+
73
+ options = { :timeout => 0, :interval => 0, :exception => Exception }.merge( options )
74
+ start_time = Time.now
75
+
76
+ begin
77
+
78
+ return yield
79
+
80
+ rescue *options[ :exception ]
81
+
82
+ if (Time.now - start_time) <= options[ :timeout ] && ![ *options[ :unless ] ].include?( $!.class )
83
+ sleep( options[ :interval ] ) if options[ :interval ] > 0
84
+ retry
85
+ end
86
+
87
+ # raise exception with correct exception backtrace
88
+ Kernel::raise $!
89
+
90
+ end
91
+ end
92
+
93
+ # enable hooking for performance measurement & debug logging
94
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
95
+
96
+ end # Retryable
97
+
98
+ end # MobyUtil
@@ -0,0 +1,77 @@
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 StringHelper
23
+
24
+ # Function determines if string is "true" or "false"
25
+ # == params
26
+ # string:: String
27
+ # == returns
28
+ # TrueClass/FalseClass
29
+ def self.boolean?( string )
30
+
31
+ # raise exception if argument type other than String
32
+ Kernel::raise ArgumentError.new("Invalid argument format %s (Expected: %s)" % [ string.class, "String" ]) unless string.kind_of?( String )
33
+
34
+ /^(true|false)$/i.match( string ).kind_of?( MatchData )
35
+
36
+ end
37
+
38
+ # Function determines if string is numeric
39
+ # == params
40
+ # string:: Numeric string
41
+ # == returns
42
+ # TrueClass/FalseClass
43
+ def self.numeric?( string )
44
+
45
+ # raise exception if argument type other than String
46
+
47
+ Kernel::raise ArgumentError.new("Invalid argument format %s (Expected: %s)" % [ string.class, "String" ]) unless string.kind_of?( String )
48
+
49
+ /[0-9]+/.match( string ).kind_of?( MatchData )
50
+
51
+ end
52
+
53
+ # Function converts "true" or "false" to boolean
54
+ # == params
55
+ # string:: String
56
+ # == returns
57
+ # TrueClass/FalseClass
58
+ def self.to_boolean( string )
59
+
60
+ if MobyUtil::StringHelper::boolean?( string )
61
+
62
+ /true/i.match( string ).kind_of?( MatchData )
63
+
64
+ else
65
+
66
+ Kernel::raise ArgumentError.new("Invalid value '%s' for boolean (Expected: %s)" % [ string, "'true', 'false'" ] )
67
+
68
+ end
69
+
70
+ end
71
+
72
+ # enable hooking for performance measurement & debug logging
73
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
74
+
75
+ end # StringHelper
76
+
77
+ end # MobyUtil
@@ -0,0 +1,188 @@
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
+ # Utility for handling database connections
21
+
22
+ module MobyUtil
23
+
24
+ class DBAccess
25
+
26
+ DB_TYPE_MYSQL = 'mysql'
27
+ DB_TYPE_SQLITE = 'sqlite'
28
+
29
+ include Singleton
30
+
31
+ # == description
32
+ # Initialize the singleton
33
+ # connection is maintained as long as the connectivity parameters remain the same
34
+ # this is to avoid constant connect as this takes time
35
+ #
36
+ def initialize
37
+ @@_connections = {}
38
+ @@_mysql = nil
39
+ end
40
+
41
+ # == description
42
+ # Class Method that returns existing connections
43
+ #
44
+ def DBAccess.connections()
45
+ return @@_connections
46
+ end
47
+
48
+ # == description
49
+ # Runs an SQL query on the on the given MobyUtil::DBConnection
50
+ #
51
+ # == arguments
52
+ # dbc
53
+ # MobyUtil::DBConnection
54
+ # description: object with the connection details of an open sql connection
55
+ #
56
+ # query_string
57
+ # String
58
+ # description: database-specific SQL query (note that mysql and sqlite have slightly different syntax)
59
+ # example: "select * from tdriver_locale;"
60
+ #
61
+ # == returns
62
+ # Array
63
+ # description: Array of rows returned by the server. Each row is an array of String values.
64
+ #
65
+ # == throws
66
+ # ArgumentError
67
+ # description: if the argument provided is not the right object type
68
+ #
69
+ def self.query( dbc, query_string )
70
+ # Create first instance of this class if it doesn't exist
71
+ self.instance
72
+
73
+ raise ArgumentError.new("Invalid connection object provided.") if dbc.nil? or !dbc.kind_of? MobyUtil::DBConnection
74
+
75
+ db_type = dbc.db_type
76
+ host = dbc.host
77
+ username = dbc.username
78
+ password = dbc.password
79
+ database_name = dbc.database_name
80
+
81
+ # Check creation parameters
82
+ raise DbTypeNotDefinedError.new( "Database type need to be either 'mysql' or 'sqlite'!" ) if db_type == nil
83
+ raise DbTypeNotSupportedError.new( "Database type '#{db_type}' not supported! Type need to be either 'mysql' or 'sqlite'!" ) unless db_type == DB_TYPE_MYSQL or db_type == DB_TYPE_SQLITE
84
+ if db_type == DB_TYPE_MYSQL
85
+ raise ArgumentError.new("Host must be provided as a non empty string.") if host.nil? or host.class != String or host.empty?
86
+ raise ArgumentError.new("Username must be provided as a non empty string.") if username.nil? or username.class != String or username.empty?
87
+ raise ArgumentError.new("Password must be provided as a string.") if password.nil? or password.class != String
88
+ end
89
+ raise ArgumentError.new("The database name must be provided as a non empty string.") if database_name.nil? or database_name.class != String or database_name.empty?
90
+ raise ArgumentError.new("The query qtring must be provided as a non empty string.") if query_string.nil? or query_string.class != String or query_string.empty?
91
+
92
+ # Check for exsting connection for that host and create it if needed
93
+ if !@@_connections.has_key?( host + db_type + database_name ) # make connection ID unique by using host, type and db on the key
94
+ dbc.dbh = connect_db( db_type, host, username, password, database_name )
95
+ @@_connections[ host + db_type + database_name ] = dbc
96
+ end
97
+
98
+ if db_type == DB_TYPE_MYSQL
99
+ query_result = @@_connections[ host + db_type + database_name ].dbh.query( query_string )
100
+ elsif dbc.db_type == DB_TYPE_SQLITE
101
+ query_result = @@_connections[ host + db_type + database_name ].dbh.query( query_string )
102
+ end
103
+
104
+ # Return a uniform set of results as an array of rows, rows beeing an array of values ( Array<Array<String>> )
105
+ result = Array.new
106
+ if db_type == DB_TYPE_MYSQL and !query_result.nil?
107
+ query_result.num_rows.times do |i|
108
+ result << query_result.fetch_row
109
+ end
110
+ elsif db_type == DB_TYPE_SQLITE and !query_result.nil?
111
+ # Create Array<SQLite3::ResultSet::ArrayWithTypesAndFields<String>> type result
112
+ # it effectively behaves the same as with Array<Array<String>> but the inner Arrays have .fields and .types properties
113
+ # which return the column name and type for each value on the row (Array) returned.
114
+ while ( row = query_result.next )
115
+ result << row
116
+ end
117
+ # it is essentially a prepare method so we need to call close to free the connection
118
+ query_result.close
119
+ end
120
+ return result
121
+ end
122
+
123
+ # == description
124
+ # Retunrs the number of affected rows on the latest sql query on the given MobyUtil::DBConnection
125
+ #
126
+ # == arguments
127
+ # dbc
128
+ # MobyUtil::DBConnection
129
+ # description: object with the connection details of an open sql connection
130
+ #
131
+ # == returns
132
+ # Integer
133
+ # description: number of rows affected
134
+ #
135
+ # == throws
136
+ # ArgumentError
137
+ # description: if the argument provided is not the right object type
138
+ #
139
+ def self.affected_rows(dbc)
140
+ raise ArgumentError.new("Invalid connection object provided.") if dbc.nil? or !dbc.kind_of? MobyUtil::DBConnection
141
+
142
+ # Check for exsting connection for that host and create it if needed
143
+ if !@@_connections.has_key?( dbc.host + dbc.db_type + dbc.database_name ) # make connection ID unique by using host, type and db on the key
144
+ dbc.dbh = connect_db( dbc.db_type, dbc.host, dbc.username, dbc.password, dbc.database_name )
145
+ @@_connections[ dbc.host + dbc.db_type + dbc.database_name ] = dbc
146
+ end
147
+ result = 0
148
+ if dbc.db_type == DB_TYPE_MYSQL
149
+ result = @@_connections[ dbc.host + dbc.db_type + dbc.database_name ].dbh.affected_rows
150
+ elsif dbc.db_type == DB_TYPE_SQLITE
151
+ result = @@_connections[ dbc.host + dbc.db_type + dbc.database_name ].dbh.changes
152
+ end
153
+ return result
154
+ end
155
+
156
+
157
+
158
+ private
159
+
160
+ # == description
161
+ # Function establishes a new connection to as sql server and returns it's handle
162
+ #
163
+ def self.connect_db( db_type, host, username, password, database_name )
164
+
165
+ # if mysql API and connection are not initialized, then initialize the mysql API
166
+ if ( db_type == DB_TYPE_MYSQL ) && ( @@_mysql.nil? )
167
+ require 'mysql'
168
+ @@_mysql = Mysql::init
169
+ elsif db_type == DB_TYPE_SQLITE
170
+ require 'sqlite3'
171
+ end
172
+
173
+ begin
174
+ dbh = @@_mysql.connect( host, username, password, database_name) if db_type == DB_TYPE_MYSQL
175
+ dbh.query 'SET NAMES utf8' if db_type == DB_TYPE_MYSQL # set the utf8 encoding
176
+ dbh = SQLite3::Database.new( database_name ) if db_type == DB_TYPE_SQLITE
177
+ rescue
178
+ raise SqlConnectError.new( $!.message )
179
+ end
180
+
181
+ return dbh
182
+
183
+ end
184
+
185
+ end # class
186
+
187
+ end # module
188
+