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,154 @@
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 EnvironmentHelper
23
+
24
+ unless defined?( UNKNOWN )
25
+ LINUX = :linux
26
+ SOLARIS = :solaris
27
+ WINDOWS = :windows
28
+ OSX = :osx
29
+ CYGWIN = :cygwin
30
+ UNKNOWN = :unknown # keep this as last constant
31
+ end
32
+
33
+ def self.java?
34
+
35
+ RUBY_PLATFORM == "java"
36
+
37
+ end
38
+
39
+ def self.posix?
40
+
41
+ ( platform == LINUX || platform == OSX || platform == CYGWIN || platform == SOLARIS )
42
+
43
+ end
44
+
45
+ def self.cygwin?
46
+
47
+ platform == CYGWIN
48
+
49
+ end
50
+
51
+ def self.solaris?
52
+
53
+ platform == SOLARIS
54
+
55
+ end
56
+
57
+ def self.linux?
58
+
59
+ platform == LINUX
60
+
61
+ end
62
+
63
+ def self.windows?
64
+
65
+ platform == WINDOWS
66
+
67
+ end
68
+
69
+ def self.osx?
70
+
71
+ platform == OSX
72
+
73
+ end
74
+
75
+ def self.unknown_os?
76
+
77
+ platform == UNKNOWN
78
+
79
+ end
80
+
81
+ # Function to retrieve platform type
82
+ # == returns
83
+ # Integer:: LINUX
84
+ def self.platform
85
+
86
+ case RbConfig::CONFIG[ 'host_os' ]
87
+
88
+ when /mswin|mingw|windows/i
89
+
90
+ WINDOWS
91
+
92
+ when /cygwin/i
93
+
94
+ CYGWIN
95
+
96
+ when /linux/i
97
+
98
+ LINUX
99
+
100
+ when /sunos|solaris/i
101
+
102
+ SOLARIS
103
+
104
+ when /darwin/
105
+
106
+ OSX
107
+
108
+ else
109
+
110
+ OTHER
111
+
112
+ end
113
+
114
+ end
115
+
116
+ # Function to retrieve platform type
117
+ # == returns
118
+ # String::
119
+ def self.ruby_platform
120
+
121
+ RbConfig::CONFIG[ 'target_os' ]
122
+
123
+ end
124
+
125
+ def self.change_file_ownership!( target, user_name, user_group, recursively = true )
126
+
127
+ `chown -h #{ recursively ? '-R' : '' } #{ user_name }:#{ user_group } #{ target }` if MobyUtil::EnvironmentHelper.posix?
128
+
129
+ end
130
+
131
+ # linux
132
+ def self.user_group( name = nil )
133
+
134
+ `id -g -n #{ name }`.chomp if MobyUtil::EnvironmentHelper.posix?
135
+
136
+ end
137
+
138
+ # linux
139
+ def self.user_name
140
+
141
+ result = ENV[ 'LOGNAME' ]
142
+ result = ENV[ 'SUDO_USER' ] if result == "root" || result == ""
143
+ result = ENV[ 'USER' ] if result == "root" || result == ""
144
+
145
+ result
146
+
147
+ end
148
+
149
+ # enable hooking for performance measurement & debug logging
150
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
151
+
152
+ end # EnvironmentHelper
153
+
154
+ end # MobyUtil
@@ -0,0 +1,40 @@
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
+ # TODO: move custom errors to exceptions.rb
21
+ module MobyUtil
22
+
23
+ # template for custom error classes
24
+ class CustomError < StandardError
25
+
26
+ def initialize ( msg = nil )
27
+
28
+ super( msg )
29
+
30
+ end
31
+
32
+ end
33
+
34
+ class EmptyFilenameError < MobyUtil::CustomError; end
35
+
36
+ class FileNotFoundError < MobyUtil::CustomError; end
37
+
38
+ class UnexpectedVariableTypeError < MobyUtil::CustomError; end
39
+
40
+ end # MobyUtil
@@ -0,0 +1,53 @@
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
+ class Exception
21
+
22
+ # TODO: document me
23
+ def nested_backtrace
24
+
25
+ if backtrace
26
+
27
+ _backtrace = backtrace.dup
28
+
29
+ begin
30
+
31
+ _backtrace[ 0 ] = "#{ _backtrace.first.to_s } raised #{ self.class.name }: #{ message.to_s }"
32
+
33
+ _backtrace.unshift( caller.first )
34
+
35
+ rescue
36
+
37
+ # exception raised, do not alter backtrace
38
+
39
+ end
40
+
41
+ else
42
+
43
+ # no backtrace available
44
+ _backtrace = []
45
+
46
+ end
47
+
48
+ # return backtrace array
49
+ _backtrace
50
+
51
+ end
52
+
53
+ end # Exception
@@ -0,0 +1,12 @@
1
+ # place all custom TDriver exception classes here
2
+ class MobyStandardError < StandardError
3
+
4
+ # Construct a new error, optionally passing in a message
5
+ def initialize ( message = nil )
6
+ super( message )
7
+ end
8
+
9
+ end
10
+
11
+ # file not found error
12
+ class FileNotFoundError < MobyStandardError; end;
@@ -0,0 +1,328 @@
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 "fileutils" unless defined?( ::FileUtils )
21
+
22
+ module MobyUtil
23
+
24
+ class FileHelper
25
+
26
+ # Function to verify that given folder exists
27
+ # == params
28
+ # path:: String containing path
29
+ # == returns
30
+ def self.folder_exist?( path )
31
+
32
+ begin
33
+
34
+ Dir.entries( path ).kind_of?( Array )
35
+
36
+ rescue
37
+
38
+ false
39
+
40
+ end
41
+
42
+ end
43
+
44
+ # Function to load dynamically ruby module(s) from given path
45
+ # == params
46
+ # path:: String containing path
47
+ # == returns
48
+ def self.load_modules( *path )
49
+
50
+ # deterimine caller methods working folder
51
+ source_path = File.dirname( MobyUtil::KernelHelper.parse_caller( caller(3).first ).first )
52
+
53
+ # Compatiblity for Ruby 1.9.2 caller format
54
+ if source_path == "." || source_path[0].to_s == "<"
55
+ source_path = File.dirname( MobyUtil::KernelHelper.parse_caller( caller(2).first ).first )
56
+ end
57
+
58
+ path.each{ | path |
59
+
60
+ # expand path if given path is relative path
61
+ path = File.join( source_path, path ) if is_relative_path? path
62
+
63
+ # automatically load ruby implementation files if given path is folder
64
+ path = File.join( path, '*.rb' ) if File.directory?( path )
65
+
66
+ require_files = Dir.glob( MobyUtil::FileHelper.fix_path( path ) )
67
+
68
+ raise RuntimeError, "File not found #{ path }" if !File.directory?( path ) && !File.file?( path ) && require_files.empty?
69
+
70
+ # load each module found from given folder
71
+ require_files.each { | module_name |
72
+
73
+ # load implementation file
74
+ require module_name
75
+
76
+ }
77
+
78
+ }
79
+
80
+ end
81
+
82
+ # Function to fix folder/file path, e.g. remove duplicate back-/slashes
83
+ # == params
84
+ # logger_instance:: Instance of TDriver logger
85
+ # == returns
86
+ # String:: String presentation of fixed path
87
+ def self.fix_path( path )
88
+
89
+ path.check_type( String, "Wrong argument type $1 for file path (expected $2)" )
90
+
91
+ # replace back-/slashes to File::SEPARATOR
92
+ path.gsub( /[\\\/]/, File::SEPARATOR ).to_s
93
+
94
+ end
95
+
96
+ # Private helper function to set tdriver_home directory depending on os.
97
+ # Known possible issue: javaruby or similar, will not return correctly
98
+ # == params
99
+ # == returns
100
+ # String:: String presentation of TDriver home directory
101
+ def self.tdriver_home
102
+
103
+ File.expand_path(
104
+ MobyUtil::FileHelper.fix_path(
105
+ ENV['TDRIVER_HOME'] || ( MobyUtil::EnvironmentHelper.windows? ? "c:/tdriver" : "/tmp/cutedriver/etc/tdriver" )
106
+ )
107
+ )
108
+
109
+ end
110
+
111
+ # Function for expand tdriver specific relative file paths
112
+ # === params
113
+ # file_path:: String containing (file-) path
114
+ # === returns
115
+ # String:: String containing expanded file path
116
+ # === raises
117
+ # TypeError:: Wrong argument type <class> for file path (expected <class>)
118
+ # ArgumentError:: Given path is empty
119
+ def self.is_relative_path?( path )
120
+
121
+ path.check_type( String, "Wrong argument type $1 for file path (expected $2)" )
122
+
123
+ #raise ArgumentError.new("Given path is empty") if path.empty?
124
+ path.not_empty( "Filepath must not be empty string" )
125
+
126
+ dirname = File.dirname( path )
127
+
128
+ if MobyUtil::EnvironmentHelper.windows?
129
+
130
+ # windows
131
+ ( dirname =~ /^[a-z]+:(\\|\/)/i ).nil? && ( dirname[ 0 ].chr =~ /(\\|\/)/ ).nil?
132
+
133
+ else
134
+
135
+ # linux
136
+ ( path[ 0 ].chr != '~' ) && ( dirname[ 0 ].chr != File::SEPARATOR )
137
+
138
+ end
139
+
140
+ end
141
+
142
+ # Function for expand tdriver specific relative file paths
143
+ # === params
144
+ # file_path:: String containing (file-) path
145
+ # === returns
146
+ # String:: String containing expanded file path
147
+ # === raises
148
+ def self.expand_path( file_path )
149
+
150
+ _file_path = file_path # we don't want to modify original variable
151
+
152
+ return _file_path if _file_path.nil? || _file_path.empty?
153
+
154
+ _file_path = MobyUtil::FileHelper.fix_path( _file_path )
155
+
156
+ File.expand_path( MobyUtil::FileHelper.is_relative_path?( _file_path ) ? File.join( MobyUtil::FileHelper.tdriver_home, _file_path ) : _file_path )
157
+
158
+ end
159
+
160
+ # Function for retrieve tdriver configuration file content from absolute or tdrive home path
161
+ # If relative path given, assume that file is located in TDriver home folder
162
+ # === params
163
+ # file_path:: String containing the name and path of file
164
+ # === returns
165
+ # String:: File content
166
+ # === raises
167
+ # ParameterFileNotFoundError - if empty parameter or file doesn't exist
168
+ # ParameterFileParseError:: If parsing failes
169
+ def self.get_file( file_path )
170
+
171
+ #p __method__, file_path, caller
172
+
173
+ #file_path.check_type( String, "wrong argument type $1 for get_file method (expected $2)")
174
+
175
+ # raise exception if file name is empty or nil
176
+ raise EmptyFilenameError, "File name is empty or not defined" if file_path.nil? || file_path.to_s.empty?
177
+
178
+ # raise exception if file name is file_path variable format other than string
179
+ raise UnexpectedVariableTypeError.new( "Invalid filename format #{ file_path.class } (expected: String)") if !file_path.kind_of?( String )
180
+
181
+ file_path = MobyUtil::FileHelper.expand_path( file_path )
182
+
183
+ # raise exception if file not found
184
+ raise FileNotFoundError.new( "File not found: #{ file_path }" ) unless File.exist?( file_path )
185
+
186
+ begin
187
+ # read all content of file
188
+ file_content = IO.read( file_path )
189
+ rescue => ex
190
+ # raise exception if error occured during reading the file
191
+ raise IOError.new("Error occured while reading file #{ file_path }\nDescription: #{ ex.message }")
192
+ end
193
+
194
+ # return file content
195
+ file_content
196
+
197
+ end
198
+
199
+ # Function for create (nested) folder path
200
+ # === params
201
+ # path:: String containing path to be created
202
+ # === returns
203
+ # NilClass
204
+ # === raises
205
+ # IOError:: Error occured while creating folder
206
+ def self.mkdir_path( path )
207
+
208
+ begin
209
+
210
+ current_path = ""
211
+
212
+ path.split( File::SEPARATOR ).each{ | folder |
213
+
214
+ if !folder.empty?
215
+
216
+ current_path << folder << File::SEPARATOR
217
+
218
+ Dir.mkdir( current_path ) unless File.exist?( current_path )
219
+
220
+ else
221
+
222
+ current_path << File::SEPARATOR
223
+
224
+ end
225
+
226
+ } unless File.directory?( path ) && File.exist?( path )
227
+
228
+ rescue => exception
229
+
230
+ raise IOError.new("Error occured while creating folder #{ current_path } (#{ exception.message })")
231
+
232
+ end
233
+
234
+ nil
235
+
236
+ end
237
+
238
+ # Function for copy file(s) to destination folder, folder will be created if it doesn't exist.
239
+ # === params
240
+ # source:: Array or String containing source filename(s)
241
+ # destination:: String containing of destination folder
242
+ # args:: String containing arguments used for copying
243
+ # file:: String target filename, used to rename source filename on destination
244
+ # === returns
245
+ # NilClass
246
+ # === raises
247
+ # IOError:: Error occured while creating folder
248
+ def self.copy_file( source, destination, verbose = false, overwrite = true, create_folders = true, &block )
249
+
250
+ source.check_type( String, "Wrong argument type $1 for source file (expected $2)" )
251
+
252
+ destination.check_type( String, "Wrong argument type $1 for destination file (expected $2)" )
253
+
254
+ sources = []
255
+
256
+ if File.directory?( source )
257
+
258
+ source_folders = source if ( source_folders = MobyUtil::FileHelper.folder_tree( source ) ).empty?
259
+
260
+ source_folders.each{ | folder |
261
+
262
+ Dir.glob( File.join( folder, "*.*" ) ).each{ | file |
263
+
264
+ sources << [ file, File.join( destination, folder.gsub( source, "" ), "/", File.basename( file ) ) ]
265
+ }
266
+ }
267
+
268
+ else
269
+
270
+ if File.basename( source ) =~ /\*/
271
+ # retrieve all files when wildcards used
272
+ Dir.glob( File.join( File.dirname( source ), File.basename( source ) ) ).each{ | file | sources << [ file, File.join( destination, File.basename( file ) ) ] }
273
+ else
274
+ # no wildcards
275
+ sources << [ source, destination ]
276
+ end
277
+
278
+ end
279
+
280
+ sources.each{ | task |
281
+
282
+ source, destination = task
283
+
284
+ destination_folder = ( destination = MobyUtil::FileHelper.fix_path( destination ) )[ -1 ].chr =~ /[\\\/]/ ? destination : File.dirname( destination )
285
+
286
+ # create destination folder if it doesn't exist and create_folders flag is enabled
287
+ MobyUtil::FileHelper.mkdir_path( destination_folder ) if create_folders
288
+
289
+ raise RuntimeError.new( "Unable to copy #{ source } to #{ destination } due to source file does not exist" ) unless File.exist?( source )
290
+
291
+ ::FileUtils.copy(
292
+
293
+ MobyUtil::FileHelper.fix_path( source ),
294
+ destination,
295
+ :verbose => verbose
296
+
297
+ ) unless ( !overwrite && File.exist?( destination ) )
298
+
299
+ # yield given block, can be used eg. changing the target file's access levels etc.
300
+ yield( destination, source, destination_folder ) if block_given?
301
+
302
+ }
303
+
304
+ end
305
+
306
+ # Function for build list of sub-/folder(s) from given source folder
307
+ # === params
308
+ # source:: String containing source folder
309
+ # folders:: Array internal variable, used in recursion, can be used as result value if given variable is empty array.
310
+ # === returns
311
+ # Array list of folder names
312
+ # === raises
313
+ def self.folder_tree( source, folders = [] )
314
+
315
+ Dir.glob( source + "/*" ).each{ | folder |
316
+ if File.directory?( folder ); folders << folder; MobyUtil::FileHelper.folder_tree( folder, folders ); end
317
+ }
318
+
319
+ folders.uniq.compact
320
+
321
+ end
322
+
323
+ # enable hooking for performance measurement & debug logging
324
+ TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
325
+
326
+ end # FileHelper
327
+
328
+ end # MobyUtil