Add ARC method 4 Huffman squeezing decompression implementation and tests

This commit is contained in:
2025-09-02 03:06:31 +01:00
parent bfb9a6b524
commit afc6f3e2bc
7 changed files with 238 additions and 5 deletions

View File

@@ -48,10 +48,11 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/alice29.lh5
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/arcpack.bin
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/data/arcsqueeze.bin
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data/)
# 'Google_Tests_run' is the target name
# 'test1.cpp tests2.cpp' are source files with tests
add_executable(tests_run apple_rle.cpp crc32.c crc32.h adc.cpp bzip2.cpp lzip.cpp lzfse.cpp zstd.cpp lzma.cpp flac.cpp
zoo/lzd.cpp arc/pack.cpp
lh5.cpp
arc/pack.cpp)
zoo/lzd.cpp arc/pack.cpp lh5.cpp arc/squeeze.cpp)
target_link_libraries(tests_run gtest gtest_main "Aaru.Compression.Native")

81
tests/arc/squeeze.cpp Normal file
View File

@@ -0,0 +1,81 @@
/*
* This file is part of the Aaru Data Preservation Suite.
* Copyright (c) 2019-2025 Natalia Portillo.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include <climits>
#include <cstddef>
#include <cstdint>
#include "../../library.h"
#include "../crc32.h"
#include "gtest/gtest.h"
#define EXPECTED_CRC32 0x66007dba
static const uint8_t *buffer;
class squeezeFixture : public ::testing::Test
{
public:
squeezeFixture()
{
// initialization;
// can also be done in SetUp()
}
protected:
void SetUp()
{
char path[PATH_MAX];
char filename[PATH_MAX];
getcwd(path, PATH_MAX);
snprintf(filename, PATH_MAX, "%s/data/arcsqueeze.bin", path);
FILE *file = fopen(filename, "rb");
buffer = (const uint8_t *)malloc(88044);
fread((void *)buffer, 1, 88044, file);
fclose(file);
}
void TearDown() { free((void *)buffer); }
~squeezeFixture()
{
// resources cleanup, no exceptions allowed
}
// shared user data
};
TEST_F(squeezeFixture, squeeze)
{
size_t destLen = 152089;
size_t srcLen = 88044;
auto *outBuf = (uint8_t *)malloc(152089);
auto err = arc_decompress_squeeze(buffer, srcLen, outBuf, &destLen);
EXPECT_EQ(err, 0);
EXPECT_EQ(destLen, 152089);
auto crc = crc32_data(outBuf, 152089);
free(outBuf);
EXPECT_EQ(crc, EXPECTED_CRC32);
}

BIN
tests/data/arcsqueeze.bin Executable file

Binary file not shown.

View File

@@ -25,7 +25,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include "../library.h"
#include "../../library.h"
#include "../crc32.h"
#include "gtest/gtest.h"