Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Compression / bzip2server.cpp
bloba51fda2298e855bcf4a144a8142ded85f4863482
1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "tao/ORB.h"
4 #include "tao/Compression/Compression.h"
5 #include "tao/Compression/bzip2/Bzip2Compressor_Factory.h"
7 bool
8 test_invalid_compression_factory (Compression::CompressionManager_ptr cm)
10 bool succeed = false;
11 try
13 // Get an invalid compression factory
14 Compression::CompressorFactory_var factory = cm->get_factory (100);
16 catch (const Compression::UnknownCompressorId&)
18 succeed = true;
20 catch (const CORBA::Exception&)
24 if (!succeed)
26 ACE_ERROR ((LM_ERROR,
27 "(%t) ERROR, get invalid compression factory failed\n"));
30 return succeed;
33 bool
34 test_duplicate_compression_factory (
35 Compression::CompressionManager_ptr cm,
36 Compression::CompressorFactory_ptr cf)
38 bool succeed = false;
39 try
41 // Register duplicate
42 cm->register_factory (cf);
44 catch (const Compression::FactoryAlreadyRegistered&)
46 succeed = true;
48 catch (const CORBA::Exception&)
52 if (!succeed)
54 ACE_ERROR ((LM_ERROR,
55 "(%t) ERROR, register duplicate factory failed\n"));
58 return succeed;
61 bool
62 test_register_nil_compression_factory (
63 Compression::CompressionManager_ptr cm)
65 bool succeed = false;
66 try
68 // Register nil factory
69 cm->register_factory (Compression::CompressorFactory::_nil());
71 catch (const CORBA::BAD_PARAM& ex)
73 if ((ex.minor() & 0xFFFU) == 44)
75 succeed = true;
78 catch (const CORBA::Exception&)
82 if (!succeed)
84 ACE_ERROR ((LM_ERROR,
85 "(%t) ERROR, register nill factory failed\n"));
88 return succeed;
91 bool
92 test_compression (CORBA::ULong nelements,
93 Compression::CompressionManager_ptr cm)
95 bool succeed = false;
97 CORBA::OctetSeq mytest;
98 mytest.length (nelements);
99 for (CORBA::ULong j = 0; j != nelements; ++j)
101 mytest[j] = 'a';
104 Compression::Compressor_var compressor = cm->get_compressor (
105 ::Compression::COMPRESSORID_BZIP2, 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"));
121 else
123 succeed = true;
124 ACE_DEBUG ((LM_DEBUG, "Compression worked with bzip2, original "
125 "size %d, compressed size %d\n",
126 mytest.length(), myout.length ()));
128 return succeed;
132 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
134 int retval = 0;
137 CORBA::ORB_var orb =
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::Bzip2_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 ()))
159 retval = 1;
161 if (!test_register_nil_compression_factory (manager.in ()))
162 retval = 1;
164 if (!test_compression (1024, manager.in ()))
165 retval = 1;
167 if (!test_compression (5, manager.in ()))
168 retval = 1;
170 if (!test_invalid_compression_factory (manager.in ()))
171 retval = 1;
173 orb->destroy ();
175 catch (const CORBA::Exception& ex)
177 ex._tao_print_exception ("Exception caught:");
178 retval = 1;
181 return retval;