mirror of
https://github.com/aaru-dps/Aaru.Checksums.Native.git
synced 2025-12-16 19:24:29 +00:00
Add unit tests.
This commit is contained in:
14
tests/CMakeLists.txt
Normal file
14
tests/CMakeLists.txt
Normal 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
54
tests/crc32.cpp
Normal 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
1
tests/lib
Submodule
Submodule tests/lib added at 3b49be074d
Reference in New Issue
Block a user