Add unit tests for Fletcher-32.

This commit is contained in:
2021-10-05 03:15:52 +01:00
parent f9e29de5dc
commit fce44d1a38
2 changed files with 55 additions and 1 deletions

View File

@@ -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 fletcher16.cpp)
add_executable(tests_run adler32.cpp crc16.cpp crc32.cpp crc64.cpp fletcher16.cpp fletcher32.cpp)
target_link_libraries(tests_run gtest gtest_main "Aaru.Checksums.Native")

54
tests/fletcher32.cpp Normal file
View File

@@ -0,0 +1,54 @@
//
// Created by claunia on 5/10/21.
//
#include <cstdint>
#include "../library.h"
#include "../fletcher32.h"
#include "gtest/gtest.h"
#define EXPECTED_FLETCHER32 0x211261f5
static const uint8_t* buffer;
class fletcher32Fixture : public ::testing::Test
{
public:
fletcher32Fixture()
{
// 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); }
~fletcher32Fixture()
{
// resources cleanup, no exceptions allowed
}
// shared user data
};
TEST_F(fletcher32Fixture, fletcher32_auto)
{
fletcher32_ctx* ctx = fletcher32_init();
uint32_t fletcher;
EXPECT_NE(ctx, nullptr);
fletcher32_update(ctx, buffer, 1048576);
fletcher32_final(ctx, &fletcher);
EXPECT_EQ(fletcher, EXPECTED_FLETCHER32);
}