void TestUsageNullPointers(void) { ObjectsInit(); Ptr<CGameWorld> pWorld; CPointer pNull = ONull; Ptr<CPlayerVehicle> pVehicle = ONull; Ptr<CHarrier> pHarrier; pWorld = pNull; pWorld->AddTickable(pNull); pWorld->AddTickable(pVehicle); pWorld->AddTickable(ONull); pVehicle = pNull; pWorld->AddPlayer(pVehicle); pWorld->AddPlayer(pNull); pWorld->AddPlayer(ONull); pVehicle = pHarrier; AssertString("This code must compile", "This code must compile"); pWorld = pHarrier; //This probably shouldn't compile but it does because pHarrier (Ptr<CHarrier>) extends CPointer. ObjectsKill(); }
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(); }