testability-driver 1.1.1 → 1.2.1
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.
- 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/lib/tdriver/tdriver.rb
CHANGED
@@ -25,130 +25,174 @@
|
|
25
25
|
#
|
26
26
|
# Please see class documentation for more info
|
27
27
|
|
28
|
-
# initializing
|
28
|
+
# initializing tdriver
|
29
29
|
$TDRIVER_INITIALIZED = false
|
30
30
|
|
31
|
-
# unicode support
|
32
|
-
$KCODE = 'u'
|
31
|
+
# unicode support for 1.8.7
|
32
|
+
$KCODE = 'u' if RUBY_VERSION < "1.9"
|
33
33
|
|
34
34
|
# prevent Object#id Warnings
|
35
35
|
Object.send( :undef_method, :id ) if Object.respond_to?( :id )
|
36
36
|
|
37
|
-
# TODO: document me
|
38
|
-
def require_relative( file )
|
39
|
-
|
40
|
-
# require with full expanded path
|
41
|
-
require File.expand_path( File.join( File.dirname( caller.first.scan( /(.*?):/ ).to_s ), file ) )
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
37
|
# load all required components
|
46
38
|
require File.expand_path( File.join( File.dirname( __FILE__ ), 'loader.rb' ) )
|
47
39
|
|
48
40
|
module TDriver
|
49
41
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
42
|
+
class << self
|
43
|
+
|
44
|
+
# Function to create and (or if already created re-) connect SUT object
|
45
|
+
# === params
|
46
|
+
# hash:: Defines SUT type, identification attributes etc.
|
47
|
+
# :id:: Valid id that can be matched in tdriver_parameters.xml
|
48
|
+
# === raises
|
49
|
+
# ArgumentError:: Wrong argument Type '%s' (Expected Hash)
|
50
|
+
# ArgumentError:: SUT type not defined
|
51
|
+
# ArgumentError:: SUT type '%s' not supported
|
52
|
+
# ArgumentError:: Sut id not given
|
53
|
+
# MobyUtil::ParameterFileNotFoundError:: if paramter file (tdriver_parameters.xml in TDriver home directory) is not found
|
54
|
+
# === returns
|
55
|
+
# Object:: Object that SutFactory returns
|
56
|
+
# === example
|
57
|
+
# @sut = TDriver.connect_sut(:Id =>'sut_qt') # for qt, id in configuration file sut_qt
|
58
|
+
def connect_sut( sut_attributes = {} )
|
59
|
+
|
60
|
+
MobyBase::SUTFactory.instance.make( sut_attributes )
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
# Function to disconnect SUT object.
|
65
|
+
# === params
|
66
|
+
# hash:: Defines SUT type, identification attributes etc.
|
67
|
+
# :id:: Valid id that can be matched in tdriver_parameters.xml and is already connected
|
68
|
+
# === raises
|
69
|
+
# ArgumentError:: Not connected to device 'id' if not connected at all / device already disconnected
|
70
|
+
# ArgumentError:: Sut id not given
|
71
|
+
# === returns
|
72
|
+
# Object:: SUT object
|
73
|
+
# === example
|
74
|
+
# @sut = TDriver.disconnect_sut(:Id =>'sut_qt') # for qt, should be connected already
|
75
|
+
def disconnect_sut( sut_attributes = {} )
|
76
|
+
|
77
|
+
MobyBase::SUTFactory.instance.disconnect_sut( sut_attributes )
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
# Function to reboot SUT object.
|
82
|
+
# === params
|
83
|
+
# hash:: Defines SUT type, identification attributes etc.
|
84
|
+
# :id:: Valid id that can be matched in tdriver_parameters.xml and is already connected
|
85
|
+
# === raises
|
86
|
+
# ArgumentError:: Not connected to device 'id' if not connected at all / device already disconnected
|
87
|
+
# ArgumentError:: Sut id not given
|
88
|
+
# === example
|
89
|
+
# @sut = TDriver.reboot_sut(:Id =>'sut_qt') # for Qt, should be connected already
|
90
|
+
def reboot_sut( sut_attributes = {} )
|
91
|
+
|
92
|
+
MobyBase::SUTFactory.instance.reboot_sut( sut_attributes )
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
# Wrapper for SUT functionality. For documentation, please see TDriver::connect_sut
|
97
|
+
def sut( *args )
|
98
|
+
|
99
|
+
connect_sut( *args )
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
# Wrapper for TDriver::Parameter.configured_suts to retrieve all configured sut names
|
104
|
+
def suts
|
105
|
+
|
106
|
+
$parameters.configured_suts
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
# Wrapper for TDriver::ParameterUserAPI class with methods e.g. [] and []=, files and load_xml etc.
|
111
|
+
def parameter( *arguments )
|
112
|
+
|
113
|
+
if arguments.count == 0
|
114
|
+
|
115
|
+
$parameters_api
|
116
|
+
|
117
|
+
else
|
118
|
+
|
119
|
+
$parameters_api[ *arguments ]
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
# TODO: document me
|
126
|
+
def state_object( options )
|
127
|
+
|
128
|
+
# create state object with given options
|
129
|
+
MobyBase::StateObject.new( options )
|
130
|
+
|
131
|
+
end
|
121
132
|
|
122
|
-
|
123
|
-
|
124
|
-
|
133
|
+
# == nodoc
|
134
|
+
# Wrapper for MobyUtil::Logger class
|
135
|
+
def logger
|
136
|
+
|
137
|
+
$logger
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
# == nodoc
|
142
|
+
# TODO: document me
|
143
|
+
def config_dir
|
144
|
+
|
145
|
+
if ENV['TDRIVER_HOME']
|
146
|
+
|
147
|
+
config_dir = ENV['TDRIVER_HOME']
|
148
|
+
|
149
|
+
elsif MobyUtil::EnvironmentHelper.windows?
|
150
|
+
|
151
|
+
config_dir = "c:/tdriver"
|
152
|
+
|
153
|
+
else
|
154
|
+
|
155
|
+
config_dir = "/etc/tdriver"
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
File.expand_path( config_dir )
|
160
|
+
|
161
|
+
end
|
125
162
|
|
126
|
-
|
163
|
+
# == nodoc
|
164
|
+
# TODO: document me
|
165
|
+
def library_dir
|
166
|
+
|
167
|
+
File.expand_path( File.dirname( __FILE__ ) )
|
127
168
|
|
128
169
|
end
|
170
|
+
|
171
|
+
private
|
129
172
|
|
130
|
-
|
173
|
+
# TODO: document me
|
174
|
+
def initialize_tdriver
|
175
|
+
|
176
|
+
# initialize parameters
|
177
|
+
$parameters.init
|
131
178
|
|
132
|
-
|
133
|
-
|
179
|
+
# enable logging engine
|
180
|
+
$logger.enable_logging
|
134
181
|
|
135
|
-
|
136
|
-
|
137
|
-
end
|
182
|
+
# set xml cache buffer size
|
183
|
+
MobyUtil::XML.buffer_size = $parameters[ :xml_cache_buffer_size, 10 ].to_i
|
138
184
|
|
139
|
-
|
140
|
-
|
185
|
+
# initialization done, everything is ready
|
186
|
+
$TDRIVER_INITIALIZED = true
|
141
187
|
|
142
|
-
end
|
188
|
+
end
|
143
189
|
|
144
|
-
|
145
|
-
$parameters.init
|
190
|
+
end
|
146
191
|
|
147
|
-
# enable logging
|
148
|
-
|
192
|
+
# enable hooking for performance measurement & debug logging
|
193
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
149
194
|
|
150
|
-
#
|
151
|
-
|
195
|
+
# initialize TDriver
|
196
|
+
initialize_tdriver
|
152
197
|
|
153
|
-
#
|
154
|
-
$TDRIVER_INITIALIZED = true
|
198
|
+
end # TDriver
|
@@ -0,0 +1,51 @@
|
|
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 TrueClass and FalseClass class functionality
|
21
|
+
class TrueClass
|
22
|
+
|
23
|
+
def true?
|
24
|
+
|
25
|
+
/^true$/i.match( self.to_s ) != nil
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
def false?
|
30
|
+
|
31
|
+
false
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class FalseClass
|
38
|
+
|
39
|
+
def true?
|
40
|
+
|
41
|
+
false
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
def false?
|
46
|
+
|
47
|
+
/^false$/i.match( self.to_s ) != nil
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -17,84 +17,126 @@
|
|
17
17
|
##
|
18
18
|
############################################################################
|
19
19
|
|
20
|
-
module
|
21
|
-
|
22
|
-
class Crc16
|
20
|
+
module TDriver
|
23
21
|
|
24
|
-
|
25
|
-
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
26
|
-
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
27
|
-
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
28
|
-
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
29
|
-
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
30
|
-
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
31
|
-
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
32
|
-
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
33
|
-
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
34
|
-
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
35
|
-
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
36
|
-
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
37
|
-
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
38
|
-
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
39
|
-
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
40
|
-
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
41
|
-
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
42
|
-
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
43
|
-
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
44
|
-
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
45
|
-
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
46
|
-
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
47
|
-
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
48
|
-
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
49
|
-
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
50
|
-
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
51
|
-
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
52
|
-
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
53
|
-
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
54
|
-
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
55
|
-
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
56
|
-
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
|
57
|
-
]
|
58
|
-
|
59
|
-
@@IBM_16 = [
|
60
|
-
0x0000, 0x1081, 0x2102, 0x3183,
|
61
|
-
0x4204, 0x5285, 0x6306, 0x7387,
|
62
|
-
0x8408, 0x9489, 0xa50a, 0xb58b,
|
63
|
-
0xc60c, 0xd68d, 0xe70e, 0xf78f
|
64
|
-
]
|
65
|
-
|
66
|
-
def self.crc16( buf, crc = 0 )
|
67
|
-
buf.each_byte{ | x | crc = ( ( crc << 8 ) ^ @@CCITT_16[ ( crc >> 8 ) ^ x ] ) & 0xffff }
|
68
|
-
crc
|
69
|
-
end
|
22
|
+
class Checksum
|
70
23
|
|
71
|
-
|
72
|
-
if defined?( TDriver::NativeExtensions )
|
24
|
+
class << self
|
73
25
|
|
74
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
def initialize_class
|
29
|
+
|
30
|
+
@CCITT_16 = [
|
31
|
+
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
|
32
|
+
0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
|
33
|
+
0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
|
34
|
+
0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
|
35
|
+
0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
|
36
|
+
0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
|
37
|
+
0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
|
38
|
+
0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
|
39
|
+
0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
|
40
|
+
0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
|
41
|
+
0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
|
42
|
+
0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
|
43
|
+
0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
|
44
|
+
0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
|
45
|
+
0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
|
46
|
+
0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
|
47
|
+
0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
|
48
|
+
0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
|
49
|
+
0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
|
50
|
+
0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
|
51
|
+
0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
|
52
|
+
0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
|
53
|
+
0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
|
54
|
+
0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
|
55
|
+
0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
|
56
|
+
0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
|
57
|
+
0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
|
58
|
+
0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
|
59
|
+
0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
|
60
|
+
0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
|
61
|
+
0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
|
62
|
+
0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
|
63
|
+
]
|
75
64
|
|
76
|
-
|
65
|
+
@IBM_16 = [
|
66
|
+
0x0000, 0x1081, 0x2102, 0x3183,
|
67
|
+
0x4204, 0x5285, 0x6306, 0x7387,
|
68
|
+
0x8408, 0x9489, 0xa50a, 0xb58b,
|
69
|
+
0xc60c, 0xd68d, 0xe70e, 0xf78f
|
70
|
+
]
|
77
71
|
|
78
72
|
end
|
79
73
|
|
80
|
-
|
81
|
-
|
82
|
-
#
|
83
|
-
def
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
74
|
+
public
|
75
|
+
|
76
|
+
# CRC-16-CCITT
|
77
|
+
def crc16( buf, crc = 0 )
|
78
|
+
|
79
|
+
# calculate the checksum
|
80
|
+
buf.each_byte{ | x | crc = ( ( crc << 8 ) ^ @CCITT_16[ ( crc >> 8 ) ^ x ] ) & 0xffff }
|
81
|
+
|
82
|
+
# result
|
83
|
+
crc
|
84
|
+
|
85
|
+
end # crc16
|
86
|
+
|
87
|
+
# check if implementation is already loaded from TDriver native Ruby C Extension; native crc routines are ~10% faster
|
88
|
+
unless instance_methods.include?( 'crc16_ibm' )
|
89
|
+
|
90
|
+
# IBM-CRC-16: fallback when native extensions are not supported (e.g. jruby)
|
91
|
+
def crc16_ibm( buf, crc = 0xffff )
|
92
|
+
|
93
|
+
buf.each_byte do | c |
|
94
|
+
|
95
|
+
crc = ( ( crc >> 4 ) & 0x0fff ) ^ @IBM_16[ ( ( crc ^ c ) & 15 ) ]
|
96
|
+
|
97
|
+
crc = ( ( crc >> 4 ) & 0x0fff ) ^ @IBM_16[ ( ( crc ^ ( c >> 4 ) ) & 15 ) ]
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
# result
|
102
|
+
~crc & 0xffff
|
103
|
+
|
104
|
+
end # crc16_ibm
|
105
|
+
|
106
|
+
end # unless
|
107
|
+
|
108
|
+
end # self
|
109
|
+
|
110
|
+
# enable hooking for performance measurement & debug logging
|
111
|
+
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
112
|
+
|
113
|
+
# initialize the class
|
114
|
+
initialize_class
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
# deprecated
|
121
|
+
module CRC
|
122
|
+
|
123
|
+
class Crc16
|
124
|
+
|
125
|
+
class << self
|
126
|
+
|
127
|
+
def method_missing( id, *args )
|
128
|
+
|
129
|
+
#warn_caller "$1:$2 warning: deprecated method, use TDriver::Checksum##{ id.to_s } instead of CRC::Crc16##{ id.to_s }"
|
130
|
+
|
131
|
+
TDriver::Checksum.__send__( id, *args )
|
132
|
+
|
91
133
|
end
|
92
134
|
|
93
135
|
end
|
94
136
|
|
95
137
|
# enable hooking for performance measurement & debug logging
|
96
138
|
TDriver::Hooking.hook_methods( self ) if defined?( TDriver::Hooking )
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|