testability-driver 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/config/sut_parameters.rb +21 -8
- data/config/tdriver_custom_error_recovery.rb +83 -0
- data/ext/extconf.rb +3 -2
- data/ext/native_extensions.c +60 -2
- data/lib/tdriver-devtools/behaviour/old/xml/example/flick-example.rb +2 -105
- data/lib/tdriver/base/behaviour/factory.rb +154 -89
- data/lib/tdriver/base/behaviour/factory_new.rb +409 -0
- data/lib/tdriver/base/errors.rb +3 -3
- data/lib/tdriver/base/state_object.rb +85 -22
- data/lib/tdriver/base/sut/adapter.rb +26 -0
- data/lib/tdriver/base/sut/controller.rb +1 -1
- data/lib/tdriver/base/sut/generic/behaviours/application.rb +89 -118
- data/lib/tdriver/base/sut/generic/behaviours/find.rb +67 -62
- data/lib/tdriver/base/sut/generic/behaviours/sut.rb +296 -187
- data/lib/tdriver/base/sut/generic/behaviours/switchbox_behaviour.rb +7 -7
- data/lib/tdriver/base/sut/generic/commands/application.rb +366 -295
- data/lib/tdriver/base/sut/sut.rb +19 -3
- data/lib/tdriver/base/test_object/abstract.rb +41 -21
- data/lib/tdriver/base/test_object/adapter.rb +62 -9
- data/lib/tdriver/base/test_object/behaviours/syncronization.rb +10 -6
- data/lib/tdriver/base/test_object/behaviours/test_object.rb +84 -47
- data/lib/tdriver/base/test_object/factory.rb +124 -68
- data/lib/tdriver/base/test_object/loader.rb +3 -4
- data/lib/tdriver/base/test_object/verification.rb +3 -3
- data/lib/tdriver/base/test_object/xml/adapter.rb +734 -0
- data/lib/tdriver/loader.rb +12 -0
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery.rb +3 -2
- data/lib/tdriver/report/error_recovery/tdriver_error_recovery_settings.rb +14 -14
- data/lib/tdriver/report/report.rb +4 -8
- data/lib/tdriver/report/report_api.rb +9 -0
- data/lib/tdriver/report/report_crash_file_capture.rb +4 -4
- data/lib/tdriver/report/report_creator.rb +57 -35
- data/lib/tdriver/report/report_cucumber.rb +1 -1
- data/lib/tdriver/report/report_cucumber_listener.rb +5 -158
- data/lib/tdriver/report/report_cucumber_reporter.rb +7 -161
- data/lib/tdriver/report/report_execution_statistics.rb +4 -4
- data/lib/tdriver/report/report_file_capture.rb +5 -5
- data/lib/tdriver/report/report_grouping.rb +24 -22
- data/lib/tdriver/report/report_junit_xml.rb +5 -5
- data/lib/tdriver/report/report_test_case_run.rb +31 -22
- data/lib/tdriver/report/report_test_run.rb +107 -104
- data/lib/tdriver/report/report_writer.rb +150 -83
- data/lib/tdriver/tdriver.rb +147 -103
- data/lib/tdriver/util/common/boolean.rb +51 -0
- data/lib/tdriver/util/common/crc16.rb +110 -68
- data/lib/tdriver/util/common/hash.rb +63 -7
- data/lib/tdriver/util/common/kernel.rb +46 -1
- data/lib/tdriver/util/common/loader.rb +1 -0
- data/lib/tdriver/util/common/object.rb +20 -8
- data/lib/tdriver/util/common/string.rb +21 -2
- data/lib/tdriver/util/logger/logger.rb +4 -4
- data/lib/tdriver/util/parameter/loader.rb +2 -19
- data/lib/tdriver/util/parameter/parameter.rb +874 -177
- data/lib/tdriver/util/plugin/service.rb +1 -1
- data/lib/tdriver/util/recorder/recorder.rb +7 -1
- data/lib/tdriver/util/xml/abstraction.rb +13 -1
- data/lib/tdriver/util/xml/parsers/nokogiri/abstraction.rb +63 -10
- data/lib/tdriver/util/xml/parsers/nokogiri/attribute.rb +8 -2
- data/lib/tdriver/util/xml/parsers/nokogiri/document.rb +16 -3
- data/lib/tdriver/util/xml/parsers/nokogiri/node.rb +36 -32
- data/lib/tdriver/util/xml/parsers/nokogiri/nodeset.rb +19 -22
- data/lib/tdriver/util/xml/xml.rb +147 -32
- data/lib/tdriver/verify/verify.rb +1112 -289
- data/lib/tdriver/version.rb +1 -1
- data/xml/templates/generic.xml +14 -2
- metadata +51 -24
- data/lib/tdriver/util/parameter/parameter_hash.rb +0 -104
- data/lib/tdriver/util/parameter/parameter_new.rb +0 -869
- data/lib/tdriver/util/parameter/parameter_template.rb +0 -120
- data/lib/tdriver/util/parameter/parameter_user_api.rb +0 -116
- data/lib/tdriver/util/parameter/parameter_xml.rb +0 -261
data/config/sut_parameters.rb
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
# Generic configuration file for sut data.
|
20
20
|
# Can be used to provide ruby code for sut configurations.
|
21
21
|
module SutParameters
|
22
|
+
|
22
23
|
# Verify blocks define the verify_always blocks that are automatically added to given sut.
|
23
24
|
# Takes an array of VerifyBlock objects
|
24
25
|
# VerifyBlock parameters:
|
@@ -27,13 +28,25 @@ module SutParameters
|
|
27
28
|
# - Error message
|
28
29
|
# Configured verify_always blocks will not return the failed error block code in the error message.
|
29
30
|
VERIFY_BLOCKS = [
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
31
|
+
|
32
|
+
# Example block
|
33
|
+
MobyUtil::VerifyBlock.new(
|
34
|
+
|
35
|
+
# proc block to execute
|
36
|
+
Proc.new{ |sut|
|
37
|
+
# Verifies that some application is always running
|
38
|
+
sut.application.name != "qttasserver"
|
39
|
+
},
|
40
|
+
|
41
|
+
# expected return value
|
42
|
+
true,
|
43
|
+
|
44
|
+
# error message
|
45
|
+
"Top most application is qttas, no application is running"
|
46
|
+
|
47
|
+
)
|
48
|
+
|
49
|
+
]
|
50
|
+
|
38
51
|
end
|
39
52
|
|
@@ -0,0 +1,83 @@
|
|
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 TDriverCustomErrorRecovery
|
21
|
+
|
22
|
+
# This method is called by TDriver Reporter when error is detected in connection
|
23
|
+
# === params
|
24
|
+
# === returns
|
25
|
+
# === raises
|
26
|
+
def error_in_connection()
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# This method is called by TDriver Reporter when test set execution is starting
|
31
|
+
# === params
|
32
|
+
# === returns
|
33
|
+
# === raises
|
34
|
+
def starting_test_set_run()
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
# This method is called by TDriver Reporter when test case execution is starting
|
39
|
+
# === params
|
40
|
+
# test_case: the test case name
|
41
|
+
# connected_suts: All the connected TDriver suts
|
42
|
+
# === returns
|
43
|
+
# === raises
|
44
|
+
def starting_test_case(test_case,connected_suts)
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
# This method is called by TDriver Reporter when a error is detected in test case execution
|
49
|
+
# === params
|
50
|
+
# connected_suts: All the connected TDriver suts
|
51
|
+
# === returns
|
52
|
+
# === raises
|
53
|
+
def error_in_test_case(connected_suts)
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
# This method is called by TDriver Reporter when test case details are updated
|
58
|
+
# === params
|
59
|
+
# details: Execution details recived from the current test case
|
60
|
+
# === returns
|
61
|
+
# === raises
|
62
|
+
def updating_test_case_details(details)
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
# This method is called by TDriver Reporter when test case execution is ended
|
67
|
+
# === params
|
68
|
+
# connected_suts: All the connected TDriver suts
|
69
|
+
# === returns
|
70
|
+
# === raises
|
71
|
+
def ending_test_case(status,connected_suts)
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
# This method is called by TDriver Reporter when test set execution is ending
|
76
|
+
# === params
|
77
|
+
# === returns
|
78
|
+
# === raises
|
79
|
+
def ending_test_set_run()
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
data/ext/extconf.rb
CHANGED
@@ -29,8 +29,9 @@ MobyUtil::GemHelper.install( MobyUtil::FileHelper.tdriver_home ){ | tdriver_home
|
|
29
29
|
[ "../xml/parameters/tdriver_parameters.xml", "tdriver_parameters.xml", false ],
|
30
30
|
[ "../xml/parameters/tdriver_parameters.xml", "default/tdriver_parameters.xml", true ],
|
31
31
|
[ "../config/sut_parameters.rb", "sut_parameters.rb", true ],
|
32
|
-
[ "../config/sut_setup.rb", "sut_setup.rb",
|
33
|
-
[ "../config/sut_teardown.rb", "sut_teardown.rb",
|
32
|
+
[ "../config/sut_setup.rb", "sut_setup.rb", false ],
|
33
|
+
[ "../config/sut_teardown.rb", "sut_teardown.rb", false ],
|
34
|
+
[ "../config/tdriver_custom_error_recovery.rb", "tdriver_custom_error_recovery.rb", false ],
|
34
35
|
|
35
36
|
# templates
|
36
37
|
[ "../xml/templates/*.xml", "templates/", true ],
|
data/ext/native_extensions.c
CHANGED
@@ -30,6 +30,7 @@ static const CRC_16[ 16 ] = {
|
|
30
30
|
|
31
31
|
};
|
32
32
|
|
33
|
+
/*
|
33
34
|
static VALUE crc16_ibm( VALUE self, VALUE string ) {
|
34
35
|
|
35
36
|
// verify argument type
|
@@ -55,16 +56,73 @@ static VALUE crc16_ibm( VALUE self, VALUE string ) {
|
|
55
56
|
|
56
57
|
return INT2FIX( ~crc & 0xffff );
|
57
58
|
|
59
|
+
}
|
60
|
+
*/
|
61
|
+
|
62
|
+
//static VALUE crc16_ibm( VALUE self, VALUE string, VALUE unused_crc ) {
|
63
|
+
static VALUE crc16_ibm( int argc, VALUE* argv, VALUE self ) {
|
64
|
+
//klass VALUE self, VALUE string, VALUE unused_crc ) {
|
65
|
+
|
66
|
+
// variables for arguments
|
67
|
+
VALUE string, initial_crc;
|
68
|
+
|
69
|
+
// retrieve arguments
|
70
|
+
rb_scan_args(argc, argv, "11", &string, &initial_crc);
|
71
|
+
|
72
|
+
int crc; // = 0xffff;
|
73
|
+
|
74
|
+
if (NIL_P(initial_crc)){
|
75
|
+
|
76
|
+
crc = 0xffff;
|
77
|
+
|
78
|
+
} else {
|
79
|
+
|
80
|
+
// verify initial crc value
|
81
|
+
Check_Type( initial_crc, T_FIXNUM );
|
82
|
+
|
83
|
+
crc = NUM2INT( initial_crc );
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
// verify argument type
|
88
|
+
Check_Type( string, T_STRING );
|
89
|
+
|
90
|
+
const char* data = RSTRING_PTR( string );
|
91
|
+
|
92
|
+
int len = RSTRING_LEN( string );
|
93
|
+
|
94
|
+
int c = 0;
|
95
|
+
|
96
|
+
while( len-- ){
|
97
|
+
|
98
|
+
c = *data++;
|
99
|
+
|
100
|
+
crc = ( crc >> 4 ) ^ CRC_16[ ( crc ^ c ) & 15 ];
|
101
|
+
|
102
|
+
crc = ( crc >> 4 ) ^ CRC_16[ ( crc ^ ( c >> 4 ) ) & 15 ];
|
103
|
+
|
104
|
+
}
|
105
|
+
|
106
|
+
return INT2FIX( ~crc & 0xffff );
|
107
|
+
|
108
|
+
|
58
109
|
}
|
59
110
|
|
60
111
|
void Init_native_extensions() {
|
61
112
|
|
113
|
+
// main tdriver module
|
62
114
|
VALUE mTDriver = rb_define_module( "TDriver" );
|
63
115
|
|
64
|
-
|
116
|
+
// checksum module
|
117
|
+
VALUE cChecksum = rb_define_class_under( mTDriver, "Checksum", rb_cObject );
|
118
|
+
|
119
|
+
// checksum methods
|
120
|
+
rb_define_singleton_method( cChecksum, "crc16_ibm", crc16_ibm, -1 );
|
65
121
|
|
122
|
+
// deprecated - for backwards compatibility
|
123
|
+
VALUE mNativeExtensions = rb_define_module_under( mTDriver, "NativeExtensions" );
|
66
124
|
VALUE mCRC = rb_define_module_under( mNativeExtensions, "CRC" );
|
125
|
+
rb_define_singleton_method( mCRC, "crc16_ibm", crc16_ibm, -1 );
|
67
126
|
|
68
|
-
rb_define_singleton_method( mCRC, "crc16_ibm", crc16_ibm, 1 );
|
69
127
|
|
70
128
|
}
|
@@ -92,31 +92,7 @@ module MobyBehaviour
|
|
92
92
|
# app.QPushButton( :text => "Close" ).flick :Left
|
93
93
|
#
|
94
94
|
def flick( direction, button = :Left, optional_params = {} )
|
95
|
-
|
96
|
-
begin
|
97
|
-
use_tap_screen = optional_params[:use_tap_screen].nil? ? MobyUtil::Parameter[ @sut.id][ :use_tap_screen, 'false'] :
|
98
|
-
optional_params[:use_tap_screen].to_s
|
99
|
-
optional_params[:useTapScreen] = use_tap_screen
|
100
|
-
|
101
|
-
speed = calculate_speed(@sut.parameter(:gesture_flick_distance), @sut.parameter(:gesture_flick_speed))
|
102
|
-
distance = @sut.parameter(:gesture_flick_distance).to_i
|
103
|
-
params = {:gesture_type => :MouseGesture, :direction => direction, :speed => speed, :distance => distance, :isDrag => false, :button => button, :useTapScreen => use_tap_screen}
|
104
|
-
params.merge!(optional_params)
|
105
|
-
|
106
|
-
do_gesture(params)
|
107
|
-
do_sleep(speed)
|
108
|
-
|
109
|
-
rescue Exception => e
|
110
|
-
|
111
|
-
MobyUtil::Logger.instance.log "behaviour" , "FAIL;Failed flick with direction \"#{direction}\", button \"#{button.to_s}\".;#{identity};flick;"
|
112
|
-
Kernel::raise e
|
113
|
-
end
|
114
|
-
|
115
|
-
MobyUtil::Logger.instance.log "behaviour" , "PASS;Operation flick executed successfully with direction \"#{direction}\", button \"#{button.to_s}\".;#{identity};flick;"
|
116
|
-
|
117
|
-
nil
|
118
|
-
end
|
119
|
-
|
95
|
+
end
|
120
96
|
|
121
97
|
private
|
122
98
|
|
@@ -126,98 +102,19 @@ module MobyBehaviour
|
|
126
102
|
# gesture_type: :MouseGesture, :MouseGestureTo, :MouseGestureToCoordinates
|
127
103
|
# params = {:direction => :Up, duration => 2, :distance =>100, :isDrag =>false, :isMove =>false }
|
128
104
|
def do_gesture(params)
|
129
|
-
validate_gesture_params!(params)
|
130
|
-
|
131
|
-
if attribute('objectType') == 'Embedded'
|
132
|
-
params['x'] = center_x
|
133
|
-
params['y'] = center_y
|
134
|
-
params['useCoordinates'] = 'true'
|
135
|
-
end
|
136
|
-
|
137
|
-
command = command_params #in qt_behaviour
|
138
|
-
command.command_name(params[:gesture_type].to_s)
|
139
|
-
command.command_params( params )
|
140
|
-
@sut.execute_command( command )
|
141
105
|
end
|
142
106
|
|
143
|
-
def validate_gesture_params!(params)
|
144
|
-
#direction
|
145
|
-
if params[:gesture_type] == :MouseGesture
|
146
|
-
if params[:direction].kind_of?(Integer)
|
147
|
-
raise ArgumentError.new( "Invalid direction." ) unless 0 <= params[:direction].to_i and params[:direction].to_i <= 360
|
148
|
-
else
|
149
|
-
raise ArgumentError.new( "Invalid direction." ) unless @@_valid_directions.include?(params[:direction])
|
150
|
-
params[:direction] = @@_direction_map[params[:direction]]
|
151
|
-
end
|
152
|
-
#distance
|
153
|
-
params[:distance] = params[:distance].to_i unless params[:distance].kind_of?(Integer)
|
154
|
-
raise ArgumentError.new( "Distance must be an integer and greater than zero." ) unless params[:distance] > 0
|
155
|
-
elsif params[:gesture_type] == :MouseGestureToCoordinates
|
156
|
-
raise ArgumentError.new("X and Y must be integers.") unless params[:x].kind_of?(Integer) and params[:y].kind_of?(Integer)
|
157
|
-
elsif params[:gesture_type] == :MouseGestureTo
|
158
|
-
raise ArgumentError.new("targetId and targetType must be defined.") unless params[:targetId] and params[:targetType]
|
159
|
-
end
|
160
|
-
|
161
|
-
#duration/speed
|
162
|
-
params[:speed] = params[:speed].to_f unless params[:speed].kind_of?(Numeric)
|
163
|
-
raise ArgumentError.new( "Duration must be a number and greated than zero, was:" + params[:speed].to_s) unless params[:speed] > 0
|
164
|
-
duration_secs = params[:speed].to_f
|
165
|
-
duration_secs = duration_secs*1000
|
166
|
-
params[:speed] = duration_secs.to_i
|
167
|
-
|
168
|
-
#mouseMove true always
|
169
|
-
params[:mouseMove] = true
|
170
|
-
|
171
|
-
params[:button] = :Left unless params[:button]
|
172
|
-
raise ArgumentError.new( "Invalid button." ) unless @@_valid_buttons.include?(params[:button])
|
173
|
-
params[:button] = @@_buttons_map[params[:button]]
|
174
|
-
|
175
|
-
if params[:isMove] == true
|
176
|
-
params[:press] = 'false'
|
177
|
-
params[:release] = 'false'
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
|
183
107
|
def do_sleep(time)
|
184
|
-
|
185
|
-
if MobyUtil::Parameter[ @sut.id ][ :sleep_disabled, nil ] != 'true'
|
186
|
-
time = time.to_f
|
187
|
-
time = time * 1.3
|
188
|
-
#for flicks the duration of the gesture is short but animation (scroll etc..) may not
|
189
|
-
#so wait at least one second
|
190
|
-
time = 1 if time < 1
|
191
|
-
sleep time
|
192
|
-
end
|
193
|
-
|
194
108
|
end
|
195
109
|
|
196
110
|
def calculate_speed(distance, speed)
|
197
|
-
|
198
|
-
distance = distance.to_f
|
199
|
-
speed = speed.to_f
|
200
|
-
duration = distance/speed
|
201
|
-
duration
|
202
|
-
|
203
111
|
end
|
204
112
|
|
205
113
|
def distance_to_point(x, y)
|
206
|
-
|
207
|
-
x = x.to_i
|
208
|
-
y = y.to_i
|
209
|
-
dist_x = x - center_x.to_i
|
210
|
-
dist_y = y - center_y.to_i
|
211
|
-
|
212
|
-
return 0 if dist_y == 0 and dist_x == 0
|
213
|
-
distance = Math.hypot( dist_x, dist_y )
|
214
|
-
distance
|
215
|
-
|
216
114
|
end
|
217
115
|
|
218
116
|
end
|
219
117
|
|
220
118
|
end
|
221
|
-
end
|
222
119
|
|
223
|
-
|
120
|
+
end
|
@@ -199,19 +199,19 @@ module MobyBase
|
|
199
199
|
|
200
200
|
rescue MobyUtil::EmptyFilenameError
|
201
201
|
|
202
|
-
|
202
|
+
raise EmptyFilenameError, "Unable to load behaviours xml file due to filename is empty or nil"
|
203
203
|
|
204
|
-
rescue MobyUtil::FileNotFoundError
|
204
|
+
rescue MobyUtil::FileNotFoundError
|
205
205
|
|
206
|
-
|
206
|
+
raise
|
207
207
|
|
208
|
-
rescue IOError
|
208
|
+
rescue IOError
|
209
209
|
|
210
|
-
|
210
|
+
raise IOError, "Error occured while loading behaviours xml file %s. Reason: %s" % [ @file_name, $!.message ]
|
211
211
|
|
212
|
-
rescue
|
212
|
+
rescue
|
213
213
|
|
214
|
-
|
214
|
+
raise RuntimeError, "Error occured while parsing behaviours xml file %s. Reason: %s (%s)" % [ @file_name, $!.message, $!.class ]
|
215
215
|
|
216
216
|
end
|
217
217
|
|
@@ -223,111 +223,175 @@ module MobyBase
|
|
223
223
|
|
224
224
|
behaviour_files.each{ | behaviours |
|
225
225
|
|
226
|
-
|
226
|
+
begin
|
227
227
|
|
228
|
-
|
229
|
-
|
228
|
+
# skip parsing the xml if string is empty
|
229
|
+
next if behaviours[ :xml ].empty?
|
230
230
|
|
231
|
-
|
232
|
-
|
231
|
+
# parse behaviour xml
|
232
|
+
document = MobyUtil::XML.parse_string( behaviours[ :xml ] )
|
233
233
|
|
234
|
-
|
234
|
+
rescue
|
235
235
|
|
236
|
-
|
237
|
-
"Error occured while parsing behaviour XML file %s. Error: %s " % [ behaviours[ :filename ], exception.message ]
|
238
|
-
)
|
236
|
+
raise MobyUtil::XML::ParseError, "Error occured while parsing behaviour XML file #{ behaviours[ :filename ] }. Error: #{ $!.message }"
|
239
237
|
|
240
|
-
|
238
|
+
end
|
241
239
|
|
242
|
-
|
243
|
-
|
240
|
+
# process each behaviours element
|
241
|
+
document.root.xpath( "/behaviours" ).each{ | behaviours_element |
|
242
|
+
|
243
|
+
# retrieve root attributes
|
244
|
+
root_attributes = behaviours_element.attributes
|
244
245
|
|
245
|
-
|
246
|
-
|
246
|
+
# process each behaviour element
|
247
|
+
behaviours_element.xpath( "behaviour" ).each{ | node |
|
247
248
|
|
248
|
-
|
249
|
-
|
249
|
+
# retrieve behaviour attributes & module node
|
250
|
+
attributes = node.attributes
|
250
251
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
252
|
+
name = attributes[ "name" ].to_s
|
253
|
+
object_type = attributes[ "object_type" ].to_s
|
254
|
+
input_type = attributes[ "input_type" ].to_s
|
255
|
+
sut_type = attributes[ "sut_type" ].to_s
|
256
|
+
version = attributes[ "version" ].to_s
|
256
257
|
|
257
|
-
|
258
|
+
env = ( attributes[ "env" ] || '*' ).to_s
|
258
259
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
version = attributes[ "version" ].to_s
|
266
|
-
|
267
|
-
# verify that all required attributes and nodes are found in behaviour xml node
|
268
|
-
#Kernel::raise RuntimeError.new("Behaviour does not have a name, please see behaviour XML files") if name.empty?
|
269
|
-
name.not_empty("Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError)
|
270
|
-
|
271
|
-
#Kernel::raise RuntimeError.new("Behaviour target object type not defined for #{ name } in XML") if object_type.empty?
|
272
|
-
object_type.not_empty("Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
260
|
+
module_node = node.xpath( 'module' ).first
|
261
|
+
|
262
|
+
# verify that all required attributes and nodes are found in behaviour xml node
|
263
|
+
name.not_empty "Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError
|
264
|
+
|
265
|
+
object_type.not_empty "Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
|
273
266
|
|
274
|
-
|
275
|
-
input_type.not_empty("Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
267
|
+
input_type.not_empty "Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
|
276
268
|
|
277
|
-
|
278
|
-
sut_type.not_empty("Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
269
|
+
sut_type.not_empty "Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
|
279
270
|
|
280
|
-
|
281
|
-
version.not_empty("Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
271
|
+
version.not_empty "Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError
|
282
272
|
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
#Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
|
292
|
-
module_name.not_empty("Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError)
|
273
|
+
module_node.not_nil "Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError
|
274
|
+
|
275
|
+
# retrieve module name & implementation filename
|
276
|
+
module_attributes = module_node.attributes
|
277
|
+
module_file = module_attributes[ "file" ].to_s # optional
|
278
|
+
module_name = module_attributes[ "name" ].to_s
|
279
|
+
|
280
|
+
module_name.not_empty "Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError
|
293
281
|
|
294
|
-
|
282
|
+
methods_hash = {}
|
295
283
|
|
296
|
-
|
297
|
-
|
284
|
+
# create hash of methods
|
285
|
+
node.xpath( 'methods/method' ).each{ | method |
|
298
286
|
|
299
|
-
|
300
|
-
|
287
|
+
# retrieve method description & example and store to methods hash
|
288
|
+
methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
|
289
|
+
:description => method.at_xpath( 'description/text()' ).to_s,
|
290
|
+
:example => method.at_xpath( 'example/text()' ).to_s
|
291
|
+
}
|
301
292
|
|
302
|
-
|
293
|
+
}
|
294
|
+
|
295
|
+
# create and store beahaviour hash
|
296
|
+
@@behaviours << {
|
297
|
+
|
298
|
+
:name => name,
|
299
|
+
:requires => root_attributes[ "plugin" ].to_s.split(";"),
|
300
|
+
:object_type => object_type.split(";"),
|
301
|
+
:input_type => input_type.split(";"),
|
302
|
+
#:sut_type => sut_type.split(";"),
|
303
|
+
:version => version.split(";"),
|
304
|
+
:env => env.split(";"),
|
305
|
+
|
306
|
+
:module => {
|
307
|
+
:file => module_file,
|
308
|
+
:name => module_name
|
309
|
+
},
|
310
|
+
|
311
|
+
:methods => methods_hash
|
312
|
+
|
313
|
+
}
|
303
314
|
|
304
|
-
:example => method.at_xpath( 'example/text()' ).to_s
|
305
315
|
|
306
316
|
}
|
307
317
|
|
308
318
|
}
|
309
319
|
|
310
|
-
|
311
|
-
@@behaviours << {
|
320
|
+
=begin
|
312
321
|
|
313
|
-
|
314
|
-
|
315
|
-
:object_type => object_type.split(";"),
|
316
|
-
:input_type => input_type.split(";"),
|
317
|
-
# :sut_type => sut_type.split(";"),
|
318
|
-
:version => version.split(";"),
|
319
|
-
:env => env.split(";"),
|
322
|
+
# parse retrieve behaviour definitions
|
323
|
+
document.root.xpath( "/behaviours/behaviour" ).each{ | node |
|
320
324
|
|
321
|
-
|
322
|
-
|
323
|
-
:name => module_name
|
324
|
-
},
|
325
|
+
# retrieve behaviour attributes & module node
|
326
|
+
attributes = node.attributes
|
325
327
|
|
326
|
-
|
328
|
+
name = attributes[ "name" ].to_s
|
329
|
+
object_type = attributes[ "object_type" ].to_s
|
330
|
+
input_type = attributes[ "input_type" ].to_s
|
331
|
+
sut_type = attributes[ "sut_type" ].to_s
|
332
|
+
version = attributes[ "version" ].to_s
|
327
333
|
|
328
|
-
|
334
|
+
env = ( attributes[ "env" ] || '*' ).to_s
|
329
335
|
|
330
|
-
|
336
|
+
module_node = node.xpath( 'module' ).first
|
337
|
+
|
338
|
+
# verify that all required attributes and nodes are found in behaviour xml node
|
339
|
+
name.not_empty("Behaviour element does not have name (name) attribute defined, please see behaviour XML files", RuntimeError)
|
340
|
+
|
341
|
+
object_type.not_empty("Behaviour element does not have target object type (object_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
342
|
+
|
343
|
+
input_type.not_empty("Behaviour element does not have target object input type (input_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
344
|
+
|
345
|
+
sut_type.not_empty("Behaviour element does not have target object sut type (sut_type) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
346
|
+
|
347
|
+
version.not_empty("Behaviour element does not have target object SUT version (version) attribute defined, please see #{ name } in behaviour XML files", RuntimeError)
|
348
|
+
|
349
|
+
module_node.not_nil("Behaviour does not have implementation module element defined, please see #{ name } in behaviour XML files", RuntimeError)
|
350
|
+
|
351
|
+
# retrieve module name & implementation filename
|
352
|
+
module_attributes = module_node.attributes
|
353
|
+
module_file = module_attributes[ "file" ].to_s # optional
|
354
|
+
module_name = module_attributes[ "name" ].to_s
|
355
|
+
|
356
|
+
#Kernel::raise RuntimeError.new( "Behaviour implementation module name not defined for #{ name } in XML") if module_name.empty?
|
357
|
+
module_name.not_empty("Behaviour does not have implementation module name defined, please see #{ name } in behaviour XML files", RuntimeError)
|
358
|
+
|
359
|
+
methods_hash = {}
|
360
|
+
|
361
|
+
# create hash of methods
|
362
|
+
node.xpath( 'methods/method' ).each{ | method |
|
363
|
+
|
364
|
+
# retrieve method description & example and store to methods hash
|
365
|
+
methods_hash[ method.attribute( "name" ).to_s.to_sym ] = {
|
366
|
+
:description => method.at_xpath( 'description/text()' ).to_s,
|
367
|
+
:example => method.at_xpath( 'example/text()' ).to_s
|
368
|
+
}
|
369
|
+
|
370
|
+
}
|
371
|
+
|
372
|
+
# create and store beahaviour hash
|
373
|
+
@@behaviours << {
|
374
|
+
|
375
|
+
:name => name,
|
376
|
+
:requires => root_attributes[ "plugin" ].to_s.split(";"),
|
377
|
+
:object_type => object_type.split(";"),
|
378
|
+
:input_type => input_type.split(";"),
|
379
|
+
#:sut_type => sut_type.split(";"),
|
380
|
+
:version => version.split(";"),
|
381
|
+
:env => env.split(";"),
|
382
|
+
|
383
|
+
:module => {
|
384
|
+
:file => module_file,
|
385
|
+
:name => module_name
|
386
|
+
},
|
387
|
+
|
388
|
+
:methods => methods_hash
|
389
|
+
|
390
|
+
}
|
391
|
+
|
392
|
+
}
|
393
|
+
|
394
|
+
=end
|
331
395
|
|
332
396
|
}
|
333
397
|
|
@@ -413,20 +477,21 @@ module MobyBase
|
|
413
477
|
|
414
478
|
end
|
415
479
|
|
416
|
-
|
417
480
|
def get_behaviour_from_cache( target, sut_type, object_type, sut_version, input_type )
|
418
481
|
|
419
482
|
if @_behaviour_cache.has_key?( object_type )
|
420
483
|
|
421
|
-
|
422
|
-
|
484
|
+
# apply modules to target object
|
485
|
+
@_behaviour_cache[ object_type ].each{ | module_name | target.instance_eval( "self.extend(#{ module_name })" ) }
|
423
486
|
|
424
|
-
|
425
|
-
|
487
|
+
# return true
|
488
|
+
true
|
426
489
|
|
427
490
|
else
|
428
|
-
|
429
|
-
|
491
|
+
|
492
|
+
# return false
|
493
|
+
false
|
494
|
+
|
430
495
|
end
|
431
496
|
|
432
497
|
end
|