1 #include "ace/Log_Msg.h"
2 #include "ace/High_Res_Timer.h"
3 #include "ace/Compression/rle/RLECompressor.h"
6 #include "tao/objectid.h"
7 #include "tao/Compression/Compression.h"
8 #include "tao/Compression/rle/RLECompressor_Factory.h"
12 // Older versions of GCC do not support std::unique_ptr!
13 struct ACE_Byte_Array_ptr
: std::auto_ptr
<ACE_Byte
> {
14 explicit ACE_Byte_Array_ptr(ACE_Byte
*_Ptr
= 0)
15 : std::auto_ptr
<ACE_Byte
>(_Ptr
) {}
16 ~ACE_Byte_Array_ptr(void) {
17 delete [] (this->release());
21 /* This test produces the following output (RLECompressor)
23 ******** TEST RLE Compressor ************
25 ****---> TEST256 (Compress/Expand Data)
26 Original (test256) Buffer - HEXDUMP 256 bytes
27 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 0..............0
28 00 31 00 00 00 00 00 00 00 00 00 00 00 00 31 00 .1............1.
29 00 00 32 00 00 00 00 00 00 00 00 00 00 32 00 00 ..2..........2..
30 00 00 00 33 00 00 00 00 00 00 00 00 33 00 00 00 ...3........3...
31 00 00 00 00 34 00 00 00 00 00 00 34 00 00 00 00 ....4......4....
32 00 00 00 00 00 35 00 00 00 00 35 00 00 00 00 00 .....5....5.....
33 00 00 00 00 00 00 36 00 00 36 00 00 00 00 00 00 ......6..6......
34 00 00 00 00 00 00 00 37 37 00 00 00 00 00 00 00 .......77.......
35 00 00 00 00 00 00 00 38 38 00 00 00 00 00 00 00 .......88.......
36 00 00 00 00 00 00 39 00 00 39 00 00 00 00 00 00 ......9..9......
37 00 00 00 00 00 41 00 00 00 00 41 00 00 00 00 00 .....A....A.....
38 00 00 00 00 42 00 00 00 00 00 00 42 00 00 00 00 ....B......B....
39 00 00 00 43 00 00 00 00 00 00 00 00 43 00 00 00 ...C........C...
40 00 00 44 00 00 00 00 00 00 00 00 00 00 44 00 00 ..D..........D..
41 00 45 00 00 00 00 00 00 00 00 00 00 00 00 45 00 .E............E.
42 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 F..............F
43 Compress Time - total 0.000071 secs
44 Compressed Buffer - HEXDUMP 114 bytes
45 00 30 8d 00 02 30 00 31 8b 00 00 31 82 00 00 32 .0...0.1...1...2
46 89 00 00 32 84 00 00 33 87 00 00 33 86 00 00 34 ...2...3...3...4
47 85 00 00 34 88 00 00 35 83 00 00 35 8a 00 00 36 ...4...5...5...6
48 81 00 00 36 8c 00 81 37 8d 00 81 38 8c 00 00 39 ...6...7...8...9
49 81 00 00 39 8a 00 00 41 83 00 00 41 88 00 00 42 ...9...A...A...B
50 85 00 00 42 86 00 00 43 87 00 00 43 84 00 00 44 ...B...C...C...D
51 89 00 00 44 82 00 00 45 8b 00 02 45 00 46 8d 00 ...D...E...E.F..
53 DeCompress Time - total 0.000006 secs
54 ****---> END TEST256 - OK!
56 ****---> TESTArray (Compress/Expand on Progressive Boundaries)
57 Compression Data - HEXDUMP 16 bytes
58 41 42 42 43 43 43 44 44 45 46 47 48 49 4a 4a 4a ABBCCCDDEFGHIJJJ
66 00 41 81 42 00 43 .A.B.C
68 00 41 81 42 81 43 .A.B.C
70 00 41 81 42 82 43 .A.B.C
72 00 41 81 42 82 43 00 44 .A.B.C.D
74 00 41 81 42 82 43 81 44 .A.B.C.D
76 00 41 81 42 82 43 81 44 00 45 .A.B.C.D.E
78 00 41 81 42 82 43 81 44 01 45 46 .A.B.C.D.EF
80 00 41 81 42 82 43 81 44 02 45 46 47 .A.B.C.D.EFG
82 00 41 81 42 82 43 81 44 03 45 46 47 48 .A.B.C.D.EFGH
84 00 41 81 42 82 43 81 44 04 45 46 47 48 49 .A.B.C.D.EFGHI
86 00 41 81 42 82 43 81 44 05 45 46 47 48 49 4a .A.B.C.D.EFGHIJ
88 00 41 81 42 82 43 81 44 04 45 46 47 48 49 81 4a .A.B.C.D.EFGHI.J
90 00 41 81 42 82 43 81 44 04 45 46 47 48 49 82 4a .A.B.C.D.EFGHI.J
91 ****---> END TESTArray - OK!
93 ****---> TEST128 (Compress Boundary)
94 Original (test128) Buffer - HEXDUMP 128 bytes
95 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
96 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
97 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
98 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
99 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
101 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
102 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
103 Compress Time - total 0.000019 secs
104 Compressed (test128) Buffer - HEXDUMP 2 bytes
106 DeCompress Time - total 0.000004 secs
107 ****---> END TEST128 - OK!
109 ****---> TEST129A (Compress Boundary Extended)
110 Original (test129A) Buffer - HEXDUMP 129 bytes
111 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
112 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
113 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
114 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
115 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
116 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
117 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
118 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
120 Compress Time - total 0.000010 secs
121 Compressed (test129A) Buffer - HEXDUMP 4 bytes
123 DeCompress Time - total 0.000004 secs
124 ****---> END TEST129A - OK!
126 ****---> TEST129B (Compress Boundary NonExtend)
127 Original (test129B) Buffer - HEXDUMP 129 bytes
128 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
129 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
131 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
132 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
133 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
134 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
135 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
137 Compress Time - total 0.000030 secs
138 Compressed (test129B) Buffer - HEXDUMP 4 bytes
140 DeCompress Time - total 0.000005 secs
141 ****---> END TEST129B - OK!
143 ********* END TEST RLE ************
144 ACE::RLECompression Ratio = 0.352185 : 1
145 TAO::RLECompression Ratio = 0.352185 : 1
149 // constants for Test256
150 const ACE_Byte test256_array
[] = {
151 '0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0',
152 0,'1',0,0,0,0,0,0,0,0,0,0,0,0,'1',0,
153 0,0,'2',0,0,0,0,0,0,0,0,0,0,'2',0,0,
154 0,0,0,'3',0,0,0,0,0,0,0,0,'3',0,0,0,
155 0,0,0,0,'4',0,0,0,0,0,0,'4',0,0,0,0,
156 0,0,0,0,0,'5',0,0,0,0,'5',0,0,0,0,0,
157 0,0,0,0,0,0,'6',0,0,'6',0,0,0,0,0,0,
158 0,0,0,0,0,0,0,'7','7',0,0,0,0,0,0,0,
159 0,0,0,0,0,0,0,'8','8',0,0,0,0,0,0,0,
160 0,0,0,0,0,0,'9',0,0,'9',0,0,0,0,0,0,
161 0,0,0,0,0,'A',0,0,0,0,'A',0,0,0,0,0,
162 0,0,0,0,'B',0,0,0,0,0,0,'B',0,0,0,0,
163 0,0,0,'C',0,0,0,0,0,0,0,0,'C',0,0,0,
164 0,0,'D',0,0,0,0,0,0,0,0,0,0,'D',0,0,
165 0,'E',0,0,0,0,0,0,0,0,0,0,0,0,'E',0,
166 'F',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'F'
168 const size_t BUFF_256_SIZE
= sizeof(test256_array
);
170 // constants for Test128
171 const size_t BUFF_128_SIZE
= 128U;
172 const ACE_Byte comp_128_out
[] = {0xFF, 0x00};
173 // constants for Test129
174 const size_t BUFF_129_SIZE
= 129U;
175 const ACE_Byte comp_129B_char
= 'x';
176 const ACE_Byte comp_129A_out
[] = {0xFF, 0x00, 0x00, 0x00};
177 const ACE_Byte comp_129B_out
[] = {0xFF, 0x00, 0x00, comp_129B_char
};
179 struct HRTimer
: ACE_High_Res_Timer
181 const ACE_TCHAR
* msg_
;
182 HRTimer(const ACE_TCHAR
* msg
) : msg_(msg
) {
183 this->reset(); this->start();
186 this->stop(); this->print_ave(this->msg_
, 1);
190 static int init_compressor(::CORBA::ORB_ptr orb
)
194 ::CORBA::Object_var compression_manager
=
195 orb
->resolve_initial_references(TAO_OBJID_COMPRESSIONMANAGER
);
197 ::Compression::CompressionManager_var manager
=
198 ::Compression::CompressionManager::_narrow(compression_manager
.in());
200 if (::CORBA::is_nil(manager
.in())) {
201 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: nil compression manager.\n")),-1);
204 Compression::CompressorFactory_ptr compressor_factory
;
205 ACE_NEW_RETURN (compressor_factory
, TAO::RLE_CompressorFactory (), 1);
206 Compression::CompressorFactory_var compr_fact
= compressor_factory
;
208 manager
->register_factory (compr_fact
.in ());
211 ACE_ERROR_RETURN((LM_ERROR
,
212 ACE_TEXT("ERROR: Unable to initialise RLE compressor manager.\n")),-1);
218 static int test256_compressor(const ::Compression::Compressor_var
&compressor
)
220 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n****---> TEST256 (Compress/Expand Data)\n")));
222 if (::CORBA::is_nil(compressor
.in())) {
223 ACE_ERROR_RETURN((LM_ERROR
,
224 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
227 ACE_HEX_DUMP(( LM_INFO
,
228 reinterpret_cast<const char*>(test256_array
),
230 ACE_TEXT("Original (test256) Buffer")
233 ::CORBA::ULong in_len
= static_cast< CORBA::ULong
>(sizeof(test256_array
));
234 const ::CORBA::Octet
* in_buf
= reinterpret_cast<const CORBA::Octet
*>(test256_array
);
236 ::Compression::Buffer
in_data(in_len
, in_len
, const_cast<CORBA::Octet
*>(in_buf
), false);
238 ::Compression::Buffer comp_out
;
240 comp_out
.length(static_cast< ::CORBA::ULong
>(in_len
* 1.1));
243 HRTimer
_hrt(ACE_TEXT("Compress Time - "));
244 compressor
->compress(in_data
, comp_out
);
247 ACE_HEX_DUMP(( LM_INFO
,
248 reinterpret_cast<const char*>(comp_out
.get_buffer()),
250 ACE_TEXT("Compressed Buffer")
253 ::Compression::Buffer decomp_out
; decomp_out
.length(in_len
);
256 HRTimer
_hrt(ACE_TEXT("DeCompress Time - "));
257 compressor
->decompress(comp_out
, decomp_out
);
260 // Make sure we got back the original OK.
261 if (ACE_OS::memcmp( in_data
.get_buffer(), decomp_out
.get_buffer(), in_data
.length()))
263 ACE_ERROR_RETURN((LM_ERROR
,
264 ACE_TEXT("ERROR: Did not Compress/Decompress (test256) correctly.\n")),-1);
267 ACE_ERROR_RETURN((LM_INFO
, ACE_TEXT("****---> END TEST256 - OK!\n")), 0);
270 static int testArray_compressor(const ::Compression::Compressor_var
&compressor
)
272 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n****---> TESTArray (Compress/Expand on Progressive Boundaries)\n")));
274 if (::CORBA::is_nil(compressor
.in())) {
275 ACE_ERROR_RETURN((LM_ERROR
,
276 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
280 Compression::Buffer out
; // We compress to this buffer
281 int len
; // We expect this compressed Length
282 ACE_Byte hex
[16]; // We expect this compressed Data
284 /*00*/ { 0, 0, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
285 /*01*/ { 2, 2, {0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A"
286 /*02*/ { 3, 3, {0x01,0x41,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".AB"
287 /*03*/ { 4, 4, {0x00,0x41,0x81,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B"
288 /*04*/ { 6, 6, {0x00,0x41,0x81,0x42,0x00,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C"
289 /*05*/ { 6, 6, {0x00,0x41,0x81,0x42,0x81,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C"
290 /*06*/ { 6, 6, {0x00,0x41,0x81,0x42,0x82,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C"
291 /*07*/ { 8, 8, {0x00,0x41,0x81,0x42,0x82,0x43,0x00,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D"
292 /*08*/ { 8, 8, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D"
293 /*09*/ {10,10, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x00,0x45,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D.E"
294 /*10*/ {11,11, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x01,0x45,0x46,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D.EF"
295 /*11*/ {12,12, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x02,0x45,0x46,0x47,0x00,0x00,0x00,0x00}}, //".A.B.C.D.EFG"
296 /*12*/ {13,13, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x03,0x45,0x46,0x47,0x48,0x00,0x00,0x00}}, //".A.B.C.D.EFGH"
297 /*13*/ {14,14, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x04,0x45,0x46,0x47,0x48,0x49,0x00,0x00}}, //".A.B.C.D.EFGHI"
298 /*14*/ {15,15, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x05,0x45,0x46,0x47,0x48,0x49,0x4A,0x00}}, //".A.B.C.D.EFGHIJ"
299 /*15*/ {16,16, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x04,0x45,0x46,0x47,0x48,0x49,0x81,0x4A}}, //".A.B.C.D.EFGHI.J"
300 /*16*/ {16,16, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x04,0x45,0x46,0x47,0x48,0x49,0x82,0x4A}}, //".A.B.C.D.EFGHI.J"
303 char comp_data
[] = "ABBCCCDDEFGHIJJJ"; // Test String with compressor run switching
305 ACE_HEX_DUMP((LM_INFO
, comp_data
, (sizeof(comp_data
) - 1), ACE_TEXT("Compression Data")));
307 for (unsigned i
= 0; i
< sizeof(comp_data
); i
++) {
309 COMP_RESULT
&result
= comp_result
[i
]; // Get A reference to our result for testing output
311 Compression::Buffer
in_data(i
, i
, reinterpret_cast<CORBA::Octet
*>(comp_data
), false), &out_data
= result
.out
;
313 compressor
->compress(in_data
, out_data
);
315 const char *out_ptr
= reinterpret_cast<const char*>(out_data
.get_buffer());
316 int out_len
= int(out_data
.length());
318 if (out_len
> 0) { // We expect out_len == 0 when i == 0.
319 ACE_HEX_DUMP((LM_INFO
, out_ptr
, out_len
, 0)); // Show the hex output
320 } else if (out_len
== result
.len
) { // Hopefully We expected out_len == 0
321 continue; // If So then just continue (nothing to check)
324 // Now Make sure all is good and we can also expand back to what we had
325 if (out_len
== result
.len
) { // Expected result length?
326 if (ACE_OS::memcmp(out_ptr
, result
.hex
, out_len
) == 0) { // Make sure its what we expected
327 Compression::Buffer
out_buf(i
); // Set maximum out space (exactly -> Ignored by TAO)
328 compressor
->decompress(out_data
, out_buf
);
329 if (out_buf
.length() == i
) { // Make sure we got our length back
330 if (ACE_OS::memcmp(comp_data
, out_buf
.get_buffer(), i
) == 0) {
331 continue; // It is what we expected.
337 ACE_ERROR_RETURN((LM_INFO
, ACE_TEXT("****---> END TESTArray - TestLoop %d ERROR!\n"),i
), -1);
340 ACE_ERROR_RETURN((LM_INFO
, ACE_TEXT("****---> END TESTArray - OK!\n")), 0);
343 static int test128_compressor(const ::Compression::Compressor_var
&compressor
)
345 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n****---> TEST128 (Compress Boundary)\n")));
347 if (::CORBA::is_nil(compressor
.in())) {
348 ACE_ERROR_RETURN((LM_ERROR
,
349 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
352 ACE_Byte_Array_ptr
buff_128(new ACE_Byte
[BUFF_128_SIZE
]);
354 ACE_OS::memset(buff_128
.get(), 0, BUFF_128_SIZE
); // Set Buffer to zero.
356 ACE_HEX_DUMP(( LM_INFO
,
357 reinterpret_cast<const char*>(buff_128
.get()),
359 ACE_TEXT("Original (test128) Buffer")
362 ::CORBA::ULong in_len
= static_cast< CORBA::ULong
>(BUFF_128_SIZE
);
363 ::CORBA::Octet
* in_buf
= reinterpret_cast<CORBA::Octet
*>(buff_128
.get());
365 ::Compression::Buffer
in_data(in_len
, in_len
, in_buf
, false);
367 ::Compression::Buffer comp_out
;
369 comp_out
.length(static_cast< ::CORBA::ULong
>(sizeof(comp_128_out
))); // SHould Compress to 2
372 HRTimer
_hrt(ACE_TEXT("Compress Time - "));
373 compressor
->compress(in_data
, comp_out
);
376 ACE_HEX_DUMP(( LM_INFO
,
377 reinterpret_cast<const char*>(comp_out
.get_buffer()),
379 ACE_TEXT("Compressed (test128) Buffer")
382 if (comp_out
.length() != sizeof(comp_128_out
) // Size must equal
383 || ACE_OS::memcmp(comp_out
.get_buffer(), comp_128_out
, comp_out
.length()))
385 ACE_ERROR_RETURN((LM_ERROR
,
386 ACE_TEXT("ERROR: Did not Compress/Decompress (test128) correctly.\n")),-1);
389 ::Compression::Buffer decomp_out
; decomp_out
.length(in_len
);
392 HRTimer
_hrt(ACE_TEXT("DeCompress Time - "));
393 compressor
->decompress(comp_out
, decomp_out
);
396 // Make sure we got back the original OK.
397 if (ACE_OS::memcmp( in_data
.get_buffer(), decomp_out
.get_buffer(), in_data
.length()))
399 ACE_ERROR_RETURN((LM_ERROR
,
400 ACE_TEXT("ERROR: Did not Compress/Decompress (test128) correctly.\n")),-1);
403 ACE_ERROR_RETURN((LM_INFO
, ACE_TEXT("****---> END TEST128 - OK!\n")), 0);
406 static int test129A_compressor(const ::Compression::Compressor_var
&compressor
)
408 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n****---> TEST129A (Compress Boundary Extended)\n")));
410 if (::CORBA::is_nil(compressor
.in())) {
411 ACE_ERROR_RETURN((LM_ERROR
,
412 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
415 const ACE_Byte_Array_ptr
buff_129(new ACE_Byte
[BUFF_129_SIZE
]);
417 ACE_OS::memset(buff_129
.get(), 0, BUFF_129_SIZE
); // Set Buffer to zero.
419 ACE_HEX_DUMP(( LM_INFO
,
420 reinterpret_cast<const char*>(buff_129
.get()),
422 ACE_TEXT("Original (test129A) Buffer")
425 ::CORBA::ULong in_len
= static_cast< CORBA::ULong
>(BUFF_129_SIZE
);
426 ::CORBA::Octet
* in_buf
= reinterpret_cast< CORBA::Octet
*>(buff_129
.get());
428 ::Compression::Buffer
in_data(in_len
, in_len
, in_buf
, false);
430 ::Compression::Buffer comp_out
;
432 comp_out
.length(static_cast< ::CORBA::ULong
>(sizeof(comp_129A_out
)));
435 HRTimer
_hrt(ACE_TEXT("Compress Time - "));
436 compressor
->compress(in_data
, comp_out
);
439 ACE_HEX_DUMP(( LM_INFO
,
440 reinterpret_cast<const char*>(comp_out
.get_buffer()),
442 ACE_TEXT("Compressed (test129A) Buffer")
445 if (comp_out
.length() != sizeof(comp_129A_out
) // Size must equal
446 || ACE_OS::memcmp(comp_out
.get_buffer(), comp_129A_out
, comp_out
.length()))
448 ACE_ERROR_RETURN((LM_ERROR
,
449 ACE_TEXT("ERROR: Did not Compress/Decompress (test129A) correctly.\n")),-1);
452 ::Compression::Buffer decomp_out
; decomp_out
.length(BUFF_129_SIZE
);
455 HRTimer
_hrt(ACE_TEXT("DeCompress Time - "));
456 compressor
->decompress(comp_out
, decomp_out
);
459 // Make sure we got back the original OK.
460 if (ACE_OS::memcmp( in_data
.get_buffer(), decomp_out
.get_buffer(), in_data
.length()))
462 ACE_ERROR_RETURN((LM_ERROR
,
463 ACE_TEXT("ERROR: Did not Compress/Decompress (test129A) correctly.\n")),-1);
466 ACE_ERROR_RETURN((LM_INFO
, ACE_TEXT("****---> END TEST129A - OK!\n")), 0);
469 static int test129B_compressor(const ::Compression::Compressor_var
&compressor
)
471 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n****---> TEST129B (Compress Boundary NonExtend)\n")));
473 if (::CORBA::is_nil(compressor
.in())) {
474 ACE_ERROR_RETURN((LM_ERROR
,
475 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
478 const ACE_Byte_Array_ptr
buff_129(new ACE_Byte
[BUFF_129_SIZE
]);
480 ACE_OS::memset(buff_129
.get(), 0, BUFF_129_SIZE
); // Set Buffer to zero.
482 buff_129
.get()[128] = comp_129B_char
; // Add a non Repeat Character
484 ACE_HEX_DUMP(( LM_INFO
,
485 reinterpret_cast<const char*>(buff_129
.get()),
487 ACE_TEXT("Original (test129B) Buffer")
490 ::CORBA::ULong in_len
= static_cast< CORBA::ULong
>(BUFF_129_SIZE
);
491 ::CORBA::Octet
* in_buf
= reinterpret_cast< CORBA::Octet
*>(buff_129
.get());
493 ::Compression::Buffer
in_data(in_len
, in_len
, in_buf
, false);
495 ::Compression::Buffer comp_out
;
497 comp_out
.length(static_cast< ::CORBA::ULong
>(sizeof(comp_129B_out
)));
500 HRTimer
_hrt(ACE_TEXT("Compress Time - "));
501 compressor
->compress(in_data
, comp_out
);
504 ACE_HEX_DUMP(( LM_INFO
,
505 reinterpret_cast<const char*>(comp_out
.get_buffer()),
507 ACE_TEXT("Compressed (test129B) Buffer")
510 if (comp_out
.length() != sizeof(comp_129B_out
) // Size must equal
511 || ACE_OS::memcmp(comp_out
.get_buffer(), comp_129B_out
, comp_out
.length()))
513 ACE_ERROR_RETURN((LM_ERROR
,
514 ACE_TEXT("ERROR: Did not Compress/Decompress (test129B) correctly.\n")),-1);
517 ::Compression::Buffer decomp_out
; decomp_out
.length(BUFF_129_SIZE
);
520 HRTimer
_hrt(ACE_TEXT("DeCompress Time - "));
521 compressor
->decompress(comp_out
, decomp_out
);
524 // Make sure we got back the original OK.
525 if (ACE_OS::memcmp( in_data
.get_buffer(), decomp_out
.get_buffer(), in_data
.length()))
527 ACE_ERROR_RETURN((LM_ERROR
,
528 ACE_TEXT("ERROR: Did not Compress/Decompress (test129B) correctly.\n")),-1);
531 ACE_ERROR_RETURN((LM_INFO
, ACE_TEXT("****---> END TEST129B - OK!\n")), 0);
535 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
539 ::CORBA::ORB_var orb
= ::CORBA::ORB_init(argc
, argv
);
541 if (init_compressor(orb
.in ()) != 0) {
542 ACE_ERROR_RETURN((LM_ERROR
,
543 ACE_TEXT("ERROR: Unable to initialise RLE compressor.\n")),-1);
546 ::CORBA::Object_var compression_manager
=
547 orb
->resolve_initial_references(TAO_OBJID_COMPRESSIONMANAGER
);
549 ::Compression::CompressionManager_var manager
=
550 ::Compression::CompressionManager::_narrow(compression_manager
.in());
552 if (::CORBA::is_nil(manager
.in())) {
553 ACE_ERROR_RETURN((LM_ERROR
,
554 ACE_TEXT("ERROR: nil compression manager.\n")),-1);
557 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n******** TEST RLE Compressor ************\n")));
559 ::Compression::Compressor_var rleCompressor
= manager
->get_compressor(::Compression::COMPRESSORID_RLE
, 0);
561 if (::CORBA::is_nil(rleCompressor
.in())) {
562 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: Unable to locate TAO::RLECompressor - exiting.\n")),-1);
563 } else if (test256_compressor(rleCompressor
) == -1) {
564 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test256) - exiting.\n")),-1);
565 } else if (testArray_compressor(rleCompressor
) == -1) {
566 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (testArray) - exiting.\n")),-1);
567 } else if (test128_compressor(rleCompressor
) == -1) {
568 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test128) - exiting.\n")),-1);
569 } else if (test129A_compressor(rleCompressor
) == -1) {
570 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test129A) - exiting.\n")),-1);
571 } else if (test129B_compressor(rleCompressor
) == -1) {
572 ACE_ERROR_RETURN((LM_ERROR
, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test129B) - exiting.\n")),-1);
575 ACE_DEBUG((LM_INFO
, ACE_TEXT("\n********* END TEST RLE ************\n")));
577 float ace_ratio
= ACE_RLECompression::instance()->compression_ratio();
578 ACE_DEBUG((LM_INFO
, ACE_TEXT("ACE::RLECompression Ratio = %f : 1\n"), ace_ratio
));
579 float tao_ratio
= rleCompressor
->compression_ratio();
580 ACE_DEBUG((LM_INFO
, ACE_TEXT("TAO::RLECompression Ratio = %f : 1\n"), tao_ratio
));
584 } catch (const CORBA::Exception
& ex
) {
585 ex
._tao_print_exception ("RLECompressorTest: UNEXPECTED exception - ");