Prepare script lifecycle and data layer
This commit is contained in:
@@ -21,12 +21,14 @@ public:
|
||||
bool m_onEnableCalled = false;
|
||||
bool m_onDisableCalled = false;
|
||||
bool m_onDestroyCalled = false;
|
||||
int m_onEnableCount = 0;
|
||||
int m_onDisableCount = 0;
|
||||
|
||||
void Awake() override { m_awakeCalled = true; }
|
||||
void Start() override { m_startCalled = true; }
|
||||
void Update(float deltaTime) override { m_updateCalled = true; }
|
||||
void OnEnable() override { m_onEnableCalled = true; }
|
||||
void OnDisable() override { m_onDisableCalled = true; }
|
||||
void OnEnable() override { m_onEnableCalled = true; ++m_onEnableCount; }
|
||||
void OnDisable() override { m_onDisableCalled = true; ++m_onDisableCount; }
|
||||
void OnDestroy() override { m_onDestroyCalled = true; }
|
||||
|
||||
private:
|
||||
@@ -107,4 +109,24 @@ TEST(Component_Test, SetEnabled_NoCallback_WhenStateUnchanged) {
|
||||
EXPECT_FALSE(comp.m_onDisableCalled);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
TEST(Component_Test, SetEnabled_AttachedInactiveGameObject_DelaysOnEnableUntilActivation) {
|
||||
GameObject go;
|
||||
TestComponent* comp = go.AddComponent<TestComponent>();
|
||||
|
||||
go.SetActive(false);
|
||||
comp->m_onEnableCalled = false;
|
||||
comp->m_onDisableCalled = false;
|
||||
comp->m_onEnableCount = 0;
|
||||
comp->m_onDisableCount = 0;
|
||||
|
||||
comp->SetEnabled(false);
|
||||
EXPECT_EQ(comp->m_onDisableCount, 0);
|
||||
|
||||
comp->SetEnabled(true);
|
||||
EXPECT_EQ(comp->m_onEnableCount, 0);
|
||||
|
||||
go.SetActive(true);
|
||||
EXPECT_EQ(comp->m_onEnableCount, 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -21,10 +21,21 @@ public:
|
||||
bool m_awakeCalled = false;
|
||||
bool m_startCalled = false;
|
||||
bool m_updateCalled = false;
|
||||
bool m_onEnableCalled = false;
|
||||
bool m_onDisableCalled = false;
|
||||
bool m_onDestroyCalled = false;
|
||||
int m_startCount = 0;
|
||||
int m_updateCount = 0;
|
||||
int m_onEnableCount = 0;
|
||||
int m_onDisableCount = 0;
|
||||
int m_onDestroyCount = 0;
|
||||
|
||||
void Awake() override { m_awakeCalled = true; }
|
||||
void Start() override { m_startCalled = true; }
|
||||
void Update(float deltaTime) override { m_updateCalled = true; }
|
||||
void Start() override { m_startCalled = true; ++m_startCount; }
|
||||
void Update(float deltaTime) override { m_updateCalled = true; ++m_updateCount; }
|
||||
void OnEnable() override { m_onEnableCalled = true; ++m_onEnableCount; }
|
||||
void OnDisable() override { m_onDisableCalled = true; ++m_onDisableCount; }
|
||||
void OnDestroy() override { m_onDestroyCalled = true; ++m_onDestroyCount; }
|
||||
|
||||
private:
|
||||
std::string m_customName;
|
||||
@@ -45,7 +56,6 @@ TEST(GameObject_Test, DefaultConstructor_DefaultValues) {
|
||||
EXPECT_EQ(go.GetName(), "GameObject");
|
||||
EXPECT_TRUE(go.IsActive());
|
||||
EXPECT_NE(go.GetID(), GameObject::INVALID_ID);
|
||||
EXPECT_EQ(go.GetID(), 1u);
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, NamedConstructor) {
|
||||
@@ -203,6 +213,34 @@ TEST(GameObject_Test, SetActive_False) {
|
||||
EXPECT_FALSE(go.IsActive());
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, SetActive_PropagatesEnableDisableToChildren) {
|
||||
GameObject parent("Parent");
|
||||
GameObject child("Child");
|
||||
TestComponent* comp = child.AddComponent<TestComponent>();
|
||||
|
||||
child.SetParent(&parent);
|
||||
|
||||
parent.SetActive(false);
|
||||
EXPECT_EQ(comp->m_onDisableCount, 1);
|
||||
|
||||
parent.SetActive(true);
|
||||
EXPECT_EQ(comp->m_onEnableCount, 1);
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, SetParent_PropagatesActiveHierarchyChanges) {
|
||||
GameObject activeParent("ActiveParent");
|
||||
GameObject inactiveParent("InactiveParent");
|
||||
GameObject child("Child");
|
||||
TestComponent* comp = child.AddComponent<TestComponent>();
|
||||
|
||||
inactiveParent.SetActive(false);
|
||||
child.SetParent(&inactiveParent);
|
||||
EXPECT_EQ(comp->m_onDisableCount, 1);
|
||||
|
||||
child.SetParent(&activeParent);
|
||||
EXPECT_EQ(comp->m_onEnableCount, 1);
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, IsActiveInHierarchy_True) {
|
||||
GameObject parent("Parent");
|
||||
GameObject child("Child");
|
||||
@@ -238,6 +276,17 @@ TEST(GameObject_Test, Lifecycle_Start) {
|
||||
go.Start();
|
||||
|
||||
EXPECT_TRUE(comp->m_startCalled);
|
||||
EXPECT_EQ(comp->m_startCount, 1);
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, Lifecycle_Start_IsOnlyCalledOnce) {
|
||||
GameObject go;
|
||||
TestComponent* comp = go.AddComponent<TestComponent>();
|
||||
|
||||
go.Start();
|
||||
go.Start();
|
||||
|
||||
EXPECT_EQ(comp->m_startCount, 1);
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, Lifecycle_Update) {
|
||||
@@ -247,6 +296,17 @@ TEST(GameObject_Test, Lifecycle_Update) {
|
||||
go.Update(0.016f);
|
||||
|
||||
EXPECT_TRUE(comp->m_updateCalled);
|
||||
EXPECT_EQ(comp->m_updateCount, 1);
|
||||
}
|
||||
|
||||
TEST(GameObject_Test, Destroy_CallsOnDestroyOnce_WhenStandalone) {
|
||||
GameObject go;
|
||||
TestComponent* comp = go.AddComponent<TestComponent>();
|
||||
|
||||
go.Destroy();
|
||||
|
||||
EXPECT_TRUE(comp->m_onDestroyCalled);
|
||||
EXPECT_EQ(comp->m_onDestroyCount, 1);
|
||||
}
|
||||
|
||||
TEST_F(GameObjectTest, Find_Exists) {
|
||||
|
||||
Reference in New Issue
Block a user