cutedriver-driver 2.0.0.20210120164037

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +16 -0
  3. data/bin/start_app_perf +200 -0
  4. data/bin/tdriver-devtools +3 -0
  5. data/config/sut_parameters.rb +52 -0
  6. data/config/sut_setup.rb +32 -0
  7. data/config/sut_teardown.rb +32 -0
  8. data/config/tdriver_custom_error_recovery.rb +83 -0
  9. data/ext/extconf.rb +70 -0
  10. data/ext/native_extensions.c +315 -0
  11. data/lib/matti.rb +25 -0
  12. data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +120 -0
  13. data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
  14. data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
  15. data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
  16. data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
  17. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
  18. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
  19. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
  20. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
  21. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
  22. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
  23. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
  24. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
  25. data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
  26. data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
  27. data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
  28. data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1945 -0
  29. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
  30. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
  31. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
  32. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
  33. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
  34. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
  35. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
  36. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
  37. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
  38. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
  39. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
  40. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
  41. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
  42. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
  43. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
  44. data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
  45. data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
  46. data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
  47. data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
  48. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
  49. data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
  50. data/lib/tdriver-devtools/doc/generate.rb +917 -0
  51. data/lib/tdriver-devtools/doc/update +1 -0
  52. data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
  53. data/lib/tdriver-devtools/doc/xslt/template.xsl +2170 -0
  54. data/lib/tdriver-devtools/doc/xslt/update +3 -0
  55. data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
  56. data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
  57. data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
  58. data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
  59. data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
  60. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
  61. data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
  62. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
  63. data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
  64. data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
  65. data/lib/tdriver.rb +23 -0
  66. data/lib/tdriver/base/behaviour/abstract.rb +29 -0
  67. data/lib/tdriver/base/behaviour/behaviours/object_abstract.rb +107 -0
  68. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +99 -0
  69. data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +278 -0
  70. data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +119 -0
  71. data/lib/tdriver/base/behaviour/factory.rb +495 -0
  72. data/lib/tdriver/base/behaviour/loader.rb +46 -0
  73. data/lib/tdriver/base/command_data/command_data.rb +51 -0
  74. data/lib/tdriver/base/command_data/loader.rb +29 -0
  75. data/lib/tdriver/base/controller/abstraction.rb +56 -0
  76. data/lib/tdriver/base/controller/loader.rb +21 -0
  77. data/lib/tdriver/base/errors.rb +134 -0
  78. data/lib/tdriver/base/loader.rb +47 -0
  79. data/lib/tdriver/base/state_object.rb +373 -0
  80. data/lib/tdriver/base/sut/adapter.rb +54 -0
  81. data/lib/tdriver/base/sut/controller.rb +151 -0
  82. data/lib/tdriver/base/sut/factory.rb +339 -0
  83. data/lib/tdriver/base/sut/generic/behaviours/agent.rb +77 -0
  84. data/lib/tdriver/base/sut/generic/behaviours/application.rb +427 -0
  85. data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
  86. data/lib/tdriver/base/sut/generic/behaviours/find.rb +107 -0
  87. data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +337 -0
  88. data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1888 -0
  89. data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +210 -0
  90. data/lib/tdriver/base/sut/generic/behaviours/verification.rb +222 -0
  91. data/lib/tdriver/base/sut/generic/commands/agent.rb +43 -0
  92. data/lib/tdriver/base/sut/generic/commands/application.rb +274 -0
  93. data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
  94. data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +94 -0
  95. data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +64 -0
  96. data/lib/tdriver/base/sut/generic/plugin.rb +97 -0
  97. data/lib/tdriver/base/sut/loader.rb +35 -0
  98. data/lib/tdriver/base/sut/sut.rb +98 -0
  99. data/lib/tdriver/base/test_object/abstract.rb +208 -0
  100. data/lib/tdriver/base/test_object/adapter.rb +740 -0
  101. data/lib/tdriver/base/test_object/behaviours/syncronization.rb +144 -0
  102. data/lib/tdriver/base/test_object/behaviours/test_object.rb +1047 -0
  103. data/lib/tdriver/base/test_object/cache.rb +134 -0
  104. data/lib/tdriver/base/test_object/factory.rb +684 -0
  105. data/lib/tdriver/base/test_object/loader.rb +51 -0
  106. data/lib/tdriver/base/test_object/verification.rb +178 -0
  107. data/lib/tdriver/base/test_object/xml/abstraction.rb +63 -0
  108. data/lib/tdriver/base/test_object/xml/adapter.rb +773 -0
  109. data/lib/tdriver/env.rb +21 -0
  110. data/lib/tdriver/loader.rb +57 -0
  111. data/lib/tdriver/matti.rb +35 -0
  112. data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
  113. data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +168 -0
  114. data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +106 -0
  115. data/lib/tdriver/report/report.rb +61 -0
  116. data/lib/tdriver/report/report_api.rb +348 -0
  117. data/lib/tdriver/report/report_combine.rb +86 -0
  118. data/lib/tdriver/report/report_crash_file_capture.rb +178 -0
  119. data/lib/tdriver/report/report_creator.rb +665 -0
  120. data/lib/tdriver/report/report_cucumber.rb +158 -0
  121. data/lib/tdriver/report/report_cucumber_listener.rb +184 -0
  122. data/lib/tdriver/report/report_cucumber_reporter.rb +181 -0
  123. data/lib/tdriver/report/report_data_presentation.rb +156 -0
  124. data/lib/tdriver/report/report_data_table.rb +64 -0
  125. data/lib/tdriver/report/report_execution_statistics.rb +400 -0
  126. data/lib/tdriver/report/report_file_capture.rb +159 -0
  127. data/lib/tdriver/report/report_graph_generator.rb +59 -0
  128. data/lib/tdriver/report/report_grouping.rb +541 -0
  129. data/lib/tdriver/report/report_javascript.rb +199 -0
  130. data/lib/tdriver/report/report_junit_xml.rb +147 -0
  131. data/lib/tdriver/report/report_rspec.rb +108 -0
  132. data/lib/tdriver/report/report_test_case_run.rb +725 -0
  133. data/lib/tdriver/report/report_test_run.rb +1476 -0
  134. data/lib/tdriver/report/report_test_unit.rb +223 -0
  135. data/lib/tdriver/report/report_writer.rb +1621 -0
  136. data/lib/tdriver/tdriver.rb +209 -0
  137. data/lib/tdriver/util/agent/loader.rb +22 -0
  138. data/lib/tdriver/util/agent/service.rb +107 -0
  139. data/lib/tdriver/util/common/array.rb +39 -0
  140. data/lib/tdriver/util/common/boolean.rb +48 -0
  141. data/lib/tdriver/util/common/crc16.rb +149 -0
  142. data/lib/tdriver/util/common/environment.rb +154 -0
  143. data/lib/tdriver/util/common/error.rb +40 -0
  144. data/lib/tdriver/util/common/exception.rb +53 -0
  145. data/lib/tdriver/util/common/exceptions.rb +12 -0
  146. data/lib/tdriver/util/common/file.rb +328 -0
  147. data/lib/tdriver/util/common/gem.rb +109 -0
  148. data/lib/tdriver/util/common/hash.rb +288 -0
  149. data/lib/tdriver/util/common/kernel.rb +253 -0
  150. data/lib/tdriver/util/common/loader.rb +47 -0
  151. data/lib/tdriver/util/common/numeric.rb +159 -0
  152. data/lib/tdriver/util/common/object.rb +159 -0
  153. data/lib/tdriver/util/common/retryable.rb +179 -0
  154. data/lib/tdriver/util/common/stackable.rb +185 -0
  155. data/lib/tdriver/util/common/string.rb +174 -0
  156. data/lib/tdriver/util/database/access.rb +240 -0
  157. data/lib/tdriver/util/database/connection.rb +44 -0
  158. data/lib/tdriver/util/database/error.rb +34 -0
  159. data/lib/tdriver/util/database/loader.rb +28 -0
  160. data/lib/tdriver/util/filters/attribute_filter.rb +121 -0
  161. data/lib/tdriver/util/filters/loader.rb +29 -0
  162. data/lib/tdriver/util/fixture/loader.rb +22 -0
  163. data/lib/tdriver/util/fixture/service.rb +211 -0
  164. data/lib/tdriver/util/hooking/hooking.rb +477 -0
  165. data/lib/tdriver/util/keymap/keymap.rb +81 -0
  166. data/lib/tdriver/util/loader.rb +80 -0
  167. data/lib/tdriver/util/localisation/error.rb +31 -0
  168. data/lib/tdriver/util/localisation/loader.rb +25 -0
  169. data/lib/tdriver/util/localisation/localisation.rb +762 -0
  170. data/lib/tdriver/util/logger/loader.rb +22 -0
  171. data/lib/tdriver/util/logger/logger.rb +591 -0
  172. data/lib/tdriver/util/operator_data/error.rb +29 -0
  173. data/lib/tdriver/util/operator_data/loader.rb +27 -0
  174. data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
  175. data/lib/tdriver/util/other/config.rb +221 -0
  176. data/lib/tdriver/util/parameter/error.rb +48 -0
  177. data/lib/tdriver/util/parameter/loader.rb +25 -0
  178. data/lib/tdriver/util/parameter/parameter.rb +1161 -0
  179. data/lib/tdriver/util/plugin/abstract.rb +61 -0
  180. data/lib/tdriver/util/plugin/error.rb +0 -0
  181. data/lib/tdriver/util/plugin/loader.rb +28 -0
  182. data/lib/tdriver/util/plugin/service.rb +319 -0
  183. data/lib/tdriver/util/recorder/loader.rb +25 -0
  184. data/lib/tdriver/util/recorder/recorder.rb +72 -0
  185. data/lib/tdriver/util/recorder/scripter.rb +294 -0
  186. data/lib/tdriver/util/statistics/statistics.rb +89 -0
  187. data/lib/tdriver/util/user_data/error.rb +28 -0
  188. data/lib/tdriver/util/user_data/loader.rb +25 -0
  189. data/lib/tdriver/util/user_data/user_data.rb +104 -0
  190. data/lib/tdriver/util/video/camera.rb +67 -0
  191. data/lib/tdriver/util/video/camera_linux.rb +153 -0
  192. data/lib/tdriver/util/video/camera_windows.rb +174 -0
  193. data/lib/tdriver/util/video/loader.rb +31 -0
  194. data/lib/tdriver/util/video/video_utils.rb +139 -0
  195. data/lib/tdriver/util/xml/abstraction.rb +117 -0
  196. data/lib/tdriver/util/xml/attribute.rb +32 -0
  197. data/lib/tdriver/util/xml/builder.rb +53 -0
  198. data/lib/tdriver/util/xml/comment.rb +32 -0
  199. data/lib/tdriver/util/xml/document.rb +32 -0
  200. data/lib/tdriver/util/xml/element.rb +32 -0
  201. data/lib/tdriver/util/xml/error.rb +46 -0
  202. data/lib/tdriver/util/xml/loader.rb +62 -0
  203. data/lib/tdriver/util/xml/nil_node.rb +95 -0
  204. data/lib/tdriver/util/xml/nodeset.rb +32 -0
  205. data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
  206. data/lib/tdriver/util/xml/parsers/loader.rb +21 -0
  207. data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +167 -0
  208. data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +66 -0
  209. data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +64 -0
  210. data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
  211. data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +66 -0
  212. data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +39 -0
  213. data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +58 -0
  214. data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +212 -0
  215. data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +237 -0
  216. data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +39 -0
  217. data/lib/tdriver/util/xml/text.rb +32 -0
  218. data/lib/tdriver/util/xml/xml.rb +332 -0
  219. data/lib/tdriver/verify/verify.rb +2398 -0
  220. data/lib/tdriver/version.rb +21 -0
  221. data/xml/behaviours/generic.xml +530 -0
  222. data/xml/defaults/generic.xml +11 -0
  223. data/xml/defaults/sut_generic.xml +8 -0
  224. data/xml/parameters/tdriver_parameters.xml +23 -0
  225. data/xml/templates/generic.xml +292 -0
  226. metadata +324 -0
@@ -0,0 +1,185 @@
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 StackableValue
23
+
24
+ # TODO: document me
25
+ def initialize( value, explicit_format = [] )
26
+
27
+ @explicit_format = explicit_format.kind_of?( Array ) ? explicit_format : [ explicit_format ]
28
+
29
+ @stack = []
30
+
31
+ push( value )
32
+
33
+ end
34
+
35
+ # TODO: document me
36
+ def push( value )
37
+
38
+ unless @explicit_format.empty?
39
+
40
+ found = false
41
+
42
+ # collect verbose type list
43
+ verbose_type_list = @explicit_format.each_with_index.collect{ | type, index |
44
+
45
+ raise TypeError, "invalid argument type #{ type } for check_type. Did you mean #{ type.class }?" unless type.kind_of?( Class )
46
+
47
+ found = true if value.kind_of?( type )
48
+
49
+ # result string, separate types if multiple types given
50
+ "#{ ( ( index > 0 ) ? ( index + 1 < @explicit_format.count ? ", " : " or " ) : "" ) }#{ type.to_s }"
51
+
52
+ }.join
53
+
54
+ raise TypeError, "wrong variable format #{ value.class } for stackable value (expected #{ verbose_type_list })" unless found
55
+
56
+ end
57
+
58
+ # add to stack
59
+ @stack << value
60
+
61
+ end
62
+
63
+ # TODO: document me
64
+ def pop
65
+
66
+ @stack.pop unless ( @stack.count == 1 )
67
+
68
+ # return last value from stack
69
+ @stack.last
70
+
71
+ end
72
+
73
+ # TODO: document me
74
+ def restore
75
+
76
+ @stack = [ @stack.first ]
77
+
78
+ # return first value in stack array
79
+ @stack.last
80
+
81
+ end
82
+
83
+ # TODO: document me
84
+ def stacked?
85
+
86
+ # determine if there is values in stack
87
+ @stack.count > 1
88
+
89
+ end
90
+
91
+ # TODO: document me
92
+ def to_s
93
+
94
+ # return last value in stack array as string
95
+ @stack.last.to_s
96
+
97
+ end
98
+
99
+ # TODO: document me
100
+ def inspect
101
+
102
+ # return inspect of last value in stack array
103
+ @stack.last.inspect
104
+
105
+ end
106
+
107
+ # TODO: document me
108
+ def count
109
+
110
+ # return size of the stack array
111
+ @stack.count
112
+
113
+ end
114
+
115
+ # TODO: document me
116
+ def first
117
+
118
+ # return first value in stack array
119
+ @stack.first
120
+
121
+ end
122
+
123
+ # TODO: document me
124
+ def last
125
+
126
+ # return last value in stack array
127
+ @stack.last
128
+
129
+ end
130
+
131
+ # TODO: document me
132
+ def []( value )
133
+
134
+ # return last one if index is too high
135
+ value = -1 if ( value > @stack.count - 1 )
136
+
137
+ @stack[ value ]
138
+
139
+ end
140
+
141
+ # TODO: document me
142
+ def []=( position, value )
143
+
144
+ # return last one if index is too high
145
+ value = -1 if ( position > @stack.count - 1 )
146
+
147
+ @stack[ position ] = value
148
+
149
+ end
150
+
151
+ # TODO: document me
152
+ def set( value )
153
+
154
+ @stack[ -1 ] = value
155
+
156
+ end
157
+
158
+ def ==( value )
159
+
160
+ @stack.last == value
161
+
162
+ end
163
+
164
+ # TODO: document me
165
+ def kind_of?( klass )
166
+
167
+ # compary stacked value class
168
+ @stack.last.kind_of?( klass ) or klass == TDriver::StackableValue
169
+
170
+ end
171
+
172
+ # create required aliases
173
+ alias_method :size, :count
174
+
175
+ alias_method :<<, :push
176
+
177
+ alias_method :eql?, :==
178
+
179
+ alias_method :value=, :set
180
+
181
+ alias_method :value, :last
182
+
183
+ end # StackableValue
184
+
185
+ end # TDriver
@@ -0,0 +1,174 @@
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
+ # extend Ruby String class functionality
21
+ class String
22
+
23
+ def true?
24
+
25
+ /^true$/i.match( to_s ) != nil
26
+
27
+ end
28
+
29
+ def false?
30
+
31
+ /^false$/i.match( to_s ) != nil
32
+
33
+ end
34
+
35
+ def not_empty( message = "String must not be empty", exception = ArgumentError )
36
+
37
+ if empty?
38
+
39
+ # replace macros
40
+ #message.gsub!( '$1', inspect )
41
+
42
+ raise exception, message, caller
43
+
44
+ end
45
+
46
+ self
47
+
48
+ end
49
+
50
+ # TODO: document me
51
+ def encode_to_xml
52
+
53
+ gsub('&', '&amp;').gsub('<', '&lt;').gsub('>', '&gt;').gsub( '"', '&quot;' ).gsub( '\'', '&apos;' )
54
+
55
+ end
56
+
57
+ # Function determines if string is "true" or "false"
58
+ # == params
59
+ # string:: String
60
+ # == returns
61
+ # TrueClass/FalseClass
62
+ def boolean?
63
+
64
+ /^(true|false)$/i.match( self ).kind_of?( MatchData )
65
+
66
+ end
67
+
68
+ # Function determines if string is numeric
69
+ # == params
70
+ # string:: Numeric string
71
+ # == returns
72
+ # TrueClass/FalseClass
73
+ def numeric?
74
+
75
+ /^[0-9]+$/.match( self ).kind_of?( MatchData )
76
+
77
+ end
78
+
79
+ # Function converts "true" or "false" to boolean
80
+ # == params
81
+ # string:: String
82
+ # == returns
83
+ # TrueClass/FalseClass
84
+ def to_boolean( *default )
85
+
86
+ if /^(true|false)$/i.match( to_s )
87
+
88
+ $1.downcase == 'true'
89
+
90
+ else
91
+
92
+ # pass default value if string didn't contain boolean
93
+ if default.count > 0
94
+
95
+ # retrieve first value from array
96
+ default = default.first
97
+
98
+ # check that argument type is correct
99
+ default.check_type( [ TrueClass, FalseClass ], 'wrong argument type $1 for to_boolean default value argument (expecting $2)')
100
+
101
+ # return default value as result
102
+ default
103
+
104
+ else
105
+
106
+ # raise exception if no default given
107
+ raise TypeError, "Unable to convert string \"#{ self }\" to boolean (Expected \"true\" or \"false\")", caller
108
+
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end
116
+
117
+ module MobyUtil
118
+
119
+ class StringHelper
120
+
121
+ # Function determines if string is "true" or "false"
122
+ # == params
123
+ # string:: String
124
+ # == returns
125
+ # TrueClass/FalseClass
126
+ def self.boolean?( string )
127
+
128
+ # raise exception if argument type other than String
129
+ string.check_type( String, "Wrong argument type $1 (Expected $2)" )
130
+
131
+ /^(true|false)$/i.match( string ).kind_of?( MatchData )
132
+
133
+ end
134
+
135
+ # Function determines if string is numeric
136
+ # == params
137
+ # string:: Numeric string
138
+ # == returns
139
+ # TrueClass/FalseClass
140
+ def self.numeric?( string )
141
+
142
+ # raise exception if argument type other than String
143
+
144
+ string.check_type String, 'Wrong argument type $1 (expected: $2)'
145
+
146
+ /^[0-9]+$/.match( string ).kind_of?( MatchData )
147
+
148
+ end
149
+
150
+ # Function converts "true" or "false" to boolean
151
+ # == params
152
+ # string:: String
153
+ # == returns
154
+ # TrueClass/FalseClass
155
+ def self.to_boolean( string )
156
+
157
+ if MobyUtil::StringHelper::boolean?( string )
158
+
159
+ /true/i.match( string ).kind_of?( MatchData )
160
+
161
+ else
162
+
163
+ raise ArgumentError.new("Invalid value #{ string.inspect } for boolean (expected: \"true\" or \"false\")" )
164
+
165
+ end
166
+
167
+ end
168
+
169
+ # enable hooking for performance measurement & debug logging
170
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
171
+
172
+ end # StringHelper
173
+
174
+ end # MobyUtil
@@ -0,0 +1,240 @@
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
+ module MobyUtil
22
+
23
+ class DBAccess
24
+
25
+ DB_TYPE_MYSQL = 'mysql'
26
+ DB_TYPE_SQLITE = 'sqlite'
27
+
28
+ include Singleton
29
+
30
+ # == description
31
+ # Initialize the singleton
32
+ # connection is maintained as long as the connectivity parameters remain the same
33
+ # this is to avoid constant connect as this takes time
34
+ #
35
+ def initialize
36
+ @@_connections = {}
37
+ @@_mysql = nil
38
+ end
39
+
40
+ # == description
41
+ # Class Method that returns existing connections
42
+ #
43
+ def self.connections()
44
+ return @@_connections
45
+ end
46
+
47
+ # == description
48
+ # Runs an SQL query on the on the given MobyUtil::DBConnection
49
+ #
50
+ # == arguments
51
+ # dbc
52
+ # MobyUtil::DBConnection
53
+ # description: object with the connection details of an open sql connection
54
+ #
55
+ # query_string
56
+ # String
57
+ # description: database-specific SQL query (note that mysql and sqlite have slightly different syntax)
58
+ # example: "select * from tdriver_locale;"
59
+ #
60
+ # == returns
61
+ # Array
62
+ # description: Array of rows returned by the server. Each row is an array of String values.
63
+ #
64
+ # == throws
65
+ # ArgumentError
66
+ # description: if the argument provided is not the right object type
67
+ #
68
+ def self.query( dbc, query_string )
69
+ # Create first instance of this class if it doesn't exist
70
+ self.instance
71
+
72
+ dbc.check_type( MobyUtil::DBConnection, "Wrong argument type $1 for database connection object (expected $2)" )
73
+
74
+ query_string.check_type( String, "Wrong variable type $1 for database query string (expected $2)")
75
+ query_string.not_empty( "Database query string must not be empty string" )
76
+
77
+ db_type = dbc.db_type
78
+ host = dbc.host
79
+ username = dbc.username
80
+ password = dbc.password
81
+ database_name = dbc.database_name
82
+
83
+ # Check creation parameters
84
+
85
+ db_type.check_type( String, "Wrong argument type $1 for database type (expected $2)" )
86
+
87
+ db_type.validate( [ DB_TYPE_MYSQL, DB_TYPE_SQLITE ], "Unsupported database type $1 (expected $2)" )
88
+
89
+ if ( db_type == DB_TYPE_MYSQL )
90
+
91
+ host.check_type( String, "Wrong variable type $1 for host (expected $2)" )
92
+ host.not_empty( "Host must not be empty string" )
93
+
94
+ username.check_type( String, "Wrong variable type $1 for username (expected $2)" )
95
+ username.not_empty( "Username must not be empty string" )
96
+
97
+ password.check_type( String, "Wrong variable type $1 for password (expected $2)")
98
+
99
+ end
100
+
101
+ database_name.check_type( String, "Wrong variable type $1 for database name (expected $2)" )
102
+ database_name.not_empty( "Database name must not be empty string" )
103
+
104
+ # Check for exsting connection for that host and create it if needed
105
+ if !@@_connections.has_key?( host + db_type + database_name ) # make connection ID unique by using host, type and db on the key
106
+ dbc.dbh = connect_db( db_type, host, username, password, database_name )
107
+ @@_connections[ host + db_type + database_name ] = dbc
108
+ end
109
+
110
+ if db_type == DB_TYPE_MYSQL
111
+
112
+ begin
113
+ query_result = @@_connections[ host + db_type + database_name ].dbh.query( query_string ) # identical?
114
+ rescue
115
+ if @@_mysql
116
+ @@_mysql.close
117
+ @@_mysql=nil
118
+ end
119
+ #Possible timeout in query attempt to recreate the connection and redo the query
120
+ dbc.dbh = connect_db( db_type, host, username, password, database_name )
121
+ @@_connections[ host + db_type + database_name ] = dbc
122
+ query_result = @@_connections[ host + db_type + database_name ].dbh.query( query_string ) # identical?
123
+ end
124
+
125
+ elsif dbc.db_type == DB_TYPE_SQLITE
126
+
127
+ query_result = @@_connections[ host + db_type + database_name ].dbh.query( query_string ) # identical?
128
+
129
+ end
130
+
131
+ # Return a uniform set of results as an array of rows, rows beeing an array of values ( Array<Array<String>> )
132
+ result = []
133
+
134
+ if db_type == DB_TYPE_MYSQL and !query_result.nil?
135
+
136
+ query_result.num_rows.times do |i|
137
+
138
+ result << query_result.fetch_row
139
+
140
+ end
141
+
142
+ elsif db_type == DB_TYPE_SQLITE and !query_result.nil?
143
+
144
+ # Create Array<SQLite3::ResultSet::ArrayWithTypesAndFields<String>> type result
145
+ # it effectively behaves the same as with Array<Array<String>> but the inner Arrays have .fields and .types properties
146
+ # which return the column name and type for each value on the row (Array) returned.
147
+ while ( row = query_result.next )
148
+ result << row
149
+ end
150
+
151
+ # it is essentially a prepare method so we need to call close to free the connection
152
+ query_result.close
153
+
154
+ end
155
+
156
+ result
157
+
158
+ end
159
+
160
+ # == description
161
+ # Retunrs the number of affected rows on the latest sql query on the given MobyUtil::DBConnection
162
+ #
163
+ # == arguments
164
+ # dbc
165
+ # MobyUtil::DBConnection
166
+ # description: object with the connection details of an open sql connection
167
+ #
168
+ # == returns
169
+ # Integer
170
+ # description: number of rows affected
171
+ #
172
+ # == throws
173
+ # ArgumentError
174
+ # description: if the argument provided is not the right object type
175
+ #
176
+ def self.affected_rows(dbc)
177
+
178
+ dbc.check_type( MobyUtil::DBConnection, "Wrong argument type $1 for database connection object (expected $2)" )
179
+
180
+ # Check for exsting connection for that host and create it if needed
181
+ 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
182
+ dbc.dbh = connect_db( dbc.db_type, dbc.host, dbc.username, dbc.password, dbc.database_name )
183
+ @@_connections[ dbc.host + dbc.db_type + dbc.database_name ] = dbc
184
+ end
185
+ result = 0
186
+ if dbc.db_type == DB_TYPE_MYSQL
187
+ result = @@_connections[ dbc.host + dbc.db_type + dbc.database_name ].dbh.affected_rows
188
+ elsif dbc.db_type == DB_TYPE_SQLITE
189
+ result = @@_connections[ dbc.host + dbc.db_type + dbc.database_name ].dbh.changes
190
+ end
191
+ return result
192
+ end
193
+
194
+ # == description
195
+ # Function closes MySQL connection
196
+ #
197
+ def close_db()
198
+
199
+ if @@_mysql
200
+ @@_mysql.close
201
+ @@_mysql=nil
202
+ end
203
+
204
+ end
205
+
206
+ private
207
+
208
+ # == description
209
+ # Function establishes a new connection to as sql server and returns it's handle
210
+ #
211
+ def self.connect_db( db_type, host, username, password, database_name )
212
+
213
+ # if mysql API and connection are not initialized, then initialize the mysql API
214
+ if ( db_type == DB_TYPE_MYSQL ) && ( @@_mysql.nil? )
215
+ require 'mysql'
216
+ @@_mysql = Mysql::init
217
+ elsif db_type == DB_TYPE_SQLITE
218
+ require 'sqlite3'
219
+ end
220
+
221
+ begin
222
+ dbh = @@_mysql.connect( host, username, password, database_name) if db_type == DB_TYPE_MYSQL
223
+ dbh.query 'SET NAMES utf8' if db_type == DB_TYPE_MYSQL # set the utf8 encoding
224
+ dbh = SQLite3::Database.new( database_name ) if db_type == DB_TYPE_SQLITE
225
+ rescue
226
+ raise SqlConnectError, $!.message
227
+ end
228
+
229
+ return dbh
230
+
231
+ end
232
+
233
+ # enable hoo./base/test_object/factory.rb:king for performance measurement & debug logging
234
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
235
+
236
+ end # DBAccess
237
+
238
+ end # MobyUtil
239
+
240
+ at_exit{MobyUtil::DBAccess.instance.close_db}