Ejemplo n.º 1
0
void TestObjectsFlushRemovesStackPointers(void)
{
	CFileUtil						cFileUtil;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/ClearPointers");

	ObjectsInit("Output/ClearPointers");
	SetupObjectsConstructors();

	pRoot = ORoot();

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(2, gcObjects.NumDatabaseObjects());

	AssertNull(&pRoot);

	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	AssertString("CTestDoubleNamedString", pDouble.ClassName());

	pRoot = ORoot();
	AssertString("CRoot", pRoot.ClassName());

	ObjectsKill();
}
Ejemplo n.º 2
0
void TestEmbeddedObjectAddDistToRoot(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot = ORoot();
	Ptr<CGameWorld>			pWorld = OMalloc(CGameWorld)->Init();

	pRoot->Add(pWorld);

	Ptr<CClusterMissile>	pMissile = ONMalloc(CClusterMissile, "Frank")->Init(pWorld);
	Ptr<CHarrier>			pHarrier = OMalloc(CHarrier)->Init(pWorld);
	
	pWorld->AddPlayer(pHarrier);
	AssertInt(3, pHarrier->GetDistToRoot());

	pRoot->Add(pMissile);

	AssertInt(2, pMissile->GetDistToRoot());
	AssertInt(2, pMissile->mcMissile1.GetDistToRoot());
	AssertInt(2, pMissile->mcMissile2.GetDistToRoot());

	pMissile->mcMissile1.SetTarget(pHarrier);

	AssertInt(3, pHarrier->GetDistToRoot());

	ObjectsKill();
}
Ejemplo n.º 3
0
void TestKillSelfPointer2(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot;
	Ptr<CTestNamedObject>	pObject;
	BOOL					bResult;

	pRoot = ORoot();

	pObject = OMalloc(CTestNamedObject);
	pObject->Init(1);
	pObject->mpNamedTest1 = pObject;

	pRoot->Add(pObject);
	AssertInt(1, pRoot->NumObjects());

	AssertLongLongInt(3, gcObjects.NumMemoryIndexes());

	//pObject should not be destroyed here and not cause a stack overflow.
	bResult = pRoot->Remove(pObject);
	AssertTrue(bResult);
	AssertInt(0, pRoot->NumObjects());
	AssertLongLongInt(3, gcObjects.NumMemoryIndexes());

	//If there were cyclic pointers then the object cannot tell it should be freed when a stack pointer is removed.
	pObject = NULL;
	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());

	ObjectsKill();
}
Ejemplo n.º 4
0
void TestObjectsFlushClearGetByName(void)
{
	CFileUtil						cFileUtil;
	CPointer						pObject;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;

	cFileUtil.RemoveDir("Output");
	cFileUtil.MakeDir("Output/Dehollowfication");

	ObjectsInit("Output/Dehollowfication");
	SetupObjectsConstructors();

	pRoot = ORoot();
	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init();
	pRoot->Add(pDouble);
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	pObject = gcObjects.Get(3);
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	gcObjects.Flush(TRUE, TRUE);
	AssertLongLongInt(3, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(2, gcObjects.NumDatabaseNames());

	pObject = gcObjects.Get("Double");
	AssertNotNull(pObject.Object());
	AssertString("CTestDoubleNamedString", pObject.ClassName());

	ObjectsKill();
}
Ejemplo n.º 5
0
void TestKillLongCyclicSelfPointer(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot;
	Ptr<CTestNamedObject>	pObject1;
	Ptr<CTestNamedObject>	pObject2;
	Ptr<CTestNamedObject>	pObjectBase;
	BOOL					bResult;

	pRoot = ORoot();

	pObjectBase = OMalloc(CTestNamedObject);
	pObject1 = OMalloc(CTestNamedObject);
	pObjectBase->Init(0);
	pObject1->Init(1);
	pObjectBase->mpNamedTest1 = pObject1;
	pObject1->mpNamedTest1 = pObjectBase;

	pRoot->Add(pObjectBase);

	//pObject should be destroyed here and not cause a stack overflow.
	bResult = pRoot->Remove(pObjectBase);
	AssertTrue(bResult);

	ObjectsKill();
}
Ejemplo n.º 6
0
Ptr<CTestDoubleNamedString> SetupObjectsForDehollowfication(void)
{
	Ptr<CTestNamedString>			cNS1;
	Ptr<CTestNamedString>			cNS2;
	Ptr<CTestNamedString>			cNS3;
	Ptr<CTestNamedString>			cDiamond;
	Ptr<CTestDoubleNamedString>		pDouble;
	Ptr<CRoot>						pRoot;
	Ptr<CString>					cS1;
	Ptr<CString>					cS2;

	pRoot = ORoot();

	cDiamond = ONMalloc(CTestNamedString, "Diamond")->Init();

	cS1 = OMalloc(CString)->Init("CS1");
	cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, cDiamond, "NS1");

	cNS2 = ONMalloc(CTestNamedString, "NS2")->Init(ONull, cDiamond, "NS2");

	cNS3 = ONMalloc(CTestNamedString, "NS3")->Init(ONull, cNS1, "NS3");

	cS2 = OMalloc(CString)->Init("CS2");
	cDiamond->Init(cS2, ONull, "Diamond");

	pDouble = ONMalloc(CTestDoubleNamedString, "Double")->Init(ONull, cNS2, cNS3);

	pRoot->Add(pDouble);
	return pDouble;
}
void TestObjectGraphDeserialiserBuildGraph1(void)
{
	Ptr<CTestSaveableObject2>	cStart1;
	Ptr<CTestSaveableObject2>	cStart2;
	Ptr<CRoot>					cRoot;
	Ptr<CTestSaveableObject1>	cShared;
	Ptr<CString>				cString1;
	Ptr<CString>				cString2;
	Ptr<CTestInteger>			cIgnored;

	cRoot = ORoot();
	cStart1 = ONMalloc(CTestSaveableObject2, "Ow/Start 1")->Init("Battery");
	cStart2 = ONMalloc(CTestSaveableObject2, "Ow/Start 2")->Init("Charger");
	cShared = ONMalloc(CTestSaveableObject1, "Ow/Shared")->Init();
	cString1 = OMalloc(CString)->Init("Black");
	cString2 = OMalloc(CString)->Init("Jack");
	cIgnored = OMalloc(CTestInteger)->Init(0, 1, 0);
	
	cRoot->Add(cStart1);
	cRoot->Add(cStart2);

	cStart1->mp1 = cShared;
	cStart2->mp1 = cShared;

	cShared->miInt = 89;
	cShared->mpObject = cShared;

	cStart1->mp2 = cString1;
	cStart2->mp2 = cString2;

	cRoot->Add(cIgnored);
}
Ejemplo n.º 8
0
void TestKillSelfPointer1(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot;
	Ptr<CTestNamedObject>	pObject;
	BOOL					bResult;
	CBaseObject*			pvObject;

	pRoot = ORoot();

	pObject = OMalloc(CTestNamedObject);
	pObject->Init(1);
	pObject->mpNamedTest1 = pObject;

	pRoot->Add(pObject);
	AssertInt(1, pRoot->NumObjects());

	AssertLongLongInt(3, gcObjects.NumMemoryIndexes());

	pvObject = pObject.BaseObject();
	pObject = NULL;

	//pObject should be destroyed here and not cause a stack overflow.
	bResult = pRoot->Remove(pvObject);
	AssertTrue(bResult);
	AssertInt(0, pRoot->NumObjects());

	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());

	ObjectsKill();
}
void TestDehollowficationFromDatabaseOfTwoPointers(void)
{
	CIndexedConfig	cConfig;
	CFileUtil		cFileUtil;

	cConfig.Manual("Output\\Dehollowfication\\Database",
		FALSE,
		TRUE,
		FALSE,
		1 MB);

	cFileUtil.RemoveDir("Output\\Dehollowfication\\Database");

	MemoryInit();
	ObjectsInit(&cConfig);
	SetupDehollowficationScene();
	gcObjects.Flush(FALSE, FALSE);
	ObjectsKill();
	MemoryKill();

	MemoryInit();
	ObjectsInit(&cConfig);
	SetupDehollowficationConstructors();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CTestDoubleNamedString> pDouble = pRoot->Get<CTestDoubleNamedString>("Double Start");

	Ptr<CTestNamedString> pString1 = pDouble->mpSplit1;
	Ptr<CTestNamedString> pString2 = pDouble->mpSplit2;
	pString1->ClassName();
	pString2->ClassName();

	Ptr<CTestNamedString> pDiamond1 = pString1->mpAnother;
	Ptr<CTestNamedString> pDiamond2 = pString2->mpAnother;

	AssertTrue(pDiamond1.IsHollow());
	AssertTrue(pDiamond2.IsHollow());
	AssertPointer(pDiamond1.Object(), pDiamond2.Object());
	AssertPointer(pString1->mpAnother.Object(), pString2->mpAnother.Object());
	AssertLongLongInt(3LL, pDiamond1.GetIndex());
	AssertLongLongInt(3LL, pDiamond2.GetIndex());

	//Dehollofication of pDiamond1 happens here. pString1->mpAnother and pString2->mpAnother are remapped to the dehollowed diamond object.
	pDiamond1->ClassName();

	AssertFalse(pDiamond1.IsHollow());
	AssertFalse(pDiamond2.IsHollow());  //This should be false but it's not until I remap local pointers.
	AssertPointer(pDiamond1.Object(), pDiamond2.Object());  //These should be the same but they're not until I remap local pointers.
	AssertLongLongInt(3LL, pDiamond1.GetIndex());

	AssertFalse(pString1->mpAnother.IsHollow());
	AssertFalse(pString2->mpAnother.IsHollow());
	AssertPointer(pString1->mpAnother.Object(), pString2->mpAnother.Object());

	ObjectsKill();
	MemoryKill();
}
Ejemplo n.º 10
0
void TestEmbeddedObjectRemoveDistToRoot(void)
{
	ObjectsInit();

	Ptr<CRoot>				pRoot = ORoot();
	Ptr<CGameWorld>			pWorld = OMalloc(CGameWorld)->Init();

	pRoot->Add(pWorld);

	Ptr<CClusterMissile>	pMissile = ONMalloc(CClusterMissile, "Frank")->Init(pWorld);
	Ptr<CHarrier>			pHarrier = OMalloc(CHarrier)->Init(pWorld);
	Ptr<CMissile>			pHolder = OMalloc(CMissile)->Init(pWorld);
	
	pWorld->AddTickable(pHolder);
	AssertInt(4, pHolder->GetDistToRoot());

	pHolder->SetTarget(pHarrier);
	AssertInt(5, pHarrier->GetDistToRoot());

	Ptr<CClusterLauncher>	pLauncher = OMalloc(CClusterLauncher)->Init();

	pRoot->Add(pLauncher);
	AssertInt(2, pLauncher->GetDistToRoot());

	pLauncher->mpMissile = pMissile;

	AssertInt(3, pMissile->GetDistToRoot());
	AssertInt(3, pMissile->mcMissile1.GetDistToRoot());
	AssertInt(3, pMissile->mcMissile2.GetDistToRoot());
	AssertInt(5, pHarrier->GetDistToRoot());
	AssertInt(1, pHarrier->NumHeapFroms());

	pMissile->mcMissile1.SetTarget(pHarrier);
	AssertInt(4, pHarrier->GetDistToRoot());
	AssertInt(2, pHarrier->NumHeapFroms());

	pWorld->RemoveTickable(pHolder);
	pHolder = NULL;

	AssertInt(4, pHarrier->GetDistToRoot());
	AssertInt(1, pHarrier->NumHeapFroms());

	pRoot->Add(pHarrier);
	AssertInt(2, pHarrier->GetDistToRoot());

	pRoot->Remove(pHarrier);
	AssertInt(4, pHarrier->GetDistToRoot());

	ObjectsKill();
}
Ejemplo n.º 11
0
void TestEmbeddedObjectPointTo(void)
{
	BOOL		bResult;
	CFileUtil	cFileUtil;
	OIndex		oiComplex;
	char*		szClassName;
	
	cFileUtil.RemoveDir("Output/EmbeddedObject");

	MemoryInit();
	ObjectsInit("Output/EmbeddedObject/");
	SetupEmbeddedObjectConstructors();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CEmbeddedComplex> pComplex = OMalloc(CEmbeddedComplex)->Init();
	oiComplex = pComplex->GetOI();

	Ptr<CEmbeddedContainer> pContainer = &pComplex->mcContainer;
	pRoot->Add(pContainer);

	bResult = gcObjects.Flush(TRUE, TRUE);
	AssertTrue(bResult);

	ObjectsKill();
	MemoryKill();

	AssertNull(&pContainer);

	MemoryInit();
	ObjectsInit("Output/EmbeddedObject/");
	SetupEmbeddedObjectConstructors();

	pRoot = gcObjects.GetRoot();
	AssertTrue(pRoot.IsNotNull());
	pContainer = pRoot->Get(0);
	AssertTrue(pContainer.IsHollow());
	AssertInt(0, pContainer.Object()->GetNumEmbedded());
	AssertLongLongInt(-1, pContainer.GetIndex());

	szClassName = pContainer->ClassName();
	AssertString("CEmbeddedContainer", szClassName);

	pComplex = pContainer->GetEmbeddingContainer();
	//Kinda feels like this test just stopped...

	ObjectsKill();
	MemoryKill();
}
Ejemplo n.º 12
0
void TestObjectsObjectKillInGraph(void)
{
	Ptr<CTestNamedString>	cNS1;
	Ptr<CTestNamedString>	cNS2;
	Ptr<CRoot>				pRoot;
	Ptr<CString>			cS1;
	Ptr<CString>			cS2;
	CTestNamedString*		pcNS2;
	CString*				pcS2;

	ObjectsInit();

	pRoot = ORoot();

	cS1 = OMalloc(CString);
	cS1->Init("CS1");
	cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, ONull, "NS1");

	cS2 = OMalloc(CString)->Init("CS2");
	cNS2 = ONMalloc(CTestNamedString, "NS2")->Init(cS2, cNS1, "NS2");

	pRoot->Add(cNS2);
	
	AssertPointer(cNS2->mpAnother.Object(), cNS1.Object());
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());
	pcNS2 = &cNS2;
	cNS2 = NULL;
	pRoot = NULL;
	cS1 = NULL;
	pcS2 = &cS2;
	cS2 = NULL;
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());

	cNS1->Kill();

	AssertNull(pcNS2->mpAnother.Object());
	AssertLongLongInt(4, gcObjects.NumMemoryIndexes());
	AssertPointer(pcNS2->mszString.Object(), pcS2);

	ObjectsKill();
}
Ejemplo n.º 13
0
void TestObjectsObjectKillInArrayInGraph(void)
{
	Ptr<CTestNamedString>	cNS1;
	Ptr<CArrayObject>		cA1;
	Ptr<CArrayObject>		cA2;
	Ptr<CRoot>				pRoot;
	Ptr<CString>			cS1;

	ObjectsInit();

	pRoot = ORoot();

	cS1 = OMalloc(CString)->Init("CS1");
	cNS1 = ONMalloc(CTestNamedString, "NS1")->Init(cS1, ONull, "NS1");

	cA1 = OMalloc(CArrayObject)->Init();
	cA2 = OMalloc(CArrayObject)->Init();

	cA1->Add(cNS1);
	cA2->Add(cNS1);

	pRoot->Add(cA1);
	pRoot->Add(cA2);

	AssertInt(1, cA1->NumPointerTos());
	AssertInt(1, cA2->NumPointerTos());
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());
	pRoot = NULL;
	cS1 = NULL;
	AssertLongLongInt(6, gcObjects.NumMemoryIndexes());

	cNS1->Kill();
	AssertLongLongInt(4, gcObjects.NumMemoryIndexes());

	AssertInt(0, cA1->NumPointerTos());
	AssertInt(0, cA2->NumPointerTos());


	ObjectsKill();
}
Ejemplo n.º 14
0
void TestKillBestPractice(void)
{
	ObjectsInit();

	//Generally an object will be killed if all pointers to it a removed.
	//Sometimes we'd rather not try and remove all the pointers we just want the object to die.
	//In the example below if a missile hits a jet then both objects should be removed;
	//regardless of whether anything else points to them.
	//Those objects that did point to them will be updated to point to NULL.

	Ptr<CRoot>			pRoot;
	Ptr<CGameWorld>		pWorld;

	pRoot = ORoot();

	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	pWorld = OMalloc(CGameWorld);
	pWorld->Init();

	pRoot->Add(pWorld);

	Ptr<CHarrier> pHarrier = ONMalloc(CHarrier, "Harrier");
	pHarrier->Init(pWorld);

	Ptr<CJeep> pJeep = ONMalloc(CJeep, "Jeep");
	pJeep->Init(pWorld);

	pWorld->AddPlayer(pHarrier);
	pWorld->AddPlayer(pJeep);

	SStateOnKill	sHarrierBefore;
	SStateOnKill	sHarrierAfter;
	SStateOnKill	sJeepBefore;
	SStateOnKill	sJeepAfter;

	pHarrier->SetKillHook(&sHarrierBefore, &sHarrierAfter);
	pJeep->SetKillHook(&sJeepBefore, &sJeepAfter);

	SStateOnKill	sGooseBefore;
	SStateOnKill	sGooseAfter;
	SStateOnKill	sMaverickBefore;
	SStateOnKill	sMaverickAfter;

	Ptr<CRedJet>	pRedJetGoose = ONMalloc(CRedJet, "Goose");
	Ptr<CRedJet>	pRedJetMaverick = ONMalloc(CRedJet, "Maverick");

	pRedJetGoose->Init(pWorld);
	pRedJetMaverick->Init(pWorld);

	pRedJetGoose->SetKillHook(&sGooseBefore, &sGooseAfter);
	pRedJetMaverick->SetKillHook(&sMaverickBefore, &sMaverickAfter);

	Ptr<CMissile> pMissile1 = pHarrier->FireMissile(pRedJetGoose);
	Ptr<CMissile> pMissile2 = pHarrier->FireMissile(pRedJetGoose);
	Ptr<CMissile> pMissile3 = pHarrier->FireMissile(pRedJetMaverick);

	AssertString("Kill not called", sMaverickBefore.cPicture.mszPretenedImAPicture);
	AssertString("Kill not called", sMaverickAfter.cPicture.mszPretenedImAPicture);
	AssertLongLongInt(12, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(5, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	AssertInt(2, pWorld.GetDistToRoot());
	AssertInt(3, pHarrier.GetDistToRoot());
	AssertInt(3, pJeep.GetDistToRoot());
	AssertInt(4, pRedJetGoose.GetDistToRoot());
	AssertInt(4, pRedJetMaverick.GetDistToRoot());
	AssertInt(4, pMissile1.GetDistToRoot());
	AssertInt(4, pMissile2.GetDistToRoot());
	AssertInt(4, pMissile3.GetDistToRoot());
	AssertInt(2, pRedJetMaverick->NumHeapFroms());
	AssertInt(3, pHarrier->GetMissiles()->NumElements());

	OIndex oiMissile3 = pMissile3->GetOI();
	AssertLongLongInt(12LL, oiMissile3);

	pMissile3->Kill();  //<-- This is what is being tested.
	pMissile3 = gcObjects.TestGetFromMemory(oiMissile3);
	AssertTrue(pMissile3.IsNull());

	AssertString("Kill not called", sMaverickBefore.cPicture.mszPretenedImAPicture);
	AssertString("Kill not called", sMaverickAfter.cPicture.mszPretenedImAPicture);
	AssertLongLongInt(11, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(5, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	AssertInt(2, pWorld.GetDistToRoot());
	AssertInt(3, pHarrier.GetDistToRoot());
	AssertInt(3, pJeep.GetDistToRoot());
	AssertInt(4, pRedJetGoose.GetDistToRoot());
	AssertInt(4, pRedJetMaverick.GetDistToRoot());
	AssertInt(4, pMissile1.GetDistToRoot());
	AssertInt(4, pMissile2.GetDistToRoot());
	AssertInt(1, pRedJetMaverick->NumHeapFroms());
	AssertInt(2, pHarrier->GetMissiles()->NumElements());

	AssertString("Kill not called", sGooseBefore.cPicture.mszPretenedImAPicture);
	AssertString("Kill not called", sGooseAfter.cPicture.mszPretenedImAPicture);

	pRedJetGoose->Kill();
	AssertString("012345678901234", sGooseBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sGooseAfter.cPicture.mszPretenedImAPicture);
	AssertInt(1, pMissile1->NumTos());
	CPointer pTarget1(pMissile1->GetTarget());
	AssertTrue(pTarget1.IsNull());
	AssertInt(1, pMissile2->NumTos());
	CPointer pTarget2 = pMissile2->GetTarget();
	AssertTrue(pTarget2.IsNull());
	AssertLongLongInt(10, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(4, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());
	AssertInt(2, pWorld.GetDistToRoot());
	AssertInt(3, pHarrier.GetDistToRoot());
	AssertInt(3, pJeep.GetDistToRoot());
	AssertInt(4, pRedJetMaverick.GetDistToRoot());
	AssertInt(4, pMissile1.GetDistToRoot());
	AssertInt(4, pMissile2.GetDistToRoot());

	pMissile1->Kill();
	pMissile2->Kill();
	AssertInt(0, pHarrier->GetMissiles()->NumElements());
	AssertTrue(pMissile1.IsNull());
	AssertTrue(pMissile2.IsNull());

	pJeep = NULL;
	pRedJetMaverick = NULL;
	pHarrier = NULL;

	//pHarrier.maMissiles.moi == 6
	//pWorld.maTickables.moi == 4
	//pWorld is pointed to from:
	//  pRoot.mpObjects
	//  pHarrier
	//  pJeep
	//  pRedJetMaverick

	pRoot->Remove(pWorld);
	//ERROR: (baseobject.cpp:1159) void __thiscall CBaseObject::ValidateCanFindRoot(void) Object {02596128 [ 4]:CArrayObject(128) 6} has a positive dist to root and should be able to find the Root object.

	AssertLongLongInt(8, gcObjects.NumMemoryIndexes());
	pWorld = NULL;

	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(1, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());

	AssertInt('X', sHarrierBefore.sPoint.x);
	AssertInt('Y', sHarrierBefore.sPoint.y);
	AssertInt('Z', sHarrierBefore.sPoint.z);
	AssertString("012345678901234", sHarrierBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sHarrierAfter.cPicture.mszPretenedImAPicture);
	AssertString("012345678901234", sJeepBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sJeepAfter.cPicture.mszPretenedImAPicture);

	ObjectsKill();
}
Ejemplo n.º 15
0
void TestEmbeddedObjectContainerDehollowfication(void)
{
	BOOL		bResult;
	CFileUtil	cFileUtil;
	char*		szClassName;
	OIndex		oiComplex;

	cFileUtil.RemoveDir("Output/EmbeddedObject");

	MemoryInit();
	ObjectsInit("Output/EmbeddedObject/");
	SetupEmbeddedObjectConstructors();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CEmbeddedComplex> pComplex = OMalloc(CEmbeddedComplex)->Init();
	oiComplex = pComplex->GetOI();

	pRoot->Add(pComplex);

	bResult = gcObjects.Flush(TRUE, TRUE);
	AssertTrue(bResult);

	ObjectsKill();
	MemoryKill();

	AssertInt(176, sizeof(CEmbeddedTest));
	AssertInt(544, sizeof(CEmbeddedContainer));
	AssertInt(1032, sizeof(CEmbeddedComplex));

	MemoryInit();
	ObjectsInit("Output/EmbeddedObject/");
	SetupEmbeddedObjectConstructors();

	pRoot = gcObjects.GetRoot();
	AssertTrue(pRoot.IsNotNull());
	pComplex = pRoot->Get(0);
	AssertTrue(pComplex.IsHollow());
	
	szClassName = pComplex->ClassName();
	AssertString("CEmbeddedComplex", szClassName);
	AssertLongLongInt(oiComplex, pComplex.GetIndex());

	AssertInt(1, pComplex->mai[0]);
	AssertInt(2, pComplex->mai[1]);
	
	AssertLongLongInt(INVALID_O_INDEX, pComplex->mcSimple.GetOI());
	AssertInt(85, pComplex->mcSimple.miAmANumber);
	AssertFloat(58.0f, pComplex->mcSimple.mfSoAmI, 0);

	AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.GetOI());
	AssertInt(73, pComplex->mcContainer.mi);
	AssertFloat(666.0f, pComplex->mcContainer.mf, 0);
	AssertString("And", pComplex->mcContainer.msz);

	AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.mcOne.GetOI());
	AssertInt(85, pComplex->mcContainer.mcOne.miAmANumber);
	AssertFloat(58.0f, pComplex->mcContainer.mcOne.mfSoAmI, 0);

	AssertLongLongInt(INVALID_O_INDEX, pComplex->mcContainer.mcTwo.GetOI());
	AssertInt(85, pComplex->mcContainer.mcTwo.miAmANumber);
	AssertFloat(58.0f, pComplex->mcContainer.mcTwo.mfSoAmI, 0);

	AssertLongLongInt(3, gcObjects.NumMemoryIndexes());

	ObjectsKill();
	MemoryKill();
}
Ejemplo n.º 16
0
void TestEmbeddedObjectKill(void)
{
	char	szClusterMissileState[64];
	char	szMissile1State[64];

	ObjectsInit();

	Ptr<CRoot> pRoot = ORoot();
	Ptr<CGameWorld> pWorld = OMalloc(CGameWorld)->Init();

	pRoot->Add(pWorld);

	Ptr<CClusterMissile> pClusterMissile = ONMalloc(CClusterMissile, "Anna")->Init(pWorld);
	pWorld = NULL;

	Ptr<CPointerContainer> pPointerPointer = OMalloc(CPointerContainer);
	pRoot->Add(pPointerPointer);
	pPointerPointer->Init(&pClusterMissile->mcMissile1);

	Ptr<CPointerContainer> pPointerPointer2 = OMalloc(CPointerContainer);
	pRoot->Add(pPointerPointer2);
	pPointerPointer2->Init(&pClusterMissile);

	//The number of allocated object shouldn't change until all the froms are removed
	//both from the embedded object and the 'normal' object.
	AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(7, gcUnknowns.NumElements());

	pClusterMissile->SetKillString(szClusterMissileState);
	pClusterMissile->mcMissile1.SetKillString(szMissile1State);

	AssertInt(2, pClusterMissile->NumHeapFroms());
	AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms());
	strcpy(szClusterMissileState, "Alive");
	strcpy(szMissile1State, "Alive");

	pPointerPointer->Clear();

	AssertInt(1, pClusterMissile->NumHeapFroms());
	AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(0, pClusterMissile->mcMissile1.NumHeapFroms());
	AssertString("Alive", szClusterMissileState);
	AssertString("Alive", szMissile1State);

	pPointerPointer->mp = &pClusterMissile->mcMissile1;

	AssertInt(2, pClusterMissile->NumHeapFroms());
	AssertInt(1, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms());

	pPointerPointer2->Clear();

	AssertInt(1, pClusterMissile->NumHeapFroms());
	AssertInt(0, pClusterMissile->CEmbeddedObject::NumHeapFroms());
	AssertInt(1, pClusterMissile->mcMissile1.NumHeapFroms());
	AssertString("Alive", szClusterMissileState);
	AssertString("Alive", szMissile1State);

	pClusterMissile = NULL;

	//Make sure nothing has been de-allocated.
	AssertLongLongInt(7, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(7, gcUnknowns.NumElements());

	pPointerPointer->Clear();

	AssertString("Killed", szClusterMissileState);
	AssertString("Killed", szMissile1State);

	AssertLongLongInt(6, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(6, gcUnknowns.NumElements());

	gcObjects.Flush(TRUE, FALSE);

	AssertLongLongInt(0, gcObjects.GetMemory()->NumIndexed());
	AssertLongLongInt(0, gcUnknowns.NumElements());

	ObjectsKill();
}
void TestRemappingOfOIs(CObjectWriter* pcWriter, CObjectReader* pcReader)
{
	CFileUtil					cFileUtil;
	Ptr<CTestSaveableObject2>	cBase;
	Ptr<CTestSaveableObject2>	cStart1;
	Ptr<CRoot>					cRoot;
	Ptr<CString>				szOne;
	Ptr<CString>				cString1;
	Ptr<CString>				cString2;
	CObjectGraphSerialiser		cGraphSerialiser;
	CObjectGraphDeserialiser	cGraphDeserialiser;
	Ptr<CTestSaveableObject1>	cShared;
	int							i;
	CObjectAllocator			cAllocator;
	CDependentReadObjects		cDependentReadObjects;

	cFileUtil.MakeDir("Output/GraphDeserialiser/Simple/Remapping");

	ObjectsInit("Output/GraphDeserialiser/Simple/Remapping");
	TestObjectGraphDeserialiserAddConstructors();
	TestObjectGraphDeserialiserBuildGraph1();

	cBase = gcObjects.Get("Ow/Start 1");
	AssertTrue(cBase.IsNotNull());
	AssertLongLongInt(3, cBase->GetOI());
	cString1 = gcObjects.Get(6LL);
	AssertString("Black", cString1->Text());
	AssertLongLongInt(6LL, cString1->GetOI());
	cString2 = gcObjects.Get(7LL);
	AssertString("Jack", cString2->Text());
	AssertLongLongInt(7LL, cString2->GetOI());

	cGraphSerialiser.Init(pcWriter);
	AssertTrue(cGraphSerialiser.Write(&cBase));
	cGraphSerialiser.Kill();
	pcWriter->Kill();

	ObjectsKill();

	ObjectsInit("Output/GraphDeserialiser/Simple/Remapping");
	TestObjectGraphDeserialiserAddConstructors();

	cRoot = ORoot();

	for (i = 0; i < 20; i++)
	{
		szOne = OMalloc(CString);
		szOne->Init("Hello World ");
		szOne->Append(i);
		cRoot->Add(szOne);
		AssertLongLongInt(3+i, szOne->GetOI());
	}

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cGraphDeserialiser.Init(pcReader, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cStart1 = cGraphDeserialiser.Read("Ow/Start 1");
	AssertTrue(cStart1.IsNotNull());
	AssertLongLongInt(23, cStart1->GetOI());

	AssertTrue(cStart1->mp1.IsNotNull());
	AssertString("CTestSaveableObject1", cStart1->mp1->ClassName());
	cShared = cStart1->mp1;
	AssertLongLongInt(25, cShared->GetOI());

	AssertTrue(cStart1->mp2.IsNotNull());
	AssertString("CString", cStart1->mp2->ClassName());
	cString1 = cStart1->mp2;
	AssertLongLongInt(24, cString1->GetOI());
	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();

	for (i = 0; i < 20; i++)
	{
		szOne = OMalloc(CString);
		szOne->Init("Hello World ");
		szOne->Append(i + 20);
		cRoot->Add(szOne);
		AssertLongLongInt(26+i, szOne->GetOI());
	}

	pcReader->Kill();

	ObjectsKill();
}
void TestDehollowficationFromDatabase(void)
{
	CIndexedConfig	cConfig;
	CFileUtil		cFileUtil;

	cConfig.Manual("Output\\Dehollowfication\\Database",
					FALSE,
					TRUE,
					FALSE,
					1 MB);

	cFileUtil.RemoveDir("Output\\Dehollowfication\\Database");

	MemoryInit();
	ObjectsInit(&cConfig);
	SetupDehollowficationScene();
	gcObjects.Flush(FALSE, FALSE);
	ObjectsKill();
	MemoryKill();

	MemoryInit();
	ObjectsInit(&cConfig);
	SetupDehollowficationConstructors();
	AssertLongLongInt(0, gcUnknowns.NumElements());
	AssertInt(0, gcObjects.GetStackPointers()->UsedPointers());

	AssertLongLongInt(0, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(0, gcObjects.NumMemoryNames());
	AssertLongLongInt(11, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjectsCached());
	AssertLongLongInt(6, gcObjects.NumDatabaseNames());

	Ptr<CRoot> pRoot = ORoot();

	AssertTrue(pRoot->IsSetHollow());

	AssertLongLongInt(2, gcUnknowns.NumElements());
	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(1, gcObjects.NumMemoryNames());
	AssertLongLongInt(1, gcObjects.NumDatabaseObjectsCached());
	AssertLongLongInt(6, gcObjects.NumDatabaseNames());
	AssertInt(1, gcObjects.GetStackPointers()->UsedPointers());

	Ptr<CTestDoubleNamedString> pTest = pRoot->Get<CTestDoubleNamedString>("Double Start");  //This will cause pRoot.Set to be dehollowed.
	AssertInt(2, gcObjects.GetStackPointers()->UsedPointers());
	AssertFalse(pRoot->IsSetHollow());
	AssertTrue(pTest.IsNotNull());
	AssertTrue(pTest.IsHollow());
	AssertLongLongInt(10, pTest.GetIndex());
	AssertLongLongInt(4, gcUnknowns.NumElements());
	AssertLongLongInt(4, gcObjects.NumMemoryIndexes());
	
	AssertString("12345", pTest->mpSplit1->mszEmbedded.Text()); //This will cause pTest and pTest.Split1 to be dehollowed.
	AssertLongLongInt(9, gcUnknowns.NumElements());
	AssertLongLongInt(9, gcObjects.NumMemoryIndexes());
	AssertFalse(pTest.IsHollow());
	AssertLongLongInt(10, pTest.GetIndex());
	AssertInt(2, gcObjects.GetStackPointers()->UsedPointers());
	AssertTrue(pTest->mpSplit1->mpAnother.IsHollow());
	AssertTrue(pTest->mpSplit2.IsHollow());
	AssertTrue(pTest->mpSplit1->mszString.IsHollow());
	AssertString("Diamond End", pTest->mpSplit1->mpAnother.GetName());
	AssertString("6789", pTest->mpSplit1->mszString->Text());
	AssertFalse(pTest->mpSplit1->mszString.IsHollow());

	AssertInt(2, gcObjects.GetStackPointers()->UsedPointers());

	Ptr<CTestNamedString> pDiamond = pTest->mpSplit1->mpAnother;
	AssertLongLongInt(9, gcUnknowns.NumElements());
	AssertLongLongInt(9, gcObjects.NumMemoryIndexes());
	AssertInt(3, gcObjects.GetStackPointers()->UsedPointers());
	AssertTrue(pTest->mpSplit1->mpAnother.IsHollow());
	AssertTrue(pDiamond.IsHollow());

	pDiamond->ClassName(); //This will cause pDiamond to be de-hollowed

	AssertFalse(pDiamond.IsHollow());
	AssertFalse(pTest->mpSplit1->mpAnother.IsHollow());

	AssertLongLongInt(10, gcUnknowns.NumElements());
	AssertLongLongInt(10, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(6, gcObjects.NumMemoryNames());
	AssertLongLongInt(3, gcObjects.NumDatabaseObjectsCached());
	AssertLongLongInt(6, gcObjects.NumDatabaseNames());

	AssertTrue(pTest->mpSplit2.IsHollow());
	pTest->mpSplit2->ClassSize();
	AssertFalse(pTest->mpSplit2.IsHollow());
	AssertFalse(pTest->mpSplit2->mpAnother.IsHollow());
	AssertPointer(pDiamond.Object(), pTest->mpSplit2->mpAnother.Object());

	AssertLongLongInt(11, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(6, gcObjects.NumMemoryNames());
	AssertLongLongInt(2, gcObjects.NumDatabaseObjectsCached());
	AssertLongLongInt(6, gcObjects.NumDatabaseNames());

	Ptr<CTestNamedString> pRandom = pRoot->Get<CTestNamedString>("NamedString 3");
	AssertTrue(pRandom.IsNotNull());
	AssertTrue(pRandom.IsHollow());

	AssertTrue(pRandom->mszString.IsHollow());
	AssertFalse(pRandom.IsHollow());
	AssertTrue(pTest->mpSplit2->mszString.IsHollow());

	AssertString("World", pRandom->mszString->Text());
	AssertFalse(pRandom->mszString.IsHollow());
	AssertFalse(pTest->mpSplit2->mszString.IsHollow());
	AssertPointer(pRandom->mszString.Object(), pTest->mpSplit2->mszString.Object());

	AssertLongLongInt(11, gcObjects.NumDatabaseObjects());

	ObjectsKill();

	AssertTrue(pRoot.IsNull());
	AssertTrue(pTest.IsNull());
	AssertTrue(pDiamond.IsNull());
	AssertTrue(pRandom.IsNull());

	pDiamond.UnsafeClearObject();

	MemoryKill();
}
Ejemplo n.º 19
0
void TestKillCanFindRoot(void)
{
	ObjectsInit();

	Ptr<CRoot>			pRoot;
	Ptr<CGameWorld>		pWorld;
	CGameWorld*			pcWorld;

	pRoot = ORoot();

	pWorld = OMalloc(CGameWorld);
	pWorld->Init();

	pRoot->Add(pWorld);

	Ptr<CHarrier> pHarrier = ONMalloc(CHarrier, "Harrier");
	pHarrier->Init(pWorld);

	Ptr<CJeep> pJeep = ONMalloc(CJeep, "Jeep");
	pJeep->Init(pWorld);

	pWorld->AddPlayer(pHarrier);
	pWorld->AddPlayer(pJeep);

	SStateOnKill	sHarrierBefore;
	SStateOnKill	sHarrierAfter;
	SStateOnKill	sJeepBefore;
	SStateOnKill	sJeepAfter;

	pHarrier->SetKillHook(&sHarrierBefore, &sHarrierAfter);
	pJeep->SetKillHook(&sJeepBefore, &sJeepAfter);

	SStateOnKill	sGooseBefore;
	SStateOnKill	sGooseAfter;
	SStateOnKill	sMaverickBefore;
	SStateOnKill	sMaverickAfter;

	Ptr<CRedJet>	pRedJetGoose = ONMalloc(CRedJet, "Goose");
	Ptr<CRedJet>	pRedJetMaverick = ONMalloc(CRedJet, "Maverick");

	pRedJetGoose->Init(pWorld);
	pRedJetMaverick->Init(pWorld);

	pRedJetGoose->SetKillHook(&sGooseBefore, &sGooseAfter);
	pRedJetMaverick->SetKillHook(&sMaverickBefore, &sMaverickAfter);

	AssertTrue(pJeep->CanFindRoot());
	AssertTrue(pRedJetMaverick->CanFindRoot());
	AssertTrue(pHarrier->CanFindRoot());
	AssertTrue(pHarrier->GetMissiles()->CanFindRoot());
	AssertTrue(pRedJetGoose->CanFindRoot());
	AssertTrue(pWorld->CanFindRoot());
	AssertTrue(pWorld->GetTickables()->CanFindRoot());
	AssertTrue(pRoot->CanFindRoot());
	AssertTrue(pRoot->TestGetSet()->CanFindRoot());
	AssertLongLongInt(9, gcObjects.NumMemoryIndexes());

	//     
	// 4        ArrayObject[6](4)
	// 4                 ^
	// 4                 |                     pRedJetGoose[8,Goose](4)
	// 4                 |                            ^/
	//                   |                           //  pRedJetMaverick[9,Maverick](4)
	// 3  pHarrier[5,Harrier](3)   pJeep[7,Jeep](3) //   ^/  
	// 3                |^     ^   /^     ^        //   //
	// 3                ||      \ //      |       //   //
	// 3                ||       //       |      //   //
	// 3                ||      //\       |     //   //
	// 3                ||     //  \      |    /.   //
	// 3                ||    //   ArrayObject[4](3)/
	//                  ||   //    ^          .    /
	// 2                ||  //    /          /    /
	// 2                v| v/    /          v    v 
	// 2               pWorld[3](2)---------------
	//                   ^
	// 1                 |
	// 1             SetObject[2](1)
	//                   ^
	// 0                 |
	// 0              pRoot[1,GraphRoot](0)
	//  

	pRoot->Remove(pWorld);
	AssertFalse(pJeep->CanFindRoot());
	AssertFalse(pRedJetMaverick->CanFindRoot());
	AssertFalse(pHarrier->CanFindRoot());
	AssertFalse(pHarrier->GetMissiles()->CanFindRoot());  //The destruction of the pointer created by pHarrier->GetMissiles() set a lot of the root distances to -2.
	AssertFalse(pRedJetGoose->CanFindRoot());
	AssertFalse(pWorld->CanFindRoot());
	AssertFalse(pWorld->GetTickables()->CanFindRoot());
	AssertTrue(pRoot->CanFindRoot());
	AssertTrue(pRoot->TestGetSet()->CanFindRoot());
	AssertInt(-1, pJeep->GetDistToRoot());
	AssertInt(-1, pRedJetMaverick->GetDistToRoot());
	AssertInt(-1, pHarrier->GetDistToRoot());
	AssertInt(-1, pHarrier->GetMissiles()->GetDistToRoot());
	AssertInt(-1, pRedJetGoose->GetDistToRoot());
	AssertInt(-1, pWorld->GetDistToRoot());
	AssertInt(-1, pWorld->GetTickables()->GetDistToRoot());
	AssertLongLongInt(9, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(5, gcObjects.NumMemoryNames());
	AssertLongLongInt(0, gcObjects.NumDatabaseObjects());
	AssertLongLongInt(0, gcObjects.NumDatabaseNames());

	pJeep = NULL;
	pRedJetMaverick = NULL;
	pHarrier = NULL;
	pRedJetGoose = NULL;
	pcWorld = &pWorld;
	pWorld = NULL;

	AssertLongLongInt(2, gcObjects.NumMemoryIndexes());
	AssertLongLongInt(1, gcObjects.NumMemoryNames());

	AssertInt('X', sHarrierBefore.sPoint.x);
	AssertInt('Y', sHarrierBefore.sPoint.y);
	AssertInt('Z', sHarrierBefore.sPoint.z);
	AssertString("012345678901234", sHarrierBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sHarrierAfter.cPicture.mszPretenedImAPicture);
	AssertString("012345678901234", sJeepBefore.cPicture.mszPretenedImAPicture);
	AssertString("Alas I am Dead!", sJeepAfter.cPicture.mszPretenedImAPicture);

	ObjectsKill();
}
Ptr<CTestDoubleNamedString> SetupDehollowficationScene(void)
{
	Ptr<CTestNamedString>			cNS1;
	Ptr<CTestNamedString>			cNS2;
	Ptr<CTestNamedString>			cDiamond;
	Ptr<CTestDoubleNamedString>	cDouble;
	Ptr<CString>					sz1;
	Ptr<CString>					sz3;
	Ptr<CString>					sz2;
	Ptr<CString>					sz4;
	Ptr<CRoot>						cRoot;
	Ptr<CTestNamedString>			cNS3;

	cRoot = ORoot();

	cDiamond = ONMalloc(CTestNamedString, "Diamond End");
	sz1 = OMalloc(CString);

	cNS1 = ONMalloc(CTestNamedString, "NamedString 1");
	cNS1->Init(sz1, cDiamond, "Hello");
	sz1->Init("World");

	cNS2 = ONMalloc(CTestNamedString, "NamedString 2");
	sz2 = OMalloc(CString);

	cNS2->Init(sz2, cDiamond, "12345");
	sz2->Init("6789");

	sz3 = OMalloc(CString);
	sz3->Init("End");
	cDiamond->Init(sz3, ONull, "Before Swine");

	sz4 = OMalloc(CString);
	sz4->Init("Start");
	cDouble = ONMalloc(CTestDoubleNamedString, "Double Start");
	cDouble->Init(sz4, cNS1, ONull);

	cRoot->Add(cDouble);

	cDouble->mpSplit1 = cNS2;

	cNS3 = ONMalloc(CTestNamedString, "NamedString 3");
	cNS3->Init(sz1, ONull, "Random");

	cRoot->Add(cNS3);

//
//      sz3
//       |
//    cDiamond
//      / \
// sz2 /   \  sz1
//  | /     \  |
//  cNS2    cNS1
//    \     /
//     \   / sz4
//      \ /  /
//    cDouble   sz1 
//       \       |
//        \    cNS3
//         \   /
//          \ /
//          Set
//           |
//         cRoot
//       

	return cDouble;
}
void TestOverwritingOfExistingNamesFromChunkedFiles(void)
{
	CObjectWriterChunked			cWriterStart1;
	CObjectWriterChunked			cWriterStart2;
	CFileUtil						cFileUtil;
	Ptr<CTestSaveableObject2>		cOwStart1;
	Ptr<CTestSaveableObject2>		cOwStart2;
	CObjectGraphSerialiser			cGraphSerialiser;
	CObjectGraphDeserialiser		cGraphDeserialiser;
	CObjectReaderChunkFileDisk		cReaderStart1;
	CObjectReaderChunkFileDisk		cReaderStart2;
	Ptr<CTestSaveableObject1>		cShared;
	Ptr<CRoot>						cRoot;
	CPointer						cObject;
	int								iNumUnknowns;
	int								iNumIndexes;
	int								iNumNames;
	CObjectAllocator				cAllocator;
	CDependentReadObjects			cDependentReadObjects;

	cWriterStart1.Init("Output/GraphDeserialiser/Simple/Remapping", "", "Start1");
	cWriterStart2.Init("Output/GraphDeserialiser/Simple/Remapping", "", "Start2");

	cFileUtil.MakeDir("Output/GraphDeserialiser/Simple/Remapping");

	ObjectsInit("Output/GraphDeserialiser/Simple/Remapping");
	TestObjectGraphDeserialiserAddConstructors();
	TestObjectGraphDeserialiserBuildGraph1();

	cOwStart1 = gcObjects.Get("Ow/Start 1");
	cGraphSerialiser.Init(&cWriterStart1);
	AssertTrue(cGraphSerialiser.Write(&cOwStart1));
	cGraphSerialiser.Kill();
	cWriterStart1.Kill();

	cOwStart2 = gcObjects.Get("Ow/Start 2");
	cGraphSerialiser.Init(&cWriterStart2);
	AssertTrue(cGraphSerialiser.Write(&cOwStart2));
	cGraphSerialiser.Kill();
	cWriterStart2.Kill();

	cShared = gcObjects.Get("Ow/Shared");
	
	AssertInt(3, cShared->NumHeapFroms());
	AssertPointer(&cOwStart1, cShared->GetHeapFrom(0));
	AssertPointer(&cOwStart2, cShared->GetHeapFrom(1));
	AssertPointer(&cShared, cShared->GetHeapFrom(2));  //Remember: cShared->mpObject = cShared;
	AssertInt(2, cOwStart1->NumPointerTos());
	AssertPointer(&cShared, cOwStart1->TestGetPointerTo(0));
	AssertPointer(&cOwStart1->mp1, cOwStart1->TestGetPointerTo(0));
	AssertPointer(&cOwStart1->mp2, cOwStart1->TestGetPointerTo(1));
	AssertInt(2, cOwStart1->GetDistToRoot());
	AssertInt(3, cShared->GetDistToRoot());

	ObjectsKill();

	ObjectsInit("Output/GraphDeserialiser/Simple/Remapping");
	TestObjectGraphDeserialiserAddConstructors();
	cRoot = ORoot();

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cReaderStart1.Init("Output/GraphDeserialiser/Simple/Remapping", "Start1");
	cGraphDeserialiser.Init(&cReaderStart1, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cOwStart1 = cGraphDeserialiser.Read("Ow/Start 1");
	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();
	cReaderStart1.Kill();

	AssertInt(-1, cOwStart1->GetDistToRoot());
	
	cRoot->Add(cOwStart1);

	cShared = gcObjects.Get("Ow/Shared");

	//Make sure the pointed 'froms' are correctly setup after loading.
	AssertInt(2, cShared->NumHeapFroms());
	AssertPointer(&cOwStart1, cShared->GetHeapFrom(0));
	AssertPointer(&cShared, cShared->GetHeapFrom(1));
	AssertInt(2, cOwStart1->NumPointerTos());
	AssertPointer(&cShared, cOwStart1->TestGetPointerTo(0));
	AssertPointer(&cOwStart1->mp1, cOwStart1->TestGetPointerTo(0));
	AssertPointer(&cOwStart1->mp2, cOwStart1->TestGetPointerTo(1));
	AssertInt(2, cOwStart1->GetDistToRoot());
	AssertInt(3, cShared->GetDistToRoot());

	AssertInt(89, cOwStart1->mp1->miInt);
	cOwStart1->mp1->miInt = 66;

	iNumUnknowns = gcUnknowns.NumElements();
	iNumIndexes = (int)gcObjects.NumMemoryIndexes();
	iNumNames = gcObjects.NumMemoryNames();

	cAllocator.Init(&gcObjects);
	cDependentReadObjects.Init();
	cReaderStart2.Init("Output/GraphDeserialiser/Simple/Remapping", "Start2");
	cGraphDeserialiser.Init(&cReaderStart2, FALSE, &cAllocator, &cDependentReadObjects, gcObjects.GetMemory());
	cOwStart2 = cGraphDeserialiser.Read("Ow/Start 2");
	cGraphDeserialiser.Kill();
	cDependentReadObjects.Kill();
	cAllocator.Kill();
	cReaderStart2.Kill();

	AssertInt(iNumUnknowns+2, gcUnknowns.NumElements());
	AssertInt(iNumIndexes+2, (int)gcObjects.NumMemoryIndexes());
	AssertInt(iNumNames+1, (int)gcObjects.NumMemoryNames());

	AssertNotNull(cOwStart2.Object());
	cRoot->Add(cOwStart2);

	AssertNotNull(&cOwStart2);
	AssertInt(89, cOwStart2->mp1->miInt);
	AssertLongLongInt(cOwStart1->mp1->GetOI(), cOwStart2->mp1->GetOI());
	AssertInt(89, cOwStart1->mp1->miInt);
	AssertPointer(&cOwStart1->mp1, &cOwStart2->mp1);

	cObject = gcObjects.Get("Ow/Start 2");
	AssertPointer(&cOwStart2, &cObject);

	cObject = gcObjects.Get(cOwStart2->GetOI());
	AssertPointer(&cOwStart2, &cObject);

	ObjectsKill();
}