libmpm

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

commit 64a01c3aea3c8d0400b5641ff29bfb724e785417
parent f1f8c333381f2913f9e0c21adb60913990f45d4a
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  9 May 2017 19:07:08 +0200

Add(Tests): Add test for create_directory_name

Diffstat:
Msrc/packer.c | 3+--
Mtests/test_packer.c | 18++++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/packer.c b/src/packer.c @@ -806,8 +806,7 @@ bool packer_read_archive_header(packer_t *ctx) { return ret; } -static char *packer_create_directory_name(packer_t *ctx, char sep) -{ +MPX_STATIC char *packer_create_directory_name(packer_t *ctx, char sep) { char *out = NULL; out = malloc(strlen(ctx->header->package->name) diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -552,6 +552,23 @@ TEST(packer_file_to_disk) { return TEST_SUCCESS; } +MPX_STATIC char *packer_create_directory_name(packer_t *ctx, char sep); +TEST(packer_create_directory_name) { + packer_t *ctx = NULL; + + ctx = packer_init("0"); + ctx->header = calloc(1, sizeof(ctx->header)); + ctx->header->package = calloc(1, sizeof(ctx->header->package)); + ctx->header->package->name = strdup("1"); + ctx->header->package->version = strdup("2"); + + set_malloc_fail(0); + TEST_ASSERT(packer_create_directory_name(ctx, '_') == NULL, "Error did not raise"); + + packer_free(ctx); + return TEST_SUCCESS; +} + TEST(packer_create_archive_cleanup) { unlink(PACKAGE_OUTPUT_FN); return TEST_SUCCESS; @@ -606,5 +623,6 @@ void register_test_packer(void) { 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_directory_name); reg_test("packer", packer_create_archive_cleanup); }