int main( int argc, char * argv[] ) { Process process; Session session; Folder * folder; string name = "/cpp_folder_create"; string subname = "test"; try { if ( argc > 1 ) { process.Init( argv[1], argv[0] ); } else { process.Init( "10701", argv[0] ); } } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } try { session.Init(); session.CreateFolder( name ); folder = new Folder( session, name ); } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } // Invalid arguments to tested function. try { folder->CreateFolder( "" ); cerr << "Test failed - line " << __LINE__ << endl; return 1; } catch( pso::Exception exc ) { if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } } // End of invalid args. This call should succeed. try { folder->CreateFolder( subname ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } return 0; }
int main() { Process process; Session session; int i, rc; psoObjectDefinition folderDef; memset( &folderDef, 0, sizeof folderDef ); folderDef.type = PSO_FOLDER; try { process.Init( "10701", "InjectErrors" ); session.Init(); session.CreateFolder( foldername ); } catch( pso::Exception exc ) { rc = exc.ErrorCode(); if ( rc == PSO_OBJECT_ALREADY_PRESENT ) { CleanupPreviousRun( session ); } else { cerr << "Init Photon failed, error = " << exc.Message() << endl; if ( rc == PSO_CONNECT_ERROR ) cerr << "Is the server running?" << endl; return 1; } } cout << " ------- Photon defects injector ------- " << endl << endl; cout << " This program will inject pseudo-random defects in a shared memory." << endl << endl; vector<myQueue> q( NUM_QUEUES, myQueue() ); vector<myMap> h( NUM_MAPS, myMap() ); vector<myLifo> l( NUM_LIFOS, myLifo() ); for ( i = 0; i < NUM_QUEUES; ++ i ) { q[i].name += ('0' + i/10 ); q[i].name += ('0' + (i%10) ); } for ( i = 0; i < NUM_MAPS; ++i ) { h[i].name += ('0' + i/10 ); h[i].name += ('0' + (i%10) ); } for ( i = 0; i < NUM_LIFOS; ++i ) { l[i].name += ('0' + i/10 ); l[i].name += ('0' + (i%10) ); } try { PopulateQueues( session, q ); PopulateHashMaps( session, h ); PopulateLifos( session, l ); } catch( pso::Exception exc ) { cerr << "Creating and populating the objects failed, error = " << exc.Message() << endl; return 1; } cout << "Queues, maps, etc. are created and populated." << endl << endl; rc = AddDefectsQueues( q ); if ( rc != 0 ) { cerr << "Adding defect to queues failed!" << endl; return 1; } cout << "All defects were added to queues." << endl << endl; rc = AddDefectsHashMaps( h ); if ( rc != 0 ) { cerr << "Adding defect to hash maps failed!" << endl; return 1; } cout << "All defects were added to hash maps." << endl << endl; rc = AddDefectsLifos( l ); if ( rc != 0 ) { cerr << "Adding defect to LIFO queues failed!" << endl; return 1; } cout << "All defects were added to LIFO queues." << endl << endl; return 0; }
int main( int argc, char * argv[] ) { Process process; Session session; FastMap * map; string fname = "/cpp_fastmap_fielddefODBC"; string hname = fname + "/test"; size_t len; psoObjectDefinition mapDef = { PSO_FAST_MAP, 0, 0, 0 }; DataDefBuilderODBC fieldDef( 5 ); KeyDefBuilderODBC keyDef( 3 ); DataDefinition * returnedDataDef; KeyDefinition * returnedKeyDef; unsigned char * buffer; try { fieldDef.AddField( "field1", 6, PSO_TINYINT, 0, 0, 0 ); fieldDef.AddField( "field2", 6, PSO_INTEGER, 0, 0, 0 ); fieldDef.AddField( "field3", 6, PSO_CHAR, 30, 0, 0 ); fieldDef.AddField( "field4", 6, PSO_SMALLINT, 0, 0, 0 ); fieldDef.AddField( "field5", 6, PSO_LONGVARBINARY, 0, 0, 0 ); keyDef.AddKeyField( "keyfield1", 9, PSO_KEY_INTEGER, 0 ); keyDef.AddKeyField( "keyfield2", 9, PSO_KEY_CHAR, 30 ); keyDef.AddKeyField( "keyfield3", 9, PSO_KEY_LONGVARBINARY, 0 ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { if ( argc > 1 ) { process.Init( argv[1], argv[0] ); } else { process.Init( "10701", argv[0] ); } } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } try { session.Init(); session.CreateFolder( fname ); DataDefinition dataDefObj( session, "cpp_fastmap_datadef_odbc", PSO_DEF_PHOTON_ODBC_SIMPLE, fieldDef.GetDefinition(), fieldDef.GetDefLength() ); KeyDefinition keyDefObj( session, "cpp_fastmap_datadef_odbc", PSO_DEF_PHOTON_ODBC_SIMPLE, keyDef.GetDefinition(), keyDef.GetDefLength() ); session.CreateMap( hname, mapDef, dataDefObj, keyDefObj ); map = new FastMap( session, hname ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { returnedDataDef = map->GetDataDefinition(); returnedKeyDef = map->GetKeyDefinition(); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { len = 5 * sizeof(psoFieldDefinition); buffer = new unsigned char [len]; if ( len != returnedDataDef->GetLength() ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } returnedDataDef->GetDefinition( buffer, len ); if ( memcmp( fieldDef.GetDefinition(), buffer, len ) != 0 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } delete [] buffer; len = 3 * sizeof(psoKeyFieldDefinition); buffer = new unsigned char [len]; if ( len != returnedKeyDef->GetLength() ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } returnedKeyDef->GetDefinition( buffer, len ); if ( memcmp( keyDef.GetDefinition(), buffer, len ) != 0 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } return 0; }
int main( int argc, char * argv[] ) { Process process; Session session; int errcode; string name = "/cpp_session_last_error"; try { if ( argc > 1 ) { process.Init( argv[1], argv[0] ); } else { process.Init( "10701", argv[0] ); } } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } try { session.Init(); // Is last error properly initialized? errcode = session.LastError(); if ( errcode != PSO_OK ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } // Our first "test call" session.CreateFolder( name ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { errcode = session.LastError(); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } if ( errcode != PSO_OK ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } // Create the same object a second time and check that last error is // the one we expect. try { session.CreateFolder( name ); // Should never come here cerr << "Test failed - line " << __LINE__ << endl; return 1; } catch( pso::Exception exc ) { if ( exc.ErrorCode() != PSO_OBJECT_ALREADY_PRESENT ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } } try { errcode = session.LastError(); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } if ( errcode != PSO_OBJECT_ALREADY_PRESENT ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } return 0; }
int main( int argc, char * argv[] ) { Process process; Session session; HashMap hashmap; string fname = "/cpp_hashmap_getfirst"; string hname = fname + "/test"; const char * key = "My Key"; const char * data = "My Data"; char buffer[50]; char buffKey[50]; uint32_t dataLength, keyLength; psoObjectDefinition mapDef = { PSO_HASH_MAP, 0, 0, 0 }; psoKeyFieldDefinition keyDef = { "MyKey", PSO_KEY_VARBINARY, 20 }; psoFieldDefinition fields[1] = { { "Field_1", PSO_VARCHAR, {10} } }; try { if ( argc > 1 ) { process.Init( argv[1], argv[0] ); } else { process.Init( "10701", argv[0] ); } } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } try { session.Init(); session.CreateFolder( fname ); DataDefinition dataDefObj( session, "cpp_hashmap_getfirst", PSO_DEF_PHOTON_ODBC_SIMPLE, (unsigned char *)fields, sizeof(psoFieldDefinition) ); KeyDefinition keyDefObj( session, "cpp_hashmap_getfirst", PSO_DEF_PHOTON_ODBC_SIMPLE, (unsigned char *)&keyDef, sizeof(psoKeyFieldDefinition) ); session.CreateMap( hname, mapDef, dataDefObj, keyDefObj ); hashmap.Open( session, hname ); hashmap.Insert( key, 6, data, 7 ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } // Invalid arguments to tested function. try { hashmap.GetFirst( NULL, 50, buffer, 50, keyLength, dataLength ); // Should never come here cerr << "Test failed - line " << __LINE__ << endl; return 1; } catch( pso::Exception exc ) { if ( exc.ErrorCode() != PSO_NULL_POINTER ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } } try { hashmap.GetFirst( buffKey, 2, buffer, 50, keyLength, dataLength ); // Should never come here cerr << "Test failed - line " << __LINE__ << endl; return 1; } catch( pso::Exception exc ) { if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } } try { hashmap.GetFirst( buffKey, 50, NULL, 50, keyLength, dataLength ); // Should never come here cerr << "Test failed - line " << __LINE__ << endl; return 1; } catch( pso::Exception exc ) { if ( exc.ErrorCode() != PSO_NULL_POINTER ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } } try { hashmap.GetFirst( buffKey, 50, buffer, 2, keyLength, dataLength ); // Should never come here cerr << "Test failed - line " << __LINE__ << endl; return 1; } catch( pso::Exception exc ) { if ( exc.ErrorCode() != PSO_INVALID_LENGTH ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } } // End of invalid args. This call should succeed. try { hashmap.GetFirst( buffKey, 50, buffer, 50, keyLength, dataLength ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } if ( memcmp( buffer, data, 7 ) != 0 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } return 0; }
int main( int argc, char * argv[] ) { Process process; Session session; Queue * queue; string fname = "/cpp_queue_status"; string qname = fname + "/test"; const char * data1 = "My Data1"; const char * data2 = "My Data2"; const char * data3 = "My Data3"; psoObjStatus status; psoObjectDefinition queueDef = { PSO_QUEUE, 0, 0, 0 }; psoFieldDefinition fields[1] = { { "Field_1", PSO_VARCHAR, {10} } }; try { if ( argc > 1 ) { process.Init( argv[1], argv[0] ); } else { process.Init( "10701", argv[0] ); } } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } try { session.Init(); session.CreateFolder( fname ); DataDefinition dataDefObj( session, "cpp_queue_status", PSO_DEF_PHOTON_ODBC_SIMPLE, (unsigned char *)fields, sizeof(psoFieldDefinition) ); session.CreateQueue( qname, queueDef, dataDefObj ); queue = new Queue( session, qname ); queue->Push( data1, strlen(data1) ); queue->Push( data2, strlen(data2) ); queue->Push( data3, strlen(data3) ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } // End of invalid args. This call should succeed. try { queue->Status( status ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } if ( status.numDataItem != 3 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } if ( status.numBlocks != 1 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } if ( status.numBlockGroup != 1 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } if ( status.freeBytes == 0 || status.freeBytes >=PSON_BLOCK_SIZE ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } return 0; }
int main( int argc, char * argv[] ) { Process process; Session session; HashMap * hashmap; string fname = "/cpp_hashmap_definition"; string hname = fname + "/test"; psoObjectDefinition mapDef = { PSO_HASH_MAP, 0, 0, 0 }; psoFieldDefinition fields[5] = { { "field1", PSO_TINYINT, {0} }, { "field2", PSO_INTEGER, {0} }, { "field3", PSO_CHAR, {30} }, { "field4", PSO_SMALLINT, {0} }, { "field5", PSO_LONGVARBINARY, {0} } }; psoKeyFieldDefinition keys[2] = { { "LastName", PSO_KEY_CHAR, 30 }, { "FirstName", PSO_KEY_VARCHAR, 30 } }; DataDefinition * retDataDef = NULL; KeyDefinition * retKeyDef = NULL; unsigned char * retFields = NULL; unsigned char * retKeys = NULL; try { if ( argc > 1 ) { process.Init( argv[1], argv[0] ); } else { process.Init( "10701", argv[0] ); } } catch( pso::Exception exc ) { cerr << "Test failed in init phase, error = " << exc.Message() << endl; cerr << "Is the server running?" << endl; return 1; } try { session.Init(); session.CreateFolder( fname ); DataDefinition dataDefObj( session, "cpp_hashmap_definition", PSO_DEF_PHOTON_ODBC_SIMPLE, (unsigned char *)fields, 5*sizeof(psoFieldDefinition) ); KeyDefinition keyDefObj( session, "cpp_hashmap_definition", PSO_DEF_PHOTON_ODBC_SIMPLE, (unsigned char *)keys, 2*sizeof(psoKeyFieldDefinition) ); session.CreateMap( hname, mapDef, dataDefObj, keyDefObj ); hashmap = new HashMap( session, hname ); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { retDataDef = hashmap->GetDataDefinition(); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { if ( retDataDef->GetType() != PSO_DEF_PHOTON_ODBC_SIMPLE ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } if ( retDataDef->GetLength() != 5*sizeof(psoFieldDefinition) ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } retFields = new unsigned char [5*sizeof(psoFieldDefinition)]; retDataDef->GetDefinition( retFields, 5*sizeof(psoFieldDefinition) ); if ( memcmp( retFields, fields, 5*sizeof(psoFieldDefinition) ) != 0 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { retKeyDef = hashmap->GetKeyDefinition(); } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } try { if ( retKeyDef->GetType() != PSO_DEF_PHOTON_ODBC_SIMPLE ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } if ( retKeyDef->GetLength() != 2*sizeof(psoKeyFieldDefinition) ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } retKeys = new unsigned char [2*sizeof(psoKeyFieldDefinition)]; retKeyDef->GetDefinition( retKeys, 2*sizeof(psoKeyFieldDefinition) ); if ( memcmp( retKeys, keys, 2*sizeof(psoKeyFieldDefinition) ) != 0 ) { cerr << "Test failed - line " << __LINE__ << endl; return 1; } } catch( pso::Exception exc ) { cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl; return 1; } return 0; }