libmpm

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

commit a9c39a5d7987f0aa35159dc5a4ae4c61dfeb91c0
parent 5e290110fcfdda796434cfc4ccd984109fdb0e5e
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 28 Apr 2017 19:01:23 +0200

Fix(Tests): fix file_init test, now covering all error cases

Diffstat:
Msrc/packer.c | 2+-
Mtests/test_packer.c | 17+++++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/packer.c b/src/packer.c @@ -473,7 +473,7 @@ static int packer_file_free(void *magic) { return 1; } -static packer_file_t *packer_file_init(const char *file, const char *dir) { +MPX_STATIC packer_file_t *packer_file_init(const char *file, const char *dir) { packer_file_t *ret = NULL; ret = calloc(1, sizeof(*ret)); diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -501,6 +501,22 @@ TEST(packer_read_package_header) { return TEST_SUCCESS; } +MPX_STATIC packer_file_t *packer_file_init(const char *file, const char *dir); +TEST(packer_file_init) { + char *file = "truc"; + char *dir = "machin"; + + set_calloc_fail(0); + TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise"); + set_malloc_fail(0); + TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise"); + set_strcpy_fail(0); + TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise"); + set_strcat_fail(0); + TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise"); + return TEST_SUCCESS; +} + TEST(packer_create_archive_cleanup) { unlink(PACKAGE_OUTPUT_FN); return TEST_SUCCESS; @@ -551,5 +567,6 @@ void register_test_packer(void) { reg_test("packer", packer_read_package_header_compilation); reg_test("packer", packer_read_package_header_package); reg_test("packer", packer_read_package_header); + reg_test("packer", packer_file_init); reg_test("packer", packer_create_archive_cleanup); }