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,42 @@
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
+ # nokogiri parser
21
+ require 'nokogiri'
22
+
23
+ # for utf-8/unicode support
24
+ require 'kconv'
25
+
26
+ # abstraction for document, nodeset and element
27
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'abstraction.rb' ) )
28
+
29
+ # nokogiri parser wrapper
30
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'document.rb' ) )
31
+
32
+ # nokogiri parser wrapper
33
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'nodeset.rb' ) )
34
+
35
+ # nokogiri parser wrapper
36
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'element.rb' ) )
37
+
38
+ # nokogiri parser wrapper
39
+ require File.expand_path( File.join( File.dirname( __FILE__ ), 'builder.rb' ) )
40
+
41
+ # nokogiri parser wrapper
42
+ #require File.expand_path( File.join( File.dirname( __FILE__ ), 'attribute.rb' ) )
@@ -0,0 +1,187 @@
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
+ module XML
23
+
24
+ module Nokogiri
25
+
26
+ module Nodeset # behaviour
27
+
28
+ include Abstraction
29
+
30
+ def []( node )
31
+
32
+ element_object( @xml[ node ] )
33
+
34
+ end
35
+
36
+ def first
37
+
38
+ element_object( @xml.first )
39
+
40
+ end
41
+
42
+ def last
43
+
44
+ element_object( @xml.last )
45
+
46
+ end
47
+
48
+ def each( &block )
49
+
50
+ @xml.each{ | element |
51
+
52
+ yield( element_object( element ) )
53
+
54
+ }
55
+
56
+ self
57
+
58
+ end
59
+
60
+ def collect( &block )
61
+
62
+ _collect( &block )
63
+ #nodeset_object( _collect( &block ) )
64
+
65
+ end
66
+
67
+ def collect!( &block )
68
+
69
+ @xml = _collect( &block )
70
+
71
+ self
72
+
73
+ end
74
+
75
+ def compact
76
+
77
+ nodeset_object( @xml.compact )
78
+
79
+ end
80
+
81
+ def compact!
82
+
83
+ @xml = @xml.compact
84
+
85
+ self
86
+
87
+ end
88
+
89
+ def sort( &block )
90
+
91
+ nodeset_object( _sort( &block ) )
92
+
93
+ end
94
+
95
+ def sort!( &block )
96
+
97
+ @xml = _sort( &block )
98
+
99
+ self
100
+
101
+ end
102
+
103
+ def empty?
104
+
105
+ @xml.empty?
106
+
107
+ end
108
+
109
+
110
+ def length
111
+
112
+ @xml.length
113
+
114
+ end
115
+
116
+
117
+ def to_a
118
+
119
+ @xml.collect{ | element |
120
+
121
+ element_object( element )
122
+
123
+ }
124
+
125
+ end
126
+
127
+ def delete( node )
128
+
129
+ @xml.each do | element |
130
+
131
+ if ( node.xml.content == element.content )
132
+
133
+ @xml.delete( element )
134
+
135
+ break
136
+
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+
143
+ # aliases for length method
144
+ alias size length
145
+
146
+ alias count length
147
+
148
+ private
149
+
150
+ def _collect( &block )
151
+
152
+ @xml.collect{ | element |
153
+
154
+ yield( element_object( element ) )
155
+
156
+ }
157
+
158
+ end
159
+
160
+ def _sort( &block )
161
+
162
+ @xml.sort{ | element_a, element_b |
163
+
164
+ if block_given?
165
+
166
+ yield( element_object( element_a ), element_object( element_b ) )
167
+
168
+ else
169
+
170
+ element_a <=> element_b
171
+
172
+ end
173
+
174
+ }
175
+
176
+ end
177
+
178
+ # enable hooking for performance measurement & debug logging
179
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
180
+
181
+ end # Nodeset
182
+
183
+ end # Nokogiri
184
+
185
+ end # XML
186
+
187
+ end # MobyUtil
@@ -0,0 +1,170 @@
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
+ module XML
23
+
24
+ # default values
25
+ #@@parser = MobyUtil::XML::LibXML
26
+ @@parser = MobyUtil::XML::Nokogiri
27
+
28
+ # Get current XML parser
29
+ # == params
30
+ # == return
31
+ # Module::
32
+ # == raises
33
+ def self.current_parser
34
+
35
+ @@parser
36
+
37
+ end
38
+
39
+ # Set XML parser to be used
40
+ # == params
41
+ # Module::
42
+ # == return
43
+ # nil
44
+ # Document:: XML document object
45
+ # == raises
46
+ def self.current_parser=( value )
47
+
48
+ @@parser = value
49
+
50
+ nil
51
+
52
+ end
53
+
54
+ # Create XML Document object by parsing XML from string
55
+ #
56
+ # Usage: MobyUtil::XML.parse_string('<root>value</root>')
57
+ # ==> Returns XML document object; default xml parser will be used.
58
+ #
59
+ # == params
60
+ # xml_string:: String containing XML
61
+ # parser:: XML parser class e.g. MobyUtil::XML::Nokogiri
62
+ # == return
63
+ # Document:: XML document object
64
+ # == raises
65
+ def self.parse_string( xml_string )
66
+
67
+ begin
68
+
69
+ MobyUtil::XML::Document.new( nil, current_parser ).extend( @@parser::Document ).tap{ | document |
70
+
71
+ # parse given string
72
+ document.xml = document.parse( xml_string )
73
+
74
+ }
75
+
76
+ rescue Exception => exception
77
+
78
+ # string for exception message
79
+ dump_location = ""
80
+
81
+ # check if xml parse error logging is enabled
82
+ if MobyUtil::KernelHelper.to_boolean( MobyUtil::Parameter[ :logging_xml_parse_error_dump, 'true' ] )
83
+
84
+ # generate filename for xml dump
85
+ filename = MobyUtil::KernelHelper.to_boolean( MobyUtil::Parameter[ :logging_xml_parse_error_dump_overwrite, 'false' ] ) ? 'xml_error_dump.xml' : 'xml_error_dump_%i.xml' % Time.now
86
+
87
+ # ... join filename with xml dump output path
88
+ path = File.join( MobyUtil::FileHelper.expand_path( MobyUtil::Parameter[ :logging_xml_parse_error_dump_path, 'logfiles/' ] ), filename )
89
+
90
+ # create error dump folder if not exist, used e.g. when xml parse error
91
+ MobyUtil::FileHelper.mkdir_path( File.dirname( path ) )
92
+
93
+ # write xml string to file
94
+ File.open( path, "w" ){ | file | file << xml_string }
95
+
96
+ dump_location = ". Saved to %s" % path
97
+
98
+ end
99
+
100
+ # raise exception
101
+ Kernel::raise MobyUtil::XML::ParseError.new( "%s (%s)%s" % [ exception.message.gsub("\n", ''), exception.class, dump_location ] )
102
+
103
+ end
104
+
105
+ end
106
+
107
+ # Create XML Document object by parsing XML from file
108
+ #
109
+ # Usage: MobyUtil::XML.parse_file('xml_dump.xml')
110
+ # ==> Returns XML document object; default xml parser will be used.
111
+ #
112
+ # == params
113
+ # filename:: String containing path and filename of XML file.
114
+ # parser:: XML parser class e.g. MobyUtil::XML::Nokogiri
115
+ # == return
116
+ # Document:: XML document object
117
+ # == raises
118
+ # IOError:: File '%s' not found
119
+ def self.parse_file( filename )
120
+
121
+ # raise exception if file not found
122
+ Kernel::raise IOError.new( "File '%s' not found" % filename ) unless File.exist?( filename )
123
+
124
+ self.parse_string( IO.read( filename ), current_parser )
125
+
126
+ end
127
+
128
+ # Create XML builder object dynamically
129
+ #
130
+ # Usage:
131
+ #
132
+ # MobyUtil::XML.build{
133
+ # root{
134
+ # element(:name => "element_name", :id => "0") {
135
+ # child(:name => "1st_child_of_element_0", :value => "123" )
136
+ # child(:name => "2nd_child_of_element_0", :value => "456" )
137
+ # }
138
+ # }
139
+ # }.to_xml
140
+ #
141
+ # == params
142
+ # &block::
143
+ # == return
144
+ # MobyUtil::XML::Builder
145
+ # == raises
146
+ def self.build( &block )
147
+
148
+ begin
149
+
150
+ MobyUtil::XML::Builder.new.extend( @@parser::Builder ).tap{ | builder |
151
+
152
+ builder.build( &block )
153
+
154
+ }
155
+
156
+ rescue Exception => exception
157
+
158
+ Kernel::raise MobyUtil::XML::BuilderError.new( "%s (%s)" % [ exception.message, exception.class ] )
159
+
160
+
161
+ end
162
+
163
+ end
164
+
165
+ # enable hooking for performance measurement & debug logging
166
+ MobyUtil::Hooking.instance.hook_methods( self ) if defined?( MobyUtil::Hooking )
167
+
168
+ end # XML
169
+
170
+ end # MobyUtil
@@ -0,0 +1,687 @@
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 TDriverVerify
21
+
22
+ TIMEOUT_CYCLE_SECONDS = 0.1 if !defined?( TIMEOUT_CYCLE_SECONDS )
23
+
24
+ @@on_error_verify_block = nil
25
+
26
+ def on_error_verify_block( &block )
27
+
28
+ raise ArgumentError.new( "No verify block given" ) unless block_given?
29
+
30
+ @@on_error_verify_block = block
31
+
32
+ end
33
+
34
+ def reset_on_error_verify_block
35
+
36
+ @@on_error_verify_block = nil
37
+
38
+ end
39
+
40
+ def execute_on_error_verify_block
41
+
42
+ unless @@on_error_verify_block.nil?
43
+
44
+ begin
45
+
46
+ @@on_error_verify_block.call
47
+
48
+ rescue Exception => exception
49
+
50
+ raise exception.class.new( "Exception was raised while executing on_error_verify_block. Reason: %s" % [ exception.message ])
51
+
52
+ end
53
+
54
+ else
55
+
56
+ raise ArgumentError.new( "No verify block defined with on_error_verify_block method" )
57
+
58
+ end
59
+
60
+ end
61
+
62
+ # Verifies that the block given to this method evaluates without throwing any exceptions. Verification is synchronized with all connected suts.
63
+ # If this method is called for a sut, synchronization is only done with that sut.
64
+ #
65
+ # === params
66
+ # timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
67
+ # message:: (optional) A String that is displayed as additional information if the verification fails.
68
+ # === returns
69
+ # nil
70
+ # === raises
71
+ # ArgumentError:: message was not a String or timeout an integer, or no block was given.
72
+ # VerificationError:: The verification failed.
73
+
74
+ def verify( timeout = nil, message = nil, &block )
75
+
76
+ logging_enabled = MobyUtil::Logger.instance.enabled
77
+
78
+ verify_caller = caller(1).first.to_s
79
+
80
+ begin
81
+
82
+ MobyUtil::Logger.instance.enabled = false
83
+ Kernel::raise ArgumentError.new("No block was given.") unless block_given?
84
+ Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
85
+ Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
86
+
87
+ #Set the testobject timeout to 0 for the duration of the verify call
88
+ original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
89
+ MobyBase::TestObjectFactory.instance.timeout = 0
90
+
91
+ timeout_time = get_end_time(timeout)
92
+ #TIMEOUT_CYCLE_SECONDS
93
+
94
+ loop do
95
+
96
+ counter = ref_counter
97
+
98
+ begin # catch errors thrown in the provided block
99
+
100
+ yield
101
+
102
+ # no error => verification ok
103
+ break
104
+
105
+ rescue Exception => e
106
+
107
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
108
+
109
+ source_contents = ""
110
+ error_msg = ""
111
+
112
+ if Time.new > timeout_time
113
+
114
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed\n"
115
+
116
+ begin
117
+
118
+ source_contents = MobyUtil::KernelHelper.find_source(verify_caller)
119
+
120
+ rescue Exception
121
+ # failed to load line from file, do nothing
122
+ MobyUtil::Logger.instance.enabled = logging_enabled
123
+ MobyUtil::Logger.instance.log "behaviour" , "WARNING;Failed to load source line: #{e.backtrace.inspect}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
124
+ end
125
+
126
+ if !source_contents.empty?
127
+ error_msg << source_contents
128
+ end
129
+
130
+ error_msg << "\nNested exception:" << e.message << "\n"
131
+
132
+ Kernel::raise MobyBase::VerificationError.new(error_msg)
133
+
134
+ end
135
+
136
+ end
137
+
138
+ sleep TIMEOUT_CYCLE_SECONDS
139
+
140
+ refresh_suts if counter == ref_counter
141
+
142
+ end # do
143
+
144
+ rescue Exception => e
145
+
146
+ execute_on_error_verify_block unless @@on_error_verify_block.nil?
147
+
148
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
149
+
150
+ MobyUtil::Logger.instance.enabled = logging_enabled
151
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s}#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
152
+ Kernel::raise e
153
+
154
+ ensure
155
+
156
+ MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
157
+
158
+ end
159
+
160
+ MobyUtil::Logger.instance.enabled = logging_enabled
161
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify;"
162
+
163
+ return nil
164
+
165
+ end
166
+
167
+
168
+ # Verifies that the block given to this method throws an exception while being evaluated. Verification is synchronized with all connected suts.
169
+ # If this method is called for a sut, synchronization is only done with that sut.
170
+ #
171
+ # === params
172
+ # timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
173
+ # message:: (optional) A String that is displayed as additional information if the verification fails.
174
+ # === returns
175
+ # nil
176
+ # === raises
177
+ # ArgumentError:: message was not a String or timeout an integer, or no block was given.
178
+ # VerificationError:: The verification failed.
179
+ def verify_not( timeout = nil, message = nil, &block )
180
+
181
+ logging_enabled = MobyUtil::Logger.instance.enabled
182
+ verify_caller = caller(1).first.to_s
183
+ begin
184
+
185
+ MobyUtil::Logger.instance.enabled = false
186
+ Kernel::raise ArgumentError.new("No block was given.") unless block_given?
187
+ Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
188
+ Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
189
+
190
+ #Set the testobject timeout to 0 for the duration of the verify call
191
+ original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
192
+ MobyBase::TestObjectFactory.instance.timeout = 0
193
+
194
+ timeout_time = get_end_time(timeout)
195
+ #TIMEOUT_CYCLE_SECONDS
196
+
197
+ loop do
198
+ counter = ref_counter
199
+ artificial_exception_raised = false
200
+ begin # catch errors thrown in the provided block
201
+
202
+ yield
203
+ artificial_exception_raised = true
204
+ Kernel::raise "test"
205
+ rescue Exception => e
206
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
207
+
208
+ source_contents = ""
209
+ error_msg = ""
210
+
211
+ if (!artificial_exception_raised)
212
+ # an error was encountered => verification ok
213
+ break
214
+ end
215
+
216
+ if Time.new > timeout_time
217
+
218
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed\n"
219
+
220
+ source_contents = MobyUtil::KernelHelper.find_source(verify_caller)
221
+
222
+ if !source_contents.empty?
223
+ error_msg << source_contents
224
+ end
225
+
226
+ Kernel::raise MobyBase::VerificationError.new(error_msg)
227
+
228
+ end
229
+
230
+ sleep TIMEOUT_CYCLE_SECONDS
231
+
232
+ refresh_suts if counter == ref_counter
233
+
234
+ end
235
+
236
+ end # do
237
+
238
+
239
+ rescue Exception => e
240
+
241
+ execute_on_error_verify_block unless @@on_error_verify_block.nil?
242
+
243
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
244
+
245
+ MobyUtil::Logger.instance.enabled = logging_enabled
246
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s}#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_not;"
247
+ Kernel::raise e
248
+
249
+ ensure
250
+
251
+ MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
252
+
253
+ end
254
+
255
+ MobyUtil::Logger.instance.enabled = logging_enabled
256
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_not;"
257
+ return nil
258
+
259
+ end
260
+
261
+ # Verifies that the block given to this method evaluates to true. Verification is synchronized with all connected suts.
262
+ # If this method is called for a sut, synchronization is only done with that sut.
263
+ #
264
+ # === params
265
+ # timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
266
+ # message:: (optional) A String that is displayed as additional information if the verification fails.
267
+ # === returns
268
+ # nil
269
+ # === raises
270
+ # ArgumentError:: message was not a String or timeout an integer, or no block was given.
271
+ # VerificationError:: The verification failed.
272
+ # RuntimeError:: An unexpected error was encountered during verification.
273
+ def verify_true( timeout = nil, message = nil, &block )
274
+
275
+ logging_enabled = MobyUtil::Logger.instance.enabled
276
+ verify_caller = caller(1).first.to_s
277
+
278
+ begin
279
+ MobyUtil::Logger.instance.enabled = false
280
+ Kernel::raise ArgumentError.new("No block was given.") unless block_given?
281
+ Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
282
+ Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
283
+
284
+ #Set the testobject timeout to 0 for the duration of the verify call
285
+ original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
286
+ MobyBase::TestObjectFactory.instance.timeout = 0
287
+
288
+ timeout_time = get_end_time(timeout)
289
+ #TIMEOUT_CYCLE_SECONDS
290
+
291
+ loop do
292
+
293
+ counter = ref_counter
294
+
295
+ begin # catch errors thrown due to verification results
296
+
297
+
298
+ begin # catch errors thrown in the provided block
299
+
300
+ result = yield
301
+
302
+ rescue Exception => e
303
+
304
+ #@@on_error_verify_block.call unless @@on_error_verify_block.nil?
305
+
306
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
307
+
308
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
309
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
310
+ error_msg << "\nDetails: "
311
+ error_msg << "\n" << e.inspect
312
+
313
+ raise MobyBase::VerificationError.new( error_msg )
314
+
315
+ end
316
+
317
+ unless result == true
318
+
319
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed."
320
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
321
+
322
+ error_msg << "\nThe block did not return true. It returned: " << result.inspect
323
+
324
+ raise MobyBase::VerificationError.new( error_msg )
325
+
326
+ end
327
+
328
+ # break loop if no exceptions thrown
329
+ break
330
+
331
+ rescue MobyBase::VerificationError => ve
332
+
333
+ # refresh and retry unless timeout reached
334
+
335
+ if ( Time.new > timeout_time )
336
+
337
+ execute_on_error_verify_block unless @@on_error_verify_block.nil?
338
+
339
+ Kernel::raise ve
340
+
341
+ end
342
+
343
+ sleep TIMEOUT_CYCLE_SECONDS
344
+
345
+ refresh_suts if counter == ref_counter
346
+
347
+ rescue Exception => e
348
+
349
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
350
+
351
+ MobyUtil::Logger.instance.enabled = logging_enabled
352
+
353
+ # an unexpected error has occurred
354
+ Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
355
+
356
+ end # begin, catch any VerificationErrors
357
+
358
+ end # do
359
+
360
+ rescue Exception => e
361
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
362
+ MobyUtil::Logger.instance.enabled = logging_enabled
363
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_true;"
364
+ Kernel::raise e
365
+ ensure
366
+ MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
367
+ end
368
+
369
+ MobyUtil::Logger.instance.enabled = logging_enabled
370
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_true;"
371
+ return nil
372
+
373
+ end
374
+
375
+ # Verifies that the block given to this method evaluates to false. Verification is synchronized with all connected suts.
376
+ # If this method is called for a sut, synchronization is only done with that sut.
377
+ #
378
+ # === params
379
+ # timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
380
+ # message:: (optional) A String that is displayed as additional information if the verification fails.
381
+ # === returns
382
+ # nil
383
+ # === raises
384
+ # ArgumentError:: message was not a String or timeout an integer, or no block was given.
385
+ # VerificationError:: The verification failed.
386
+ # RuntimeError:: An unexpected error was encountered during verification.
387
+ def verify_false( timeout = nil, message = nil, &block )
388
+
389
+ logging_enabled = MobyUtil::Logger.instance.enabled
390
+
391
+ verify_caller = caller(1).first.to_s
392
+
393
+ begin
394
+
395
+ MobyUtil::Logger.instance.enabled = false
396
+
397
+ Kernel::raise ArgumentError.new("No block was given.") unless block_given?
398
+
399
+ Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
400
+ Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
401
+
402
+ #Set the testobject timeout to 0 for the duration of the verify call
403
+ original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
404
+ MobyBase::TestObjectFactory.instance.timeout = 0
405
+
406
+ timeout_time = get_end_time(timeout)
407
+ #TIMEOUT_CYCLE_SECONDS
408
+
409
+ loop do
410
+ counter = ref_counter
411
+ begin # catch errors thrown due to verification results
412
+
413
+ begin # catch errors thrown in the provided block
414
+ result = yield
415
+ rescue Exception => e
416
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
417
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
418
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
419
+ error_msg << "\nDetails: "
420
+ error_msg << "\n" << e.inspect
421
+ raise MobyBase::VerificationError.new(error_msg)
422
+ end
423
+
424
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed:"
425
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
426
+ error_msg << "The block did not return false. It returned: " << result.inspect
427
+ raise MobyBase::VerificationError.new(error_msg) unless result == false
428
+
429
+ # break loop if no exceptions thrown
430
+ break
431
+
432
+ rescue MobyBase::VerificationError => ve
433
+
434
+ # refresh and retry unless timeout reached
435
+
436
+ if Time.new > timeout_time
437
+ Kernel::raise ve
438
+ end
439
+
440
+ sleep TIMEOUT_CYCLE_SECONDS
441
+
442
+ refresh_suts if counter == ref_counter
443
+
444
+
445
+ rescue Exception => e
446
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
447
+ # an unexpected error has occurred
448
+ MobyUtil::Logger.instance.enabled = logging_enabled
449
+ Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
450
+
451
+ end # begin, catch any VerificationErrors
452
+
453
+ end # do
454
+
455
+ rescue Exception => e
456
+
457
+ execute_on_error_verify_block unless @@on_error_verify_block.nil?
458
+
459
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
460
+
461
+ MobyUtil::Logger.instance.enabled = logging_enabled
462
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n #{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_false;"
463
+
464
+ Kernel::raise e
465
+
466
+ ensure
467
+ MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
468
+ end
469
+
470
+ MobyUtil::Logger.instance.enabled = logging_enabled
471
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_false;"
472
+ return nil
473
+
474
+ end
475
+
476
+ # Verifies that the block given to this method evaluates to the expected value. Verification is synchronized with all connected suts.
477
+ # If this method is called for a sut, synchronization is only done with that sut.
478
+ #
479
+ # === params
480
+ # expected:: Expected result value of the block
481
+ # timeout:: (optional) Integer defining the amount of seconds during which the verification must pass.
482
+ # message:: (optional) A String that is displayed as additional information if the verification fails.
483
+ # === returns
484
+ # nil
485
+ # === raises
486
+ # ArgumentError:: message was not a String or timeout an integer, or no block was given.
487
+ # VerificationError:: The verification failed.
488
+ # RuntimeError:: An unexpected error was encountered during verification.
489
+ def verify_equal( expected, timeout = nil, message = nil, &block )
490
+ logging_enabled = MobyUtil::Logger.instance.enabled
491
+ verify_caller = caller(1).first.to_s
492
+ begin
493
+ MobyUtil::Logger.instance.enabled = false
494
+ Kernel::raise ArgumentError.new("No block was given.") unless block_given?
495
+ Kernel::raise ArgumentError.new("Argument timeout was not an Integer.") unless timeout.nil? or timeout.kind_of?(Integer)
496
+ Kernel::raise ArgumentError.new("Argument message was not a String.") unless message.nil? or message.kind_of?(String)
497
+
498
+ #Set the testobject timeout to 0 for the duration of the verify call
499
+ original_sync_timeout = MobyBase::TestObjectFactory.instance.timeout
500
+ MobyBase::TestObjectFactory.instance.timeout = 0
501
+
502
+ timeout_time = get_end_time(timeout)
503
+
504
+ #TIMEOUT_CYCLE_SECONDS
505
+
506
+ loop do
507
+ counter = ref_counter
508
+ begin # catch errors thrown due to verification results
509
+
510
+ begin # catch errors thrown in the provided block
511
+ result = yield
512
+
513
+ rescue Exception => e
514
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
515
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed as an exception was thrown when the verification block was executed."
516
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
517
+ error_msg << "\nDetails: "
518
+ error_msg << "\n" << e.inspect
519
+ raise MobyBase::VerificationError.new(error_msg)
520
+ end
521
+ if result != expected
522
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed:"
523
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
524
+ error_msg << "\nThe block did not return #{expected.inspect}. It returned: " << result.inspect
525
+ raise MobyBase::VerificationError.new(error_msg)
526
+ end
527
+ # break loop if no exceptions thrown
528
+ break
529
+
530
+ rescue MobyBase::VerificationError => ve
531
+
532
+ # refresh and retry unless timeout reached
533
+
534
+ if Time.new > timeout_time
535
+ Kernel::raise ve
536
+ end
537
+
538
+ sleep TIMEOUT_CYCLE_SECONDS
539
+
540
+ refresh_suts if counter == ref_counter
541
+ rescue MobyBase::ContinuousVerificationError
542
+ raise
543
+ rescue Exception => e
544
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
545
+ # an unexpected error has occurred
546
+ Kernel::raise RuntimeError.new("An unexpected error was encountered during verification:\n" << e.inspect )
547
+
548
+ end # begin, catch any VerificationErrors
549
+
550
+ end # do
551
+
552
+ rescue Exception => e
553
+
554
+ execute_on_error_verify_block unless @@on_error_verify_block.nil?
555
+
556
+ raise if e.kind_of? MobyBase::ContinuousVerificationError
557
+
558
+ MobyUtil::Logger.instance.enabled = logging_enabled
559
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed:#{e.to_s}.\n#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_equal;" << expected.to_s
560
+ Kernel::raise e
561
+ ensure
562
+ MobyBase::TestObjectFactory.instance.timeout = original_sync_timeout unless original_sync_timeout.nil?
563
+ end
564
+
565
+ MobyUtil::Logger.instance.enabled = logging_enabled
566
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_equal;" << expected.to_s
567
+ return nil
568
+
569
+ end
570
+
571
+ # Verifies that the given signal is emitted.
572
+ #
573
+ # === params
574
+ # timeout:: Integer, defining the amount of seconds during which the verification must pass.
575
+ # signal_name:: String, name of the signal
576
+ # message:: (optional) A String that is displayed as additional information if the verification fails.
577
+ # block:: code to execute while listening signals
578
+ # === returns
579
+ # nil
580
+ # === raises
581
+ # ArgumentError:: message or signal_name was not a String or timeout a non negative Integer
582
+ # VerificationError:: The verification failed.
583
+ def verify_signal( timeout, signal_name, message = nil, &block )
584
+
585
+ logging_enabled = MobyUtil::Logger.instance.enabled
586
+ verify_caller = caller(1).first.to_s
587
+
588
+ begin
589
+
590
+ MobyUtil::Logger.instance.enabled = false
591
+
592
+ Kernel::raise ArgumentError.new("Argument timeout was not a non negative Integer.") unless (timeout.kind_of?(Integer) && timeout >= 0)
593
+ Kernel::raise ArgumentError.new("Argument message was not a non empty String.") unless (message.nil? || (message.kind_of?(String) && !message.empty?))
594
+
595
+ # wait for the signal
596
+ begin
597
+
598
+ self.wait_for_signal( timeout, signal_name, &block )
599
+
600
+ rescue Exception => e
601
+
602
+ error_msg = "Verification #{message.nil? ? '' : '"' << message.to_s << '" '}at #{verify_caller} failed:"
603
+ error_msg << MobyUtil::KernelHelper.find_source(verify_caller)
604
+ error_msg << "The signal #{signal_name} was not emitted in #{timeout} seconds."
605
+ error_msg << "\nNested exception:\n" << e.inspect
606
+ Kernel::raise MobyBase::VerificationError.new(error_msg)
607
+
608
+ end
609
+
610
+ rescue Exception => e
611
+
612
+ execute_on_error_verify_block unless @@on_error_verify_block.nil?
613
+
614
+ MobyUtil::Logger.instance.enabled = logging_enabled
615
+ MobyUtil::Logger.instance.log "behaviour" , "FAIL;Verification #{message.nil? ? '' : '\"' << message << '\" '}failed: #{e.to_s} using timeout '#{timeout}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_signal;#{signal_name}"
616
+ Kernel::raise e
617
+ end
618
+
619
+ MobyUtil::Logger.instance.enabled = logging_enabled
620
+ MobyUtil::Logger.instance.log "behaviour" , "PASS;Verification #{message.nil? ? '' : '\"' << message << '\" '}at #{verify_caller} was successful#{timeout.nil? ? '' : ' using timeout ' + timeout.to_s}.;#{self.kind_of?(MobyBase::SUT) ? self.id.to_s + ';sut' : ';'};{};verify_signal;#{signal_name}"
621
+ return nil
622
+
623
+ end
624
+
625
+ private
626
+
627
+
628
+ def get_end_time(timeout)
629
+
630
+ if self.kind_of?(MobyBase::SUT)
631
+ Time.new + (timeout.nil? ? MobyUtil::Parameter[self.sut][ :synchronization_timeout].to_i : timeout.to_i)
632
+ else
633
+ Time.new + (timeout.nil? ? MobyUtil::Parameter[ :synchronization_timeout].to_i : timeout.to_i)
634
+ end
635
+ end
636
+
637
+ # Current count of combined sut refresh calls to all suts
638
+ def ref_counter
639
+ counter = 0
640
+ if self.kind_of? MobyBase::SUT
641
+ counter = self.dump_count
642
+ else
643
+ MobyBase::SUTFactory.instance.connected_suts.each do |sut_id, sut_attributes|
644
+ counter += sut_attributes[:sut].dump_count
645
+ end
646
+ end
647
+ counter
648
+ end
649
+
650
+ # Refresh ui state inside verify
651
+ def refresh_suts
652
+ begin
653
+ if self.kind_of? MobyBase::SUT
654
+ appid = self.get_application_id
655
+ if appid != "-1"
656
+ self.refresh({:id => appid})
657
+ else
658
+ self.refresh
659
+ end
660
+ else
661
+ #refresh all connected suts
662
+ MobyBase::SUTFactory.instance.connected_suts.each do |sut_id, sut_attributes|
663
+ appid = sut_attributes[:sut].get_application_id
664
+ if appid != "-1"
665
+ sut_attributes[:sut].refresh({:id => appid}) if sut_attributes[:is_connected]
666
+ else
667
+ sut_attributes[:sut].refresh if sut_attributes[:is_connected]
668
+ end
669
+ end
670
+ end
671
+
672
+ # Ignore all availability errors
673
+ rescue RuntimeError => e
674
+ # This occurs when no applications are registered to sut
675
+ if !(e.message =~ /no longer available/)
676
+ # all other errors are passed up
677
+ raise e
678
+ end
679
+ end
680
+ end
681
+
682
+ end
683
+
684
+ module MattiVerify
685
+ include TDriverVerify
686
+
687
+ end