libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit f1f8c333381f2913f9e0c21adb60913990f45d4a
parent 4d8ff0f93e287bf325283c1f4e684f45687c66fc
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  9 May 2017 19:01:01 +0200

Add(Tests): Add tests for file_to_disk:

And fix a minor leaks on the function

Diffstat:
Msrc/packer_file.c | 1+
Mtests/test_packer.c | 15+++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/src/packer_file.c b/src/packer_file.c @@ -206,6 +206,7 @@ packer_file_t *read_packer_file_from_binary(const char *content, off_t *ctr) { file->content = malloc(file->file_size + 1); if (file->content == NULL) { + inflateEnd(&stream); free(file->fn); free(file); return NULL; diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -538,6 +538,20 @@ TEST(read_packer_file_from_binary) { return TEST_SUCCESS; } +TEST(packer_file_to_disk) { + packer_file_t *ptr = packer_file_init("one", "/two/"); + + TEST_ASSERT(packer_file_to_disk(ptr) == false, "Error did not raise"); + /* Hardcoding the file name to a wrong one */ + free(ptr->fn); + ptr->fn = strdup("/test"); + + TEST_ASSERT(packer_file_to_disk(ptr) == false, "Error did not raise"); + packer_file_free(ptr); + free(ptr); + return TEST_SUCCESS; +} + TEST(packer_create_archive_cleanup) { unlink(PACKAGE_OUTPUT_FN); return TEST_SUCCESS; @@ -591,5 +605,6 @@ void register_test_packer(void) { reg_test("packer", packer_file_init); reg_test("packer", packer_extract_archive_1); reg_test("packer", read_packer_file_from_binary); + reg_test("packer", packer_file_to_disk); reg_test("packer", packer_create_archive_cleanup); }