summaryrefslogtreecommitdiff
path: root/cpp/test/XMLTransform/transform/Validate.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2003-07-18 19:47:14 +0000
committerBernard Normier <bernard@zeroc.com>2003-07-18 19:47:14 +0000
commit3c02842b6143c6ce9297feecd7c9497312c76da8 (patch)
tree478210bed985772e2957ee0a65b9cd3f5f390234 /cpp/test/XMLTransform/transform/Validate.cpp
parentuse lazy initialization of communicator for each request (diff)
downloadice-3c02842b6143c6ce9297feecd7c9497312c76da8.tar.bz2
ice-3c02842b6143c6ce9297feecd7c9497312c76da8.tar.xz
ice-3c02842b6143c6ce9297feecd7c9497312c76da8.zip
Major Freeze update
Diffstat (limited to 'cpp/test/XMLTransform/transform/Validate.cpp')
-rw-r--r--cpp/test/XMLTransform/transform/Validate.cpp801
1 files changed, 297 insertions, 504 deletions
diff --git a/cpp/test/XMLTransform/transform/Validate.cpp b/cpp/test/XMLTransform/transform/Validate.cpp
index a872d3b391c..f8ed0fd0efc 100644
--- a/cpp/test/XMLTransform/transform/Validate.cpp
+++ b/cpp/test/XMLTransform/transform/Validate.cpp
@@ -49,572 +49,371 @@ usage(const char* n)
}
static void
-validatePrimitive(const DBEnvironmentPtr& dbEnv)
-{
- DBPtr db;
-
+validatePrimitive(const CommunicatorPtr& communicator, const string& envName)
+{
cout << "validating primitive transformations... " << flush;
-
- try
+
+ //
+ // Validate byte to short transformation
+ //
+
{
+ IntShortMap map(communicator, envName, "byteToShort", false);
+ for(IntShortMap::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ test(p->second == p->first);
+ }
+ }
- //
- // Validate byte to short transformation
- //
- db = dbEnv->openDB("byteToShort", false);
-
- {
- IntShortMap map(db);
- for(IntShortMap::iterator p = map.begin(); p != map.end(); ++p)
- {
- test(p->second == p->first);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate short to int transformation
- //
- db = dbEnv->openDB("shortToInt", false);
-
- {
- IntIntMap map(db);
- for(IntIntMap::iterator p = map.begin(); p != map.end(); ++p)
- {
- test(p->second == p->first);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate int to long transformation
- //
- db = dbEnv->openDB("intToLong", false);
-
- {
- IntLongMap map(db);
- for(IntLongMap::iterator p = map.begin(); p != map.end(); ++p)
- {
- test(p->second == p->first);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate long to byte transformation
- //
- db = dbEnv->openDB("longToByte", false);
-
- {
- IntByteMap map(db);
- for(IntByteMap::iterator p = map.begin(); p != map.end(); ++p)
- {
- test(p->second == p->first);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate float to double transformation
- //
- db = dbEnv->openDB("floatToDouble", false);
-
- {
- IntDoubleMap map(db);
- for(IntDoubleMap::iterator p = map.begin(); p != map.end(); ++p)
- {
- test(p->second - p->first <= 0.001);
- }
- }
-
- db->close();
- db = 0;
-
- cout << "ok" << endl;
+ //
+ // Validate short to int transformation
+ //
+
+ {
+ IntIntMap map(communicator, envName, "shortToInt", false);
+ for(IntIntMap::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ test(p->second == p->first);
+ }
}
- catch(...)
+
+ //
+ // Validate int to long transformation
+ //
+
{
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
+ IntLongMap map(communicator, envName, "intToLong", false);
+ for(IntLongMap::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ test(p->second == p->first);
+ }
}
-
- if(db)
+
+ //
+ // Validate long to byte transformation
+ //
+ {
+ IntByteMap map(communicator, envName, "longToByte", false);
+ for(IntByteMap::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ test(p->second == p->first);
+ }
+ }
+
{
- db->close();
+ IntDoubleMap map(communicator, envName, "floatToDouble", false);
+ for(IntDoubleMap::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ test(p->second - p->first <= 0.001);
+ }
}
+
+ cout << "ok" << endl;
+
}
static void
-validatePrimitiveSequence(const DBEnvironmentPtr& dbEnv)
+validatePrimitiveSequence(const CommunicatorPtr& communicator, const string& envName)
{
Int i;
- DBPtr db;
-
cout << "validating primitive sequence transformations... " << flush;
- try
+ //
+ // Validate byte to short sequence transformation
+ //
+
{
- //
- // Validate byte to short sequence transformation
- //
- db = dbEnv->openDB("byteToShortSeq", false);
-
- {
- IntSeq1Map map(db);
- test(map.size() == 1);
- IntSeq1Map::iterator p = map.find(0);
- test(p != map.end());
- const Test::Seq1& seq = p->second;
- test(seq.size() == NUM_ELEMENTS);
- for(i = 0; i < NUM_ELEMENTS; i++)
- {
- test(seq[i] == i);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate short to int sequence transformation
- //
- db = dbEnv->openDB("shortToIntSeq", false);
-
- {
- IntSeq2Map map(db);
- test(map.size() == 1);
- IntSeq2Map::iterator p = map.find(0);
- test(p != map.end());
- const Test::Seq2& seq = p->second;
- test(seq.size() == NUM_ELEMENTS);
- for(i = 0; i < NUM_ELEMENTS; i++)
- {
- test(seq[i] == i);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate int to long sequence transformation
- //
- db = dbEnv->openDB("intToLongSeq", false);
-
- {
- IntSeq3Map map(db);
- test(map.size() == 1);
- IntSeq3Map::iterator p = map.find(0);
- test(p != map.end());
- const Test::Seq3& seq = p->second;
- test(seq.size() == NUM_ELEMENTS);
- for(i = 0; i < NUM_ELEMENTS; i++)
- {
- test(seq[i] == i);
- }
- }
-
- db->close();
- db = 0;
-
- //
- // Validate long to byte sequence transformation
- //
- db = dbEnv->openDB("longToByteSeq", false);
-
- {
- IntSeq4Map map(db);
- test(map.size() == 1);
- IntSeq4Map::iterator p = map.find(0);
- test(p != map.end());
- const Test::Seq4& seq = p->second;
- test(seq.size() == NUM_ELEMENTS);
- for(i = 0; i < NUM_ELEMENTS; i++)
- {
- test(seq[i] == i);
- }
- }
-
- db->close();
- db = 0;
-
- cout << "ok" << endl;
+ IntSeq1Map map(communicator, envName, "byteToShortSeq", false);
+ test(map.size() == 1);
+ IntSeq1Map::iterator p = map.find(0);
+ test(p != map.end());
+ const Test::Seq1& seq = p->second;
+ test(seq.size() == NUM_ELEMENTS);
+ for(i = 0; i < NUM_ELEMENTS; i++)
+ {
+ test(seq[i] == i);
+ }
}
- catch(...)
+
+ //
+ // Validate short to int sequence transformation
+ //
+
{
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
+ IntSeq2Map map(communicator, envName, "shortToIntSeq", false);
+ test(map.size() == 1);
+ IntSeq2Map::iterator p = map.find(0);
+ test(p != map.end());
+ const Test::Seq2& seq = p->second;
+ test(seq.size() == NUM_ELEMENTS);
+ for(i = 0; i < NUM_ELEMENTS; i++)
+ {
+ test(seq[i] == i);
+ }
+ }
+
+ //
+ // Validate int to long sequence transformation
+ //
+
+ {
+ IntSeq3Map map(communicator, envName, "intToLongSeq", false);
+ test(map.size() == 1);
+ IntSeq3Map::iterator p = map.find(0);
+ test(p != map.end());
+ const Test::Seq3& seq = p->second;
+ test(seq.size() == NUM_ELEMENTS);
+ for(i = 0; i < NUM_ELEMENTS; i++)
+ {
+ test(seq[i] == i);
+ }
}
- if(db)
+ //
+ // Validate long to byte sequence transformation
+ //
{
- db->close();
+ IntSeq4Map map(communicator, envName, "longToByteSeq", false);
+ test(map.size() == 1);
+ IntSeq4Map::iterator p = map.find(0);
+ test(p != map.end());
+ const Test::Seq4& seq = p->second;
+ test(seq.size() == NUM_ELEMENTS);
+ for(i = 0; i < NUM_ELEMENTS; i++)
+ {
+ test(seq[i] == i);
+ }
}
+
+ cout << "ok" << endl;
}
static void
-validateEnum(const DBEnvironmentPtr& dbEnv)
+validateEnum(const CommunicatorPtr& communicator, const string& envName)
{
- DBPtr db;
-
cout << "validating enumeration transformations... " << flush;
- try
- {
- //
- // Validate removal of E1::three
- //
- db = dbEnv->openDB("enum", false);
-
- {
- IntE1Map map(db);
- test(map.size() == 2);
- IntE1Map::iterator p;
- p = map.find(0);
- test(p != map.end());
- test(p->second == Test::one);
- p = map.find(1);
- test(p != map.end());
- test(p->second == Test::two);
- }
-
- db->close();
- db = 0;
-
- cout << "ok" << endl;
- }
- catch(...)
+
+ //
+ // Validate removal of E1::three
+ //
{
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
+ IntE1Map map(communicator, envName, "enum", false);
+ test(map.size() == 2);
+ IntE1Map::iterator p;
+ p = map.find(0);
+ test(p != map.end());
+ test(p->second == Test::one);
+ p = map.find(1);
+ test(p != map.end());
+ test(p->second == Test::two);
}
- if(db)
- {
- db->close();
- }
+ cout << "ok" << endl;
}
static void
-validateDictionary(const DBEnvironmentPtr& dbEnv)
+validateDictionary(const CommunicatorPtr& communicator, const string& envName)
{
- DBPtr db;
-
cout << "validating dictionary transformations... " << flush;
- try
+ //
+ // Validate removal of E1::three
+ //
{
- //
- // Validate removal of E1::three
- //
- db = dbEnv->openDB("dict", false);
-
- {
- IntD1Map map(db);
- IntD1Map::iterator p = map.find(0);
- test(p != map.end());
- const Test::D1& dict = p->second;
- test(dict.size() == 2);
- Test::D1::const_iterator q;
- q = dict.find("one");
- test(q != dict.end());
- test(q->second == Test::one);
- q = dict.find("two");
- test(q != dict.end());
- test(q->second == Test::two);
- }
-
- db->close();
- db = 0;
-
- cout << "ok" << endl;
- }
- catch(...)
- {
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
- }
-
- if(db)
- {
- db->close();
+ IntD1Map map(communicator, envName, "dict", false);
+ IntD1Map::iterator p = map.find(0);
+ test(p != map.end());
+ const Test::D1& dict = p->second;
+ test(dict.size() == 2);
+ Test::D1::const_iterator q;
+ q = dict.find("one");
+ test(q != dict.end());
+ test(q->second == Test::one);
+ q = dict.find("two");
+ test(q != dict.end());
+ test(q->second == Test::two);
}
+ cout << "ok" << endl;
}
static void
-validateStruct(const DBEnvironmentPtr& dbEnv)
+validateStruct(const CommunicatorPtr& communicator, const string& envName)
{
- DBPtr db;
-
cout << "validating struct transformations... " << flush;
- try
- {
- //
- // Validate S1
- //
- db = dbEnv->openDB("struct", false);
-
- {
- IntS1Map map(db);
- for(IntS1Map::iterator p = map.begin(); p != map.end(); ++p)
- {
- test(p->second.i == p->first);
- test(p->second.s == 0);
- }
- }
-
- db->close();
- db = 0;
-
- cout << "ok" << endl;
- }
- catch(...)
- {
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
- }
-
- if(db)
+
+ //
+ // Validate S1
+ //
{
- db->close();
+ IntS1Map map(communicator, envName, "struct", false);
+ for(IntS1Map::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ test(p->second.i == p->first);
+ test(p->second.s == 0);
+ }
}
+ cout << "ok" << endl;
+
}
static void
-validateClass(const DBEnvironmentPtr& dbEnv)
+validateClass(const CommunicatorPtr& communicator, const string& envName)
{
- DBPtr db;
-
- CommunicatorPtr communicator = dbEnv->getCommunicator();
communicator->addObjectFactory(Test::C1::ice_factory(), Test::C1::ice_staticId());
communicator->addObjectFactory(Test::C2::ice_factory(), Test::C2::ice_staticId());
cout << "validating class transformations... " << flush;
- try
{
- //
- // Validate C2
- //
- db = dbEnv->openDB("class", false);
-
- {
- IntC1Map map(db);
- for(IntC1Map::iterator p = map.begin(); p != map.end(); ++p)
- {
- Test::C2Ptr c2 = Test::C2Ptr::dynamicCast(p->second);
- test(c2);
- test(c2->s.size() == 1 && c2->s[0] == '0' + p->first);
- test(c2->b == p->first);
- test(c2->l == p->first);
- test(c2->i == p->first);
- if(c2->s == "3")
- {
- //
- // Test facets
- //
- Ice::ObjectPtr obj;
- Test::C1Ptr c1;
-
- obj = c2->ice_findFacet("c1-0");
- test(obj);
- c1 = Test::C1Ptr::dynamicCast(obj);
- test(c1);
- test(c1->s == "c1-0");
- test(c1->b == 0);
-
- obj = c2->ice_findFacet("c1-1");
- test(obj);
- c1 = Test::C1Ptr::dynamicCast(obj);
- test(c1);
- test(c1->s == "c1-1");
- test(c1->b == 1);
-
- obj = c2->ice_findFacet("c1-2");
- test(obj);
- Test::C2Ptr c2Facet = Test::C2Ptr::dynamicCast(obj);
- test(c2Facet);
- test(c2Facet->s == "c1-2");
- test(c2Facet->b == 2);
- test(c2Facet->i == 2);
- test(c2Facet->l == 2);
-
- obj = c2Facet->ice_findFacet("c2-0");
- test(obj);
- c1 = Test::C1Ptr::dynamicCast(obj);
- test(c1);
- test(c1->s == "c2-0");
- test(c1->b == 0);
- }
- }
- }
-
- db->close();
- db = 0;
-
- cout << "ok" << endl;
- }
- catch(...)
- {
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
+ IntC1Map map(communicator, envName, "class", false);
+ for(IntC1Map::iterator p = map.begin(); p != map.end(); ++p)
+ {
+ Test::C2Ptr c2 = Test::C2Ptr::dynamicCast(p->second);
+ test(c2);
+ test(c2->s.size() == 1 && c2->s[0] == '0' + p->first);
+ test(c2->b == p->first);
+ test(c2->l == p->first);
+ test(c2->i == p->first);
+ if(c2->s == "3")
+ {
+ //
+ // Test facets
+ //
+ Ice::ObjectPtr obj;
+ Test::C1Ptr c1;
+
+ obj = c2->ice_findFacet("c1-0");
+ test(obj);
+ c1 = Test::C1Ptr::dynamicCast(obj);
+ test(c1);
+ test(c1->s == "c1-0");
+ test(c1->b == 0);
+
+ obj = c2->ice_findFacet("c1-1");
+ test(obj);
+ c1 = Test::C1Ptr::dynamicCast(obj);
+ test(c1);
+ test(c1->s == "c1-1");
+ test(c1->b == 1);
+
+ obj = c2->ice_findFacet("c1-2");
+ test(obj);
+ Test::C2Ptr c2Facet = Test::C2Ptr::dynamicCast(obj);
+ test(c2Facet);
+ test(c2Facet->s == "c1-2");
+ test(c2Facet->b == 2);
+ test(c2Facet->i == 2);
+ test(c2Facet->l == 2);
+
+ obj = c2Facet->ice_findFacet("c2-0");
+ test(obj);
+ c1 = Test::C1Ptr::dynamicCast(obj);
+ test(c1);
+ test(c1->s == "c2-0");
+ test(c1->b == 0);
+ }
+ }
}
- communicator->removeObjectFactory(Test::C1::ice_staticId());
- communicator->removeObjectFactory(Test::C2::ice_staticId());
+ cout << "ok" << endl;
- if(db)
- {
- db->close();
- }
+ communicator->removeObjectFactory(Test::C1::ice_staticId());
+ communicator->removeObjectFactory(Test::C2::ice_staticId());
}
static void
-validateEvictor(const DBEnvironmentPtr& dbEnv)
+validateEvictor(const CommunicatorPtr& communicator, const string& envName)
{
- DBPtr db;
Freeze::EvictorPtr evictor;
- CommunicatorPtr communicator = dbEnv->getCommunicator();
communicator->addObjectFactory(Test::C1::ice_factory(), Test::C1::ice_staticId());
communicator->addObjectFactory(Test::C2::ice_factory(), Test::C2::ice_staticId());
cout << "validating evictor transformations... " << flush;
- try
+
+ //
+ // Validate C2
+ //
+ evictor = Freeze::createEvictor(communicator, envName, "evictor", false);
{
- //
- // Validate C2
- //
- db = dbEnv->openDB("evictor", false);
- evictor = db->createEvictor(db->createEvictionStrategy());
-
- {
- EvictorIteratorPtr iter = evictor->getIterator();
- while(iter->hasNext())
- {
- Current current;
- LocalObjectPtr cookie;
-
- current.id = iter->next();
-
- ObjectPtr object = evictor->locate(current, cookie);
- test(object);
-
- Test::C2Ptr c2 = Test::C2Ptr::dynamicCast(object);
- test(c2);
- test(c2->s.size() == 1 && c2->s == current.id.name);
- int i = current.id.name[0] - '0';
- test(c2->b == i);
- test(c2->l == i);
- test(c2->i == i);
- if(c2->s == "3")
- {
- //
- // Test facets
- //
- Ice::ObjectPtr obj;
- Test::C1Ptr c1;
-
- obj = c2->ice_findFacet("c1-0");
- test(obj);
- c1 = Test::C1Ptr::dynamicCast(obj);
- test(c1);
- test(c1->s == "c1-0");
- test(c1->b == 0);
-
- obj = c2->ice_findFacet("c1-1");
- test(obj);
- c1 = Test::C1Ptr::dynamicCast(obj);
- test(c1);
- test(c1->s == "c1-1");
- test(c1->b == 1);
-
- obj = c2->ice_findFacet("c1-2");
- test(obj);
- Test::C2Ptr c2Facet = Test::C2Ptr::dynamicCast(obj);
- test(c2Facet);
- test(c2Facet->s == "c1-2");
- test(c2Facet->b == 2);
- test(c2Facet->i == 2);
- test(c2Facet->l == 2);
-
- obj = c2Facet->ice_findFacet("c2-0");
- test(obj);
- c1 = Test::C1Ptr::dynamicCast(obj);
- test(c1);
- test(c1->s == "c2-0");
- test(c1->b == 0);
- }
-
- evictor->finished(current, object, cookie);
- }
- iter->destroy();
- }
-
- evictor->deactivate("");
- db->close();
- db = 0;
-
- cout << "ok" << endl;
- }
- catch(...)
- {
- cout << "failed" << endl;
- if(db)
- {
- db->close();
- }
- throw;
+ EvictorIteratorPtr iter = evictor->getIterator();
+ while(iter->hasNext())
+ {
+ Current current;
+ LocalObjectPtr cookie;
+
+ current.id = iter->next();
+
+ ObjectPtr object = evictor->locate(current, cookie);
+ test(object);
+
+ Test::C2Ptr c2 = Test::C2Ptr::dynamicCast(object);
+ test(c2);
+ test(c2->s.size() == 1 && c2->s == current.id.name);
+ int i = current.id.name[0] - '0';
+ test(c2->b == i);
+ test(c2->l == i);
+ test(c2->i == i);
+ if(c2->s == "3")
+ {
+ //
+ // Test facets
+ //
+ Ice::ObjectPtr obj;
+ Test::C1Ptr c1;
+
+ obj = c2->ice_findFacet("c1-0");
+ test(obj);
+ c1 = Test::C1Ptr::dynamicCast(obj);
+ test(c1);
+ test(c1->s == "c1-0");
+ test(c1->b == 0);
+
+ obj = c2->ice_findFacet("c1-1");
+ test(obj);
+ c1 = Test::C1Ptr::dynamicCast(obj);
+ test(c1);
+ test(c1->s == "c1-1");
+ test(c1->b == 1);
+
+ obj = c2->ice_findFacet("c1-2");
+ test(obj);
+ Test::C2Ptr c2Facet = Test::C2Ptr::dynamicCast(obj);
+ test(c2Facet);
+ test(c2Facet->s == "c1-2");
+ test(c2Facet->b == 2);
+ test(c2Facet->i == 2);
+ test(c2Facet->l == 2);
+
+ obj = c2Facet->ice_findFacet("c2-0");
+ test(obj);
+ c1 = Test::C1Ptr::dynamicCast(obj);
+ test(c1);
+ test(c1->s == "c2-0");
+ test(c1->b == 0);
+ }
+
+ evictor->finished(current, object, cookie);
+ }
+ iter->destroy();
}
+
+ evictor->deactivate("");
+
+ cout << "ok" << endl;
communicator->removeObjectFactory(Test::C1::ice_staticId());
communicator->removeObjectFactory(Test::C2::ice_staticId());
-
- if(db)
- {
- db->close();
- }
}
static int
run(int argc, char* argv[], const CommunicatorPtr& communicator)
{
- string dbEnvDir = "db";
+ string envName = "db";
int idx = 1;
while(idx < argc)
@@ -628,7 +427,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
return EXIT_FAILURE;
}
- dbEnvDir = argv[idx + 1];
+ envName = argv[idx + 1];
for(int i = idx ; i + 2 < argc ; ++i)
{
argv[i] = argv[i + 2];
@@ -647,31 +446,25 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
}
}
- DBEnvironmentPtr dbEnv;
-
try
{
- dbEnv = Freeze::initialize(communicator, dbEnvDir);
- validatePrimitive(dbEnv);
- validatePrimitiveSequence(dbEnv);
- validateEnum(dbEnv);
- validateDictionary(dbEnv);
- validateStruct(dbEnv);
- validateClass(dbEnv);
- validateEvictor(dbEnv);
+ validatePrimitive(communicator, envName);
+ validatePrimitiveSequence(communicator, envName);
+ validateEnum(communicator, envName);
+ validateDictionary(communicator, envName);
+ validateStruct(communicator, envName);
+ validateClass(communicator, envName);
+ validateEvictor(communicator, envName);
}
- catch(...)
+ catch(Exception& ex)
{
- if(dbEnv)
- {
- dbEnv->close();
- }
- throw;
+ cerr << "Caught Exception" << endl;
+ cerr << ex << endl;
}
-
- if(dbEnv)
+ catch(...)
{
- dbEnv->close();
+ cerr << "Caught exception" << endl;
+ throw;
}
return EXIT_SUCCESS;