diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index cdccb9a..d9fca14 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,5 +10,5 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/random # 'Google_Tests_run' is the target name # 'test1.cpp tests2.cpp' are source files with tests -add_executable(tests_run adler32.cpp crc32.cpp) +add_executable(tests_run adler32.cpp crc16.cpp crc32.cpp) target_link_libraries(tests_run gtest gtest_main "Aaru.Checksums.Native") \ No newline at end of file diff --git a/tests/crc16.cpp b/tests/crc16.cpp new file mode 100644 index 0000000..5b59a9b --- /dev/null +++ b/tests/crc16.cpp @@ -0,0 +1,54 @@ +// +// Created by claunia on 5/10/21. +// + +#include + +#include "../library.h" +#include "../crc16.h" +#include "gtest/gtest.h" + +#define EXPECTED_CRC16 0x2d6d + +static const uint8_t* buffer; + +class crc16Fixture : public ::testing::Test +{ + public: + crc16Fixture() + { + // 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); } + + ~crc16Fixture() + { + // resources cleanup, no exceptions allowed + } + + // shared user data +}; + +TEST_F(crc16Fixture, crc16_auto) +{ + crc16_ctx* ctx = crc16_init(); + uint16_t crc; + + EXPECT_NE(ctx, nullptr); + + crc16_update(ctx, buffer, 1048576); + crc16_final(ctx, &crc); + + EXPECT_EQ(crc, EXPECTED_CRC16); +}