1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
// $Id$
#include "ace/Get_Opt.h"
#include "ace/OS_NS_stdio.h"
#include "tao/ORB.h"
#include "tao/Compression/Compression.h"
#include "tao/Compression/bzip2/Bzip2Compressor_Factory.h"
bool
test_invalid_compression_factory (Compression::CompressionManager_ptr cm)
{
bool succeed = false;
try
{
// Get an invalid compression factory
Compression::CompressorFactory_var factory =
cm->get_factory (100);
}
catch (const Compression::UnknownCompressorId& ex)
{
ACE_UNUSED_ARG (ex);
succeed = true;
}
catch (const CORBA::Exception&)
{
}
if (!succeed)
{
ACE_ERROR ((LM_ERROR,
"(%t) ERROR, get invalid compression factory failed\n"));
}
return succeed;
}
bool
test_duplicate_compression_factory (
Compression::CompressionManager_ptr cm,
Compression::CompressorFactory_ptr cf)
{
bool succeed = false;
try
{
// Register duplicate
cm->register_factory (cf);
}
catch (const Compression::FactoryAlreadyRegistered&)
{
succeed = true;
}
catch (const CORBA::Exception&)
{
}
if (!succeed)
{
ACE_ERROR ((LM_ERROR,
"(%t) ERROR, register duplicate factory failed\n"));
}
return succeed;
}
bool
test_register_nil_compression_factory (
Compression::CompressionManager_ptr cm)
{
bool succeed = false;
try
{
// Register nil factory
cm->register_factory (Compression::CompressorFactory::_nil());
}
catch (const CORBA::BAD_PARAM& ex)
{
if ((ex.minor() & 0xFFFU) == 44)
{
succeed = true;
}
}
catch (const CORBA::Exception&)
{
}
if (!succeed)
{
ACE_ERROR ((LM_ERROR,
"(%t) ERROR, register nill factory failed\n"));
}
return succeed;
}
bool
test_compression (CORBA::ULong nelements,
Compression::CompressionManager_ptr cm)
{
bool succeed = false;
CORBA::OctetSeq mytest;
mytest.length (nelements);
for (CORBA::ULong j = 0; j != nelements; ++j)
{
mytest[j] = 'a';
}
Compression::Compressor_var compressor = cm->get_compressor (
::Compression::COMPRESSORID_BZIP2, 6);
CORBA::OctetSeq myout;
myout.length ((CORBA::ULong)(mytest.length() * 1.1));
compressor->compress (mytest, myout);
CORBA::OctetSeq decompress;
decompress.length (nelements);
compressor->decompress (myout, decompress);
if (decompress != mytest)
{
ACE_ERROR ((LM_ERROR, "Error, decompress not working\n"));
}
else
{
succeed = true;
ACE_DEBUG ((LM_DEBUG, "Compression worked with bzip2, original "
"size %d, compressed size %d\n",
mytest.length(), myout.length ()));
}
return succeed;
}
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
int retval = 0;
try
{
CORBA::ORB_var orb =
CORBA::ORB_init (argc, argv);
CORBA::Object_var compression_manager =
orb->resolve_initial_references("CompressionManager");
Compression::CompressionManager_var manager =
Compression::CompressionManager::_narrow (compression_manager.in ());
if (CORBA::is_nil(manager.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Panic: nil compression manager\n"),
1);
Compression::CompressorFactory_ptr compressor_factory;
ACE_NEW_RETURN (compressor_factory, TAO::Bzip2_CompressorFactory (), 1);
Compression::CompressorFactory_var compr_fact = compressor_factory;
manager->register_factory(compr_fact.in ());
if (!test_duplicate_compression_factory (manager.in (), compr_fact.in ()))
retval = 1;
if (!test_register_nil_compression_factory (manager.in ()))
retval = 1;
if (!test_compression (1024, manager.in ()))
retval = 1;
if (!test_compression (5, manager.in ()))
retval = 1;
if (!test_invalid_compression_factory (manager.in ()))
retval = 1;
orb->destroy ();
}
catch (const CORBA::Exception& ex)
{
ex._tao_print_exception ("Exception caught:");
retval = 1;
}
return retval;
}
|