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.
- checksums.yaml +7 -0
- data/README.md +16 -0
- data/bin/start_app_perf +200 -0
- data/bin/tdriver-devtools +3 -0
- data/config/sut_parameters.rb +52 -0
- data/config/sut_setup.rb +32 -0
- data/config/sut_teardown.rb +32 -0
- data/config/tdriver_custom_error_recovery.rb +83 -0
- data/ext/extconf.rb +70 -0
- data/ext/native_extensions.c +315 -0
- data/lib/matti.rb +25 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +120 -0
- data/lib/tdriver-devtools/behaviour/old/xml/example/impl.rb_invalid +194 -0
- data/lib/tdriver-devtools/behaviour/old/xml/generate_behaviour_xml.rb +95 -0
- data/lib/tdriver-devtools/behaviour/old/xml/lib/tdriver_generator.rb +722 -0
- data/lib/tdriver-devtools/behaviour/old/xml/qdoc_generator.rb +321 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.method.template +43 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.module.template +54 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.argument_type.template +7 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.exception.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.line.template +2 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.howto.template +5 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.method.template +23 -0
- data/lib/tdriver-devtools/behaviour/old/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/behaviour/old/xml/update +3 -0
- data/lib/tdriver-devtools/behaviour/xml/generate.rb +88 -0
- data/lib/tdriver-devtools/behaviour/xml/rdoc_behaviour_xml_generator.rb +1945 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.default.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.argument_type.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.exception.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.arguments.template +4 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.deprecated.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.exceptions.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.info.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.returns.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.tables.template +3 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.method.template +12 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.returns.template +5 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.item.template +1 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.row.template +2 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.table.template +8 -0
- data/lib/tdriver-devtools/behaviour/xml/templates/behaviour.xml.template +14 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/QtExampleGestureBehaviour.xml +138 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/created.rid +1 -0
- data/lib/tdriver-devtools/doc/behaviour_xml/tdriver.hash +1 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_hold.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/feature_xml/qt_widget_tap.feature.xml +9 -0
- data/lib/tdriver-devtools/doc/generate.rb +917 -0
- data/lib/tdriver-devtools/doc/update +1 -0
- data/lib/tdriver-devtools/doc/xslt/html.rb +7 -0
- data/lib/tdriver-devtools/doc/xslt/template.xsl +2170 -0
- data/lib/tdriver-devtools/doc/xslt/update +3 -0
- data/lib/tdriver-devtools/plugin/placeholder.txt +1 -0
- data/lib/tdriver-devtools/tdriver-devtools.rb +404 -0
- data/lib/tdriver-devtools/tests/feature_tests/example/behaviour_example.rb +100 -0
- data/lib/tdriver-devtools/tests/feature_tests/generate.rb +82 -0
- data/lib/tdriver-devtools/tests/feature_tests/lib/custom_rdoc_generator.rb +468 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/feature_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_attribute.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/templates/scenario_method.template +5 -0
- data/lib/tdriver-devtools/tests/feature_tests/update +3 -0
- data/lib/tdriver.rb +23 -0
- data/lib/tdriver/base/behaviour/abstract.rb +29 -0
- data/lib/tdriver/base/behaviour/behaviours/object_abstract.rb +107 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_composition.rb +99 -0
- data/lib/tdriver/base/behaviour/behaviours/object_behaviour_description.rb +278 -0
- data/lib/tdriver/base/behaviour/behaviours/object_composition.rb +119 -0
- data/lib/tdriver/base/behaviour/factory.rb +495 -0
- data/lib/tdriver/base/behaviour/loader.rb +46 -0
- data/lib/tdriver/base/command_data/command_data.rb +51 -0
- data/lib/tdriver/base/command_data/loader.rb +29 -0
- data/lib/tdriver/base/controller/abstraction.rb +56 -0
- data/lib/tdriver/base/controller/loader.rb +21 -0
- data/lib/tdriver/base/errors.rb +134 -0
- data/lib/tdriver/base/loader.rb +47 -0
- data/lib/tdriver/base/state_object.rb +373 -0
- data/lib/tdriver/base/sut/adapter.rb +54 -0
- data/lib/tdriver/base/sut/controller.rb +151 -0
- data/lib/tdriver/base/sut/factory.rb +339 -0
- data/lib/tdriver/base/sut/generic/behaviours/agent.rb +77 -0
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +427 -0
- data/lib/tdriver/base/sut/generic/behaviours/controller.rb +67 -0
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +107 -0
- data/lib/tdriver/base/sut/generic/behaviours/flash_behaviour.rb +337 -0
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +1888 -0
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +210 -0
- data/lib/tdriver/base/sut/generic/behaviours/verification.rb +222 -0
- data/lib/tdriver/base/sut/generic/commands/agent.rb +43 -0
- data/lib/tdriver/base/sut/generic/commands/application.rb +274 -0
- data/lib/tdriver/base/sut/generic/commands/fixture.rb +47 -0
- data/lib/tdriver/base/sut/generic/commands/key_sequence.rb +94 -0
- data/lib/tdriver/base/sut/generic/commands/screen_capture.rb +64 -0
- data/lib/tdriver/base/sut/generic/plugin.rb +97 -0
- data/lib/tdriver/base/sut/loader.rb +35 -0
- data/lib/tdriver/base/sut/sut.rb +98 -0
- data/lib/tdriver/base/test_object/abstract.rb +208 -0
- data/lib/tdriver/base/test_object/adapter.rb +740 -0
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +144 -0
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +1047 -0
- data/lib/tdriver/base/test_object/cache.rb +134 -0
- data/lib/tdriver/base/test_object/factory.rb +684 -0
- data/lib/tdriver/base/test_object/loader.rb +51 -0
- data/lib/tdriver/base/test_object/verification.rb +178 -0
- data/lib/tdriver/base/test_object/xml/abstraction.rb +63 -0
- data/lib/tdriver/base/test_object/xml/adapter.rb +773 -0
- data/lib/tdriver/env.rb +21 -0
- data/lib/tdriver/loader.rb +57 -0
- data/lib/tdriver/matti.rb +35 -0
- data/lib/tdriver/report/error_recovery/tdriver_custom_error_recovery.rb +83 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +168 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +106 -0
- data/lib/tdriver/report/report.rb +61 -0
- data/lib/tdriver/report/report_api.rb +348 -0
- data/lib/tdriver/report/report_combine.rb +86 -0
- data/lib/tdriver/report/report_crash_file_capture.rb +178 -0
- data/lib/tdriver/report/report_creator.rb +665 -0
- data/lib/tdriver/report/report_cucumber.rb +158 -0
- data/lib/tdriver/report/report_cucumber_listener.rb +184 -0
- data/lib/tdriver/report/report_cucumber_reporter.rb +181 -0
- data/lib/tdriver/report/report_data_presentation.rb +156 -0
- data/lib/tdriver/report/report_data_table.rb +64 -0
- data/lib/tdriver/report/report_execution_statistics.rb +400 -0
- data/lib/tdriver/report/report_file_capture.rb +159 -0
- data/lib/tdriver/report/report_graph_generator.rb +59 -0
- data/lib/tdriver/report/report_grouping.rb +541 -0
- data/lib/tdriver/report/report_javascript.rb +199 -0
- data/lib/tdriver/report/report_junit_xml.rb +147 -0
- data/lib/tdriver/report/report_rspec.rb +108 -0
- data/lib/tdriver/report/report_test_case_run.rb +725 -0
- data/lib/tdriver/report/report_test_run.rb +1476 -0
- data/lib/tdriver/report/report_test_unit.rb +223 -0
- data/lib/tdriver/report/report_writer.rb +1621 -0
- data/lib/tdriver/tdriver.rb +209 -0
- data/lib/tdriver/util/agent/loader.rb +22 -0
- data/lib/tdriver/util/agent/service.rb +107 -0
- data/lib/tdriver/util/common/array.rb +39 -0
- data/lib/tdriver/util/common/boolean.rb +48 -0
- data/lib/tdriver/util/common/crc16.rb +149 -0
- data/lib/tdriver/util/common/environment.rb +154 -0
- data/lib/tdriver/util/common/error.rb +40 -0
- data/lib/tdriver/util/common/exception.rb +53 -0
- data/lib/tdriver/util/common/exceptions.rb +12 -0
- data/lib/tdriver/util/common/file.rb +328 -0
- data/lib/tdriver/util/common/gem.rb +109 -0
- data/lib/tdriver/util/common/hash.rb +288 -0
- data/lib/tdriver/util/common/kernel.rb +253 -0
- data/lib/tdriver/util/common/loader.rb +47 -0
- data/lib/tdriver/util/common/numeric.rb +159 -0
- data/lib/tdriver/util/common/object.rb +159 -0
- data/lib/tdriver/util/common/retryable.rb +179 -0
- data/lib/tdriver/util/common/stackable.rb +185 -0
- data/lib/tdriver/util/common/string.rb +174 -0
- data/lib/tdriver/util/database/access.rb +240 -0
- data/lib/tdriver/util/database/connection.rb +44 -0
- data/lib/tdriver/util/database/error.rb +34 -0
- data/lib/tdriver/util/database/loader.rb +28 -0
- data/lib/tdriver/util/filters/attribute_filter.rb +121 -0
- data/lib/tdriver/util/filters/loader.rb +29 -0
- data/lib/tdriver/util/fixture/loader.rb +22 -0
- data/lib/tdriver/util/fixture/service.rb +211 -0
- data/lib/tdriver/util/hooking/hooking.rb +477 -0
- data/lib/tdriver/util/keymap/keymap.rb +81 -0
- data/lib/tdriver/util/loader.rb +80 -0
- data/lib/tdriver/util/localisation/error.rb +31 -0
- data/lib/tdriver/util/localisation/loader.rb +25 -0
- data/lib/tdriver/util/localisation/localisation.rb +762 -0
- data/lib/tdriver/util/logger/loader.rb +22 -0
- data/lib/tdriver/util/logger/logger.rb +591 -0
- data/lib/tdriver/util/operator_data/error.rb +29 -0
- data/lib/tdriver/util/operator_data/loader.rb +27 -0
- data/lib/tdriver/util/operator_data/operator_data.rb +93 -0
- data/lib/tdriver/util/other/config.rb +221 -0
- data/lib/tdriver/util/parameter/error.rb +48 -0
- data/lib/tdriver/util/parameter/loader.rb +25 -0
- data/lib/tdriver/util/parameter/parameter.rb +1161 -0
- data/lib/tdriver/util/plugin/abstract.rb +61 -0
- data/lib/tdriver/util/plugin/error.rb +0 -0
- data/lib/tdriver/util/plugin/loader.rb +28 -0
- data/lib/tdriver/util/plugin/service.rb +319 -0
- data/lib/tdriver/util/recorder/loader.rb +25 -0
- data/lib/tdriver/util/recorder/recorder.rb +72 -0
- data/lib/tdriver/util/recorder/scripter.rb +294 -0
- data/lib/tdriver/util/statistics/statistics.rb +89 -0
- data/lib/tdriver/util/user_data/error.rb +28 -0
- data/lib/tdriver/util/user_data/loader.rb +25 -0
- data/lib/tdriver/util/user_data/user_data.rb +104 -0
- data/lib/tdriver/util/video/camera.rb +67 -0
- data/lib/tdriver/util/video/camera_linux.rb +153 -0
- data/lib/tdriver/util/video/camera_windows.rb +174 -0
- data/lib/tdriver/util/video/loader.rb +31 -0
- data/lib/tdriver/util/video/video_utils.rb +139 -0
- data/lib/tdriver/util/xml/abstraction.rb +117 -0
- data/lib/tdriver/util/xml/attribute.rb +32 -0
- data/lib/tdriver/util/xml/builder.rb +53 -0
- data/lib/tdriver/util/xml/comment.rb +32 -0
- data/lib/tdriver/util/xml/document.rb +32 -0
- data/lib/tdriver/util/xml/element.rb +32 -0
- data/lib/tdriver/util/xml/error.rb +46 -0
- data/lib/tdriver/util/xml/loader.rb +62 -0
- data/lib/tdriver/util/xml/nil_node.rb +95 -0
- data/lib/tdriver/util/xml/nodeset.rb +32 -0
- data/lib/tdriver/util/xml/parsers/libxml/libxml.rb +140 -0
- data/lib/tdriver/util/xml/parsers/loader.rb +21 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +167 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +66 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/builder.rb +64 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/comment.rb +39 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +66 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/element.rb +39 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/loader.rb +58 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +212 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +237 -0
- data/lib/tdriver/util/xml/parsers/nokogiri/text.rb +39 -0
- data/lib/tdriver/util/xml/text.rb +32 -0
- data/lib/tdriver/util/xml/xml.rb +332 -0
- data/lib/tdriver/verify/verify.rb +2398 -0
- data/lib/tdriver/version.rb +21 -0
- data/xml/behaviours/generic.xml +530 -0
- data/xml/defaults/generic.xml +11 -0
- data/xml/defaults/sut_generic.xml +8 -0
- data/xml/parameters/tdriver_parameters.xml +23 -0
- data/xml/templates/generic.xml +292 -0
- metadata +324 -0
@@ -0,0 +1,109 @@
|
|
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 GemHelper
|
23
|
+
|
24
|
+
def self.create_build_files
|
25
|
+
|
26
|
+
# Create build files. These are required, as RubyGems expects that external dependencies
|
27
|
+
# are built during the gem installation process and will not complete the installation
|
28
|
+
# if these files are missing.
|
29
|
+
|
30
|
+
begin
|
31
|
+
|
32
|
+
# remove following line when native extensions are supported by tdriver
|
33
|
+
#raise LoadError
|
34
|
+
|
35
|
+
# skip native extension build if running in java environment
|
36
|
+
raise LoadError if MobyUtil::EnvironmentHelper.java?
|
37
|
+
|
38
|
+
# skip also if windows env. until proper solution found how to compile in windows env.
|
39
|
+
raise LoadError if MobyUtil::EnvironmentHelper.windows?
|
40
|
+
|
41
|
+
# makefile creation module
|
42
|
+
require 'mkmf'
|
43
|
+
|
44
|
+
# name of ruby native extension
|
45
|
+
extension_name = 'tdriver/native_extensions'
|
46
|
+
|
47
|
+
# destination
|
48
|
+
dir_config( extension_name )
|
49
|
+
|
50
|
+
# create makefile for implementation
|
51
|
+
create_makefile( extension_name )
|
52
|
+
|
53
|
+
rescue Exception
|
54
|
+
|
55
|
+
# create dummy makefile if building native extension fails or is not supported
|
56
|
+
File.open( 'Makefile', 'w' ) { | f | f.write "all:\n\ninstall:\n\n" }
|
57
|
+
|
58
|
+
if MobyUtil::EnvironmentHelper.windows?
|
59
|
+
|
60
|
+
File.open( 'nmake.bat', 'w') { |f| f.write "SET ERRORLEVEL=0" }
|
61
|
+
File.open( 'make.bat', 'w') { |f| f.write "SET ERRORLEVEL=0" }
|
62
|
+
File.open( 'extconf.dll', 'w' ) {}
|
63
|
+
|
64
|
+
else
|
65
|
+
|
66
|
+
File.open( 'make', 'w' ){ | f | f.write '#!/bin/sh'; f.chmod f.stat.mode | 0111; }
|
67
|
+
File.open( 'extconf.so', 'w' ) {}
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.grant_file_access_rights( folder, user_name = nil, user_group = nil )
|
76
|
+
|
77
|
+
if MobyUtil::EnvironmentHelper.posix?
|
78
|
+
|
79
|
+
# change folder ownership to user and add writing access to each file
|
80
|
+
user_name = MobyUtil::EnvironmentHelper.user_name if user_name.nil?
|
81
|
+
user_group = MobyUtil::EnvironmentHelper.user_group( user_name ) if user_group.nil?
|
82
|
+
|
83
|
+
MobyUtil::EnvironmentHelper.change_file_ownership!( folder, user_name, user_group, true )
|
84
|
+
|
85
|
+
`chmod -R u+w #{ folder }`
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
# TODO: document
|
92
|
+
def self.install( *parameters, &block )
|
93
|
+
|
94
|
+
raise ArgumentError.new( "Target folder must be specified as first argument" ) if parameters.empty?
|
95
|
+
|
96
|
+
yield( *parameters )
|
97
|
+
|
98
|
+
MobyUtil::GemHelper.create_build_files
|
99
|
+
|
100
|
+
MobyUtil::GemHelper.grant_file_access_rights( parameters.first )
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
# enable hooking for performance measurement & debug logging
|
105
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
106
|
+
|
107
|
+
end # GemHelper
|
108
|
+
|
109
|
+
end # MobyUtil
|
@@ -0,0 +1,288 @@
|
|
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 Hash class functionality
|
21
|
+
class Hash
|
22
|
+
|
23
|
+
def not_empty( message = "Hash must not be empty", exception = ArgumentError )
|
24
|
+
|
25
|
+
raise exception, message, caller if empty?
|
26
|
+
|
27
|
+
self
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# verify that receiver object contains one of given keys. Raises exception is key not found.
|
32
|
+
def require_one( keys, message = "None of key(s) $1 found from hash" )
|
33
|
+
|
34
|
+
# create array of types
|
35
|
+
keys_array = Array( keys )
|
36
|
+
|
37
|
+
found = false
|
38
|
+
|
39
|
+
verbose_keys_list = keys_array.each_with_index.collect{ | key, index |
|
40
|
+
|
41
|
+
if has_key?( key )
|
42
|
+
found = true
|
43
|
+
break
|
44
|
+
end
|
45
|
+
|
46
|
+
# result string, separate types if multiple types given
|
47
|
+
"#{ ( ( index > 0 ) ? ( index + 1 < keys_array.count ? ", " : " or " ) : "" ) }#{ key.inspect }"
|
48
|
+
|
49
|
+
}
|
50
|
+
|
51
|
+
# raise exception if type did not match
|
52
|
+
unless found
|
53
|
+
|
54
|
+
# convert macros
|
55
|
+
[ verbose_keys_list.join ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
56
|
+
|
57
|
+
# raise the exception
|
58
|
+
raise ArgumentError, message, caller
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
self
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
# verify that receiver object contains given key. Raises exception is key not found.
|
67
|
+
def require_key( key, message = 'required key $1 not found from hash' )
|
68
|
+
|
69
|
+
# store caller backtrace before calling fetch
|
70
|
+
backtrace = caller
|
71
|
+
|
72
|
+
fetch( key ){
|
73
|
+
|
74
|
+
raise ArgumentError, message.gsub( "$1", key.inspect ), backtrace
|
75
|
+
|
76
|
+
}
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
# verify that receiver object contains all of given keys. Raises exception is key not found.
|
81
|
+
def require_keys( keys, message = "Required key(s) $1 not found from hash" )
|
82
|
+
|
83
|
+
# create array of types
|
84
|
+
keys_array = Array( keys )
|
85
|
+
|
86
|
+
found = true
|
87
|
+
|
88
|
+
verbose_keys_list = keys_array.each_with_index.collect{ | key, index |
|
89
|
+
|
90
|
+
found = false unless has_key?( key )
|
91
|
+
|
92
|
+
# result string, separate types if multiple types given
|
93
|
+
"#{ ( ( index > 0 ) ? ( index + 1 < keys_array.count ? ", " : " and " ) : "" ) }#{ key.inspect }"
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
# raise exception if type did not match
|
98
|
+
unless found
|
99
|
+
|
100
|
+
# convert macros
|
101
|
+
[ verbose_keys_list.join ].each_with_index{ | param, index | message.gsub!( "$#{ index + 1 }", param.to_s ) }
|
102
|
+
|
103
|
+
# raise the exception
|
104
|
+
raise ArgumentError, message, caller
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
self
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
# collect given keypairs from hash
|
113
|
+
def collect_keys( *keys )
|
114
|
+
|
115
|
+
#Hash[ self.select{ | key, value | true if keys.include?( key ) } ]
|
116
|
+
|
117
|
+
# optimized version, approx 47.9% faster
|
118
|
+
keys.inject( {} ){ | hash, key | hash[ key ] = self[ key ] if has_key?( key ); hash }
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
# remove keys from hash, return hash of deleted keys as result
|
123
|
+
def delete_keys!( *keys )
|
124
|
+
|
125
|
+
#Hash[ keys.flatten.collect{ | key | [ key, delete( key ) ] if has_key?( key ) }.compact ]
|
126
|
+
|
127
|
+
# optimized version, approx 23.4% faster
|
128
|
+
keys.inject( {} ){ | hash, key | hash[ key ] = delete( key ) if has_key?( key ); hash }
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
# delete multiple keys from hash, does not modify original hash
|
133
|
+
def delete_keys( *keys )
|
134
|
+
|
135
|
+
# create a duplicate of current hash
|
136
|
+
result = dup; keys.flatten.each{ | key | result.delete( key ) }; result
|
137
|
+
|
138
|
+
# optimized version, approx 5% faster
|
139
|
+
#keys.inject( dup ){ | hash, key | hash.delete( key ); hash }
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
# store keys and values to hash if not already defined
|
144
|
+
def default_values( hash )
|
145
|
+
|
146
|
+
hash.each_pair{ | key, value | self[ key ] = value unless has_key?( key ) }
|
147
|
+
|
148
|
+
self
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
# store key and value to hash if not already defined
|
153
|
+
def default_value( key, value )
|
154
|
+
|
155
|
+
self[ key ] = value unless has_key?( key )
|
156
|
+
|
157
|
+
self
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
def strip_dynamic_attributes!
|
162
|
+
|
163
|
+
=begin
|
164
|
+
# remove dynamic attributes from hash and return as result
|
165
|
+
Hash[
|
166
|
+
|
167
|
+
# iterate through each hash key
|
168
|
+
select{ | key, value |
|
169
|
+
|
170
|
+
# dynamic attribute name has "__" prefix
|
171
|
+
if key.to_s =~ /^__/
|
172
|
+
|
173
|
+
# remove dynamic attribute key from hash
|
174
|
+
delete( key )
|
175
|
+
|
176
|
+
# add to hash
|
177
|
+
true
|
178
|
+
|
179
|
+
else
|
180
|
+
|
181
|
+
# do not add to hash
|
182
|
+
false
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
}
|
187
|
+
|
188
|
+
]
|
189
|
+
=end
|
190
|
+
|
191
|
+
# optimized version, approx 3.2% faster
|
192
|
+
prefix = '__'
|
193
|
+
|
194
|
+
keys.inject( {} ){ | hash, key |
|
195
|
+
|
196
|
+
hash[ key ] = delete( key ) if key.to_s[0..1] == prefix
|
197
|
+
|
198
|
+
hash
|
199
|
+
|
200
|
+
}
|
201
|
+
|
202
|
+
end # strip_dynamic_attributes!
|
203
|
+
|
204
|
+
# TODO: document me
|
205
|
+
def to_attributes
|
206
|
+
|
207
|
+
collect{ | key, value |
|
208
|
+
|
209
|
+
"#{ key.to_s }=\"#{ value.to_s.encode_to_xml }\""
|
210
|
+
|
211
|
+
}.join(" ")
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
# TODO: document me
|
216
|
+
def recursive_merge( other )
|
217
|
+
|
218
|
+
merge( other ){ | key, old_value, new_value |
|
219
|
+
|
220
|
+
new_value
|
221
|
+
|
222
|
+
if old_value.kind_of?( Hash ) && new_value.kind_of?( Hash )
|
223
|
+
|
224
|
+
# merge hashes, call self recursively
|
225
|
+
old_value.recursive_merge( new_value )
|
226
|
+
|
227
|
+
elsif old_value.kind_of?( Array ) && new_value.kind_of?( Array )
|
228
|
+
|
229
|
+
# concatenate arrays
|
230
|
+
old_value.clone.concat( new_value ).uniq
|
231
|
+
|
232
|
+
else
|
233
|
+
|
234
|
+
# return new value as is
|
235
|
+
new_value
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
end # recursive_merge
|
242
|
+
|
243
|
+
# TODO: document me
|
244
|
+
def recursive_merge!( other )
|
245
|
+
|
246
|
+
replace(
|
247
|
+
|
248
|
+
recursive_merge( other )
|
249
|
+
|
250
|
+
)
|
251
|
+
|
252
|
+
end # recursive_merge!
|
253
|
+
|
254
|
+
# TODO: document me
|
255
|
+
def if_found( key )
|
256
|
+
|
257
|
+
if has_key?( key )
|
258
|
+
|
259
|
+
yield( key, self[ key ] )
|
260
|
+
|
261
|
+
end
|
262
|
+
|
263
|
+
end # if_found
|
264
|
+
|
265
|
+
# TODO: document me
|
266
|
+
def rename_key!( key, new )
|
267
|
+
|
268
|
+
if has_key?( key )
|
269
|
+
|
270
|
+
self[ new ] = delete( key )
|
271
|
+
|
272
|
+
else
|
273
|
+
|
274
|
+
if block_given?
|
275
|
+
|
276
|
+
yield( key, new )
|
277
|
+
|
278
|
+
else
|
279
|
+
|
280
|
+
raise IndexError, "key #{ key.inspect } not found", caller
|
281
|
+
|
282
|
+
end
|
283
|
+
|
284
|
+
end # has_key?
|
285
|
+
|
286
|
+
end # rename_key!
|
287
|
+
|
288
|
+
end # Hash
|
@@ -0,0 +1,253 @@
|
|
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 Kernel
|
21
|
+
|
22
|
+
|
23
|
+
# TODO: document me
|
24
|
+
def __method_path__
|
25
|
+
|
26
|
+
# retrieve filename, line number and method name
|
27
|
+
/^(.+?):(\d+)(?::in `(.*)')?/.match( caller.reverse[ -2 ].to_s )
|
28
|
+
|
29
|
+
# construct string with module/class and method name
|
30
|
+
"#{ ( [ Class, Module ].include?( self.class ) ? self.name : self.class.name ).to_s }##{ caller.first.to_s.scan(/`(.+)'$/).to_s }"
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
# TODO: document me
|
35
|
+
def warn_caller( message, remove_eval = true )
|
36
|
+
|
37
|
+
# verify that message argument type is correct
|
38
|
+
raise TypeError, "wrong argument type #{ message.class } for message (expected String)" unless message.kind_of?( String )
|
39
|
+
|
40
|
+
# verify that remove_eval argument type is correct
|
41
|
+
raise TypeError, "wrong argument type #{ remove_eval.class } for remove evaluate calls value (expected TrueClass or FalseClass)" unless [ TrueClass, FalseClass ].include?( remove_eval.class )
|
42
|
+
|
43
|
+
# retrieve caller method, file and line number
|
44
|
+
begin
|
45
|
+
|
46
|
+
# remove evals if required
|
47
|
+
caller_stack = ( remove_eval == true ? caller.select{ | str | str !~ /^\(eval\)\:/ and str !~ /`eval'$/ } : caller )
|
48
|
+
|
49
|
+
# retrieve filename, line number and method name
|
50
|
+
/^(.+?):(\d+)(?::in `(.*)')?/.match( caller_stack.reverse[ -2 ].to_s )
|
51
|
+
|
52
|
+
# store matches
|
53
|
+
file, line, method = $1, $2, $3
|
54
|
+
|
55
|
+
rescue
|
56
|
+
|
57
|
+
# could not retrieve filename, line number and method name
|
58
|
+
file, line, method = [ '##', '##', 'unknown' ]
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
# print warning to STDOUT
|
63
|
+
warn message.gsub( '$1', file.to_s ).gsub( '$2', line.to_s ).gsub( '$3', method.to_s )
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
module MobyUtil
|
70
|
+
|
71
|
+
# Helper class to store verify block for
|
72
|
+
# constant verifications for sut state
|
73
|
+
class VerifyBlock
|
74
|
+
|
75
|
+
attr_accessor :block,:expected, :message,:source, :timeout
|
76
|
+
|
77
|
+
def initialize(block, expected, message = nil, timeout = nil, source = "")
|
78
|
+
|
79
|
+
@block = block
|
80
|
+
@expected = expected
|
81
|
+
@message = message
|
82
|
+
@timeout = timeout
|
83
|
+
@source = source
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
class KernelHelper
|
90
|
+
|
91
|
+
# Function to determine if given value is boolean
|
92
|
+
# == params
|
93
|
+
# value:: String containing boolean
|
94
|
+
# == returns
|
95
|
+
# TrueClass::
|
96
|
+
# FalseClass::
|
97
|
+
def self.boolean?( value )
|
98
|
+
|
99
|
+
/^(true|false)$/i.match( value.to_s ).kind_of?( MatchData ) rescue false
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# Function to return boolean of given value
|
104
|
+
# == params
|
105
|
+
# value:: String containing boolean
|
106
|
+
# == returns
|
107
|
+
# TrueClass::
|
108
|
+
# FalseClass::
|
109
|
+
def self.to_boolean( value, default = nil )
|
110
|
+
|
111
|
+
/^(true|false)$/i.match( value.to_s ) ? $1.downcase == 'true' : default
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
# Function to return class constant from a string
|
116
|
+
# == params
|
117
|
+
# constant_name:: String containing path
|
118
|
+
# == returns
|
119
|
+
# Class
|
120
|
+
def self.get_constant( constant_name )
|
121
|
+
|
122
|
+
begin
|
123
|
+
|
124
|
+
constant_name.split("::").inject( Kernel ){ | scope, const_name | scope.const_get( const_name ) }
|
125
|
+
|
126
|
+
rescue
|
127
|
+
|
128
|
+
raise NameError, "invalid constant #{ constant_name }"
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.parse_caller( at )
|
135
|
+
|
136
|
+
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
|
137
|
+
|
138
|
+
file = Regexp.last_match[ 1 ]
|
139
|
+
line = Regexp.last_match[ 2 ].to_i
|
140
|
+
method = Regexp.last_match[ 3 ]
|
141
|
+
|
142
|
+
[ file, line, method ]
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
def self.deprecated( deprecated_name, new_name = "" )
|
149
|
+
|
150
|
+
output = "warning: #{ deprecated_name } is deprecated"
|
151
|
+
|
152
|
+
output += "; use #{ new_name } instead" unless new_name.empty?
|
153
|
+
|
154
|
+
$stderr.puts output
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
# Searches for the given source file for a line
|
159
|
+
#
|
160
|
+
# === params
|
161
|
+
# from_file:: String defining the file to load. If at_line is nil, this argument can also contain a path and line number separated by : (eg. some_dir/some_file.rb:123).
|
162
|
+
# at_line:: (optional) Integer, number of the line (first line is 1).
|
163
|
+
# === returns
|
164
|
+
# String:: Contents of the line
|
165
|
+
# === throws
|
166
|
+
# RuntimeError:: from_file is not correctly formed, the file cannot be loaded or the line cannot be found.
|
167
|
+
def self.find_source( backtrace )
|
168
|
+
|
169
|
+
result = "\n"
|
170
|
+
|
171
|
+
begin
|
172
|
+
|
173
|
+
# split with colon
|
174
|
+
call_stack = backtrace.to_s.split(':')
|
175
|
+
|
176
|
+
# TODO: document me
|
177
|
+
line_number = ( call_stack.size == 2 ? call_stack[ 1 ].to_i : call_stack[ call_stack.size - 2 ] ).to_i
|
178
|
+
|
179
|
+
file_path = ""
|
180
|
+
|
181
|
+
# TODO: document me
|
182
|
+
if ( call_stack.size == 2 )
|
183
|
+
|
184
|
+
file_path = call_stack[ 0 ]
|
185
|
+
|
186
|
+
else
|
187
|
+
|
188
|
+
# TODO: document me
|
189
|
+
( call_stack.size - 2 ).times do | index |
|
190
|
+
|
191
|
+
file_path << "#{ call_stack[ index ].to_s }:"
|
192
|
+
|
193
|
+
end
|
194
|
+
|
195
|
+
# remove the trailing colon
|
196
|
+
file_path.slice!(-1)
|
197
|
+
|
198
|
+
end
|
199
|
+
|
200
|
+
# TODO: document me
|
201
|
+
lines_to_read = line_number >= 2 ? 3 : line_number
|
202
|
+
#puts "lines to read: " << lines_to_read.to_s
|
203
|
+
|
204
|
+
# TODO: document me
|
205
|
+
start_line = line_number #- (lines_to_read <= 1 ? 0 : 1)
|
206
|
+
#puts "start line:" << start_line.to_s
|
207
|
+
|
208
|
+
# expand file path and name
|
209
|
+
filename = File.expand_path( file_path.to_s )
|
210
|
+
|
211
|
+
# open source file
|
212
|
+
File.open( filename, "r") { | source |
|
213
|
+
|
214
|
+
# read lines
|
215
|
+
lines = source.readlines
|
216
|
+
|
217
|
+
# raise exception if line number is larger than total number of lines
|
218
|
+
raise RuntimeError.new(
|
219
|
+
|
220
|
+
"Unable to fetch line #{ start_line.to_s } from source file #{ filename } due to it is out of range (total lines: #{ lines.size })"
|
221
|
+
|
222
|
+
) if start_line > lines.size
|
223
|
+
|
224
|
+
# TODO: document me
|
225
|
+
lines_to_read = ( lines.size - start_line + 1 ) < 3 ? ( lines.size - start_line + 1 ) : lines_to_read
|
226
|
+
|
227
|
+
# the array is zero based, first line is at position 0
|
228
|
+
lines_to_read.times do | index |
|
229
|
+
|
230
|
+
# add "=>" to line which failed
|
231
|
+
result << ( ( line_number == ( start_line + index ) ) ? "=> " : " " ) + lines[ start_line + index - 1 ]
|
232
|
+
|
233
|
+
end
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
rescue Exception => e
|
238
|
+
|
239
|
+
result << "Unable to load source lines.\n#{ e.inspect }"
|
240
|
+
|
241
|
+
end
|
242
|
+
|
243
|
+
# return result string
|
244
|
+
result
|
245
|
+
|
246
|
+
end
|
247
|
+
|
248
|
+
# enable hooking for performance measurement & debug logging
|
249
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
250
|
+
|
251
|
+
end # KernelHelper
|
252
|
+
|
253
|
+
end # MobyUtil
|