1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
4 #include "tao/Compression/Compression.h"
5 #include "tao/Compression/zlib/ZlibCompressor_Factory.h"
8 test_invalid_compression_factory (Compression::CompressionManager_ptr cm
)
13 // Get an invalid compression factory
14 Compression::CompressorFactory_var factory
= cm
->get_factory (100);
16 catch (const Compression::UnknownCompressorId
&)
20 catch (const CORBA::Exception
&)
27 "(%t) ERROR, get invalid compression factory failed\n"));
35 test_duplicate_compression_factory (
36 Compression::CompressionManager_ptr cm
,
37 Compression::CompressorFactory_ptr cf
)
43 cm
->register_factory (cf
);
45 catch (const Compression::FactoryAlreadyRegistered
&)
49 catch (const CORBA::Exception
&)
56 "(%t) ERROR, register duplicate factory failed\n"));
63 test_register_nil_compression_factory (
64 Compression::CompressionManager_ptr cm
)
69 // Register nil factory
70 cm
->register_factory (Compression::CompressorFactory::_nil());
72 catch (const CORBA::BAD_PARAM
& ex
)
74 if ((ex
.minor() & 0xFFFU
) == 44)
79 catch (const CORBA::Exception
&)
86 "(%t) ERROR, register nill factory failed\n"));
93 test_compression (CORBA::ULong nelements
,
94 Compression::CompressionManager_ptr cm
)
98 CORBA::OctetSeq mytest
;
99 mytest
.length (nelements
);
100 for (CORBA::ULong j
= 0; j
!= nelements
; ++j
)
105 Compression::Compressor_var compressor
= cm
->get_compressor (::Compression::COMPRESSORID_ZLIB
, 6);
107 CORBA::OctetSeq myout
;
108 myout
.length ((CORBA::ULong
)(mytest
.length() * 1.1));
110 compressor
->compress (mytest
, myout
);
112 CORBA::OctetSeq decompress
;
113 decompress
.length (nelements
);
115 compressor
->decompress (myout
, decompress
);
117 if (decompress
!= mytest
)
119 ACE_ERROR ((LM_ERROR
, "Error, decompress not working\n"));
124 ACE_DEBUG ((LM_DEBUG
, "Compression worked with zlib, original "
125 "size %d, compressed size %d\n",
126 mytest
.length(), myout
.length ()));
132 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
138 CORBA::ORB_init (argc
, argv
);
140 CORBA::Object_var compression_manager
=
141 orb
->resolve_initial_references("CompressionManager");
143 Compression::CompressionManager_var manager
=
144 Compression::CompressionManager::_narrow (compression_manager
.in ());
146 if (CORBA::is_nil(manager
.in ()))
147 ACE_ERROR_RETURN ((LM_ERROR
,
148 " (%P|%t) Panic: nil compression manager\n"),
151 Compression::CompressorFactory_ptr compressor_factory
;
153 ACE_NEW_RETURN (compressor_factory
, TAO::Zlib_CompressorFactory (), 1);
155 Compression::CompressorFactory_var compr_fact
= compressor_factory
;
156 manager
->register_factory(compr_fact
.in ());
158 if (!test_duplicate_compression_factory (manager
.in (), compr_fact
.in ()))
161 if (!test_register_nil_compression_factory (manager
.in ()))
164 if (!test_compression (1024, manager
.in ()))
167 if (!test_compression (5, manager
.in ()))
171 if (!test_invalid_compression_factory (manager
.in ()))
176 catch (const CORBA::Exception
& ex
)
178 ex
._tao_print_exception ("Exception caught:");