diff options
Diffstat (limited to 'mddmgr/test')
-rw-r--r-- | mddmgr/test/Makefile | 109 | ||||
-rw-r--r-- | mddmgr/test/test_extbmarkint.cc | 374 | ||||
-rw-r--r-- | mddmgr/test/test_extendobjs.cc | 324 | ||||
-rw-r--r-- | mddmgr/test/test_mddjoin.cc | 228 | ||||
-rw-r--r-- | mddmgr/test/test_mddobj.cc | 473 | ||||
-rw-r--r-- | mddmgr/test/test_mddops.cc | 335 | ||||
-rw-r--r-- | mddmgr/test/test_persmddcoll.cc | 768 | ||||
-rw-r--r-- | mddmgr/test/test_persmddobj.cc | 1125 | ||||
-rw-r--r-- | mddmgr/test/test_transmddcoll.cc | 180 | ||||
-rw-r--r-- | mddmgr/test/test_transmddobj.cc | 443 |
10 files changed, 4359 insertions, 0 deletions
diff --git a/mddmgr/test/Makefile b/mddmgr/test/Makefile new file mode 100644 index 0000000..c5e03c8 --- /dev/null +++ b/mddmgr/test/Makefile @@ -0,0 +1,109 @@ +# -*-Makefile-*- +# +# This file is part of rasdaman community. +# +# Rasdaman community is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Rasdaman community is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +# +# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +# rasdaman GmbH. +# +# For more information please see <http://www.rasdaman.org> +# or contact Peter Baumann via <baumann@rasdaman.com>. # Top Level makefile. This points to the various modules that have to be build +# and/or deployed +# +# MAKEFILE FOR: +# test programs of module mddmgr +# +# COMMENTS: +# +################################################################## +######################### Definitions ############################ + +# standard include with general options +include $(RMANBASE)/Makefile.inc + +# all test programs +SRCCXX = test_extendobjs.cc test_mddobj.cc test_persmddcoll.cc test_transmddcoll.cc \ + test_extbmarkint.cc test_mddjoin.cc test_mddops.cc test_persmddobj.cc \ + test_transmddobj.cc + +OBJS = ${SRCCXX:%.cc=%.o} + +ALLTESTS = ${SRCCXX:%.cc=%} + +MISCCLEAN = core + +# Sun Solaris: -lposix4 is needed for test_tile because of clock_gettime +ifeq ($(OSTYPE),$(OSTYPE_SOLARIS)) + LDFLAGS += -lposix4 +endif + +ALLFLAGS = $(BASEDBLDFLAGS) $(LDFLAGS) $(STLLDFLAGS) -L$(SUPPORT_BASE)/lib -lz + +MAINLIBS = $(RASLIB) $(CACHETAMGR) $(MDDIF) $(CATALOGIF) \ + $(INDEXMGR) $(BLOBIF) $(ADMINIF) $(QLPARSER) $(INDEXIF) + +########################### Targets ############################## + +# make all tests +.PHONY: test +test: ALLTESTS + + +######################## Dependencies ############################ + +test_persmddcoll: test_persmddcoll.o $(MAINLIBS) + $(PURIFY) $(CXX) $(ALLFLAGS) -o $@ $^ $(STLLDFLAGS) -lm $(CACHETAMGR) \ + $(INDEXIF) + +test_transmddcoll: test_transmddcoll.o $(RASLIB) $(CACHETAMGR)\ + $(MDDIF) $(CATALOGIF) $(INDEXIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) + $(PURIFY) $(CXX) $(BASEDBLDFLAGS) $(STLLDFLAGS) $(LDFLAGS) -o $@ $^ + +test_mddobj: test_mddobj.o $(RASLIB) $(CACHETAMGR)\ + $(MDDIF) $(CATALOGIF) $(INDEXIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) + $(PURIFY) $(CXX) $(BASEDBLDFLAGS) $(STLLDFLAGS) $(LDFLAGS) -o $@ $^ -lm \ + $(CACHETAMGR) + +test_transmddobj: test_transmddobj.o $(MAINLIBS) + $(PURIFY) $(CXX) $(ALLFLAGS) -o $@ $^ $(INDEXIF) + +# can not be used as a target (module library is not remade!) +test_mddops: test_mddops.o $(RASLIB) $(CACHETAMGR)\ + $(MDDIF) $(CATALOGIF) $(INDEXIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) + $(PURIFY) $(CXX) $(STLLDFLAGS) $(LDFLAGS) $(BASEDBLDFLAGS) -o $@ $^ + +# can not be used as a target (module library is not remade!) +test_mddjoin: test_mddjoin.o $(RASLIB) $(CACHETAMGR)\ + $(MDDIF) $(CATALOGIF) $(INDEXIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) + $(PURIFY) $(CXX) $(STLLDFLAGS) $(LDFLAGS) $(BASEDBLDFLAGS) -o $@ $^ + +test_persmddobj: test_persmddobj.o $(RASLIB) $(CACHETAMGR)\ + $(MDDIF) $(CATALOGIF) $(INDEXMGR) $(BLOBIF) $(ADMINIF) $(QLPARSER) \ + $(INDEXIF) + $(PURIFY) $(CXX) $(BASEDBLDFLAGS) $(LDFLAGS) $(STLLDFLAGS) -o $@ $^ \ + $(STLLDFLAGS) -lm $(CACHETAMGR) -L$(SUPPORT_BASE)/lib -lz + +test_extbmarkint: test_extbmarkint.o $(MAINLIBS) + $(PURIFY) $(CXX) $(BASEDBLDFLAGS) $(LDFLAGS) $(STLLDFLAGS) -o $@ $^ \ + $(STLLDFLAGS) -lm $(CACHETAMGR) $(INDEXIF) -L$(SUPPORT_BASE)/lib -lz + +# general rules +include $(RMANBASE)/Makefile.rel + +# general dependencies for module libraries +include $(RMANBASE)/Makefile.dep + +# automatically created dependencies +include Makefile.dep diff --git a/mddmgr/test/test_extbmarkint.cc b/mddmgr/test/test_extbmarkint.cc new file mode 100644 index 0000000..3cc0caa --- /dev/null +++ b/mddmgr/test/test_extbmarkint.cc @@ -0,0 +1,374 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_extbmarkint.cc + * + * MODULE: mddmgr + * + * PURPOSE: + * Extends the objects created by the test of areas of interest tiling + * rasodmg/test/test_int1 (the resulting objects have 5000 frames more + * than the original ones ). + * Needed because rasodmg doens't support updating of MDDobjects + * at the time this was created. + * + * + * COMMENTS: + * none + * +*/ + +#define TEST_PROTECTED +#define TEST_PRIVATE + +#include <stdlib.h> +#include <iostream> + +#include "ulongtype.hh" + +#include "mddmgr/persmddcoll.hh" +#include "mddmgr/persmddobj.hh" +#include "mddmgr/perstile.hh" + +#include "mddmgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "oidif.hh" + +#include "raslib/rminit.hh" +#include "typefactory.hh" + +#include "mddif/dbmddobj.hh" +#include "mddif/dbmddcoll.hh" + +#include "mddbasetype.hh" +#include "mdddomaintype.hh" +#include "settype.hh" + + +/* + Global Variables +*/ +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +static char* O2DBName; +char *collName; +char defaultCollName[]= "ObjsContainer"; + +TransactionIf ta; + +/* + Functions +*/ + +// 2 - Populate collection with MDD objects +static void testConstructors( OId o, + int numberFramesTile, + int f, // first frame + int n ); // number frames + +// 3 - Retrieves an MDD collection with name cn and prints contents: +static void testAccessing( char* cn ); + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ +int +main( int argc, char** argv) +{ + // variables representing O2 database, ta and session + DatabaseIf database; + + + + if( argc < 2 ) { + cout << "Usage: test_extbmarkint <database> [collName] [oid] [frames] " << endl; + return -1; + } + O2DBName = strdup( argv[1] ); + if ( argc >= 3 ) collName = strdup( argv[2] ); + else + collName = defaultCollName; + + int numberFramesTile = 3; // 9 + OId o( double( 2)); // + if( argc >= 4 ) + { + int oid; + o = OId( double( atoi( argv[3] ))); + cout << "OId " << o << endl; + } + if( argc >= 5 ) + { + numberFramesTile = atoi( argv[4] ); + cout << "Number of frames per tile "<< numberFramesTile << endl; + } + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + + + // connect to the database + cout << "Connecting to database " << O2DBName + << "..." << endl; + int errorDBOpen; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch( ...) + { + cout << "Caught Exception " << endl; + errorDBOpen = -6; + } + if ( errorDBOpen < 0 ) + { + cout << "Database doesn't exist. Create it new ... " << endl; + cout << "Creating new database " << O2DBName + << "..." << endl; + database.create( O2DBName, "TestSMSchema" ); + cout << "Connecting to database " << O2DBName + << "..." << endl; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch(...) + { + errorDBOpen = -6; + } + } + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + char c; + + unsigned totalNumberFrames = 200; /* 2000 */ + + // The first 2000 frames + for( int i = 0; i < totalNumberFrames ; i+= numberFramesTile*30 ) + { + ta.begin( &database ); + cout << endl << "Populate collection " << i << " ..." << endl; + int numberFrames = numberFramesTile*30; + if ( i+numberFrames > totalNumberFrames ) numberFrames = totalNumberFrames-i; + testConstructors( o, numberFramesTile, i, numberFrames ); + +/* + cout <<"Transaction abort (A/a) or commit (default)? "; + cin >> c; + if ( c == 'A' || c == 'a' ) + { + ta.abort( ); + cout <<"End of Transaction Abort..."<<endl; + } + else + { +*/ + ta.commit( ); + + cout <<"End of transaction commit... "<<endl; +// } + } + + + const int lastFrame = 2400; // 5120 + + // The last frames up to lastFrame + for( i = 2121 ; i < lastFrame ; i+= numberFramesTile*30 ) // 2121 + { + ta.begin( &database ); + cout << endl << "Populate collection " << i << " ..." << endl; + int numberFrames = numberFramesTile*30; + if ( i+numberFrames > lastFrame ) numberFrames = lastFrame-i; + testConstructors( o, numberFramesTile, i, numberFrames ); + +/* + cout <<"Transaction abort (A/a) or commit (default)? "; + cin >> c; + if ( c == 'A' || c == 'a' ) + { + ta.abort( ); + cout <<"End of Transaction Abort..."<<endl; + } + else + { +*/ + ta.commit( ); +/* + cout <<"End of transaction commit... "<<endl; + } +*/ + } + + + ta.begin(&database ); + // read coll and print contents + cout << endl << "Read collection " << collName << " and print contents..." << endl; + testAccessing( collName ); + ta.commit( ); + cout <<"End of transaction commit... "<<endl; + + cout << endl << "Ending O2 session..." << endl; + database.close( ); + delete myAdmin; + + free( O2DBName ); + if ( collName != defaultCollName ) free( collName ); + return 0; + +} + +/************************************************************* + * Functions......: + * + * static void + * testConstructors( char* collName ) + * + ************************************************************/ +static void testConstructors( OId o, + int numberFramesTile, + int f, // first frame + int n ) // number frames +{ + + const BaseType* mddType; + + cout << "....testConstructors"<< endl; + + try{ + + PersMDDObj* accessedObj = new PersMDDObj( O2DBName, o ); + int typeSize= accessedObj->getCellType( )->getSize( ); + cout << "currDom " << accessedObj->getCurrentDomain( ) << endl; + accessedObj->printStatus(); + + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid; + cout << endl << endl; + mddType = accessedObj->getCellType( ); + + r_Minterval firstTile( 3 ); + firstTile << r_Sinterval( long ( 0 ), long ( numberFramesTile-1 ) ) + << r_Sinterval( long ( 0 ), long ( 79 ) ) + << r_Sinterval( long ( 0 ), long ( 119 ) ); + + r_Minterval secondTile( 3 ); + secondTile << r_Sinterval( long ( 0 ) , long ( numberFramesTile-1 ) ) + << r_Sinterval( long ( 80 ), long ( 159 ) ) + << r_Sinterval( long ( 0 ) , long ( 119 ) ); + + for ( int j = f; j < f+n ; j+=numberFramesTile ) + { + r_Minterval dom1 = firstTile; + r_Minterval dom2 = secondTile; + r_Point desl( (r_Range) j, 0, 0 ); + dom1.translate( desl ); + dom2.translate( desl ); + if ( dom1[0].high( ) >= f+n ) + { + dom1[0].set_high( long( f+n-1) ); + dom2[0].set_high( long( f+n-1) ); + } + cout << "dom1" << dom1 << " dom2 " << dom2 + << " type " << mddType->getTypeName( ) << endl; + + int sz1 = dom1.cell_count( ) * typeSize; + char* cells1 = new char[sz1]; + PersTile* tile1 = new PersTile( dom1, mddType, cells1); + accessedObj->insertTile(tile1); + + int sz2 = dom2.cell_count( ) * typeSize; + char* cells2 = new char[sz2]; + PersTile* tile2 = new PersTile( dom2, mddType, cells2 ); + + accessedObj->insertTile(tile2); + // accessedObj->printStatus( ); + } + + delete accessedObj; + + } + catch ( r_Error& errObj) + { + cout << "Error caught when opening object" << endl; + } + +} + + +/************************************************************* + * Function......: testAccessing( char* cn ) + ************************************************************/ + +static void testAccessing( char* cn ) +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing collection "<< cn << endl; + + try{ + PersMDDColl objsSet( cn ); + + // To test PersMDDColl::printStatus( ) + // objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid; + } + delete objsIt; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } +} + diff --git a/mddmgr/test/test_extendobjs.cc b/mddmgr/test/test_extendobjs.cc new file mode 100644 index 0000000..73f82b3 --- /dev/null +++ b/mddmgr/test/test_extendobjs.cc @@ -0,0 +1,324 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_extendobjs.cc + * + * MODULE: cachetamgr + * + * PURPOSE: + * Extends the objects created by the test of directional tiling + * rasodmg/test/test_dir1 (the resulting objects have 4 times more + * products and 2 times more stores than the original ones ). + * Needed because rasodmg doens't support updating of MDDobjects + * at the time this was created. + * + * + * COMMENTS: + * none + * +*/ + +#define TEST_PROTECTED +#define TEST_PRIVATE + +#include <stdlib.h> +#include <iostream> + +#include "ulongtype.hh" + +#include "mddmgr/persmddcoll.hh" +#include "mddmgr/persmddobj.hh" +#include "mddmgr/perstile.hh" + +#include "mddmgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "oidif.hh" + +#include "raslib/rminit.hh" +#include "typefactory.hh" + +#include "mddif/dbmddobj.hh" +#include "mddif/dbmddcoll.hh" + +#include "mddbasetype.hh" +#include "mdddomaintype.hh" +#include "settype.hh" + + +/* + Global Variables +*/ +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +static char* O2DBName; +char *collName; +char defaultCollName[]= "ObjsContainer"; + +TransactionIf ta; + +/* + Functions +*/ + +// 2 - Populate collection with MDD objects +static void testConstructors( char* cn , int s, int p); + +// 3 - Retrieves an MDD collection with name cn and prints contents: +static void testAccessing( char* cn ); + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ +int +main( int argc, char** argv) +{ + // variables representing O2 database, ta and session + DatabaseIf database; + + if( argc < 2 ) { + cout << "Usage: test_persmddcoll <database> [collName]" << endl; + return -1; + } + O2DBName = strdup( argv[1] ); + if ( argc == 3 ) collName = strdup( argv[2] ); + else + collName = defaultCollName; + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + + + // connect to the database + cout << "Connecting to database " << O2DBName + << "..." << endl; + int errorDBOpen; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch( ...) + { + cout << "Caught Exception " << endl; + errorDBOpen = -6; + } + if ( errorDBOpen < 0 ) + { + cout << "Database doesn't exist. Create it new ... " << endl; + cout << "Creating new database " << O2DBName + << "..." << endl; + database.create( O2DBName, "TestSMSchema" ); + cout << "Connecting to database " << O2DBName + << "..." << endl; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch(...) + { + errorDBOpen = -6; + } + } + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + char c; + + for( int p = 0; p < 4; p++ ) + { + for ( int s = 0; s < 2 ; s++) + { + ta.begin( &database ); + cout << endl << "Populate collection " << s <<" " << p << " ..." << endl; + testConstructors( collName, s, p ); + cout <<"Transaction abort (A/a) or commit (default)? "; + cin >> c; + if ( c == 'A' || c == 'a' ) + { + ta.abort( ); + cout <<"End of Transaction Abort..."<<endl; + } + else + { + ta.commit( ); + cout <<"End of transaction commit... "<<endl; + } + } + } + + + ta.begin(&database ); + // read coll and print contents + cout << endl << "Read collection " << collName << " and print contents..." << endl; + testAccessing( collName ); + ta.commit( ); + cout <<"End of transaction commit... "<<endl; + + cout << endl << "Ending O2 session..." << endl; + database.close( ); + delete myAdmin; + + free( O2DBName ); + if ( collName != defaultCollName ) free( collName ); + return 0; + +} + +/************************************************************* + * Functions......: + * + * static void + * testConstructors( char* collName ) + * + ************************************************************/ +static void testConstructors( char* collName, int s, int p ) +{ + + const BaseType* mddType; + char* uLongCells; + + cout << "....testConstructors"<< endl; + + + PersMDDObj* accessedObj; + + try{ + PersMDDColl objsSet(collName); + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << endl << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + // accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid; + cout << endl << endl; + + mddType = accessedObj->getCellType( ); + + r_Minterval firstYear("[1:365,1:60,1:100]"); + + vector< Tile* >* firstYearTiles = accessedObj->intersect( firstYear ); + + for ( int j = 0; j < firstYearTiles->size( ); j++ ) + { + r_Minterval dom = (*firstYearTiles)[j]->getDomain( ); + +/* + for( int p = 0; p < 4; p++ ) + { + for ( int s = 0; s < 2 ; s++) + { +*/ + r_Point desl( (r_Range) 730, (p+1)*60, (s+1)* 100 ); + + r_Minterval newDom( dom.dimension( ) ); + newDom.intersection_of( dom, "[1:365,1:60,1:100]"); + newDom.translate( desl ); + cout << "dom" << dom << "newDom " << newDom << endl; + + int sz = mddType->getSize( ) * newDom.cell_count( ); + uLongCells = new char[sz]; + PersTile* tile1Obj1 = new PersTile( newDom, mddType, uLongCells ); + accessedObj->insertTile(tile1Obj1); + +/* + } + } + +*/ + } + delete firstYearTiles; + } + + delete objsIt; + + cout << "Release all " << endl; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout << "Error caught when opening collection" << endl; + } + +} + + +/************************************************************* + * Function......: testAccessing( char* cn ) + ************************************************************/ + +static void testAccessing( char* cn ) +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing collection "<< cn << endl; + + try{ + PersMDDColl objsSet( cn ); + + // To test PersMDDColl::printStatus( ) + // objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid; + } + delete objsIt; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } +} + diff --git a/mddmgr/test/test_mddjoin.cc b/mddmgr/test/test_mddjoin.cc new file mode 100644 index 0000000..c7ae617 --- /dev/null +++ b/mddmgr/test/test_mddjoin.cc @@ -0,0 +1,228 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_mddjoin.cc + * + * MODULE: example for making one tile out of a vector of + * Tiles + * + * COMMENTS: + * later has to be moved to the executor + * +*/ + +static const char rcsid[] = "@(#)blobif,test_mddops: $Id: test_mddjoin.cc,v 1.9 2002/09/03 14:46:50 coman Exp $"; + +#include <stdlib.h> +#include <iostream> +#include "ulongtype.hh" +#include "booltype.hh" +#include "mddmgr/persmddobj.hh" +#include "mddmgr/perstile.hh" +#include "mddmgr/transtile.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "raslib/rminit.hh" +#include "typefactory.hh" + +// global variable for AdminIf because of O2 d_Session::begin() +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +static char O2BenchDBName[] = "NorbertBase"; +static char O2BenchSchemaName[] = "NorbertSchema"; + +static void testOperations( DatabaseIf myDB ); + +static BaseType* myType; +static BaseType* boolType; + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ + +int +main( int /* argc */, char** argv) +{ + // variables representing O2 database, ta and session + DatabaseIf database; + TransactionIf ta; + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + + // connect to the database + cout << "Connecting to database " << O2BenchDBName + << "..." << endl; + database.open( O2BenchDBName ); + ta.begin(&database); + + // only possible after AdminIf::instance on Sun! + myType = TypeFactory::mapType("ULong"); + boolType = TypeFactory::mapType("Bool"); + + testOperations( database ); + + ta.commit(); + cout << "Ending O2 session..." << endl; + database.close(); + delete myAdmin; +} + +void +printAllTiles(const MDDObj* mdd) +{ + // contains all tiles of MDD + vector<Tile*>* allTiles; + // iterator + vector<Tile*>::iterator tileIt; + // domains of a tile + r_Minterval tileDom; + + // domain of MDD object + r_Minterval dom; + dom = mdd->getCurrentDomain(); + + // get all tiles of result MDD + allTiles = mdd->intersect(dom); + + // and iterate over them + tileIt = allTiles->begin(); + while (tileIt != allTiles->end()) + { + tileDom = (*tileIt)->getDomain(); + cout << "Domain of Tile: "; + tileDom.print_status(); + cout << endl; + + cout << "Tile: " << endl; + (*tileIt)->printStatus(); + cout << endl; + + tileIt++; + } +} + +/************************************************************* + * Function......: testConstructors( DatabaseIf myDB ) + * + * Arguments.....: + * myDB: database to use (should be opened) + * Return value..: none + * Description...: constructs BLOBTiles and inserts them + * in root collection. + ************************************************************/ + +static void testOperations( DatabaseIf /* myDB */) +{ + unsigned long cell = 1000; + + ULongType ulongtype; + BaseType* type = &ulongtype; + Tile* res; + Tile* boolTile; + + vector<Tile*>* result = new vector<Tile*>; + vector<Tile*>::iterator tileIt; + Tile* bigTile; + + cout << "Creating Tile: "; + r_Minterval bigDom = + r_Minterval(3) << r_Sinterval(1l,10l) << r_Sinterval(1l,10l) + << r_Sinterval(1l,10l); + bigDom.print_status(); + cout << endl; + + bigTile = new PersTile(bigDom, type, (char*)&cell); + + r_Minterval smallDom + = r_Minterval(3) << r_Sinterval(1l,6l) << r_Sinterval(1l,6l) + << r_Sinterval(1l,6l); + + cout << "Splitting it into "; + smallDom.print_status(); + cout << " tiles." << endl; + + result = bigTile->splitTile(smallDom); + + cout << "Result tiles: " << endl; + // and iterate over them + tileIt = result->begin(); + while (tileIt != result->end()) + { + cout << " Domain of Tile " << (tileIt - result->begin()) << ": "; + ((*tileIt)->getDomain()).print_status(); + cout << endl; + + tileIt++; + } + + cout << "Joining the Tiles again:" << endl; + + r_Minterval proj = + r_Minterval(3) << r_Sinterval(2l,9l) << r_Sinterval(2l,9l) + << r_Sinterval(2l,9l); + + res = new TransTile(result, proj ); + + cout << " Result MDD equals original MDD: "; + boolTile = new TransTile(res->getDomain(), boolType); + cout << "Domain of result Tile: "; + (res->getDomain()).print_status(); + cout << endl; + res->printStatus(); + boolTile->execBinaryOp(Ops::OP_EQUAL, proj, + res, proj, + bigTile, proj); + + char init = 1; + + cout << "Checking if Tile are equal: "; + cout << (int)(*(boolTile->execCondenseOp(Ops::OP_ALL, + res->getDomain(), + &init ))) << endl; + + cout << "Creating a trimmed, projected 2-D Tile out of the Tile:" << endl; + set<r_Dimension, less<r_Dimension> >* projSet = + new set<r_Dimension, less<r_Dimension> >; + projSet->insert(1); + + r_Minterval projDom = + r_Minterval(3) << r_Sinterval(2l, 9l) << r_Sinterval(5l, 5l) + << r_Sinterval(2l, 9l); + + Tile* projectedTile = new TransTile(res, projDom, projSet); + + projectedTile->printStatus(); + + cout << endl; +} diff --git a/mddmgr/test/test_mddobj.cc b/mddmgr/test/test_mddobj.cc new file mode 100644 index 0000000..5bb70c0 --- /dev/null +++ b/mddmgr/test/test_mddobj.cc @@ -0,0 +1,473 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_mddobj.cc + * + * MODULE: test for mddobj of mddmgr + * + * COMMENTS: + * in order to compile this test program, getDBMDDObjId from + * PersMDDObj has to be made public, which is not the normal + * and expected case. + * +*/ + +#include <stdlib.h> +#include <iostream> +#include "mddmgr/perstile.hh" +#include "ulongtype.hh" +#include "mddmgr/persmddobj.hh" +#include "mddmgr/persmddcoll.hh" +#include "mddmgr/mddcoll.hh" +#include "mddmgr/mddcolliter.hh" + + +#include "raslib/rminit.hh" +RMINITGLOBALS('C') + +#include "mddif/dbmddobj.hh" +#include "raslib/minterval.hh" +#include "raslib/sinterval.hh" + +// perhaps used later +static char O2BenchDBName[] = "PaulaRasDaBase"; +static char O2BenchSchemaName[] = "SMRasDaSchema"; + +static void ClearDB( d_Database &DB ); +static void testAccessing(); +static void testConstructors(); +static void testSearch(); +static void testGetFunctions(); +static void printInterval(r_Minterval* inter); +void printMemInfo( ); + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ +int +main( int argc, char** argv) +{ + // variables representing O2 database, ta and session + d_Session session; + d_Database database; + d_Transaction ta; + + + // initialize the O2 session + cout << "Initializing O2 session..." << endl; + session.set_default_env(); + if (session.begin(argc, argv)){ + cerr << "Something wrong to start o2" << endl; + exit(1); + } + + // clear the DB (in case the base already exists) + cout << "Deleting TestMDDObjContainer of database..." << endl; + database.open( O2BenchDBName); + ta.begin( ); + Handle collHandle = 0; + collHandle = o2_get_root( "TestMDDObjContainer" ); + if ( collHandle ) + { + // I don't know if this is needed. + o2_unref_handle ( collHandle ); + database.destroy_persistent_root( "TestMDDObjContainer" ); + } + ta.commit( ); + + // connect to the database + cout << "Connecting to database " << O2BenchDBName + << "..." << endl; + database.open( O2BenchDBName ); + + // create root collection + cout << "Creating root collection..." << endl; + ta.begin(); + database.create_persistent_root( "TestMDDObjContainer", + "d_List< d_Ref<DBMDDObj> >", + OL_CONSTANT); + ta.commit(); + + // create indexes and put them in TestMDDObjContainer + cout << "Create objects and put in TestMDDObjContainer..." << endl; + ta.begin(); + testConstructors(); + ta.commit(); + + // read index and print contents + cout << "Read objects and print contents..." << endl; + ta.begin(); + testAccessing(); + ta.commit(); + + // test search operation and print contents + cout << "Search a rectangular region and print contents..." << endl; + ta.begin(); + testSearch(); + ta.commit(); + + /* + // test get member functions + cout << "Get * from object and print result..." << endl; + ta.begin(); + testGetFunctions(); + ta.commit(); + */ + + cout << "Ending O2 session..." << endl; + session.end(); + database.close(); +} + +/************************************************************* + * Function......: testConstructors() + * + * Arguments.....: none + * Return value..: none + * Description...: constructs Indices and inserts them + * in root collection. + ************************************************************/ + +static void testConstructors() +{ + ULongType anyType; + char anyCell[] = {0,0,0,0}; + unsigned long MDDObj1sz = 0; + + cout << "....testConstructors"<< endl; + + // read root object + d_List< d_Ref<DBMDDObj> > objsList("TestMDDObjContainer"); + + // create MDD Object + cout << " mddObj1" << endl; + + cout << " tile 1 = nil, 10-12, 20-24 "<< endl; + r_Sinterval limits1Obj1(10l,12l); + r_Sinterval limits2Obj1(20l,24l); + r_Minterval dom(2); + dom << limits1Obj1 << limits2Obj1; + PersTile* tile1Obj1 = new PersTile( dom, &anyType, (const char*) anyCell); + MDDObj1sz += tile1Obj1->getSize( ); + PersMDDObj* MDDObj1=new PersMDDObj( dom, "ULong"); + MDDObj1->insertTile(tile1Obj1); + + cout << " tile 2 = nil, 0-400, 22-24 "<< endl; + dom[0].set_interval(0l,400l); + dom[1].set_interval(22l,24l); + PersTile* tile2Obj1 = new PersTile( dom, &anyType, (const char*) anyCell); + + MDDObj1sz += tile1Obj1->getSize( ); + // MDDObj1->insertTile(tile2Obj1); + + cout << " tile 3 = nil, 0-600, 10-1000 "<< endl; + dom[0].set_interval(0l,600l); + dom[1].set_interval(10l,1000l); + PersTile* tile3Obj1= new PersTile( dom, &anyType, (const char*) anyCell); + MDDObj1sz += tile3Obj1->getSize( ); + // MDDObj1->insertTile(tile3Obj1); + + vector<Tile*>* newTiles = new vector< Tile* >; + newTiles->push_back(tile2Obj1); + newTiles->push_back(tile3Obj1); + MDDObj1->insertTiles(*newTiles); + delete newTiles; + + objsList.insert_element_last(MDDObj1->getDBMDDObjId()); + + cout << "Size of MDDObj1 : " << MDDObj1sz << " - " << MDDObj1sz/1024 << endl; + printMemInfo( ); + cout << "Delete MDDObj1 ..........." << endl; + delete MDDObj1; + printMemInfo( ); + cout << endl << endl; + + + unsigned long MDDObj2sz = 0; + cout << " mddObj2 "<< endl; + cout << " tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + PersTile* tile1Obj2 = new PersTile( dom2, &anyType, (const char*) anyCell); + MDDObj2sz += tile1Obj2->getSize( ); + PersMDDObj* MDDObj2 = new PersMDDObj( dom2, "ULong"); + MDDObj2->insertTile(tile1Obj2); + + cout << " tile 2 = nil, 20-39, 60-79, 60-89 "<< endl; + dom2[0].set_interval(20l,39l); + dom2[1].set_interval(60l,79l); + dom2[2].set_interval(60l,89l); + PersTile* tile2Obj2 = new PersTile( dom2, &anyType, (const char*) anyCell); + MDDObj2sz += tile2Obj2->getSize( ); + + MDDObj2->insertTile(tile2Obj2); + + objsList.insert_element_last(MDDObj2->getDBMDDObjId()); + + cout << "Size of MDDObj2 : " << MDDObj2sz << " - " << MDDObj2sz/1024 << endl; + printMemInfo( ); + cout << "Delete MDDObj2 ..........." << endl; + delete MDDObj2; + printMemInfo( ); + cout << endl << endl; +} + +/************************************************************* + * Function......: testAccessing() + * + * Arguments.....: none + * Return value..: none + * Description...: reads DirTilesIx's and shows contents + ************************************************************/ + +static void testAccessing() +{ + DBMDDObjId accessedObj; + + cout << "....testAccessing"<<endl; + + // read root object + d_List< DBMDDObjId > objsList("TestMDDObjContainer"); + // used for iterating + d_Iterator< DBMDDObjId > objsIt = objsList.create_iterator(); + + for( int i = 1 ; objsIt.not_done(); i++, objsIt.advance()) + { + accessedObj = objsIt.get_element(); + cout << " --"<<i<<". MDD object in list:" << endl; + accessedObj->printStatus(); + cout << " -- CellTypeName: " << accessedObj->getCellTypeName( ) << endl; + } + +} + +/************************************************************* + * Function......: testSearch() + * + * Arguments.....: none + * Return value..: none + * Description...: reads Index's and shows contents + ************************************************************/ + +static void testSearch() +{ + + PersMDDColl mddObjsColl ( "TestMDDObjContainer" ); + MDDObj* accessedObj; + MDDCollIter* objsIt = mddObjsColl.createIterator( ); + + +/* + DBMDDObjId accessedObj; + + cout << "....testSearch"<<endl; + + // read root object + d_List< DBMDDObjId > objsList("TestMDDObjContainer"); + // used for iterating + d_Iterator< DBMDDObjId > objsIt = objsList.create_iterator(); + +*/ + + for( int i = 0 ; objsIt->notDone(); i++, objsIt->advance()) + { + + accessedObj = objsIt->getElement(); + + if (i == 0 || i == 1) + { + vector< Tile* >* entriesList = 0; + + r_Minterval searchInt1(2); + r_Minterval searchInt2(3); + + printMemInfo( ); + + cout << " -- " << i+1 << ". MDD object in list. Search for:"; + switch (i) { + case 0: searchInt1[0].set_interval(10l,20l); + searchInt1[1].set_interval(10l,30l); + cout << " 10-20, 10-30" << endl; + entriesList = accessedObj->intersect(searchInt1); + break; + case 1: searchInt2[0].set_interval(10l,20l); + searchInt2[1].set_interval(10l,30l); + searchInt2[2].set_interval(40l,50l); + cout << " 10-20, 10-30, 40-50" <<endl; + entriesList = accessedObj->intersect(searchInt2); + break; + default: break; + } + + printMemInfo( ); + + cout << " -- Search result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile printStatus"; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" << tileInterval[i].high() <<", "; + cout << endl << " Access contents " ; + char* tileContents = ( *entryIt )->getContents( ); + + cout << endl; + + entryIt++; + } + + printMemInfo( ); + cout << " Release entriesList " << endl; + + delete entriesList; + } + } + delete objsIt; +} + +/************************************************************* + * Function......: testGetFunctions() + * + * Arguments.....: none + * Return value..: none + * Description...: reads Index's and shows contents + ************************************************************/ + +static void testGetFunctions() +{ + + MDDObj* accessedObj; + PersMDDColl persMDDObjsColl ( "TestMDDObjContainer" ); + MDDColl* mddObjsColl = &persMDDObjsColl; + + MDDCollIter* objsIt = mddObjsColl->createIterator( ); + + vector< Tile* >* entriesList; + + cout << "....testGetTiles"<<endl; + + for( int i = 0 ; objsIt->notDone(); i++, objsIt->advance()) + { + r_Minterval currDom; + r_Minterval defDom; + + cout << " " << i << ". Object" << endl; + accessedObj = objsIt->getElement( ); + + defDom = accessedObj->getDefinitionDomain( ); + cout << " GetDefinitionDomain result: "; + printInterval( &defDom ); + cout << endl; + + currDom = accessedObj->getCurrentDomain( ); + cout << " GetCurrentDomain result: "; + printInterval( &currDom ); + cout << endl; + + entriesList = accessedObj->getTiles( ); + cout << " -- GetTiles result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile printStatus"; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" << tileInterval[i].high() <<", "; + cout << endl; + entryIt++; + } + delete entriesList; + } + delete objsIt; + mddObjsColl->releaseAll( ); +} + +/************************************************************* + * Function......: + * + * Arguments.....: + * Return value..: + * Description...: + ************************************************************/ + +static void printInterval(r_Minterval* inter) +{ + for (int i = 0; i <inter->dimension( ); i++) + { + (*inter)[i].is_low_fixed( )? cout << (*inter)[i].low( ): cout << "*"; + cout << " - "; + (*inter)[i].is_high_fixed( )? cout << (*inter)[i].high( ): cout << "*"; + cout << ","; + } +} + +/************************************************************* + * Function......: + * + * Arguments.....: + * Return value..: + * Description...: + ************************************************************/ + +void printMemInfo( ) +{ + + + // allows to store values in the program + struct mallinfo meminfo = mallinfo(); + + cout << " Memory Usage Information : bytes - Kbytes" ; + cout << endl; + + cout << " space in arena : " << meminfo.arena << " - " << meminfo.arena/1024 << endl; + cout << " number of small blocks : " << meminfo.smblks << " - " << meminfo.smblks/1024 << endl; + cout << " number of ordinary blocks : " << meminfo.ordblks << " - " << meminfo.ordblks/1024 << endl; + cout << " space in free ordinary blocks : " << meminfo.fordblks << " - " << meminfo.fordblks/1024 << endl; + cout << " space in used ordinary blocks : " << meminfo.uordblks << " - " << meminfo.uordblks/1024 << endl; + + // cout << "additional space from last call: " << meminfo.uordblks - memUsed < < endl; + +} + + diff --git a/mddmgr/test/test_mddops.cc b/mddmgr/test/test_mddops.cc new file mode 100644 index 0000000..5a81bc8 --- /dev/null +++ b/mddmgr/test/test_mddops.cc @@ -0,0 +1,335 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_mddops.cc + * + * MODULE: example for executing operations on MDDs + * + * PURPOSE: + * makes operations on MDDs or parts of them + * + * COMMENTS: + * later has to be moved to the executor + * +*/ + +static const char rcsid[] = "@(#)blobif,test_mddops: $Id: test_mddops.cc,v 1.10 2002/09/03 14:46:50 coman Exp $"; + +#include <stdlib.h> +#include <iostream> +#include "o2lib_CC.hxx" +#include "o2template_CC.hxx" +#include "ulongtype.hh" +#include "mddmgr/persmddobj.hh" +#include "mddmgr/perstile.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "raslib/rminit.hh" +#include "typefactory.hh" + + +// global variable for AdminIf because of O2 d_Session::begin() +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +static char O2BenchDBName[] = "DemoBase"; +static char O2BenchSchemaName[] = "RasDaSchema"; + +static void testOperations( DatabaseIf myDB ); + +BaseType* myType; +static long myCell = 0; + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ + +int +main( int argc, char** argv) +{ + // variables representing O2 database, ta and session + DatabaseIf database; + TransactionIf ta; + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + + AdminIf* myAdmin = AdminIf::instance(); + + // only possible after AdminIf::instance on Sun! + myType = TypeFactory::mapType("ULong"); + + // connect to the database + cout << "Connecting to database " << O2BenchDBName + << "..." << endl; + database.open( O2BenchDBName ); + + testOperations( database ); + + cout << "Ending O2 session..." << endl; + database.close(); + delete myAdmin; +} + +void +printAllTiles(const MDDObj* mdd) +{ + // contains all tiles of MDD + vector<Tile*>* allTiles; + // iterator + vector<Tile*>::iterator tileIt; + // domains of a tile + r_Minterval tileDom; + + // domain of MDD object + r_Minterval dom; + dom = mdd->getCurrentDomain(); + + // get all tiles of result MDD + allTiles = mdd->intersect(dom); + + // and iterate over them + tileIt = allTiles->begin(); + while (tileIt != allTiles->end()) + { + tileDom = (*tileIt)->getDomain(); + cout << "Domain of Tile: "; + tileDom.print_status(); + cout << endl; + + cout << "Tile: " << endl; + (*tileIt)->printStatus(); + cout << endl; + + tileIt++; + } +} + +/************************************************************* + * Function......: testOperations( DatabaseIf myDB ) + * + * Arguments.....: + * myDB: database to use (should be opened) + * Return value..: none + * Description...: constructs BLOBTiles and inserts them + * in root collection. + ************************************************************/ + +MDDObj* +execBinaryOp( Ops::OpType op, + const MDDObj* op1, const r_Minterval& areaOp1, + const MDDObj* op2, const r_Minterval& areaOp2 ) +{ + // contains all tiles of op1 + vector<Tile*>* allTilesOp1; + // contains all tiles of op2 which intersect a given op1 Tile + // in the relevant area. + vector<Tile*>* intersectTilesOp2; + // iterators for tiles of the MDDs + vector<Tile*>::iterator tileOp1It; + vector<Tile*>::iterator intersectTileOp2It; + // domain of tile of Op1 + r_Minterval tileOp1Dom; + // domain of tile of Op2 + r_Minterval tileOp2Dom; + // intersection of domains in relevant area. + r_Minterval intersectDom; + // pointer to generated result tile + PersTile* resTile; + // MDDObj for result + PersMDDObj* mddres; + // translations between the two areas + r_Point offset12(areaOp1.dimension()); + r_Point offset21(areaOp1.dimension()); + // dummy + r_Minterval dummy; + + // calculate translations + r_Point originOp1 = areaOp1.get_origin(); + r_Point originOp2 = areaOp2.get_origin(); + for(r_Dimension i = 0; i<areaOp1.dimension(); i++) + { + offset12[i] = originOp2[i] - originOp1[i]; + offset21[i] = originOp1[i] - originOp2[i]; + } + + // create MDDObj for result (type has later to be + // retrieved from one of the operands) + mddres = new PersMDDObj( areaOp1, "ULong" ); + + // get all tiles in relevant area of MDD op1 + allTilesOp1 = op1->intersect(areaOp1); + + // and iterate over them + tileOp1It = allTilesOp1->begin(); + while (tileOp1It != allTilesOp1->end()) + { + // domain of the op1 tile + tileOp1Dom = (*tileOp1It)->getDomain(); + + // intersect the tile with MDD op2 (including translation) + intersectTilesOp2 = + op2->intersect(tileOp1Dom.create_translation(offset12)); + + // iterate over intersecting tiles + intersectTileOp2It = intersectTilesOp2->begin(); + while (intersectTileOp2It != intersectTilesOp2->end()) + { + tileOp2Dom = (*intersectTileOp2It)->getDomain(); + + // the relevant domain is the intersection of the + // domains of the two tiles with the relevant area. + intersectDom = tileOp1Dom.create_intersection( + tileOp2Dom.create_translation(offset21)); + intersectDom.intersection_with(areaOp1); + + // Creating tile for result. Type should later come from + // operand. + resTile = new PersTile(intersectDom, myType); + + // carry out operation on the relevant area of the tiles + resTile->execBinaryOp(op, intersectDom, + (*tileOp1It), intersectDom, + (*intersectTileOp2It), + intersectDom.create_translation(offset12)); + + // insert Tile in result tile + mddres->insertTile(resTile); + + intersectTileOp2It++; + } + tileOp1It++; + } + + return mddres; +} + +/************************************************************* + * Function......: testConstructors( DatabaseIf myDB ) + * + * Arguments.....: + * myDB: database to use (should be opened) + * Return value..: none + * Description...: constructs BLOBTiles and inserts them + * in root collection. + ************************************************************/ + +// function for creating demo tiles + +Tile* +create2DTile( long xmin, long xmax, long ymin, long ymax, + BaseType* type ) +{ + // is copied anyway in constructor + unsigned long cell = 0x10000L; + + r_Sinterval s1(xmin, xmax); + r_Sinterval s2(ymin, ymax); + r_Minterval dom(2); + dom << s1 << s2; + cout << " Domain of Tile "; + dom.print_status(); + cout << endl; + return new PersTile( dom, type, (char*)&cell); +} + +static void testOperations( DatabaseIf myDB ) +{ + Tile* aTile; + ULongType ulongtype; + BaseType* type = &ulongtype; + MDDObj* res; + + r_Sinterval limits1(1l,10l); + r_Sinterval limits2(1l,10l); + r_Minterval dom(2); + dom << limits1 << limits2; + + r_Sinterval oplimits1(2l,9l); + r_Sinterval oplimits2(2l,9l); + r_Minterval opdom(2); + opdom << oplimits1 << oplimits2; + + r_Sinterval limits21(11l,20l); + r_Sinterval limits22(11l,20l); + r_Minterval dom2(2); + dom2 << limits21 << limits22; + + r_Sinterval oplimits21(12l,19l); + r_Sinterval oplimits22(12l,19l); + r_Minterval opdom2(2); + opdom2 << oplimits21 << oplimits22; + + // create MDD Object for 1st operand + cout << "MDD Op1" << endl; + + PersMDDObj* mddop1 = new PersMDDObj( dom, "ULong" ); + + cout << " Tile 1 [ 1:5, 1:10 ] " << endl; + aTile = create2DTile(1, 5, 1, 10, type); + mddop1->insertTile(aTile); + + cout << " Tile 2 [ 6:10, 1:5 ] " << endl; + aTile = create2DTile(6, 10, 1, 5, type); + mddop1->insertTile(aTile); + + cout << " Tile 3 [ 6:10, 6:10 ] " << endl; + aTile = create2DTile(6, 10, 6, 10, type); + mddop1->insertTile(aTile); + + mddop1->printStatus(); + + // create MDD Object for 2nd operand + cout << "MDD Op2" << endl; + + PersMDDObj* mddop2 = new PersMDDObj( dom2, "ULong" ); + + cout << " Tile 1 [ 11:17, 11:15 ] " << endl; + aTile = create2DTile(11, 17, 11, 15, type); + mddop2->insertTile(aTile); + + cout << " Tile 2 [ 11:17, 16:20 ] " << endl; + aTile = create2DTile(11, 17, 16, 20, type); + mddop2->insertTile(aTile); + + cout << " Tile 3 [ 18:20, 11:20 ] " << endl; + aTile = create2DTile(18, 20, 11, 20, type); + mddop2->insertTile(aTile); + + mddop2->printStatus(); + + res = execBinaryOp(Ops::OP_PLUS, mddop1, opdom, mddop2, opdom2); + + // output result (cast should not be necessary!) + ((PersMDDObj*)res)->printStatus(); + printAllTiles(res); + +} diff --git a/mddmgr/test/test_persmddcoll.cc b/mddmgr/test/test_persmddcoll.cc new file mode 100644 index 0000000..1a08546 --- /dev/null +++ b/mddmgr/test/test_persmddcoll.cc @@ -0,0 +1,768 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ + /** + * SOURCE: test_persmddcoll.cc + * + * MODULE: test for mddobj of cachetamgr + * + * PURPOSE: + * creates a persistent collection of objects and iterators. + * + * COMMENTS: + * none + * +*/ + +#include "mymalloc/mymalloc.h" + +#include <stdlib.h> +#include <iostream> + +#define TEST_PROTECTED +#define TEST_PRIVATE + + +#include "ulongtype.hh" + +#include "tilemgr/persmddcoll.hh" +#include "tilemgr/persmddobj.hh" +#include "tilemgr/perstile.hh" + +#include "tilemgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" + +#include "raslib/rminit.hh" +#include "typefactory.hh" + +#include "mddbasetype.hh" +#include "mdddomaintype.hh" +#include "settype.hh" + +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +static char* O2DBName; +char *collName; +char defaultCollName[]= "ObjsContainer"; +static int createMDDColl( const char* collName, DatabaseIf* db ); +static void ClearDB( d_Database &DB ); +static void testAccessing( ); +static void testConstructors( ); +static void testRemove( ); +static void testSearch( ); +static void testGetFunctions( ); +static void testLaterInsert( ); +PersTile* createPersTile( const r_Minterval& dom, const BaseType* type ); +static int openCreateDB( const char* O2DBName, DatabaseIf& database ); + +TransactionIf ta; + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ + +int +main( int argc, char** argv) +{ + // variables representing O2 database, ta and session + DatabaseIf database; + DatabaseIf database1; + + if( argc < 2 ) { + cout << "Usage: test_persmddcoll <database> [collName]" << endl; + return -1; + } + O2DBName = argv[1]; + if ( argc == 3 ) collName = argv[2]; + else + collName = defaultCollName; + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + + // connect to the database + cout << "Connecting to database " << O2DBName + << "..." << endl; + + int errorDBOpen = openCreateDB( O2DBName, database ); + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + + + cout << endl << "Deleting root object from the database ..." <<endl; + ta.begin( &database ); + int i = PersMDDColl::destroyRoot( collName, &database ); + cout << " i == " << i << endl; + cout << " &database = " << long( &database) << endl; + // database.destroyRootObj( collName ); + ta.commit( ); + + + ta.begin( &database); + createMDDColl( collName, &database ); + ta.commit( ); + + // create collection and objects and put them in the collection + cout << endl << "Populate collection ..." << endl; + ta.begin( &database ); + testConstructors( ); + ta.commit( ); + + // read coll and print contents + cout << endl << "Read collection and print contents..." << endl; + ta.begin( &database ); + testAccessing( ); + ta.commit( ); + + // connect to the database + cout << "Closing database " << O2DBName + << "..." << endl; + database.close( ); + + // connect to the database + cout << endl << "Connecting to database SecondBase " + << "..." << endl; + // database1.open( "SecondBase" ); + + errorDBOpen = openCreateDB( "SecondBase", database1 ); + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening database SecondBase " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + // read coll and print contents + cout << endl << "Read collection and print contents..." << endl; + cout << "Read only? "<< endl; + int ro; + cin >> ro; + ta.begin( &database1, ro ); + cout << endl << " testAccessing before "<<endl; + testAccessing( ); + ta.commit( ); + +/* + // add some new tiles + cout << endl << "Insert more tiles to the existing objects" << endl; + ta.begin( &database ); + testLaterInsert( ); + ta.commit( ); + + // read coll and print contents + cout << endl << "Read collection and print contents..." << endl; + ta.begin( &database ); + testAccessing( ); + ta.commit( ); + + + // search for an interval + cout << endl << "Test region search ..." << endl; + ta.begin( &database ); + testSearch( ); + ta.commit( ); + + // search for an interval + cout << endl << "Test get functions of MDDObj ..." << endl; + ta.begin( &database ); + testGetFunctions( ); + ta.commit( ); + + // test remove operation and print contents + cout << endl << "Test remove ..." << endl; + ta.begin( &database ); + testRemove( ); + ta.commit( ); + + // read coll and print contents + cout << endl << "Read collection and print contents..." << endl; + ta.begin( &database ); + testAccessing( ); + ta.commit( ); +*/ + cout << endl << "Ending O2 session..." << endl; + database.close( ); + delete myAdmin; +} +/************************************************************* + * Function......: testConstructors() + * + ************************************************************/ +PersTile* +createPersTile( const r_Minterval& dom, const BaseType* type ) +{ + char* cells = (char*)mymalloc(dom.cell_count() * type->getSize()); + PersTile* t = new PersTile( dom, type, cells ); + return t; +} + +/************************************************************* + * Function......: testConstructors() + * + * Arguments.....: none + * Return value..: none + * Description...: constructs Indices and inserts them + * in root collection. + ************************************************************/ + +static void testConstructors() +{ + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + const BaseType* boolTypeObj = TypeFactory::mapType("Bool"); + char* uLongCells; + char* boolCells; + + const MDDBaseType* mType1 = + (const MDDBaseType* ) TypeFactory::mapMDDType("TestSMDomainType2D"); + const MDDBaseType* mType2 = + (const MDDBaseType* ) TypeFactory::mapMDDType("TestSMDomainType3D"); + + cout << "....testConstructors"<< endl; + + + // read root object + + try { + PersMDDColl objsSet1("WrongName"); + } + catch (...) + { + cout <<"Error caught ................."<< endl; + } + + PersMDDColl objsSet(collName); + +/* + // test for crash of O2 iterator reset in case the collection is empty + cout << "createIterator " << endl; + MDDCollIter* it = objsSet.createIterator( ); + // cout << " Iterator not Done returns " << it->notDone( ); + // if ( it->notDone( ) ) it->reset( ); + cout << " Iterator reset " << endl; + it->reset( ); + // cout << " Testing advance on an empty collection" << endl; + // it->advance( ); // OK + // cout <<" Testing get_element on an empty collection" << endl; + // MDDObj* testIterMDDObj = it->getElement( ); // FATAL ERROR + // cout <<" get_element returned " << testIterMDDObj << endl; +*/ + + // create MDD Object 1 + + cout << " mddObj1" << endl; + cout << " tile 1 = nil, 10-12, 20-24 "<< endl; + r_Sinterval limits1Obj1(10l,12l); + r_Sinterval limits2Obj1(20l,24l); + r_Minterval dom(2); + dom << limits1Obj1 << limits2Obj1; + + + r_Minterval tmpInt = *( ( MDDDomainType* ) mType1 )->getDomain( ); + PersMDDObj* MDDObj1 = new PersMDDObj( mType1, tmpInt ); + + PersTile* tile1Obj1 = createPersTile( dom, ulongTypeObj); + MDDObj1->insertTile(tile1Obj1); + + cout << " tile 2 = nil, 0-400, 22-24 "<< endl; + dom[0].set_interval(0l,400l); + dom[1].set_interval(22l,24l); + PersTile* tile2Obj1 = createPersTile( dom, ulongTypeObj); + MDDObj1->insertTile(tile2Obj1); + + cout << " tile 3 = nil, 0-600, 10-1000 "<< endl; + dom[0].set_interval(0l,600l); + dom[1].set_interval(10l,1000l); + PersTile* tile3Obj1 = createPersTile( dom, ulongTypeObj); + MDDObj1->insertTile(tile3Obj1); + + cout << " MDDObj1 == isPersistent:" << MDDObj1->isPersistent( )<< ";" ; + MDDObj1->printStatus( ); + cout << endl; + + objsSet.insert(MDDObj1); + + + // create MDD Object + + cout << " mddObj2 "<< endl; + cout << " tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + // PersMDDObj* MDDObj2 = new PersMDDObj( dom2, "Bool"); + + tmpInt = *( ( MDDDomainType* ) mType2 )->getDomain( ); + PersMDDObj* MDDObj2 = new PersMDDObj( mType2, tmpInt ); + + PersTile* tile1Obj2 = createPersTile( dom2, boolTypeObj); + MDDObj2->insertTile( tile1Obj2 ); + + cout << " tile 2 = nil, 20-39, 60-79, 60-89 "<< endl; + dom2[0].set_interval(20l,39l); + dom2[1].set_interval(60l,79l); + dom2[2].set_interval(60l,89l); + PersTile* tile2Obj2 = createPersTile( dom2, boolTypeObj); + + MDDObj2->insertTile(tile2Obj2); + + cout << " MDDObj2 == isPersistent:" << MDDObj2->isPersistent( )<< ";" ; + MDDObj2->printStatus( ); + cout << endl; + + objsSet.insert(MDDObj2); + + objsSet.releaseAll( ); + +} + +/************************************************************* + * Function......: testAccessing() + * + * Arguments.....: none + * Return value..: none + * Description...: reads DirTilesIx's and shows contents + ************************************************************/ + +static void testAccessing() +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing"<<endl; + try{ + PersMDDColl objsSet(collName); + + // To test PersMDDColl::printStatus( ) + // objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + cout << i<<". MDD object in set:" << endl; + accessedObj->printStatus(); + cout << endl << endl; + } + delete objsIt; + objsSet.releaseAll( ); + } + catch(...) + { + cout << "Error opening collection !!!! "<<endl; + exit(-1); + } +} + +/************************************************************* + * Function......: testLaterInsert() + * + * Description...: + ************************************************************/ + +static void testLaterInsert() +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing"<<endl; + + PersMDDColl objsSet(collName); + + // To test PersMDDColl::printStatus( ) + // objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + + PersTile *t, *t2, *t3; + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + switch( accessedObj->getDimension( ) ) + { + case 2 : + t2 = new PersTile( r_Minterval("[40:60,80:100]"), + accessedObj->getCellType( ) ); + t = t2; + break; + case 3 : + t3 = new PersTile(r_Minterval("[40:60,80:100,0:20]"), + accessedObj->getCellType( ) ); + t = t3; + break; + default: + cout << "Error Dimensionality not expected" << endl; + break; + } + accessedObj->insertTile(t); + cout << i<<". MDD object in set:" << endl; + accessedObj->printStatus(); + cout << endl << endl; + } + delete objsIt; + objsSet.releaseAll( ); +} + + +/************************************************************* + * Function......: testSearch() + * + * Arguments.....: none + * Return value..: none + * Description...: reads Index's and shows contents + ************************************************************/ + +static void testSearch() +{ + + MDDObj* accessedObj; + + cout << "....testSearch"<<endl; + + PersMDDColl objsSet(collName); + + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = objsIt->getElement(); + + cout << "Accessed Object " << endl; + accessedObj->printStatus( ); + cout << endl; + + if (i == 1 || i == 2) + { + r_Minterval searchInt1(2); + r_Minterval searchInt2(3); + vector< Tile* >* entriesList; + + cout << " -- " << i << ". MDD object in list. Search for:"; + switch (i) { + case 1: searchInt1[0].set_interval(10l,20l); + searchInt1[1].set_interval(10l,30l); + cout << " 10-20, 10-30" << endl; + entriesList = accessedObj->intersect(searchInt1); + break; + case 2: searchInt2[0].set_interval(10l,20l); + searchInt2[1].set_interval(10l,30l); + searchInt2[2].set_interval(40l,50l); + cout << " 10-20, 10-30, 40-50" <<endl; + entriesList = accessedObj->intersect(searchInt2); + break; + default: break; + } + cout << " -- Search result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile printStatus"; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" + << tileInterval[i].high() <<", "; + cout << endl; + + entryIt++; + } + delete entriesList; + } + } + delete objsIt; + objsSet.releaseAll( ); +} + +/************************************************************* + * Function......: testGetFunctions() + * + * Arguments.....: none + * Return value..: none + * Description...: reads Index's and shows contents + ************************************************************/ + +static void testGetFunctions() +{ + PersMDDObj* accessedObj; + + cout << "....testGetFunctions"<<endl; + + PersMDDColl objsSet(collName); + + MDDCollIter* objsIt = objsSet.createIterator( ); + + vector< Tile* >* entriesList; + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + r_Minterval currDom; + r_Minterval defDom; + + cout << " " << i << ". Object" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + + + defDom = accessedObj->getDefinitionDomain( ); + cout << " GetDefinitionDomain result: "; + defDom.print_status( ); + cout << endl; + + currDom = accessedObj->getCurrentDomain( ); + cout << " GetCurrentDomain result: "; + currDom.print_status( ); + cout << endl; + + entriesList = accessedObj->getTiles( ); + cout << " -- GetTiles result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile "; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" << tileInterval[i].high() <<", "; + cout << endl; + entryIt++; + } + delete entriesList; + } + delete objsIt; + objsSet.releaseAll( ); +} + +/************************************************************* + * Function......: testRemove() + * + * Arguments.....: none + * Return value..: none + * Description...: reads DirTilesIx's and shows contents + ************************************************************/ + +static void testRemove() +{ + PersMDDObj* accessedObj; + + cout << "....testRemove"<<endl; + + PersMDDColl objsSet(collName); + // PersMDDColl objsSet("Qualquercoisa"); + // To test PersMDDColl::printStatus and PersMDDColl::remove + + + MDDCollIter* objsIt = objsSet.createIterator( ); + + cout << "-- Remove second element from collection " << endl; + + for( int i = 1 ; objsIt->notDone( ) && i < 2; i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + } + cout << "Delete of objsIt:" << endl; + delete objsIt; + cout << "Finished Delete of objsIt." << endl; + cout << "Remove accessedObj:" << endl; + objsSet.remove( accessedObj ); + cout << "Finished Remove accessedObj." << endl; +} + +/************************************************************* + * Function......: openCreateDB() + * + ************************************************************/ + +static int openCreateDB( const char* O2DBName, DatabaseIf& database ) +{ + cout << "openCreateDB " << O2DBName << endl; + + int errorDBOpen; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch( ...) + { + cout << "Caught Exception " << endl; + errorDBOpen = -6; + } + if ( errorDBOpen < 0 ) + { + cout << "Database doesn't exist. Create it new ... " << endl; + cout << "Creating new database " << O2DBName + << "..." << endl; + database.create( O2DBName, "TestSMSchema" ); + cout << endl << "Connecting to database " << O2DBName + << "..." << endl; + + try{ + errorDBOpen = database.open( O2DBName ); + } + catch(...) + { + errorDBOpen = -6; + } + } + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + return errorDBOpen; +} + +/************************************************************* + * Function......: createMDDColl( ) + ************************************************************/ +static int +createMDDColl( const char* collName, DatabaseIf* db ) +{ + MDDDomainType* mType1 = 0; + MDDDomainType* mType2 = 0; + MDDType* mt = 0; + CollectionType* collType1 = 0; + + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + + const MDDDomainType* cmType1 = + ( MDDDomainType* ) TypeFactory::mapMDDType( "TestSMDomainType2D" ); + const MDDDomainType* cmType2 = + ( MDDDomainType* ) TypeFactory::mapMDDType( "TestSMDomainType3D" ); + + const CollectionType* collType = + (CollectionType*)TypeFactory::mapSetType( "ObjsContainerType" ); + + + if( !cmType1 || !cmType2 || !collType ) + { + char name1[] = "TestSMDomainType2D"; + char name2[] = "TestSMDomainType3D"; + + r_Sinterval limits1Obj1(0l,1000l); + r_Sinterval limits2Obj1(0l,800l); + r_Minterval dom1(2); + dom1 << limits1Obj1 << limits2Obj1; + cout << "MDD Type 1 , domain "<< dom1 << endl; + + cout << " tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + cout << "MDD Type 2 , domain "<< dom2 << endl; + + // MDDDomainType* mType1 = + mType1 = + new MDDDomainType((char*) name1, ( BaseType* ) ulongTypeObj, dom1 ); + // MDDDomainType* mType2 = + mType2 = + new MDDDomainType((char*) name2, ( BaseType* ) ulongTypeObj, dom2 ); + + cout << "MDD Type1 == "; + mType1->print_status( cout ); + cout << endl; + cout << "MDD Type2 == "; + mType2->print_status( cout ); + cout << endl; + + TypeFactory::addMDDType( mType1 ); + TypeFactory::addMDDType( mType2 ); + + if ( !collType ) + { + cout << "Collection type newly created " << endl; + // MDDType* mt = new MDDType( ); + mt = new MDDType( ); + cout << "MDDtype created "<< endl; + collType1 = new SetType( "ObjsContainerType", mType1 ); + cout << "Set Type created ... "; + collType = collType1; + TypeFactory::addSetType( (SetType*) collType ); + cout <<" and added "<< endl; + + } + + } + cout << "Creating root collection" << endl; + + OId oColl; + if( OId::allocateMDDCollOId( &oColl ) == 0 ) + cout <<"Successfully allocated OId for collection " << oColl << endl; + else + cout <<"Error allocating OId for collection " << endl; + + PersMDDColl* col; + try { + // CollectionType* ct = TypeFactory::mapSetType( "ObjsContainerType" ); + col = PersMDDColl::createRoot( collName, oColl, collType, db ); + } + catch (...) + { + cout <<"Error caught ................."<< endl; + return -1; + } + + cout << "Committing TA ..."<< endl; + ta.commit( ); + + if ( col ) delete col; + cout << "Col freed . "<< endl; + + ta.begin( db ); + return 0; +} diff --git a/mddmgr/test/test_persmddobj.cc b/mddmgr/test/test_persmddobj.cc new file mode 100644 index 0000000..b54a851 --- /dev/null +++ b/mddmgr/test/test_persmddobj.cc @@ -0,0 +1,1125 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_persmddobj.cc + * + * MODULE: test for PersMDDObj of mddmgr + * + * PURPOSE: + * creates a persistent collection of objects and iterators and tests + * usage of O2 OIds. + * + * COMMENTS: + * none + * +*/ + +#include "mymalloc/mymalloc.h" + +#define TEST_PROTECTED +#define TEST_PRIVATE + +#include <stdlib.h> +#include <iostream> + +#include "ulongtype.hh" + +#include "mddmgr/persmddcoll.hh" +#include "mddmgr/persmddobj.hh" +#include "mddmgr/perstile.hh" + +#include "mddmgr/persmddcolliter.hh" + +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" +#include "oidif.hh" + +#include "raslib/rminit.hh" +#include "typefactory.hh" + +#include "mddif/dbmddobj.hh" +#include "mddif/dbmddcoll.hh" + +#include "mddbasetype.hh" +#include "mdddomaintype.hh" +#include "settype.hh" + + +/* + Global Variables +*/ +extern char* myExecArgv0 = ""; + +RMINITGLOBALS('C') + +static char* O2DBName; +char *collName; +char defaultCollName[]= "ObjsContainer"; +OId globalOId1, globalOId2; +OId globalCollOId; +EOId globalEOId[4]; +int numObjsCreated; +TransactionIf ta; +int ExitNo; + +/* + Functions +*/ + +int +getOption( ) +{ + unsigned int result; + cout << endl; + cout << "Choose Option : " << endl; + cout << "-----------------------------------------------------------------"<<endl; + cout << " 1 - Create MDD collection with name .. " << collName << endl; + cout << " 2 - Populate collection with MDD objects (testConstructors) " << endl; + cout << " 3 - Access MDD collection given name (testAccessing) " << endl; + cout << " 4 - Access MDD collection given OId (testAccessing)" << endl; + cout << " 5 - Access MDD object given OId (testAccessingMDDObj) " << endl; + cout << " 6 - Remove MDD object from the collection given OId (testRemove) "<<endl; + cout << " 7 - Test PersMDDObj::intersect( ) (testSearch) " <<endl; + cout << " 8 - Test PersMDDColl::getCardinality( ) "<<endl; + cout << " 9 - Test PersMDDObj get functions "<< endl; + cout << " 10 - Remove MDD Collection given OId " << endl; + cout << " 11 - Insert MDD given OId in a second collection "<< endl; + cout << " 12 - Insert tile in MDD given OId "<< globalOId1 <<endl; + cout << " 13 - Test removeTile from MDD "<< globalOId1 << endl; + ExitNo = 14; + cout << " " << ExitNo << " - Exit " << endl; + cout << "------------------------------------------------------------------"<<endl; + cout << "Enter option: "; + cin >> result; + return result; +} + +// 1 - Create MDD collection +static int createMDDColl( const char* collName, DatabaseIf* db ); + +// 2 - Populate collection with MDD objects +static void testConstructors( char* cn ); + +// 3 - Retrieves an MDD collection with name cn and prints contents: +static void testAccessing( char* cn ); + +// 4 - Retrieves an MDD collection with OId o and prints contents: +static void testAccessing( OId o ); + +// 5 - Retrieves an MDD object with OId o and prints contents: +static void testAccessingMDDObj( OId o ); + +// Removes one of the MDD objects in the collection +static void testRemove( ); + +// 6 - Removes MDD object with OId o in the collection +static void testRemove( OId o ); + +// 7 - Test PersMDDObj::intersect( ) objects of the collection +static void testSearch( ); + +// 8 - Test PersMDDColl::getCardinality( ) +static void testGetCardinality( char* cn); + +// 9 - Scans collection and tests PersMDDObj get functions +static void testGetFunctions( ); + +//10 - Remove MDD collection given OId + +//11 - Insert MDD given OId in a second collection +static void testInsertMDDObjColl( OId o, char* cn ); + +//12 - Test later insertion of tile in PersMDDObj +static void testLaterInsert( OId o ); + +//13 - Test removeTile from an MDD obj +static void testRemoveTile( OId o ); + +// Tries accessing several OIds, including ilegal ones, to test +// several error conditions. +static void testAccessingOId( ); + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ +int +main( int argc, char** argv) +{ + // variables representing O2 database, ta and session + DatabaseIf database; + + if( argc < 2 ) { + cout << "Usage: test_persmddcoll <database> [collName]" << endl; + return -1; + } + O2DBName = strdup( argv[1] ); + if ( argc == 3 ) collName = strdup( argv[2] ); + else + collName = defaultCollName; + + // don't forget to initialize before using AdminIf! + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + + + // connect to the database + cout << "Connecting to database " << O2DBName + << "..." << endl; + int errorDBOpen; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch( ...) + { + cout << "Caught Exception " << endl; + errorDBOpen = -6; + } + if ( errorDBOpen < 0 ) + { + cout << "Database doesn't exist. Create it new ... " << endl; + cout << "Creating new database " << O2DBName + << "..." << endl; + database.create( O2DBName, "TestSMSchema" ); + cout << "Connecting to database " << O2DBName + << "..." << endl; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch(...) + { + errorDBOpen = -6; + } + } + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + ta.begin( &database ); + cout << endl << "Deleting root object from the database ..." <<endl; + int i = PersMDDColl::destroyRoot( collName, &database ); + cout << " i == " << i << endl; + // cout << " &database = " << long( &database) << endl; + ta.commit( ); + + char c; + int error; + + for( unsigned opt = getOption( ); opt != ExitNo ; opt = getOption( ) ) + { + cout <<"Transaction begin ... " << endl; + ta.begin( &database ); + switch ( opt ) + { + case 1: // 1 - Create MDD collection with name + // create root collection + cout << endl << "Creating mdd types and root collection..." << endl; + if ( createMDDColl( collName, &database ) != 0 ) + { + cout <<"Error caught ................."<< endl; + cout << endl << "Ending O2 session..." << endl; + ta.commit( ); + database.close( ); + delete myAdmin; + exit( 1 ); + } + break; + + case 2: // 2 - Populate collection with MDD objects (testConstructors) + // create objects and put them in the collection + cout << endl << "Populate collection ..." << endl; + testConstructors( collName ); + break; + + case 3: // 3 - Access MDD collection given name (testAccessing) + // read coll and print contents + cout << endl << "Read collection " << collName << " and print contents..." << endl; + testAccessing( collName ); + break; + + case 4: // 4 - Access MDD collection given OId (testAccessing) + cout << endl << "Read collection " << globalCollOId << " and print contents..." << endl; + testAccessing( globalCollOId ); + break; + + case 5: // 5 - Access MDD object given OId (testAccessingMDDObj) + cout << endl << "Test Accessing MDD with OId " << globalOId1 << " ... " << endl; + testAccessingMDDObj( globalOId1 ); + break; + + case 6: // 6 - Remove MDD object from the collection given OId (testRemove) + cout<< endl << "Remove MDD with OId " << globalOId1 << " ..." << endl; + testRemove( globalOId1 ); + break; + + case 7: // 7 - Test PersMDDObj::intersect( ) (testSearch) + cout << endl << "Test region search ..." << endl; + testSearch( ); + break; + + case 8: // 8 - Test PersMDDColl::getCardinality( ) + cout << endl << "Get cardinality of collection" << collName <<" ..." << endl; + testGetCardinality( collName ); + break; + + case 9: // 9 - Test PersMDDObj get functions + cout << endl <<"Test PersMDDObj get functions " << endl; + testGetFunctions( ); + break; + + case 10: // 10 - Remove MDD Collection given OId + cout << endl << "Remove MDD collection with OId "; + cout << globalCollOId << " ..." << endl; + error = PersMDDColl::destroyRoot( globalCollOId, &database ); + if (error ) + cout << " Error destroying root " << endl; + break; + + case 11: // 11 - Insert MDD given OId in a second collection + cout << endl << "Insert Object with OId " << globalOId1; + cout << " in collection Coleccao1 " << endl; + cout << "First, create collection" << endl; + if ( createMDDColl( "Coleccao1", &database ) != 0 ) + { + cout <<"Error caught ................."<< endl; + cout << endl << "Ending O2 session..." << endl; + ta.commit( ); + database.close( ); + delete myAdmin; + exit( 1 ); + } + cout << "Then insert object with OId "<< globalOId1 << endl; + testInsertMDDObjColl( globalOId1 , "Coleccao1"); + cout << endl; + break; + + case 12: // 12 - Insert new tiles in the MDD object + cout << endl << "Insert Tile in object with OId " << globalOId1; + testLaterInsert( globalOId1 ); + cout << endl; + break; + + case 13: // 13 - Remove a tile from the MDD object + cout << endl << "Remove Tile from object with OId " << globalOId1; + testRemoveTile( globalOId1 ); + cout << endl; + break; + + default: + break; + } + cout <<"Transaction abort (A/a) or commit (default)? "; + cin >> c; + if ( c == 'A' || c == 'a' ) + { + ta.abort( ); + cout <<"End of Transaction Abort..."<<endl; + } + else ta.commit( ); + if ( opt == 6 ) + { + cout<<"Garbage ? ( y /n ) "; + cin >> c; + if (c =='y' || c == 'Y' ) + { + cout <<"Garbaging ..."<< endl; + ta.begin( &database ); + database.garbage( ); + ta.commit( ); + } + } + cout <<"End of transaction commit... "<<endl; + } // for opt + + + cout << endl << "Ending O2 session..." << endl; + database.close( ); + delete myAdmin; + + free( O2DBName ); + if ( collName != defaultCollName ) free( collName ); + return 0; + +} + +/************************************************************* + * Functions......: + * + * static void + * testInsertMDDObjColl( OId o, char* cn ) + * + * static void + * testConstructors( char* collName ) + * + ************************************************************/ +static void +testInsertMDDObjColl( OId o, char* cn ) +{ + cout << "....testInsertMDDObjColl "<< o <<","<< cn << endl; + PersMDDObj* obj = new PersMDDObj( O2DBName,o ); + PersMDDColl objsSet( cn ); + objsSet.insert( obj ); + delete obj; + +} + +static void testConstructors( char* collName ) +{ + + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + const BaseType* boolTypeObj = TypeFactory::mapType("Bool"); + // char uLongCell[] = {0,0,0,0}; + char* uLongCells; + // char boolCell = 0; + char* boolCells; + + + const MDDBaseType* mType1 = + (const MDDBaseType* ) TypeFactory::mapMDDType("TestSMDomainType2D"); + const MDDBaseType* mType2 = + (const MDDBaseType* ) TypeFactory::mapMDDType("TestSMDomainType3D"); + + cout << "....testConstructors"<< endl; + + OId oid1; + if ( OId::allocateMDDOId( &oid1 ) == 0) + cout << "Successfull allocation of OId " << oid1 <<endl; + else + { + cout << "Error by allocation of OId" <<endl; + exit(1); + } + OId oid2; + if ( OId::allocateMDDOId( &oid2 ) == 0) + cout << "Successfull allocation of OId " << oid2 <<endl; + else + { + cout << "Error by allocation of OId" <<endl; + exit(1); + } + + globalOId1 = oid1; + globalOId2 = oid2; + + // read root object + + PersMDDColl objsSet(collName); + + + // create MDD Object 1 + + cout << "Creating mddObj1" << endl; + cout << "tile 1 = nil, 10-12, 20-24 "<< endl; + r_Sinterval limits1Obj1(10l,12l); + r_Sinterval limits2Obj1(20l,24l); + r_Minterval dom(2); + dom << limits1Obj1 << limits2Obj1; + + r_Minterval tmpInt = *( ( MDDDomainType* ) mType1 )->getDomain( ); + PersMDDObj* MDDObj1 = new PersMDDObj( mType1, tmpInt, O2DBName, oid1 ); + + + uLongCells = (char*) mymalloc( dom.cell_count() * ulongTypeObj->getSize() ); + PersTile* tile1Obj1 = new PersTile( dom, ulongTypeObj, uLongCells ); + + MDDObj1->insertTile(tile1Obj1); + + cout << "tile 2 = nil, 0-400, 22-24 "<< endl; + dom[0].set_interval(0l,400l); + dom[1].set_interval(22l,24l); + + uLongCells = (char*) mymalloc( dom.cell_count() * ulongTypeObj->getSize() ); + PersTile* tile2Obj1 = new PersTile( dom, ulongTypeObj, uLongCells ); + MDDObj1->insertTile(tile2Obj1); + + cout << "tile 3 = nil, 0-600, 10-1000 "<< endl; + dom[0].set_interval(0l,600l); + dom[1].set_interval(10l,1000l); + uLongCells = (char*) mymalloc( dom.cell_count() * ulongTypeObj->getSize() ); + PersTile* tile3Obj1 = new PersTile( dom, ulongTypeObj, uLongCells ); + MDDObj1->insertTile(tile3Obj1); + + cout << "MDDObj1 == isPersistent:" << MDDObj1->isPersistent( )<< ";" <<endl; + MDDObj1->printStatus( ); + cout << endl; + + objsSet.insert(MDDObj1); + + // create MDD Object + cout << "Creating mddObj2 "<< endl; + cout << "tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + + tmpInt = *( ( MDDDomainType* ) mType2 )->getDomain( ); + PersMDDObj* MDDObj2 = new PersMDDObj( mType2, tmpInt, O2DBName, oid2 ); + + boolCells = (char*) mymalloc( dom2.cell_count() * boolTypeObj->getSize() ); + PersTile* tile1Obj2 = new PersTile( dom2, boolTypeObj, boolCells); + MDDObj2->insertTile( tile1Obj2 ); + + cout << "tile 2 = nil, 20-39, 60-79, 60-89 "<< endl; + dom2[0].set_interval(20l,39l); + dom2[1].set_interval(60l,79l); + dom2[2].set_interval(60l,89l); + boolCells = (char*) mymalloc( dom2.cell_count() * boolTypeObj->getSize() ); + PersTile* tile2Obj2 = new PersTile( dom2, boolTypeObj, boolCells ); + + MDDObj2->insertTile(tile2Obj2); + + + cout << "MDDObj2 == isPersistent:" << MDDObj2->isPersistent( )<< ";" <<endl; + MDDObj2->printStatus( ); + cout << endl; + +/* + // This program doesn't work if the TA is aborted when OIds are + // allocated, even if all allocated OIds are binded. Question: is it + // because of dangling handles? This little test was done to + // check that. + // This without oids works with ta.abort + // conclusion: the problem with abort is not due to the handles + Handle hd; + d_Ref<DBMDDObj> refObj = MDDObj2->getDBMDDObjId(); + hd = refObj.o2_get_handle(); +*/ + + + objsSet.insert(MDDObj2); + numObjsCreated = 2; + + cout << "Release all " << endl; + + ( ( PersMDDColl ) objsSet ).releaseAll( ); + +} + + +/************************************************************* + * Function......: testAccessing( char* cn ) + * testAccessing( OId o ) + ************************************************************/ + +static void testAccessing( char* cn ) +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing collection "<< cn << endl; + + try{ + PersMDDColl objsSet( cn ); + + // To test PersMDDColl::printStatus( ) + // objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid; + // old version cout <<"EOId: " << eoid.getSystemName( ) << eoid.getBaseName( ) << eoid.getOId( ); + cout << endl << endl; + accessedObj->getEOId( &globalEOId[i-1] ); + } + delete objsIt; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } +} + +static void testAccessing( OId o ) +{ + PersMDDObj* accessedObj; + + cout << "....testAccessing collection "<< o << endl; + + try { + PersMDDColl objsSet( o, O2DBName ); + + OId o; + if ( objsSet.getOId( &o ) == 0 ) + cout <<"getOId " << o << endl; + else + cout <<"Error getOId " << endl; + + EOId eo; + if ( objsSet.getEOId( &eo ) == 0 ) + cout << "getEOId " << eo <<endl; + // cout << "getEOId " << eo.getSystemName( ) <<":"<<eo.getBaseName( )<<":"<<eo.getOId( ) << endl; + else + cout <<"Error getEOId " << endl; + + // To test PersMDDColl::printStatus( ) + objsSet.printStatus( ); + + // To test PersMDDObj::printStatus( ), MDDCollIter::createIterator( ) and + // MDDCollIter methods : + + cout << "Iterating through the collection with PersMDDCollIter " << endl; + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + cout << i<<". MDD object in set:" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + accessedObj->printStatus(); + EOId eoid; + if ( accessedObj->getEOId( &eoid ) ==0 ) + cout <<"EOId: " << eoid ; + // cout <<"EOId: " << eoid.getSystemName( ) << eoid.getBaseName() << eoid.getOId( ); + cout << endl << endl; + accessedObj->getEOId( &globalEOId[i-1] ); + } + delete objsIt; + objsSet.releaseAll( ); + } + catch ( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } + +} + +/************************************************************* + * Function......: testAccessingMDDObj(OId o ) + * testAccessingOId( ) + * + ************************************************************/ +static void testAccessingMDDObj(OId o) +{ + PersMDDObj *mObj; + + cout << "....testAccessingMDDObj"<<endl; + + try{ + mObj = new PersMDDObj( O2DBName, o); + mObj->printStatus( ); + delete mObj; + } + catch (...) + { + cout <<" Object not found..." << endl; + + } +} + +static void testAccessingOId() +{ + PersMDDObj *mObj1, *mObj2, *mObj; + Handle hdObj; + int result; + OId o(70000); + OId o1(5010); + OId o2(0); + OId o3(5); + + cout << "....testAccessingOId"<<endl; + + + cout << "Test OIdIf::getType( )..."<<endl; + cout << "1.st MDDObj " << endl; + cout << "getType " << globalOId1.getType( O2DBName ) << endl; + + cout << "2.nd MDDObj " << endl; + cout << "getType " << globalOId2.getType( O2DBName ) << endl; + + // This crashes + // cout << "OId == 0 " << endl; + // cout << "getType " << o2.getType( O2DBName ) << endl; + + cout << "OId == 5 " << endl; + cout << "getType " << o3.getType( O2DBName ) << endl; + + cout << "MDDCollection " << endl; + cout << "getType " << globalCollOId.getType( O2DBName ) << endl; + // mObj2 = new PersMDDObj( O2DBName, globalOId2); + // mObj2->printStatus( ); + + cout << "Not used OId " << endl; + cout << "getType " << o1.getType( O2DBName ) << endl; + + cout << "Nonexistent OId " << endl; + cout << "getType " << o.getType( O2DBName ) << endl; + // mObj2 = new PersMDDObj( O2DBName, globalOId2); + // mObj2->printStatus( ); + + cout <<"Loading PersMDDObjs from OIds " << endl; + mObj1 = new PersMDDObj( O2DBName, globalOId1); + mObj1->printStatus( ); + mObj2 = new PersMDDObj( O2DBName, globalOId2); + mObj2->printStatus( ); + + delete mObj1; + delete mObj2; + + + for ( int i = 0; i < numObjsCreated; i++ ) + { + cout << "Reading with " << i+1<< ".th EOId " ; + cout << globalEOId[i]; + // cout << globalEOId[i].getSystemName( ); + // cout << " ; "<< globalEOId[i].getBaseName( ) << ";" << globalEOId[i].getOId( ); + cout << endl; + + + // result = o2_externalNameGetObject( &globalEOId[i], &hdObj ); + result = globalEOId[i].getObject( &hdObj ); + if ( result == 0 ) + { + DBMDDObjId obj1(hdObj); + mObj = new PersMDDObj(obj1); + mObj->printStatus( ); + } + else + cout << "No such object!!" << endl; + // o2_unref_handle( ); + delete mObj; + } + +} + +/************************************************************* + * Function......: testLaterInsert() + * + ************************************************************/ + +static void testLaterInsert( OId o ) +{ + PersMDDObj* accessedObj; + + cout << "....testLaterInsert"<<endl; + + try{ + accessedObj = new PersMDDObj( O2DBName, o); + } + catch (...) + { + cout <<" Object not found..." << endl; + return; + } + + cout << "Current status of MDD object : " << endl; + accessedObj->printStatus( ); + cout << endl << "Inserting new Tile ..."<< endl; + + PersTile *t, *t2, *t3; + switch( accessedObj->getDimension( ) ) + { + case 2 : + t2 = new PersTile( r_Minterval("[40:60,80:1200]"), + accessedObj->getCellType( ) ); + t = t2; + break; + case 3 : + t3 = new PersTile(r_Minterval("[40:60,80:100,0:20]"), + accessedObj->getCellType( ) ); + t = t3; + break; + default: + cout << "Error Dimensionality not expected" << endl; + break; + } + accessedObj->insertTile(t); + cout << " New status after insertion:" << endl; + accessedObj->printStatus(); + cout << endl << endl; + + delete accessedObj; +} + + +/************************************************************* + * Function......: testSearch() + * + ************************************************************/ +static void testSearch() +{ + + MDDObj* accessedObj; + + cout << "....testSearch"<<endl; + + PersMDDColl objsSet(collName); + + MDDCollIter* objsIt = objsSet.createIterator( ); + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + accessedObj = objsIt->getElement(); + + cout << "Accessed Object " << endl; + accessedObj->printStatus( ); + cout << endl; + + if (i == 1 || i == 2) + { + r_Minterval searchInt1(2); + r_Minterval searchInt2(3); + vector< Tile* >* entriesList; + + cout << " -- " << i << ". MDD object in list. Search for:"; + switch (i) { + case 1: searchInt1[0].set_interval(10l,20l); + searchInt1[1].set_interval(10l,30l); + cout << " 10-20, 10-30" << endl; + entriesList = accessedObj->intersect(searchInt1); + break; + case 2: searchInt2[0].set_interval(10l,20l); + searchInt2[1].set_interval(10l,30l); + searchInt2[2].set_interval(40l,50l); + cout << " 10-20, 10-30, 40-50" <<endl; + entriesList = accessedObj->intersect(searchInt2); + break; + default: break; + } + cout << " -- Search result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile printStatus"; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" + << tileInterval[i].high() <<", "; + cout << endl; + + entryIt++; + } + delete entriesList; + } + } + delete objsIt; + // objsSet.releaseAll( ); +} + +/************************************************************* + * Function......: testRemoveTile(OId o ) + * + ************************************************************/ +static void testRemoveTile(OId o) +{ + PersMDDObj *mObj; + + cout << "....testRemoveTile from MDD Obj "<< o << endl; + + try{ + mObj = new PersMDDObj( O2DBName, o); + mObj->printStatus( ); + } + catch (...) + { + cout <<" Object not found..." << endl; + return; + } + + vector<Tile*>* tiles = mObj->getTiles( ); + + if ( tiles->size( ) == 0 ) + { + cout <<"MDD object has no tiles !! "<< endl; + return; + } + else + { + int ix = tiles->size( )/2; + + cout << "Removing "<< ix <<". tile from MDD Obj "<< endl; + cout << "Tile Description: " << (*tiles)[ix]->getDomain( ) << endl; + + PersTile* t = (PersTile*) (*tiles)[ix]; + + mObj->removeTile( (*tiles)[ix] ); + + delete tiles; + delete mObj; + } +} + +/************************************************************* + * Function......: testGetCardinality( const char* cn ) + * testGetFunctions() + * + ************************************************************/ +static void testGetCardinality( char* cn ) +{ + cout << "....testGetCardinality( "<< cn << " )" << endl; + + try{ + PersMDDColl objsSet( cn ); + cout<< "Cardinality of collection " << objsSet.getCardinality( ) <<endl; + } + catch( r_Error& errObj) + { + cout <<"Error caught ................."<< endl; + } +} + +static void testGetFunctions() +{ + PersMDDObj* accessedObj; + + cout << "....testGetFunctions"<<endl; + + PersMDDColl objsSet(collName); + + MDDCollIter* objsIt = objsSet.createIterator( ); + + vector< Tile* >* entriesList; + + for( int i = 1 ; objsIt->notDone( ); i++, objsIt->advance( )) + { + r_Minterval currDom; + r_Minterval defDom; + + cout << " " << i << ". Object" << endl; + accessedObj = (PersMDDObj*) objsIt->getElement(); + + + defDom = accessedObj->getDefinitionDomain( ); + cout << " GetDefinitionDomain result: "; + defDom.print_status( ); + cout << endl; + + currDom = accessedObj->getCurrentDomain( ); + cout << " GetCurrentDomain result: "; + currDom.print_status( ); + cout << endl; + + entriesList = accessedObj->getTiles( ); + cout << " -- GetTiles result: " << endl; + vector<Tile*>::iterator entryIt = entriesList->begin(); + + while (entryIt != entriesList->end()) + { + // (*entryIt)->printStatus(); + r_Minterval tileInterval = (*entryIt)->getDomain(); + int dimensionality = tileInterval.dimension(); + + cout << " PersTile "; + cout << " domain == " << dimensionality << ": "; + for (int i = 0; i <dimensionality; i++) + cout << tileInterval[i].low() << "-" << tileInterval[i].high() <<", "; + cout << endl; + entryIt++; + } + delete entriesList; + } + delete objsIt; + objsSet.releaseAll( ); +} + +/************************************************************* + * Function......: testRemove() + * testRemove( OId o ) + * + ************************************************************/ + +static void testRemove() +{ + PersMDDObj* accessedObj; + + cout << "....testRemove"<<endl; + + PersMDDColl objsSet(collName); + // PersMDDColl objsSet("Qualquercoisa"); + // To test PersMDDColl::printStatus and PersMDDColl::remove + + + MDDCollIter* objsIt = objsSet.createIterator( ); + + cout << "-- Remove second element from collection " << endl; + + for( int i = 1 ; objsIt->notDone( ) && i < 2; i++, objsIt->advance( )) + { + accessedObj = (PersMDDObj*) objsIt->getElement(); + } + cout << "Delete of objsIt:" << endl; + delete objsIt; + cout << "Finished Delete of objsIt." << endl; + cout << "Remove accessedObj:" << endl; + objsSet.remove( accessedObj ); + cout << "Finished Remove accessedObj." << endl; +} + +static void testRemove( OId o ) +{ + + cout << "....testRemove( OId == " << o <<" ) "<< endl; + + PersMDDColl objsSet(collName); + objsSet.remove( o, O2DBName ); +} + + +/************************************************************* + * Function......: createMDDColl( ) + ************************************************************/ +static int +createMDDColl( const char* collName, DatabaseIf* db ) +{ + MDDDomainType* mType1 = 0; + MDDDomainType* mType2 = 0; + MDDType* mt = 0; + CollectionType* collType1 = 0; + + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + + const MDDDomainType* cmType1 = + ( MDDDomainType* ) TypeFactory::mapMDDType( "TestSMDomainType2D" ); + const MDDDomainType* cmType2 = + ( MDDDomainType* ) TypeFactory::mapMDDType( "TestSMDomainType3D" ); + + const CollectionType* collType = + (CollectionType*)TypeFactory::mapSetType( "ObjsContainerType" ); + + + if( !cmType1 || !cmType2 || !collType ) + { + char name1[] = "TestSMDomainType2D"; + char name2[] = "TestSMDomainType3D"; + + r_Sinterval limits1Obj1(0l,1000l); + r_Sinterval limits2Obj1(0l,800l); + r_Minterval dom1(2); + dom1 << limits1Obj1 << limits2Obj1; + cout << "MDD Type 1 , domain "<< dom1 << endl; + + cout << " tile 1 = nil, 0-19, 20-59, 30-59 "<< endl; + r_Sinterval limits1Obj2(0l,19l); + r_Sinterval limits2Obj2(20l,59l); + r_Sinterval limits3Obj2(30l,59l); + r_Minterval dom2(3); + dom2 << limits1Obj2 << limits2Obj2 << limits3Obj2; + cout << "MDD Type 2 , domain "<< dom2 << endl; + + // MDDDomainType* mType1 = + mType1 = + new MDDDomainType((char*) name1, ( BaseType* ) ulongTypeObj, dom1 ); + // MDDDomainType* mType2 = + mType2 = + new MDDDomainType((char*) name2, ( BaseType* ) ulongTypeObj, dom2 ); + + cout << "MDD Type1 == "; + mType1->print_status( cout ); + cout << endl; + cout << "MDD Type2 == "; + mType2->print_status( cout ); + cout << endl; + + TypeFactory::addMDDType( mType1 ); + TypeFactory::addMDDType( mType2 ); + + if ( !collType ) + { + cout << "Collection type newly created " << endl; + // MDDType* mt = new MDDType( ); + mt = new MDDType( ); + cout << "MDDtype created "<< endl; + collType1 = new SetType( "ObjsContainerType", mType1 ); + cout << "Set Type created ... "; + collType = collType1; + TypeFactory::addSetType( (SetType*) collType ); + cout <<" and added "<< endl; + + } + + } + //ta.commit( ); + + //ta.begin( ); + + cout << "Creating root collection" << endl; + + // cout << " &database = " << long( db ) << endl; + + OId oColl; + if( OId::allocateMDDCollOId( &oColl ) == 0 ) + cout <<"Successfully allocated OId for collection " << oColl << endl; + else + cout <<"Error allocating OId for collection " << endl; + globalCollOId = oColl; + + PersMDDColl* col; + try { + // CollectionType* ct = TypeFactory::mapSetType( "ObjsContainerType" ); + col = PersMDDColl::createRoot( collName, oColl, collType, db ); + } + catch (...) + { + cout <<"Error caught ................."<< endl; + return -1; + } + + cout << "Committing TA ..."<< endl; + ta.commit( ); + + /* + + cout <<"Freeing types ... "<< endl; + + // if ( mType1 ) delete mType1; + cout << "Type 1 freed . "<< endl; + // if ( mType2 ) delete mType2; + cout << "Type 2 freed . "<< endl; + // if ( mt ) delete mt; + cout << "Type mt freed . "<< endl; + // if ( collType1 ) delete collType1; + cout << "Types collType1 freed . "<< endl; + */ + if ( col ) delete col; + cout << "Col freed . "<< endl; + + + ta.begin( db ); + return 0; +} diff --git a/mddmgr/test/test_transmddcoll.cc b/mddmgr/test/test_transmddcoll.cc new file mode 100644 index 0000000..b3045c3 --- /dev/null +++ b/mddmgr/test/test_transmddcoll.cc @@ -0,0 +1,180 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_transmddcoll.cc + * + * MODULE: test for transmddobj of cachetamgr + * + * COMMENTS: + * none + * +*/ + +#include <stdlib.h> +#include <iostream> +#include <vector.h> // STL +#include "tilemgr/transtile.hh" +#include "tilemgr/transmddobj.hh" +#include "ulongtype.hh" // from catalogif +#include "raslib/minterval.hh" +#include "tilemgr/transmddcoll.hh" +#include "tilemgr/mddcolliter.hh" +#include "adminif.hh" + +// Needed by Adminif. Adminif has to be instantiated because +// of cell base types. +extern char* myExecArgv0 = ""; +#include "raslib/rminit.hh" +RMINITGLOBALS('C') + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: + * The cellType of the MDD objects in this program is + * not set correctly because no database is open and no + * transaction is started. + ************************************************************/ + +int +main( int argc, char** argv) +{ + myExecArgv0 = argv[0]; + + const int numObjs = 10; + const int numTilesObj = 10; + r_Sinterval domSinterval; + + // In order to work with cell base types, AdminIf has to be + // instantiated. + // cout << " Adminif::instance " << endl; + AdminIf* myAdmin = AdminIf::instance(); + + ULongType anyType; + + char anyCell[4]; + int i; + MDDColl* tCollMDDObjs = new TransMDDColl( ); + + cout << " Allocating new TransMDDColl ..."<<endl; + tCollMDDObjs = new TransMDDColl( ); + cout << " new TransMDDColl allocated..."<<endl; + + cout << "Creating transient tiles for the MDD objects ... " << endl; + vector<TransTile*>* tilesVectsArr[numObjs]; + + // initialize array of vectors of tiles + for (i=0; i<numObjs; i++) + { + tilesVectsArr[i] = new vector<TransTile*>(numTilesObj); + for (int j=0; j<numTilesObj ; j++) + { + r_Minterval dom(2); + domSinterval.set_interval( r_Range(j* 10), r_Range((j+1)*10-1) ); + dom << domSinterval << domSinterval; + (*tilesVectsArr[i])[j] = new TransTile( dom, &anyType, anyCell ); + } + } + + + cout << "Creating transient MDD objects ... " << endl; + TransMDDObj* MDDObjsArr[numObjs]; + + for ( i=0; i<numObjs; i++ ) + { + r_Minterval dom(2); + domSinterval.set_interval( r_Range( i ), r_Range( 100 + i*10 ) ); + if( i == 3 || i == 5 || i == 7 ) + domSinterval.set_low( '*' ); + if( i == 2 || i == 4 || i == 6 ) + domSinterval.set_high( '*' ); + dom << domSinterval << domSinterval; + MDDObjsArr[i] = new TransMDDObj( dom, "ULong" ); + for( int j=0; j < numTilesObj; j++) + { + vector<TransTile*>* pTilesVec = tilesVectsArr[i]; + MDDObjsArr[i]->insertTile( (*pTilesVec)[j] ); + } + } + + cout << "Printing contents of created objects ... " << endl; + for( i = 0; i< numObjs; i++) + { + cout << "- " << i << ". Transient MDD Object contents: " <<endl; + MDDObjsArr[i]->printStatus( ); + cout << endl; + } + + cout << "Creating a transient collection of objects ... " << endl; + for( i = 0; i< numObjs; i++) + { + // cout << "- " << i << ". Transient MDD Object contents: " <<endl; + tCollMDDObjs->insert(MDDObjsArr[i]); + // cout << endl; + } + cout << "Contents of the Transient Collection: ... : " << endl; + tCollMDDObjs->printStatus( ); + + cout << "Testing TransMDDCollIter ... : " << endl; + MDDCollIter* transIter = tCollMDDObjs->createIterator( ); + MDDObj* currObj; + + for ( i=0; transIter->notDone( ) ; transIter->advance( ), i++) + { + cout << "- " << i << ". Trans. MDD Object returned by Iterator contents: " <<endl; + currObj = transIter->getElement( ); + currObj->printStatus( ); + } + + // delete iterator from TransMDDColl + delete transIter; + + // releases all contents from the collection. It should free all the MDD + // objects and tiles created in this program. + tCollMDDObjs->releaseAll( ); + + // delete transient MDD Collection + delete tCollMDDObjs; + + /* + This shouldn't be needed if realeaseAll from the TransMDDColl works fine + for ( i = 0 ; i < numObjs; i++ ) + { + delete MDDObjsArr[i]; + } + */ + + + // delete dynamically allocated vectors of tiles (not the tiles themselves, + // which should have been freed by releaseAll of TransMDDColl) + for (i = 0; i < numObjs; i++) + delete tilesVectsArr[i]; + + delete myAdmin; + +} diff --git a/mddmgr/test/test_transmddobj.cc b/mddmgr/test/test_transmddobj.cc new file mode 100644 index 0000000..28c50d2 --- /dev/null +++ b/mddmgr/test/test_transmddobj.cc @@ -0,0 +1,443 @@ +/* +* This file is part of rasdaman community. +* +* Rasdaman community is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* Rasdaman community is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>. +* +* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann / +rasdaman GmbH. +* +* For more information please see <http://www.rasdaman.org> +* or contact Peter Baumann via <baumann@rasdaman.com>. +/ +/** + * SOURCE: test_transmddcoll.cc + * + * MODULE: test for transmddobj of cachetamgr + * + * COMMENTS: + * none + * +*/ + +#include "rt_odb_Database.hxx" + +#define TEST_PRIVATE + +#include <stdlib.h> +#include <iostream> +#include <vector.h> // STL +#include "mddmgr/transtile.hh" +#include "mddmgr/transmddobj.hh" + +#include "typefactory.hh" +#include "ulongtype.hh" // from catalogif +#include "mddbasetype.hh" // from catalogif + +#include "raslib/minterval.hh" +#include "mddmgr/transmddcoll.hh" +#include "mddmgr/mddcolliter.hh" +#include "adminif.hh" +#include "databaseif.hh" +#include "transactionif.hh" + +#include "raslib/rminit.hh" +RMINITGLOBALS('C') + +#include <malloc.h> + +// Needed by Adminif. Adminif has to be instantiated because +// of cell base types. +extern char* myExecArgv0 = ""; + +void testConstruction( ); +void testRemovetile( ); +void testIntersection( ); +void printMemInfo( ); + + +/************************************************************* + * Function name.: int main( int argc, char** argv) + * + * Arguments.....: + * argc: number of arguments given to program + * argv: array of char* with arguments + * Return value..: exit status + * Description...: none + ************************************************************/ + +int +main( int argc, char** argv) +{ + myExecArgv0 = argv[0]; + AdminIf* myAdmin = AdminIf::instance(); + TransactionIf ta; + char O2DBName[] = "BaseTestTransMDDObj"; + + // variables representing O2 database, ta and session + DatabaseIf database; + // connect to the database + cout << "Connecting to database " << O2DBName + << "..." << endl; + int errorDBOpen; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch( ...) + { + cout << "Caught Exception " << endl; + errorDBOpen = -6; + } + if ( errorDBOpen < 0 ) + { + cout << "Database doesn't exist. Create it new ... " << endl; + cout << "Creating new database " << O2DBName + << "..." << endl; + database.create( O2DBName, "TestSMSchema" ); + cout << "Connecting to database " << O2DBName + << "..." << endl; + try{ + errorDBOpen = database.open( O2DBName ); + } + catch(...) + { + errorDBOpen = -6; + } + } + if ( errorDBOpen < 0 ) + { + cout << "Failed at opening newly created database " << errorDBOpen << endl; + cout << "Exiting " << endl; + return errorDBOpen; + } + + ta.begin( &database, 1 ); + + cout << " Main - begin " << endl; + printMemInfo( ); + + /* + cout << "---------- "; + cout << "Testing constructor and insertTile for TransMDDObj: " << endl; + testConstruction( ); + cout << "Testing constructor - end " << endl; + printMemInfo( ); + */ + + cout << "Testing intersection for TransMDDObj: " << endl; + testIntersection( ); + cout << "Testing intersection - end " << endl; + printMemInfo( ); + + + /* + cout << "---------- "; + cout << "Testing removeTile from TransMDDObj: " << endl; + testRemovetile( ); + cout << "Main - end " << endl; + printMemInfo( ); + */ + + ta.abort( ); + database.close( ); + + delete myAdmin; + +} + +void testConstruction( ) +{ + const int numTilesObj = 20; + r_Sinterval domSinterval; + cout <<"here 1" << endl; + ULongType ult; + BaseType* anyType = new( (d_Database*)(d_Database::transient_memory) ) ULongType; // anyType; + + cout << "here 2"<< endl; + const MDDBaseType* anyBaseType = + new( (d_Database*)(d_Database::transient_memory) ) MDDBaseType( "AnyType", &ult/* anyType */ ); + + // const MDDBaseType anyBaseType( "AnyType", &ult ); + + char anyCell[4]; + int j; + MDDObj* testMDDObj; + + + cout << "Creating transient tiles for the MDD object ... " << endl; + vector<TransTile*> tilesVect(numTilesObj); + + + // initialize array of tiles + for (j=0; j<numTilesObj ; j++) + { + r_Minterval dom(2); + TransTile* tt; + + domSinterval.set_interval( r_Range(j* 10), r_Range((j+1)*10-1) ); + dom << domSinterval << domSinterval; + cout << "Newly created tile domain : " << dom << " " << endl; + // printMemInfo(); + tt = new TransTile( dom, anyType, anyCell ); + cout << "Tile created " << endl; + // printMemInfo(); + tilesVect[j] = tt ; + } + + // Test trans tiles part - BEGIN + // works fine + /* + for ( int h=0; h < tilesVect.size(); h++) + delete tilesVect[h]; + */ + // release (tilesVect.begin( ), tilesVect.end( ) ); + + // Test trans tiles part - END + + + cout << "Creating the transient MDD object ... " << endl; + + r_Minterval dom(2); + domSinterval.set_interval( r_Range( 0 ), r_Range( 100 ) ); + domSinterval.set_low( '*' ); + dom << domSinterval << domSinterval; + // testMDDObj = new TransMDDObj( dom, "ULong" ); + testMDDObj = new TransMDDObj( anyBaseType, dom ); + for(j=0; j < numTilesObj; j++) + { + testMDDObj->insertTile( tilesVect[j] ); + } + // printMemInfo(); + + cout << "Printing contents of the created object ... " << endl; + testMDDObj->printStatus( ); + + cout << "Deleting the created object ... " << endl; + delete testMDDObj; + // printMemInfo(); + + +} + + +void testIntersection( ) +{ + const int numTilesObj = 20; + r_Sinterval domSinterval; + + const BaseType* ulongTypeObj = TypeFactory::mapType("ULong"); + + char uLongCell[] = {0,1,2,3}; + + const MDDBaseType* anyBaseType = + new MDDBaseType( "AnyType1", (BaseType*) ulongTypeObj ); + + TypeFactory::addTempType( (Type*) anyBaseType ); + + BaseType* bt = ( (MDDBaseType* ) anyBaseType )->getBaseType( ); + cout << "Base type size " << bt->getSize( )<< endl; + + + int j; + MDDObj* testMDDObj; + + + cout << "Creating transient tiles for the MDD object ... " << endl; + vector<TransTile*> tilesVect(numTilesObj); + + + // initialize array of tiles + for (j=0; j<numTilesObj ; j++) + { + r_Minterval dom(2); + TransTile* tt; + + domSinterval.set_interval( r_Range(j* 10), r_Range((j+1)*10-1) ); + dom << domSinterval << domSinterval; + cout << "Newly created tile domain : " << dom << " " << endl; + // printMemInfo(); + tt = new TransTile( dom, (BaseType*) ulongTypeObj, uLongCell ); + cout << "Tile created " << endl; + if (!j) + tt->printStatus( ); + // printMemInfo(); + tilesVect[j] = tt ; + } + + // Test trans tiles part - BEGIN + // works fine + /* + for ( int h=0; h < tilesVect.size(); h++) + delete tilesVect[h]; + */ + // release (tilesVect.begin( ), tilesVect.end( ) ); + + // Test trans tiles part - END + + + cout << "Creating the transient MDD object ... " << endl; + + r_Minterval dom(2); + domSinterval.set_interval( r_Range( 0 ), r_Range( 100 ) ); + domSinterval.set_low( '*' ); + dom << domSinterval << domSinterval; + testMDDObj = new TransMDDObj( anyBaseType, dom ); + for(j=0; j < numTilesObj; j++) + { + testMDDObj->insertTile( tilesVect[j] ); + } + // printMemInfo(); + + cout << "Printing contents of the created object ... " << endl; + testMDDObj->printStatus( ); + + r_Minterval searchInterval(2); + domSinterval.set_interval( r_Range( 4 ), r_Range( 96 ) ); + searchInterval<< domSinterval ; + domSinterval.set_interval( r_Range( 22 ), r_Range( 84 ) ); + searchInterval<< domSinterval ; + cout << "Intersection with "<< searchInterval << " :" << endl ; + + vector<Tile*>* intersectResult = + ( testMDDObj )->intersect( searchInterval ); + cout << "Result of intersection:" << endl; + cout << "Intersect result size " << intersectResult->size( ) << endl; + for (int tilesIter = 0; tilesIter < intersectResult->size( ) ; tilesIter++) + { + Tile* currTile; + currTile = (*intersectResult)[tilesIter]; + cout << "Tile " << tilesIter << " domain : " ; + cout << currTile->getDomain( ) << endl; + } + + // printMemInfo(); + cout << "Deleting intersection result " << endl; + // Individual tiles in the intersectResult shouldn't be deleted, since + // they are part of the TransMDDObj. They are deleted whenever the object + // is deleted. + delete intersectResult; + // printMemInfo(); + + cout << "Testing point query " << endl; + r_Point pnt1( r_Range(2) , r_Range(3) ); + unsigned long* c1 = (unsigned long*) testMDDObj->pointQuery( pnt1 ); + // char* c1 = testMDDObj->pointQuery( pnt1 ); + cout << "1. Result "<< pnt1 << ": "<< *c1 << endl; + + r_Point pnt2( r_Range(20) , r_Range(30) ); + unsigned long* c2 = (unsigned long*) testMDDObj->pointQuery( pnt2 ); + // char* c2 = testMDDObj->pointQuery( pnt2 ); + cout << "2. Result "<< pnt2 << ": "<< c2 << endl; + + cout << "Deleting the created object ... " << endl; + delete testMDDObj; + printMemInfo(); +} + + +void testRemovetile( ) +{ + const int numTilesObj = 20; + r_Sinterval domSinterval; + BaseType* anyType = new( (d_Database*)(d_Database::transient_memory) ) ULongType; // ULongType anyType; + char anyCell[4]= {'a','b','c','\0'}; + int j,i; + TransMDDObj* testMDDObj; + vector<Tile*>* allTilesObj; + vector<Tile*> tilesToDelete; + const MDDBaseType* anyBaseType = + new( (d_Database*)(d_Database::transient_memory) ) MDDBaseType( "AnyType", anyType ); + + cout << "Creating transient tiles for the MDD object ... " << endl; + vector<TransTile*> tilesVect; + + // initialize array of tiles + for ( j=0; j<numTilesObj ; j++) + { + r_Minterval dom(2); + domSinterval.set_interval( r_Range(j* 10), r_Range((j+1)*10-1) ); + dom << domSinterval << domSinterval; + cout << "New TransTile " << endl; + tilesVect.push_back( new TransTile( dom, anyType, anyCell ) ); + // printMemInfo( ); + } + + cout << "Creating the transient MDD object ... " << endl; + + r_Minterval dom(2); + domSinterval.set_interval( r_Range( 0 ), r_Range( 100 ) ); + domSinterval.set_low( '*' ); + dom << domSinterval << domSinterval; + testMDDObj = new TransMDDObj( anyBaseType, dom ); + for( j=0; j < numTilesObj; j++) + { + cout << "InsertTile " << endl ; + testMDDObj->insertTile( ( Tile*) tilesVect[j] ); + // printMemInfo( ); + } + + cout << "Printing contents of the created object ... " << endl; + testMDDObj->printStatus( ); + + cout << "Getting all tiles from the object... " << endl; + allTilesObj = testMDDObj->getTiles( ); + // printMemInfo( ); + + cout << "Removing tile 2, 4, 6, and 12 from the object... " << endl; + for ( i = 0; i < allTilesObj->size( ); i++) + { + if ( i==2 || i == 4 || i == 6 || i == 12 ) + { + tilesToDelete.push_back( (*allTilesObj)[i]); + } + } + for ( i = 0; i < tilesToDelete.size( ); i++) + { + cout << " Tile is going to be removed " << endl; + testMDDObj->removeTile(tilesToDelete[i] ); + cout << endl << " Value of pointer to tile : " << tilesToDelete[i] << endl<< endl; + // printMemInfo(); + } + testMDDObj->printStatus( ); + + cout << "Deleting the created object ... " << endl; + // printMemInfo( ); + delete testMDDObj; + cout << "Already deleted " << endl; + // printMemInfo( ); + + delete allTilesObj; +} + + +void printMemInfo( ) +{ + + + // allows to store values in the program + struct mallinfo meminfo = mallinfo(); + + cout << " Memory Usage Information : " ; + cout << endl; + + cout << " space in arena : " << meminfo.arena << endl; + cout << " number of small blocks : " << meminfo.smblks << endl; + cout << " number of ordinary blocks : " << meminfo.ordblks << endl; + cout << " space in free ordinary blocks : " << meminfo.fordblks << endl; + cout << " space in used ordinary blocks : " << meminfo.uordblks << endl; + + // cout << "additional space from last call: " << meminfo.uordblks - memUsed << endl; + +} + + |