Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Compression / RLECompressorTest.cpp
blob5cd3756b4dded6a4e60097c867502a550a2675e0
1 #include "ace/Log_Msg.h"
2 #include "ace/High_Res_Timer.h"
3 #include "ace/Compression/rle/RLECompressor.h"
5 #include "tao/ORB.h"
6 #include "tao/objectid.h"
7 #include "tao/Compression/Compression.h"
8 #include "tao/Compression/rle/RLECompressor_Factory.h"
10 #include <memory>
12 /* This test produces the following output (RLECompressor)
14 ******** TEST RLE Compressor ************
16 ****---> TEST256 (Compress/Expand Data)
17 Original (test256) Buffer - HEXDUMP 256 bytes
18 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 30 0..............0
19 00 31 00 00 00 00 00 00 00 00 00 00 00 00 31 00 .1............1.
20 00 00 32 00 00 00 00 00 00 00 00 00 00 32 00 00 ..2..........2..
21 00 00 00 33 00 00 00 00 00 00 00 00 33 00 00 00 ...3........3...
22 00 00 00 00 34 00 00 00 00 00 00 34 00 00 00 00 ....4......4....
23 00 00 00 00 00 35 00 00 00 00 35 00 00 00 00 00 .....5....5.....
24 00 00 00 00 00 00 36 00 00 36 00 00 00 00 00 00 ......6..6......
25 00 00 00 00 00 00 00 37 37 00 00 00 00 00 00 00 .......77.......
26 00 00 00 00 00 00 00 38 38 00 00 00 00 00 00 00 .......88.......
27 00 00 00 00 00 00 39 00 00 39 00 00 00 00 00 00 ......9..9......
28 00 00 00 00 00 41 00 00 00 00 41 00 00 00 00 00 .....A....A.....
29 00 00 00 00 42 00 00 00 00 00 00 42 00 00 00 00 ....B......B....
30 00 00 00 43 00 00 00 00 00 00 00 00 43 00 00 00 ...C........C...
31 00 00 44 00 00 00 00 00 00 00 00 00 00 44 00 00 ..D..........D..
32 00 45 00 00 00 00 00 00 00 00 00 00 00 00 45 00 .E............E.
33 46 00 00 00 00 00 00 00 00 00 00 00 00 00 00 46 F..............F
34 Compress Time - total 0.000071 secs
35 Compressed Buffer - HEXDUMP 114 bytes
36 00 30 8d 00 02 30 00 31 8b 00 00 31 82 00 00 32 .0...0.1...1...2
37 89 00 00 32 84 00 00 33 87 00 00 33 86 00 00 34 ...2...3...3...4
38 85 00 00 34 88 00 00 35 83 00 00 35 8a 00 00 36 ...4...5...5...6
39 81 00 00 36 8c 00 81 37 8d 00 81 38 8c 00 00 39 ...6...7...8...9
40 81 00 00 39 8a 00 00 41 83 00 00 41 88 00 00 42 ...9...A...A...B
41 85 00 00 42 86 00 00 43 87 00 00 43 84 00 00 44 ...B...C...C...D
42 89 00 00 44 82 00 00 45 8b 00 02 45 00 46 8d 00 ...D...E...E.F..
43 00 46 .F
44 DeCompress Time - total 0.000006 secs
45 ****---> END TEST256 - OK!
47 ****---> TESTArray (Compress/Expand on Progressive Boundaries)
48 Compression Data - HEXDUMP 16 bytes
49 41 42 42 43 43 43 44 44 45 46 47 48 49 4a 4a 4a ABBCCCDDEFGHIJJJ
50 HEXDUMP 2 bytes
51 00 41 .A
52 HEXDUMP 3 bytes
53 01 41 42 .AB
54 HEXDUMP 4 bytes
55 00 41 81 42 .A.B
56 HEXDUMP 6 bytes
57 00 41 81 42 00 43 .A.B.C
58 HEXDUMP 6 bytes
59 00 41 81 42 81 43 .A.B.C
60 HEXDUMP 6 bytes
61 00 41 81 42 82 43 .A.B.C
62 HEXDUMP 8 bytes
63 00 41 81 42 82 43 00 44 .A.B.C.D
64 HEXDUMP 8 bytes
65 00 41 81 42 82 43 81 44 .A.B.C.D
66 HEXDUMP 10 bytes
67 00 41 81 42 82 43 81 44 00 45 .A.B.C.D.E
68 HEXDUMP 11 bytes
69 00 41 81 42 82 43 81 44 01 45 46 .A.B.C.D.EF
70 HEXDUMP 12 bytes
71 00 41 81 42 82 43 81 44 02 45 46 47 .A.B.C.D.EFG
72 HEXDUMP 13 bytes
73 00 41 81 42 82 43 81 44 03 45 46 47 48 .A.B.C.D.EFGH
74 HEXDUMP 14 bytes
75 00 41 81 42 82 43 81 44 04 45 46 47 48 49 .A.B.C.D.EFGHI
76 HEXDUMP 15 bytes
77 00 41 81 42 82 43 81 44 05 45 46 47 48 49 4a .A.B.C.D.EFGHIJ
78 HEXDUMP 16 bytes
79 00 41 81 42 82 43 81 44 04 45 46 47 48 49 81 4a .A.B.C.D.EFGHI.J
80 HEXDUMP 16 bytes
81 00 41 81 42 82 43 81 44 04 45 46 47 48 49 82 4a .A.B.C.D.EFGHI.J
82 ****---> END TESTArray - OK!
84 ****---> TEST128 (Compress Boundary)
85 Original (test128) Buffer - HEXDUMP 128 bytes
86 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
87 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
88 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
89 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
90 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
91 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
92 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
93 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
94 Compress Time - total 0.000019 secs
95 Compressed (test128) Buffer - HEXDUMP 2 bytes
96 ff 00 ..
97 DeCompress Time - total 0.000004 secs
98 ****---> END TEST128 - OK!
100 ****---> TEST129A (Compress Boundary Extended)
101 Original (test129A) Buffer - HEXDUMP 129 bytes
102 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
103 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
104 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
105 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
106 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
107 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
108 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
109 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
110 00 .
111 Compress Time - total 0.000010 secs
112 Compressed (test129A) Buffer - HEXDUMP 4 bytes
113 ff 00 00 00 ....
114 DeCompress Time - total 0.000004 secs
115 ****---> END TEST129A - OK!
117 ****---> TEST129B (Compress Boundary NonExtend)
118 Original (test129B) Buffer - HEXDUMP 129 bytes
119 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
121 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
122 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
123 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
124 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
125 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
126 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
127 78 x
128 Compress Time - total 0.000030 secs
129 Compressed (test129B) Buffer - HEXDUMP 4 bytes
130 ff 00 00 78 ...x
131 DeCompress Time - total 0.000005 secs
132 ****---> END TEST129B - OK!
134 ********* END TEST RLE ************
135 ACE::RLECompression Ratio = 0.352185 : 1
136 TAO::RLECompression Ratio = 0.352185 : 1
140 // constants for Test256
141 const ACE_Byte test256_array[] = {
142 '0',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'0',
143 0,'1',0,0,0,0,0,0,0,0,0,0,0,0,'1',0,
144 0,0,'2',0,0,0,0,0,0,0,0,0,0,'2',0,0,
145 0,0,0,'3',0,0,0,0,0,0,0,0,'3',0,0,0,
146 0,0,0,0,'4',0,0,0,0,0,0,'4',0,0,0,0,
147 0,0,0,0,0,'5',0,0,0,0,'5',0,0,0,0,0,
148 0,0,0,0,0,0,'6',0,0,'6',0,0,0,0,0,0,
149 0,0,0,0,0,0,0,'7','7',0,0,0,0,0,0,0,
150 0,0,0,0,0,0,0,'8','8',0,0,0,0,0,0,0,
151 0,0,0,0,0,0,'9',0,0,'9',0,0,0,0,0,0,
152 0,0,0,0,0,'A',0,0,0,0,'A',0,0,0,0,0,
153 0,0,0,0,'B',0,0,0,0,0,0,'B',0,0,0,0,
154 0,0,0,'C',0,0,0,0,0,0,0,0,'C',0,0,0,
155 0,0,'D',0,0,0,0,0,0,0,0,0,0,'D',0,0,
156 0,'E',0,0,0,0,0,0,0,0,0,0,0,0,'E',0,
157 'F',0,0,0,0,0,0,0,0,0,0,0,0,0,0,'F'
159 const size_t BUFF_256_SIZE = sizeof(test256_array);
161 // constants for Test128
162 const size_t BUFF_128_SIZE = 128U;
163 const ACE_Byte comp_128_out[] = {0xFF, 0x00};
164 // constants for Test129
165 const size_t BUFF_129_SIZE = 129U;
166 const ACE_Byte comp_129B_char = 'x';
167 const ACE_Byte comp_129A_out[] = {0xFF, 0x00, 0x00, 0x00};
168 const ACE_Byte comp_129B_out[] = {0xFF, 0x00, 0x00, comp_129B_char};
170 struct HRTimer : ACE_High_Res_Timer
172 const ACE_TCHAR* msg_;
173 HRTimer(const ACE_TCHAR* msg) : msg_(msg) {
174 this->reset(); this->start();
176 ~HRTimer() {
177 this->stop(); this->print_ave(this->msg_, 1);
181 static int init_compressor(::CORBA::ORB_ptr orb)
183 try {
184 ::CORBA::Object_var compression_manager =
185 orb->resolve_initial_references(TAO_OBJID_COMPRESSIONMANAGER);
187 ::Compression::CompressionManager_var manager =
188 ::Compression::CompressionManager::_narrow(compression_manager.in());
190 if (::CORBA::is_nil(manager.in())) {
191 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: nil compression manager.\n")),-1);
194 Compression::CompressorFactory_ptr compressor_factory;
195 ACE_NEW_RETURN (compressor_factory, TAO::RLE_CompressorFactory (), 1);
196 Compression::CompressorFactory_var compr_fact = compressor_factory;
198 manager->register_factory (compr_fact.in ());
199 } catch (...) {
200 ACE_ERROR_RETURN((LM_ERROR,
201 ACE_TEXT("ERROR: Unable to initialise RLE compressor manager.\n")),-1);
204 return 0;
207 static int test256_compressor(const ::Compression::Compressor_var &compressor)
209 ACE_DEBUG((LM_INFO, ACE_TEXT("\n****---> TEST256 (Compress/Expand Data)\n")));
211 if (::CORBA::is_nil(compressor.in())) {
212 ACE_ERROR_RETURN((LM_ERROR,
213 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
216 ACE_HEX_DUMP(( LM_INFO,
217 reinterpret_cast<const char*>(test256_array),
218 BUFF_256_SIZE,
219 ACE_TEXT("Original (test256) Buffer")
222 ::CORBA::ULong in_len = static_cast< CORBA::ULong>(sizeof(test256_array));
223 const ::CORBA::Octet* in_buf = reinterpret_cast<const CORBA::Octet*>(test256_array);
225 ::Compression::Buffer in_data(in_len, in_len, const_cast<CORBA::Octet*>(in_buf), false);
227 ::Compression::Buffer comp_out;
229 comp_out.length(static_cast< ::CORBA::ULong>(in_len * 1.1));
232 HRTimer _hrt(ACE_TEXT("Compress Time - "));
233 compressor->compress(in_data, comp_out);
236 ACE_HEX_DUMP(( LM_INFO,
237 reinterpret_cast<const char*>(comp_out.get_buffer()),
238 comp_out.length(),
239 ACE_TEXT("Compressed Buffer")
242 ::Compression::Buffer decomp_out; decomp_out.length(in_len);
245 HRTimer _hrt(ACE_TEXT("DeCompress Time - "));
246 compressor->decompress(comp_out, decomp_out);
249 // Make sure we got back the original OK.
250 if (ACE_OS::memcmp( in_data.get_buffer(), decomp_out.get_buffer(), in_data.length()))
252 ACE_ERROR_RETURN((LM_ERROR,
253 ACE_TEXT("ERROR: Did not Compress/Decompress (test256) correctly.\n")),-1);
256 ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("****---> END TEST256 - OK!\n")), 0);
259 static int testArray_compressor(const ::Compression::Compressor_var &compressor)
261 ACE_DEBUG((LM_INFO, ACE_TEXT("\n****---> TESTArray (Compress/Expand on Progressive Boundaries)\n")));
263 if (::CORBA::is_nil(compressor.in())) {
264 ACE_ERROR_RETURN((LM_ERROR,
265 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
268 struct COMP_RESULT {
269 Compression::Buffer out; // We compress to this buffer
270 int len; // We expect this compressed Length
271 ACE_Byte hex[16]; // We expect this compressed Data
272 } comp_result[] = {
273 /*00*/ { 0, 0, {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
274 /*01*/ { 2, 2, {0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A"
275 /*02*/ { 3, 3, {0x01,0x41,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".AB"
276 /*03*/ { 4, 4, {0x00,0x41,0x81,0x42,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B"
277 /*04*/ { 6, 6, {0x00,0x41,0x81,0x42,0x00,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C"
278 /*05*/ { 6, 6, {0x00,0x41,0x81,0x42,0x81,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C"
279 /*06*/ { 6, 6, {0x00,0x41,0x81,0x42,0x82,0x43,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C"
280 /*07*/ { 8, 8, {0x00,0x41,0x81,0x42,0x82,0x43,0x00,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D"
281 /*08*/ { 8, 8, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D"
282 /*09*/ {10,10, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x00,0x45,0x00,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D.E"
283 /*10*/ {11,11, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x01,0x45,0x46,0x00,0x00,0x00,0x00,0x00}}, //".A.B.C.D.EF"
284 /*11*/ {12,12, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x02,0x45,0x46,0x47,0x00,0x00,0x00,0x00}}, //".A.B.C.D.EFG"
285 /*12*/ {13,13, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x03,0x45,0x46,0x47,0x48,0x00,0x00,0x00}}, //".A.B.C.D.EFGH"
286 /*13*/ {14,14, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x04,0x45,0x46,0x47,0x48,0x49,0x00,0x00}}, //".A.B.C.D.EFGHI"
287 /*14*/ {15,15, {0x00,0x41,0x81,0x42,0x82,0x43,0x81,0x44,0x05,0x45,0x46,0x47,0x48,0x49,0x4A,0x00}}, //".A.B.C.D.EFGHIJ"
288 /*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"
289 /*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"
292 char comp_data[] = "ABBCCCDDEFGHIJJJ"; // Test String with compressor run switching
294 ACE_HEX_DUMP((LM_INFO, comp_data, (sizeof(comp_data) - 1), ACE_TEXT("Compression Data")));
296 for (unsigned i = 0; i < sizeof(comp_data); i++) {
297 COMP_RESULT &result = comp_result[i]; // Get A reference to our result for testing output
299 Compression::Buffer in_data(i, i, reinterpret_cast<CORBA::Octet*>(comp_data), false), &out_data = result.out;
301 compressor->compress(in_data, out_data);
303 const char *out_ptr = reinterpret_cast<const char*>(out_data.get_buffer());
304 int out_len = int(out_data.length());
306 if (out_len > 0) { // We expect out_len == 0 when i == 0.
307 ACE_HEX_DUMP((LM_INFO, out_ptr, out_len, 0)); // Show the hex output
308 } else if (out_len == result.len) { // Hopefully We expected out_len == 0
309 continue; // If So then just continue (nothing to check)
312 // Now Make sure all is good and we can also expand back to what we had
313 if (out_len == result.len) { // Expected result length?
314 if (ACE_OS::memcmp(out_ptr, result.hex, out_len) == 0) { // Make sure its what we expected
315 Compression::Buffer out_buf(i); // Set maximum out space (exactly -> Ignored by TAO)
316 compressor->decompress(out_data, out_buf);
317 if (out_buf.length() == i) { // Make sure we got our length back
318 if (ACE_OS::memcmp(comp_data, out_buf.get_buffer(), i) == 0) {
319 continue; // It is what we expected.
325 ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("****---> END TESTArray - TestLoop %d ERROR!\n"),i), -1);
328 ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("****---> END TESTArray - OK!\n")), 0);
331 static int test128_compressor(const ::Compression::Compressor_var &compressor)
333 ACE_DEBUG((LM_INFO, ACE_TEXT("\n****---> TEST128 (Compress Boundary)\n")));
335 if (::CORBA::is_nil(compressor.in())) {
336 ACE_ERROR_RETURN((LM_ERROR,
337 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
340 std::unique_ptr<ACE_Byte[]> buff_128(new ACE_Byte[BUFF_128_SIZE]);
342 ACE_OS::memset(buff_128.get(), 0, BUFF_128_SIZE); // Set Buffer to zero.
344 ACE_HEX_DUMP(( LM_INFO,
345 reinterpret_cast<const char*>(buff_128.get()),
346 BUFF_128_SIZE,
347 ACE_TEXT("Original (test128) Buffer")
350 ::CORBA::ULong in_len = static_cast< CORBA::ULong>(BUFF_128_SIZE);
351 ::CORBA::Octet* in_buf = reinterpret_cast<CORBA::Octet*>(buff_128.get());
353 ::Compression::Buffer in_data(in_len, in_len, in_buf, false);
355 ::Compression::Buffer comp_out;
357 comp_out.length(static_cast< ::CORBA::ULong>(sizeof(comp_128_out))); // SHould Compress to 2
360 HRTimer _hrt(ACE_TEXT("Compress Time - "));
361 compressor->compress(in_data, comp_out);
364 ACE_HEX_DUMP(( LM_INFO,
365 reinterpret_cast<const char*>(comp_out.get_buffer()),
366 comp_out.length(),
367 ACE_TEXT("Compressed (test128) Buffer")
370 if (comp_out.length() != sizeof(comp_128_out) // Size must equal
371 || ACE_OS::memcmp(comp_out.get_buffer(), comp_128_out, comp_out.length()))
373 ACE_ERROR_RETURN((LM_ERROR,
374 ACE_TEXT("ERROR: Did not Compress/Decompress (test128) correctly.\n")),-1);
377 ::Compression::Buffer decomp_out; decomp_out.length(in_len);
380 HRTimer _hrt(ACE_TEXT("DeCompress Time - "));
381 compressor->decompress(comp_out, decomp_out);
384 // Make sure we got back the original OK.
385 if (ACE_OS::memcmp( in_data.get_buffer(), decomp_out.get_buffer(), in_data.length()))
387 ACE_ERROR_RETURN((LM_ERROR,
388 ACE_TEXT("ERROR: Did not Compress/Decompress (test128) correctly.\n")),-1);
391 ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("****---> END TEST128 - OK!\n")), 0);
394 static int test129A_compressor(const ::Compression::Compressor_var &compressor)
396 ACE_DEBUG((LM_INFO, ACE_TEXT("\n****---> TEST129A (Compress Boundary Extended)\n")));
398 if (::CORBA::is_nil(compressor.in())) {
399 ACE_ERROR_RETURN((LM_ERROR,
400 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
403 const std::unique_ptr<ACE_Byte[]> buff_129(new ACE_Byte[BUFF_129_SIZE]);
405 ACE_OS::memset(buff_129.get(), 0, BUFF_129_SIZE); // Set Buffer to zero.
407 ACE_HEX_DUMP(( LM_INFO,
408 reinterpret_cast<const char*>(buff_129.get()),
409 BUFF_129_SIZE,
410 ACE_TEXT("Original (test129A) Buffer")
413 ::CORBA::ULong in_len = static_cast< CORBA::ULong>(BUFF_129_SIZE);
414 ::CORBA::Octet* in_buf = reinterpret_cast< CORBA::Octet*>(buff_129.get());
416 ::Compression::Buffer in_data(in_len, in_len, in_buf, false);
418 ::Compression::Buffer comp_out;
420 comp_out.length(static_cast< ::CORBA::ULong>(sizeof(comp_129A_out)));
423 HRTimer _hrt(ACE_TEXT("Compress Time - "));
424 compressor->compress(in_data, comp_out);
427 ACE_HEX_DUMP(( LM_INFO,
428 reinterpret_cast<const char*>(comp_out.get_buffer()),
429 comp_out.length(),
430 ACE_TEXT("Compressed (test129A) Buffer")
433 if (comp_out.length() != sizeof(comp_129A_out) // Size must equal
434 || ACE_OS::memcmp(comp_out.get_buffer(), comp_129A_out, comp_out.length()))
436 ACE_ERROR_RETURN((LM_ERROR,
437 ACE_TEXT("ERROR: Did not Compress/Decompress (test129A) correctly.\n")),-1);
440 ::Compression::Buffer decomp_out; decomp_out.length(BUFF_129_SIZE);
443 HRTimer _hrt(ACE_TEXT("DeCompress Time - "));
444 compressor->decompress(comp_out, decomp_out);
447 // Make sure we got back the original OK.
448 if (ACE_OS::memcmp( in_data.get_buffer(), decomp_out.get_buffer(), in_data.length()))
450 ACE_ERROR_RETURN((LM_ERROR,
451 ACE_TEXT("ERROR: Did not Compress/Decompress (test129A) correctly.\n")),-1);
454 ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("****---> END TEST129A - OK!\n")), 0);
457 static int test129B_compressor(const ::Compression::Compressor_var &compressor)
459 ACE_DEBUG((LM_INFO, ACE_TEXT("\n****---> TEST129B (Compress Boundary NonExtend)\n")));
461 if (::CORBA::is_nil(compressor.in())) {
462 ACE_ERROR_RETURN((LM_ERROR,
463 ACE_TEXT("ERROR: nil Compressor.\n")),-1);
466 const std::unique_ptr<ACE_Byte[]> buff_129(new ACE_Byte[BUFF_129_SIZE]);
468 ACE_OS::memset(buff_129.get(), 0, BUFF_129_SIZE); // Set Buffer to zero.
470 buff_129.get()[128] = comp_129B_char; // Add a non Repeat Character
472 ACE_HEX_DUMP(( LM_INFO,
473 reinterpret_cast<const char*>(buff_129.get()),
474 BUFF_129_SIZE,
475 ACE_TEXT("Original (test129B) Buffer")
478 ::CORBA::ULong in_len = static_cast< CORBA::ULong>(BUFF_129_SIZE);
479 ::CORBA::Octet* in_buf = reinterpret_cast< CORBA::Octet*>(buff_129.get());
481 ::Compression::Buffer in_data(in_len, in_len, in_buf, false);
483 ::Compression::Buffer comp_out;
485 comp_out.length(static_cast< ::CORBA::ULong>(sizeof(comp_129B_out)));
488 HRTimer _hrt(ACE_TEXT("Compress Time - "));
489 compressor->compress(in_data, comp_out);
492 ACE_HEX_DUMP(( LM_INFO,
493 reinterpret_cast<const char*>(comp_out.get_buffer()),
494 comp_out.length(),
495 ACE_TEXT("Compressed (test129B) Buffer")
498 if (comp_out.length() != sizeof(comp_129B_out) // Size must equal
499 || ACE_OS::memcmp(comp_out.get_buffer(), comp_129B_out, comp_out.length()))
501 ACE_ERROR_RETURN((LM_ERROR,
502 ACE_TEXT("ERROR: Did not Compress/Decompress (test129B) correctly.\n")),-1);
505 ::Compression::Buffer decomp_out; decomp_out.length(BUFF_129_SIZE);
508 HRTimer _hrt(ACE_TEXT("DeCompress Time - "));
509 compressor->decompress(comp_out, decomp_out);
512 // Make sure we got back the original OK.
513 if (ACE_OS::memcmp( in_data.get_buffer(), decomp_out.get_buffer(), in_data.length()))
515 ACE_ERROR_RETURN((LM_ERROR,
516 ACE_TEXT("ERROR: Did not Compress/Decompress (test129B) correctly.\n")),-1);
519 ACE_ERROR_RETURN((LM_INFO, ACE_TEXT("****---> END TEST129B - OK!\n")), 0);
523 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
525 try {
526 ::CORBA::ORB_var orb = ::CORBA::ORB_init(argc, argv);
528 if (init_compressor(orb.in ()) != 0) {
529 ACE_ERROR_RETURN((LM_ERROR,
530 ACE_TEXT("ERROR: Unable to initialise RLE compressor.\n")),-1);
533 ::CORBA::Object_var compression_manager =
534 orb->resolve_initial_references(TAO_OBJID_COMPRESSIONMANAGER);
536 ::Compression::CompressionManager_var manager =
537 ::Compression::CompressionManager::_narrow(compression_manager.in());
539 if (::CORBA::is_nil(manager.in())) {
540 ACE_ERROR_RETURN((LM_ERROR,
541 ACE_TEXT("ERROR: nil compression manager.\n")),-1);
544 ACE_DEBUG((LM_INFO, ACE_TEXT("\n******** TEST RLE Compressor ************\n")));
546 ::Compression::Compressor_var rleCompressor = manager->get_compressor(::Compression::COMPRESSORID_RLE, 0);
548 if (::CORBA::is_nil(rleCompressor.in())) {
549 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: Unable to locate TAO::RLECompressor - exiting.\n")),-1);
550 } else if (test256_compressor(rleCompressor) == -1) {
551 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test256) - exiting.\n")),-1);
552 } else if (testArray_compressor(rleCompressor) == -1) {
553 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (testArray) - exiting.\n")),-1);
554 } else if (test128_compressor(rleCompressor) == -1) {
555 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test128) - exiting.\n")),-1);
556 } else if (test129A_compressor(rleCompressor) == -1) {
557 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test129A) - exiting.\n")),-1);
558 } else if (test129B_compressor(rleCompressor) == -1) {
559 ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("ERROR: TAO::RLECompressor reported an error (test129B) - exiting.\n")),-1);
562 ACE_DEBUG((LM_INFO, ACE_TEXT("\n********* END TEST RLE ************\n")));
564 float ace_ratio = ACE_RLECompression::instance()->compression_ratio();
565 ACE_DEBUG((LM_INFO, ACE_TEXT("ACE::RLECompression Ratio = %f : 1\n"), ace_ratio));
566 float tao_ratio = rleCompressor->compression_ratio();
567 ACE_DEBUG((LM_INFO, ACE_TEXT("TAO::RLECompression Ratio = %f : 1\n"), tao_ratio));
569 orb->shutdown ();
570 } catch (const CORBA::Exception& ex) {
571 ex._tao_print_exception ("RLECompressorTest: UNEXPECTED exception - ");
572 return -1;
575 return 0;