// IACore-OSS; The Core Library for All IA Open Source Projects // Copyright (C) 2026 IAS (ias@iasoft.dev) // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #include #include using namespace IACore; // ----------------------------------------------------------------------------- // Test Block Definition // ----------------------------------------------------------------------------- IAT_BEGIN_BLOCK(Core, DataOps) bool TestCRC32() { { String s = "123456789"; Span span(reinterpret_cast(s.data()), s.size()); u32 result = DataOps::CRC32(span); IAT_CHECK_EQ(result, 0xE3069283); } { u32 result = DataOps::CRC32({}); IAT_CHECK_EQ(result, 0U); } { std::vector buffer(33); for (size_t i = 1; i < 33; ++i) buffer[i] = (u8)i; std::vector refData(32); for (size_t i = 0; i < 32; ++i) refData[i] = (u8)(i + 1); u32 hashRef = DataOps::CRC32(Span(refData.data(), refData.size())); u32 hashUnaligned = DataOps::CRC32(Span(buffer.data() + 1, 32)); IAT_CHECK_EQ(hashRef, hashUnaligned); } return TRUE; } bool TestHash_xxHash() { { String s = "123456789"; u32 result = DataOps::Hash_xxHash(s); IAT_CHECK_EQ(result, 0x937bad67); } { String s = "The quick brown fox jumps over the lazy dog"; u32 result = DataOps::Hash_xxHash(s); IAT_CHECK_EQ(result, 0xE85EA4DE); } { String s = "Test"; u32 r1 = DataOps::Hash_xxHash(s); u32 r2 = DataOps::Hash_xxHash(Span((const u8 *)s.data(), s.size())); IAT_CHECK_EQ(r1, r2); } return TRUE; } bool TestHash_FNV1A() { { String s = "123456789"; u32 result = DataOps::Hash_FNV1A(Span((const u8 *)s.data(), s.size())); IAT_CHECK_EQ(result, 0xbb86b11c); } { u32 result = DataOps::Hash_FNV1A(Span{}); IAT_CHECK_EQ(result, 0x811C9DC5); } return TRUE; } // ------------------------------------------------------------------------- // Registration // ------------------------------------------------------------------------- IAT_BEGIN_TEST_LIST() IAT_ADD_TEST(TestCRC32); IAT_ADD_TEST(TestHash_FNV1A); IAT_ADD_TEST(TestHash_xxHash); IAT_END_TEST_LIST() IAT_END_BLOCK() IAT_REGISTER_ENTRY(Core, DataOps)