EZ_CREATE_SIMPLE_TEST(Algorithm, HashableStruct) { SimpleHashableStruct AutomaticInst; EZ_TEST_INT(AutomaticInst.m_uiTestMember1, 0); EZ_TEST_INT(AutomaticInst.m_uiTestMember2, 0); EZ_TEST_INT(AutomaticInst.m_uiTestMember3, 0); SimpleStruct NonAutomaticInst; ezMemoryUtils::ZeroFill(&NonAutomaticInst); EZ_CHECK_AT_COMPILETIME(sizeof(AutomaticInst) == sizeof(NonAutomaticInst)); EZ_TEST_INT(ezMemoryUtils::ByteCompare<ezUInt8>((ezUInt8*)&AutomaticInst, (ezUInt8*)&NonAutomaticInst, sizeof(AutomaticInst)), 0); AutomaticInst.m_uiTestMember2 = 0x42u; AutomaticInst.m_uiTestMember3 = 0x23u; ezUInt32 uiAutomaticHash = AutomaticInst.CalculateHash(); NonAutomaticInst.m_uiTestMember2 = 0x42u; NonAutomaticInst.m_uiTestMember3 = 0x23u; ezUInt32 uiNonAutomaticHash = ezHashing::CRC32Hash(&NonAutomaticInst, sizeof(NonAutomaticInst)); EZ_TEST_INT(uiAutomaticHash, uiNonAutomaticHash); AutomaticInst.m_uiTestMember1 = 0x5u; uiAutomaticHash = AutomaticInst.CalculateHash(); EZ_TEST_BOOL(uiAutomaticHash != uiNonAutomaticHash); }
EZ_CREATE_SIMPLE_TEST(Algorithm, Hashing) { // check whether compile time hashing gives the same value as runtime hashing const char* szTest = "This is a test string. 1234"; ezUInt32 uiHashRT = ezHashing::MurmurHash(szTest); ezUInt32 uiHashCT = ezHashing::MurmurHash("This is a test string. 1234"); EZ_TEST_INT(uiHashRT, 0xb999d6c4); EZ_TEST_INT(uiHashRT, uiHashCT); // check 64bit hashes ezUInt64 uiHash64 = ezHashing::MurmurHash64(szTest, std::strlen(szTest)); EZ_TEST_INT(uiHash64, 0xf8ebc5e8cb110786); // test crc32 ezUInt32 uiCrc = ezHashing::CRC32Hash(szTest, std::strlen(szTest)); EZ_TEST_INT(uiCrc, 0x73b5e898); }
void TestSerialize(T* pObject) { ezAbstractObjectGraph graph; TestContext context; ezRttiConverterWriter conv(&graph, &context, true, true); const ezRTTI* pRtti = ezGetStaticRTTI<T>(); ezUuid guid; guid.CreateNewUuid(); context.RegisterObject(guid, pRtti, pObject); ezAbstractObjectNode* pNode = conv.AddObjectToGraph(pRtti, pObject, "root"); EZ_TEST_BOOL(pNode->GetGuid() == guid); EZ_TEST_STRING(pNode->GetType(), pRtti->GetTypeName()); EZ_TEST_INT(pNode->GetProperties().GetCount(), pNode->GetProperties().GetCount()); { ezMemoryStreamStorage storage; ezMemoryStreamWriter writer(&storage); ezMemoryStreamReader reader(&storage); ezAbstractGraphDdlSerializer::Write(writer, &graph); ezStringBuilder sData, sData2; sData.SetSubString_ElementCount((const char*)storage.GetData(), storage.GetStorageSize()); ezRttiConverterReader convRead(&graph, &context); auto* pRootNode = graph.GetNodeByName("root"); EZ_TEST_BOOL(pRootNode != nullptr); T target; convRead.ApplyPropertiesToObject(pRootNode, pRtti, &target); EZ_TEST_BOOL(target == *pObject); // Overwrite again to test for leaks as existing values have to be removed first by ezRttiConverterReader. convRead.ApplyPropertiesToObject(pRootNode, pRtti, &target); EZ_TEST_BOOL(target == *pObject); { T clone; ezReflectionSerializer::Clone(pObject, &clone, pRtti); EZ_TEST_BOOL(clone == *pObject); EZ_TEST_BOOL(ezReflectionUtils::IsEqual(&clone, pObject, pRtti)); } { T* pClone = ezReflectionSerializer::Clone(pObject); EZ_TEST_BOOL(*pClone == *pObject); EZ_TEST_BOOL(ezReflectionUtils::IsEqual(pClone, pObject)); // Overwrite again to test for leaks as existing values have to be removed first by clone. ezReflectionSerializer::Clone(pObject, pClone, pRtti); EZ_TEST_BOOL(*pClone == *pObject); EZ_TEST_BOOL(ezReflectionUtils::IsEqual(pClone, pObject, pRtti)); pRtti->GetAllocator()->Deallocate(pClone); } ezAbstractObjectGraph graph2; ezAbstractGraphDdlSerializer::Read(reader, &graph2); ezMemoryStreamStorage storage2; ezMemoryStreamWriter writer2(&storage2); ezAbstractGraphDdlSerializer::Write(writer2, &graph2); sData2.SetSubString_ElementCount((const char*)storage2.GetData(), storage2.GetStorageSize()); EZ_TEST_BOOL(sData == sData2); } { ezMemoryStreamStorage storage; ezMemoryStreamWriter writer(&storage); ezMemoryStreamReader reader(&storage); ezAbstractGraphBinarySerializer::Write(writer, &graph); ezRttiConverterReader convRead(&graph, &context); auto* pRootNode = graph.GetNodeByName("root"); EZ_TEST_BOOL(pRootNode != nullptr); T target; convRead.ApplyPropertiesToObject(pRootNode, pRtti, &target); EZ_TEST_BOOL(target == *pObject); ezAbstractObjectGraph graph2; ezAbstractGraphBinarySerializer::Read(reader, &graph2); ezMemoryStreamStorage storage2; ezMemoryStreamWriter writer2(&storage2); ezAbstractGraphBinarySerializer::Write(writer2, &graph2); EZ_TEST_INT(storage.GetStorageSize(), storage2.GetStorageSize()); if (storage.GetStorageSize() == storage2.GetStorageSize()) { EZ_TEST_BOOL(ezMemoryUtils::ByteCompare<ezUInt8>(storage.GetData(), storage2.GetData(), storage.GetStorageSize()) == 0); } } }
EZ_CREATE_SIMPLE_TEST(Communication, GlobalEvent) { iTestData1 = 0; iTestData2 = 0; EZ_TEST_INT(iTestData1, 0); EZ_TEST_INT(iTestData2, 0); ezGlobalEvent::Broadcast("TestGlobalEvent1", 1); EZ_TEST_INT(iTestData1, 1); EZ_TEST_INT(iTestData2, 0); ezGlobalEvent::Broadcast("TestGlobalEvent1", 2); EZ_TEST_INT(iTestData1, 3); EZ_TEST_INT(iTestData2, 0); ezGlobalEvent::Broadcast("TestGlobalEvent1", 3); EZ_TEST_INT(iTestData1, 6); EZ_TEST_INT(iTestData2, 0); ezGlobalEvent::Broadcast("TestGlobalEvent2", 4); EZ_TEST_INT(iTestData1, 6); EZ_TEST_INT(iTestData2, 4); ezGlobalEvent::Broadcast("TestGlobalEvent3", 4); EZ_TEST_INT(iTestData1, 6); if (g_bFirstRun) { g_bFirstRun = false; EZ_TEST_INT(iTestData2, 46); } else { EZ_TEST_INT(iTestData2, 4); iTestData2 += 42; } ezGlobalEvent::Broadcast("TestGlobalEvent2", 5); EZ_TEST_INT(iTestData1, 6); EZ_TEST_INT(iTestData2, 51); ezGlobalEvent::Broadcast("TestGlobalEvent3", 4); EZ_TEST_INT(iTestData1, 6); EZ_TEST_INT(iTestData2, 51); ezGlobalEvent::Broadcast("TestGlobalEvent2", 6); EZ_TEST_INT(iTestData1, 6); EZ_TEST_INT(iTestData2, 57); ezGlobalEvent::Broadcast("TestGlobalEvent3", 4); EZ_TEST_INT(iTestData1, 6); EZ_TEST_INT(iTestData2, 57); ezGlobalLog::AddLogWriter(ezLogWriter::Console::LogMessageHandler); ezGlobalEvent::PrintGlobalEventStatistics(); ezGlobalLog::RemoveLogWriter(ezLogWriter::Console::LogMessageHandler); }