From f9e29de5dcf2ec859780536cc4f1f18adacac862 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 5 Oct 2021 03:13:47 +0100 Subject: [PATCH] Add unit tests for Fletcher-16. --- tests/CMakeLists.txt | 2 +- tests/fletcher16.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/fletcher16.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6e1560f..ce2acce 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 crc16.cpp crc32.cpp crc64.cpp) +add_executable(tests_run adler32.cpp crc16.cpp crc32.cpp crc64.cpp fletcher16.cpp) target_link_libraries(tests_run gtest gtest_main "Aaru.Checksums.Native") \ No newline at end of file diff --git a/tests/fletcher16.cpp b/tests/fletcher16.cpp new file mode 100644 index 0000000..6c604cd --- /dev/null +++ b/tests/fletcher16.cpp @@ -0,0 +1,54 @@ +// +// Created by claunia on 5/10/21. +// + +#include + +#include "../library.h" +#include "../fletcher16.h" +#include "gtest/gtest.h" + +#define EXPECTED_FLETCHER16 0x3357 + +static const uint8_t* buffer; + +class fletcher16Fixture : public ::testing::Test +{ + public: + fletcher16Fixture() + { + // 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); } + + ~fletcher16Fixture() + { + // resources cleanup, no exceptions allowed + } + + // shared user data +}; + +TEST_F(fletcher16Fixture, fletcher16_auto) +{ + fletcher16_ctx* ctx = fletcher16_init(); + uint16_t fletcher; + + EXPECT_NE(ctx, nullptr); + + fletcher16_update(ctx, buffer, 1048576); + fletcher16_final(ctx, &fletcher); + + EXPECT_EQ(fletcher, EXPECTED_FLETCHER16); +}