Beispiel #1
0
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;
}
Beispiel #2
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;

   // Internal process object not initialized
   try {
      session.Init();
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_PROCESS_NOT_INITIALIZED ) {
         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();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }
   
   return 0;
}
Beispiel #3
0
void Server::AcceptanceHandler(Session pSession, const boost::system::error_code& error) 
{
	if (!error) 
	{
		pSession->Init(this->SType);
		pSession->Start();
		this->Start();
	} else {
		printf("[!] AcceptanceHandler Error: %s.\n", error.message().c_str());
	}
}
int main()
{
   Session *xgl;

    try
    {
        assert (sizeof (unsigned int) == 4);

#ifdef _WIN32
        // Record the state of the debug heap if we are using MSVC in
        // _DEBUG mode.
        _CrtSetReportMode (_CRT_WARN, _CRTDBG_MODE_FILE);
        _CrtSetReportFile (_CRT_WARN, _CRTDBG_FILE_STDOUT);
        _CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_FILE);
        _CrtSetReportFile (_CRT_ERROR, _CRTDBG_FILE_STDOUT);
        _CrtSetReportMode (_CRT_ASSERT, _CRTDBG_MODE_FILE);
        _CrtSetReportFile (_CRT_ASSERT, _CRTDBG_FILE_STDOUT);
#ifndef NDEBUG
        _CrtMemState ms1;
        _CrtMemCheckpoint (&ms1);
#endif
        {
#endif

        xgl = new Session;

        Log ("Testing Init/Release");
        xgl->Init ();
        xgl->Release ();

        Log ("Testing Init/Release with an error");
        xgl->Init ();
        bool failed = false;
        try { xgl->TotalModes (~0, PF_X8R8G8B8); }
        catch (const char *e) {
            Log (e);
            failed = true;
        }
        Assert (failed);
        xgl->Release ();

        Log ("Testing TotalDevices");
        xgl->Init ();
        unsigned devices = xgl->TotalDevices ();
        stringstream s;
        s << devices << " devices found";
        Log (s.str ());
        xgl->Release ();

        xgl->Init ();
        cout << "There are " << xgl->TotalDevices () << " total devices" << endl;
        xgl->Release ();
        cout << "Enter the device number (0-based):" << endl;
        unsigned device_number;
        cin >> device_number;

        ForEachDevice (device_number, GetDeviceInfoTest (), xgl);
        ForEachDevice (device_number, GetScreenRectTest (), xgl);
        ForEachDevice (device_number, GetCurrentModeTest (), xgl);
        ForEachDevice (device_number, GetTotalModesTest (), xgl);
        ForEachDevice (device_number, GetHWConversionTest (), xgl);
        GetModeTest gmt;
        ForEachMode (device_number, gmt, xgl);

        unsigned width = 1024;
        unsigned height = 768;

        //cout << "Enter the mode width:" << endl;
        //cin >> width;
        //cout << "Enter the mode height:" << endl;
        //cin >> height;

        s.str ("");
        s << "Looking for a " << width << "x" << height << " mode";
        Log (s.str ());
        FindMode fm (width, height);
        ForEachMode (device_number, fm, xgl);

        if (!fm.found)
            throw "Could not find a mode for the device with these dimensions";

        cout << "1 InitDeviceTest1" << endl;
        cout << "2 InitDeviceTest2" << endl;
        cout << "3 ClearFlipTest" << endl;
        cout << "4 BackBufferTest" << endl;
        cout << "5 OffscreenBufferTest" << endl;
        cout << "6 BlitTest" << endl;
        cout << "7 StretchRectTest" << endl;
        cout << "8 DoHWConversionTest" << endl;
        cout << "9 CopyFromBackBufferTest" << endl;
        cout << "10 CheckInterpolationTest" << endl;
        cout << "11 GammaRampTest" << endl;
        cout << "12 TextTest" << endl;
        cout << "13 Quit" << endl;
        cout << "Enter a test number (0 for all): " << endl;
        unsigned n;
        cin >> n;

        switch (n)
        {
            default: throw "Invalid test number";
            case 0:
                ForEachDevice (device_number, InitDeviceTest1 (), xgl, fm.mode);
                ForEachDevice (device_number, InitDeviceTest2 (), xgl, fm.mode);
                ForEachDevice (device_number, ClearFlipTest (), xgl, fm.mode);
                ForEachDevice (device_number, BackBufferTest (), xgl, fm.mode);
                ForEachDevice (device_number, OffscreenBufferTest (), xgl, fm.mode);
                ForEachSupportedHWConversion (device_number, BlitTest (), xgl, fm.mode);
                ForEachSupportedHWConversion (device_number, StretchRectTest (), xgl, fm.mode);
                ForEachSupportedHWConversion (device_number, DoHWConversionTest (), xgl, fm.mode);
                ForEachDevice (device_number, CopyFromBackBufferTest (), xgl, fm.mode);
                ForEachDevice (device_number, CheckInterpolationTest (), xgl, fm.mode);
                ForEachDevice (device_number, GammaRampTest (), xgl, fm.mode);
                ForEachDevice (device_number, TextTest (), xgl, fm.mode);
            break;
            case 1:  ForEachDevice (device_number, InitDeviceTest1 (), xgl, fm.mode); break;
            case 2:  ForEachDevice (device_number, InitDeviceTest2 (), xgl, fm.mode); break;
            case 3:  ForEachDevice (device_number, ClearFlipTest (), xgl, fm.mode); break;
            case 4:  ForEachDevice (device_number, BackBufferTest (), xgl, fm.mode); break;
            case 5:  ForEachDevice (device_number, OffscreenBufferTest (), xgl, fm.mode); break;
            case 6:  ForEachSupportedHWConversion (device_number, BlitTest (), xgl, fm.mode); break;
            case 7:  ForEachSupportedHWConversion (device_number, StretchRectTest (), xgl, fm.mode); break;
            case 8:  ForEachSupportedHWConversion (device_number, DoHWConversionTest (), xgl, fm.mode); break;
            case 9:  ForEachDevice (device_number, CopyFromBackBufferTest (), xgl, fm.mode); break;
            case 10: ForEachDevice (device_number, CheckInterpolationTest (), xgl, fm.mode); break;
            case 11: ForEachDevice (device_number, GammaRampTest (), xgl, fm.mode); break;
            case 12: ForEachDevice (device_number, TextTest (), xgl, fm.mode); break;
            case 13: break;
        }

        delete xgl;
#ifdef _WIN32
        // Now compare the heap saved off to the current one to make
        // sure we haven't leaked any memory resources.
        }
#ifndef NDEBUG
        _CrtMemState ms2, diff;
#endif
        _CrtMemCheckpoint (&ms2);

        if (_CrtMemDifference (&diff, &ms1, &ms2))
        {
            _CrtMemDumpStatistics (&diff);
            _CrtMemDumpAllObjectsSince (&ms1);
            throw "Memory leaks detected";
        }
#endif
        Log ("Success");
        return 0;
    }
    catch (const char *e)
    {
        cerr << e << endl;
        Log (e);
        delete xgl;
        return -1;
    }
}
Beispiel #5
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;
}
Beispiel #6
0
int main( int argc, char * argv[] )
{
    Process process;
    Session session;
    DataDefinition * pDataDef = NULL;
    string name = "/cpp_datadefinition_create";
    unsigned char byteData[50];
    unsigned int dataLength = 50;

    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;
    }

    // Session is not initialized

    try {
        pDataDef = new DataDefinition( session,
                                       name,
                                       PSO_DEF_USER_DEFINED,
                                       byteData,
                                       dataLength );
        // Should never come here
        cerr << "Test failed - line " << __LINE__ << endl;
        return 1;
    }
    catch( pso::Exception exc ) {
        if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
            cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
            return 1;
        }
    }

    try {
        session.Init();
    }
    catch( pso::Exception exc ) {
        cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
        return 1;
    }

    // Wrong arguments to tested function

    try {
        pDataDef = new DataDefinition( session,
                                       "",
                                       PSO_DEF_USER_DEFINED,
                                       byteData,
                                       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 {
        pDataDef = new DataDefinition( session,
                                       "Default",
                                       PSO_DEF_USER_DEFINED,
                                       byteData,
                                       dataLength );
        // Should never come here
        cerr << "Test failed - line " << __LINE__ << endl;
        return 1;
    }
    catch( pso::Exception exc ) {
        if ( exc.ErrorCode() != PSO_ITEM_ALREADY_PRESENT ) {
            cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
            return 1;
        }
    }

    try {
        pDataDef = new DataDefinition( session,
                                       name,
                                       (psoDefinitionType)0,
                                       byteData,
                                       dataLength );
        // Should never come here
        cerr << "Test failed - line " << __LINE__ << endl;
        return 1;
    }
    catch( pso::Exception exc ) {
        if ( exc.ErrorCode() != PSO_WRONG_OBJECT_TYPE ) {
            cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
            return 1;
        }
    }

    try {
        pDataDef = new DataDefinition( session,
                                       name,
                                       PSO_DEF_USER_DEFINED,
                                       NULL,
                                       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 {
        pDataDef = new DataDefinition( session,
                                       name,
                                       PSO_DEF_USER_DEFINED,
                                       byteData,
                                       0 );
        // 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;
        }
    }

    // This call should work

    try {
        pDataDef = new DataDefinition( session,
                                       name,
                                       PSO_DEF_USER_DEFINED,
                                       byteData,
                                       dataLength );
    }
    catch( pso::Exception exc ) {
        cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
        return 1;
    }

    delete pDataDef;

    return 0;
}
Beispiel #7
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_get_definition";
   unsigned char byteData[50], returnedData[50];
   unsigned int dataLength = 50;

   for ( int i = 0; i < 50; ++i ) {
      byteData[i] = i*2 + 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;
   }

   // DataDefinition is not initialized

   try {
      dataDef.GetDefinition( returnedData, dataLength );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // Wrong arguments to tested function
   
   try {
      dataDef.GetDefinition( NULL, 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 {
      dataDef.GetDefinition( returnedData, 0 );
      // 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;
      }
   }

   // This call should work
   
   try {
      dataDef.GetDefinition( returnedData, dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << exc.ErrorCode() << endl;
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   if ( memcmp( byteData, returnedData, dataLength ) != 0 ) {
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   
   dataDef.Close();
   
   return 0;
}
Beispiel #8
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;
}
Beispiel #9
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition * pDataDef;
   string name = "Default";

   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;
   }

   // Session is not initialized
   
   try {
      pDataDef = new DataDefinition( session, name );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // Wrong arguments to tested function
   
   try {
      pDataDef = new DataDefinition( session, "" );
      // 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 {
      pDataDef = new DataDefinition( session, "blah-blah-junk" );
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NO_SUCH_ITEM ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   // This call should work
   
   try {
      pDataDef = new DataDefinition( session, name );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   delete pDataDef;
   
   return 0;
}
Beispiel #10
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;
}
Beispiel #11
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_close";
   unsigned char byteData[50];
   unsigned int dataLength = 50;

   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;
   }

   // DataDefinition is not initialized

   try {
      dataDef.Close();
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   try {
      dataDef.Close();
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   return 0;
}
Beispiel #12
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;
}
Beispiel #13
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;
}
Beispiel #14
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;
}
Beispiel #15
0
int main( int argc, char * argv[] )
{
   Process process;
   Session session;
   DataDefinition dataDef;
   string name = "/cpp_datadefinition_get_definition";
   unsigned char byteData[50];
   unsigned int dataLength = 50;
   string fieldDescription;
   
   memcpy( &byteData[0],  "Field 1  ", 9 );
   memcpy( &byteData[10], "Field 2  ", 9 );
   memcpy( &byteData[20], "Field 3  ", 9 );
   memcpy( &byteData[30], "Field 4  ", 9 );
   memcpy( &byteData[40], "Field 5  ", 9 );
   byteData[9]  = 0;
   byteData[19] = 0;
   byteData[29] = 0;
   byteData[39] = 0;
   byteData[49] = 0;
   
   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;
   }

   // DataDefinition is not initialized

   try {
      fieldDescription = dataDef.GetNext();
      // Should never come here
      cerr << "Test failed - line " << __LINE__ << endl;
      return 1;
   }
   catch( pso::Exception exc ) {
      if ( exc.ErrorCode() != PSO_NULL_HANDLE ) {
         cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
         return 1;
      }
   }

   try {
      session.Init();
      dataDef.Create( session, 
                      name,
                      PSO_DEF_USER_DEFINED,
                      byteData,
                      dataLength );
   }
   catch( pso::Exception exc ) {
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   // This call should work
   
   try {
      do {
         fieldDescription = dataDef.GetNext();
         cout << fieldDescription << endl;
      } while ( fieldDescription.length() > 0 );
   }
   catch( pso::Exception exc ) {
      cerr << exc.ErrorCode() << endl;
      cerr << "Test failed - line " << __LINE__ << ", error = " << exc.Message() << endl;
      return 1;
   }

   dataDef.Close();
   
   return 0;
}