コード例 #1
0
ファイル: InjectErrorsShMem.cpp プロジェクト: dprevost/newpso
void PopulateHashMaps( Session & session, vector<myMap> & h )
{
   int i, j;
   string data, key;
   char s[4];
   psoObjectDefinition mapDef = { PSO_HASH_MAP, 0, 0, 0 };
   
   for ( i = 0; i < NUM_MAPS; ++i ) {
      session.CreateMap( h[i].name, mapDef, "Default", "Default" );
      h[i].map.Open( session, h[i].name );

      for ( j = 0; j < 20; ++j ) {
         sprintf(s, "%d", j);
         key = string("Key ") + s;
         data = string("Inserted data item = ") + s;
         sprintf(s, "%d", i);
         data += string(" in hashMap = ") + s;
         h[i].map.Insert( key.c_str(), key.length(), data.c_str(), data.length() );
      }
   }

   session.Commit();
}
コード例 #2
0
ファイル: GetFirst.cpp プロジェクト: dprevost/newpso
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;
}
コード例 #3
0
ファイル: DataDefODBC.cpp プロジェクト: dprevost/newpso
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;
}
コード例 #4
0
ファイル: Definition.cpp プロジェクト: dprevost/newpso
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;
}