예제 #1
0
void test_a_dbobject_with_an_object::should_use_transactions()
{
    DBObject testObject(connection);
    CPPUNIT_ASSERT(testObject.find(1));
    CPPUNIT_ASSERT(testObject.isValid());

    bool value1 = true;
    unsigned long value2 = 0x87654321;
    unsigned long value3 = 0xBDEBDBED;
    ByteString value4 = "AAAAAAAAAAAAAAAFFFFFFFFFFFFFFF";

    OSAttribute attr1(value1);
    OSAttribute attr2(value2);
    OSAttribute attr3(value3);
    OSAttribute attr4(value4);

    CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4));

    // Create secondary instance for the same object.
    // This needs to have a different connection to the database to simulate
    // another process accessing the data.
    DBObject testObject2(connection2);
    CPPUNIT_ASSERT(testObject2.find(1));
    CPPUNIT_ASSERT(testObject2.isValid());

    // Check that it has the same attributes
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());

    // Check that the attributes have the same values as set on testObject.
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4);

    // New values
    bool value1a = false;
    unsigned long value2a = 0x12345678;
    unsigned long value3a = 0xABABABAB;
    ByteString value4a = "EDEDEDEDEDEDEDEDEDEDEDEDEDEDED";

    OSAttribute attr1a(value1a);
    OSAttribute attr2a(value2a);
    OSAttribute attr3a(value3a);
    OSAttribute attr4a(value4a);

    // Start transaction on object
    CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));

    // Change the attributes
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1a));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2a));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3a));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4a));

    // Verify that the attributes were set
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());

    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Verify that they are unchanged on the other instance
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());

    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4);

    // Commit the transaction
    CPPUNIT_ASSERT(testObject.commitTransaction());

    // Verify that non-modifiable attributes did not propagate but modifiable attributes
    // have now changed on the other instance
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).isByteStringAttribute());

    // NOTE: 3 attributes below cannot be modified after creation and therefore are not required to propagate.
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_TOKEN).getBooleanValue() != value1a);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() != value2a);
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() != value3a);

    // CKA_ID attribute can be modified after creation and therefore should have propagated.
    CPPUNIT_ASSERT(testObject2.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Start transaction on object
    CPPUNIT_ASSERT(testObject.startTransaction(DBObject::ReadWrite));

    // Change the attributes
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_TOKEN, attr1));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_PRIME_BITS, attr2));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_VALUE_BITS, attr3));
    CPPUNIT_ASSERT(testObject.setAttribute(CKA_ID, attr4));

    // Verify that the attributes were set
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());

    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4);

    // Create a fresh third instance for the same object to force the data to be retrieved from the database.
    DBObject testObject3(connection2);
    CPPUNIT_ASSERT(testObject3.find(1));
    CPPUNIT_ASSERT(testObject3.isValid());

    // Verify that they are unchanged on the other instance, while the transaction is still in progress.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).isByteStringAttribute());

    // Verify that the attributes from the database are still hodling the same value as when the transaction started.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Abort the transaction
    CPPUNIT_ASSERT(testObject.abortTransaction());

    // Verify that after aborting the transaction the values in testObject have reverted back to their
    // original state.
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).isByteStringAttribute());

    // After aborting a transaction the testObject should be back to pre transaction state.
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject.getAttribute(CKA_ID).getByteStringValue() == value4a);

    // Verify that testObject3 still has the original values.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).isBooleanAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).isUnsignedLongAttribute());
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).isByteStringAttribute());

    // Verify that testObject3 still has the original values.
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_TOKEN).getBooleanValue() == value1a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_PRIME_BITS).getUnsignedLongValue() == value2a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_VALUE_BITS).getUnsignedLongValue() == value3a);
    CPPUNIT_ASSERT(testObject3.getAttribute(CKA_ID).getByteStringValue() == value4a);
}
예제 #2
0
bool Game::InitGame()
{


	// register all events
	VRegisterGameEvents();

	//
	// Initialize the ResCache - Chapter 5, page 141
	//
	//    Note - this is a little different from the book. Here we have a speccial resource ZIP file class, DevelopmentResourceZipFile,
	//    that actually reads directly from the source asset files, rather than the ZIP file. This is MUCH better during development, since
	//    you don't want to have to rebuild the ZIP file every time you make a minor change to an asset.
	//
	/*
	IResourceFile *zipFile = (m_bIsEditorRunning || m_Options.m_useDevelopmentDirectories) ?
		GCC_NEW DevelopmentResourceZipFile(L"Assets.zip", DevelopmentResourceZipFile::Editor) :
		GCC_NEW ResourceZipFile(L"Assets.zip");

	m_ResCache = GCC_NEW ResCache(50, zipFile);

	if (!m_ResCache->Init())
	{
		GCC_ERROR("Failed to initialize resource cache!  Are your paths set up correctly?");
		return false;
	}
	*/

	/*
	extern std::shared_ptr<IResourceLoader> CreateWAVResourceLoader();
	extern std::shared_ptr<IResourceLoader> CreateOGGResourceLoader();
	extern std::shared_ptr<IResourceLoader> CreateDDSResourceLoader();
	extern std::shared_ptr<IResourceLoader> CreateJPGResourceLoader();
	extern std::shared_ptr<IResourceLoader> CreateXmlResourceLoader();
	extern std::shared_ptr<IResourceLoader> CreateSdkMeshResourceLoader();
	extern std::shared_ptr<IResourceLoader> CreateScriptResourceLoader();
	*/

	// Note - register these in order from least specific to most specific! They get pushed onto a list.
	// RegisterLoader is discussed in Chapter 5, page 142

	/*
	m_ResCache->RegisterLoader(CreateWAVResourceLoader());
	m_ResCache->RegisterLoader(CreateOGGResourceLoader());
	m_ResCache->RegisterLoader(CreateDDSResourceLoader());
	m_ResCache->RegisterLoader(CreateJPGResourceLoader());
	m_ResCache->RegisterLoader(CreateXmlResourceLoader());
	m_ResCache->RegisterLoader(CreateSdkMeshResourceLoader());
	m_ResCache->RegisterLoader(CreateScriptResourceLoader());
	*/

	/*
	if (!LoadStrings("English"))
	{
		GCC_ERROR("Failed to load strings");
		return false;
	}
	*/


	//Initialize Lua Script Manager 
	if (!EngineSubsystems::getInstance().m_pLuaStateManager->VInit())
	{
		//Log error
		Engine::getInstance().Sys_Printf(stdout, "Could not load LUA");
		return false;
	}


	// Load the preinit file.  This is within braces to create a scope and destroy the resource once it's loaded.  We
	// don't need to do anything with it, we just need to load it.
	{
		//Resource resource(SCRIPT_PREINIT_FILE);
		//shared_ptr<ResHandle> pResourceHandle = m_ResCache->GetHandle(&resource);  // this actually loads the XML file from the zip file
	}

	// Register function exported from C++
	//ScriptExports::Register();
	//ScriptProcess::RegisterScriptClass();
	//BaseScriptComponent::RegisterScriptFunctions();


	//This could be done differently. Depending on players choice.
	//We could initialize specific renderer
	//For ex: If player choosed OpenGL -> Create new GLRenderer
	//If player choosed Vulkan -> Create new VulkanRenderer and so on
	g_pRendGL->VSetBackgroundColor(255, 20, 20, 200);
	g_pRendGL->VOnRestore();

	

	//In Game Code Complete 4 each Game View has a list of SceneNodes  but I think it's not right because due to duplicated data
	//My game view holds only orientation and position of player and renders ui specific to that game view. (still thinking about rendering in game view....)
	//Think about game view as a camera specific to each actor. :). Each actor will have it's own game view :)
	//Game view should only update it's positions and orientation in 3D world
	//Game view takes our current renderer
	m_pGame = VCreateGameAndView();
	if (!m_pGame)
	{
		return false;
	}

	// now that all the major systems are initialized, preload resources 
	//Preload calls are discussed in Chapter 5, page 148
	//m_ResCache->Preload("*.ogg", NULL);
	//m_ResCache->Preload("*.dds", NULL);
	//m_ResCache->Preload("*.jpg", NULL);




	std::shared_ptr<TestCube> testObject1(TYW_NEW TestCube("Cube", glx::vec3<float>(0.0f, 2.0f, 5.0f)));
	std::shared_ptr<TestCube> testObject2(TYW_NEW TestCube("Cube", glx::vec3<float>(5.0f, 2.0f, 5.0f)));
	std::shared_ptr<TestCube> testObject3(TYW_NEW TestCube("Cube", glx::vec3<float>(0.0f, 10.0f, 5.0f)));
	std::shared_ptr<TestCube> testObject4(TYW_NEW TestCube("Cube", glx::vec3<float>(-5.0f, 2.0f, 5.0f)));


	EngineSubsystems::getInstance().m_pSceneManager->AddChild(1, testObject1);
	EngineSubsystems::getInstance().m_pSceneManager->AddChild(2, testObject2);
	EngineSubsystems::getInstance().m_pSceneManager->AddChild(3, testObject3);
	EngineSubsystems::getInstance().m_pSceneManager->AddChild(4, testObject4);

	//Allocate memory
	EngineSubsystems::getInstance().m_pSceneManager->OnRestore();

	m_bIsRunning = true;
	return true;
}