mirror of
https://github.com/QuasarApp/zip.git
synced 2025-04-28 13:24:33 +00:00
Update build.yml (#115)
This commit is contained in:
parent
b9558ee34f
commit
aad40be349
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@ -46,4 +46,4 @@ jobs:
|
||||
- name: Build
|
||||
run: cmake --build . --config "Debug"
|
||||
- name: Test
|
||||
run: ctest --verbose -C "Debug"
|
||||
run: ctest -VV -C "Debug"
|
||||
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(zip
|
||||
LANGUAGES C
|
||||
VERSION "0.1.15")
|
||||
VERSION "0.1.16")
|
||||
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
|
||||
|
||||
option(CMAKE_DISABLE_TESTING "Disable test creation" OFF)
|
||||
@ -35,7 +35,7 @@ if (NOT CMAKE_DISABLE_TESTING)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
find_package(Sanitizers)
|
||||
add_sanitizers(${PROJECT_NAME} ${test_out} ${test_miniz_out})
|
||||
add_sanitizers(${PROJECT_NAME} ${test_out})
|
||||
endif()
|
||||
|
||||
####
|
||||
|
@ -2,15 +2,10 @@ cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
# test
|
||||
set(test_out test.out)
|
||||
set(test_miniz_out test_miniz.out)
|
||||
|
||||
add_executable(${test_out} test.c)
|
||||
target_link_libraries(${test_out} zip)
|
||||
add_executable(${test_miniz_out} test_miniz.c)
|
||||
target_link_libraries(${test_miniz_out} zip)
|
||||
|
||||
add_test(NAME ${test_out} COMMAND ${test_out})
|
||||
add_test(NAME ${test_miniz_out} COMMAND ${test_miniz_out})
|
||||
|
||||
set(test_out ${test_out} PARENT_SCOPE)
|
||||
set(test_miniz_out ${test_miniz_out} PARENT_SCOPE)
|
||||
|
@ -1,127 +0,0 @@
|
||||
// Demonstrates miniz.c's compress() and uncompress() functions
|
||||
// (same as zlib's). Public domain, May 15 2011, Rich Geldreich,
|
||||
// richgel99@gmail.com. See "unlicense" statement at the end of tinfl.c.
|
||||
|
||||
#include <miniz.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef unsigned char uint8;
|
||||
typedef unsigned short uint16;
|
||||
typedef unsigned int uint;
|
||||
|
||||
// The string to compress.
|
||||
static const char *s_pStr =
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson."
|
||||
"Good morning Dr. Chandra. This is Hal. I am ready for my first lesson.";
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
uint step = 0;
|
||||
int cmp_status;
|
||||
uLong src_len = (uLong)strlen(s_pStr);
|
||||
uLong uncomp_len = src_len;
|
||||
uLong cmp_len;
|
||||
uint8 *pCmp, *pUncomp;
|
||||
size_t sz;
|
||||
uint total_succeeded = 0;
|
||||
(void)argc, (void)argv;
|
||||
|
||||
printf("miniz.c version: %s\n", MZ_VERSION);
|
||||
|
||||
do {
|
||||
pCmp = (uint8 *)tdefl_compress_mem_to_heap(s_pStr, src_len, &cmp_len, 0);
|
||||
if (!pCmp) {
|
||||
printf("tdefl_compress_mem_to_heap failed\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (src_len <= cmp_len) {
|
||||
printf("tdefl_compress_mem_to_heap failed: from %u to %u bytes\n",
|
||||
(mz_uint32)uncomp_len, (mz_uint32)cmp_len);
|
||||
free(pCmp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
sz = tdefl_compress_mem_to_mem(pCmp, cmp_len, s_pStr, src_len, 0);
|
||||
if (sz != cmp_len) {
|
||||
printf("tdefl_compress_mem_to_mem failed: expected %u, got %u\n",
|
||||
(mz_uint32)cmp_len, (mz_uint32)sz);
|
||||
free(pCmp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Allocate buffers to hold compressed and uncompressed data.
|
||||
free(pCmp);
|
||||
cmp_len = compressBound(src_len);
|
||||
pCmp = (mz_uint8 *)malloc((size_t)cmp_len);
|
||||
pUncomp = (mz_uint8 *)malloc((size_t)src_len);
|
||||
if ((!pCmp) || (!pUncomp)) {
|
||||
printf("Out of memory!\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// Compress the string.
|
||||
cmp_status =
|
||||
compress(pCmp, &cmp_len, (const unsigned char *)s_pStr, src_len);
|
||||
if (cmp_status != Z_OK) {
|
||||
printf("compress() failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Compressed from %u to %u bytes\n", (mz_uint32)src_len,
|
||||
(mz_uint32)cmp_len);
|
||||
|
||||
if (step) {
|
||||
// Purposely corrupt the compressed data if fuzzy testing (this is a
|
||||
// very crude fuzzy test).
|
||||
uint n = 1 + (rand() % 3);
|
||||
while (n--) {
|
||||
uint i = rand() % cmp_len;
|
||||
pCmp[i] ^= (rand() & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
// Decompress.
|
||||
cmp_status = uncompress(pUncomp, &uncomp_len, pCmp, cmp_len);
|
||||
total_succeeded += (cmp_status == Z_OK);
|
||||
|
||||
if (step) {
|
||||
printf("Simple fuzzy test: step %u total_succeeded: %u\n", step,
|
||||
total_succeeded);
|
||||
} else {
|
||||
if (cmp_status != Z_OK) {
|
||||
printf("uncompress failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Decompressed from %u to %u bytes\n", (mz_uint32)cmp_len,
|
||||
(mz_uint32)uncomp_len);
|
||||
|
||||
// Ensure uncompress() returned the expected data.
|
||||
if ((uncomp_len != src_len) ||
|
||||
(memcmp(pUncomp, s_pStr, (size_t)src_len))) {
|
||||
printf("Decompression failed!\n");
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
free(pCmp);
|
||||
free(pUncomp);
|
||||
|
||||
step++;
|
||||
|
||||
// Keep on fuzzy testing if there's a non-empty command line.
|
||||
} while (argc >= 2);
|
||||
|
||||
printf("Success.\n");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user