Add unit tests.

This commit is contained in:
2021-10-05 01:58:31 +01:00
parent 1f31d93572
commit c936a649bb
5 changed files with 74 additions and 0 deletions

3
.gitmodules vendored Normal file
View File

@@ -0,0 +1,3 @@
[submodule "tests/lib"]
path = tests/lib
url = https://github.com/google/googletest

View File

@@ -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)

14
tests/CMakeLists.txt Normal file
View File

@@ -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")

54
tests/crc32.cpp Normal file
View File

@@ -0,0 +1,54 @@
//
// Created by claunia on 5/10/21.
//
#include <stdint.h>
#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);
}

1
tests/lib Submodule

Submodule tests/lib added at 3b49be074d