diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cbffb5c --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "tests/lib"] + path = tests/lib + url = https://github.com/google/googletest diff --git a/CMakeLists.txt b/CMakeLists.txt index c789ca3..853df53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,3 +25,5 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Release") endif() add_library("Aaru.Checksums.Native" SHARED adler32.h adler32.c crc16.h crc16.c crc16_ccitt.h crc16_ccitt.c crc32.c crc32.h crc64.c crc64.h fletcher16.h fletcher16.c fletcher32.h fletcher32.c library.h spamsum.c spamsum.h crc32_clmul.c crc64_clmul.c simd.c simd.h adler32_ssse3.c adler32_avx2.c adler32_neon.c crc32_arm_simd.c crc32_vmull.c crc32_simd.h) + +add_subdirectory(tests) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..d8bc8f3 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,14 @@ +# 'Google_test' is the subproject name +project(tests) + +# 'lib' is the folder with Google Test sources +add_subdirectory(lib) +include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) + +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/random + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/random) + +# 'Google_Tests_run' is the target name +# 'test1.cpp tests2.cpp' are source files with tests +add_executable(tests_run crc32.cpp) +target_link_libraries(tests_run gtest gtest_main "Aaru.Checksums.Native") \ No newline at end of file diff --git a/tests/crc32.cpp b/tests/crc32.cpp new file mode 100644 index 0000000..061a302 --- /dev/null +++ b/tests/crc32.cpp @@ -0,0 +1,54 @@ +// +// Created by claunia on 5/10/21. +// + +#include + +#include "../library.h" +#include "../crc32.h" +#include "gtest/gtest.h" + +#define EXPECTED_CRC32 0x2B6E6854 + +const uint8_t* buffer; + +class crc32Fixture : public ::testing::Test +{ + public: + crc32Fixture() + { + // initialization; + // can also be done in SetUp() + } + + protected: + void SetUp() + { + FILE* file = fopen("/home/claunia/random", "rb"); + buffer = (const uint8_t*)malloc(1048576); + fread((void*)buffer, 1, 1048576, file); + fclose(file); + } + + void TearDown() { free((void*)buffer); } + + ~crc32Fixture() + { + // resources cleanup, no exceptions allowed + } + + // shared user data +}; + +TEST_F(crc32Fixture, crc32_auto) +{ + crc32_ctx* ctx = crc32_init(); + uint32_t crc; + + EXPECT_NE(ctx, nullptr); + + crc32_update(ctx, buffer, 1048576); + crc32_final(ctx, &crc); + + EXPECT_EQ(crc, EXPECTED_CRC32); +} diff --git a/tests/lib b/tests/lib new file mode 160000 index 0000000..3b49be0 --- /dev/null +++ b/tests/lib @@ -0,0 +1 @@ +Subproject commit 3b49be074d5c1340eeb447e6a8e78427051e675a