libmpm

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

commit 1f040ec753078f64b5da0aba0e646c1add59e7db
parent c5139079351d096e740eebf4312d6cc992c18442
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 26 Jun 2017 20:04:46 +0200

Fix(Tests): Fix test on read_package_header_compilation

Diffstat:
Mtests/test_packer.c | 30++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -387,27 +387,45 @@ TEST(packer_read_package_header_dependencies) { return TEST_SUCCESS; } +MPX_STATIC void packer_header_free(packer_header_t *ptr); MPX_STATIC int read_package_header_compilation(char *file, packer_t *ctx); TEST(packer_read_package_header_compilation) { char *file; char tmp[] = "TEst:123\0Oui\0make\0test\0install\0Test:123"; - u32_t i = htonl(2); + u32_t i = htonl(1); + packer_t ctx; + + set_malloc_fail(-1); file = malloc(sizeof(i) + sizeof(tmp)); memcpy(file, &i, sizeof(i)); memcpy(file + sizeof(i), tmp, sizeof(tmp)); - set_malloc_fail(0); TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return"); + + ctx.header = packer_header_init(); + set_strdup_fail(2); + TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return"); memcpy(file + sizeof(i), tmp, sizeof(tmp)); + packer_header_free(ctx.header); - set_malloc_fail(1); - TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return"); + ctx.header = packer_header_init(); + set_strdup_fail(3); + TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return"); memcpy(file + sizeof(i), tmp, sizeof(tmp)); + packer_header_free(ctx.header); - set_malloc_fail(3); - TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return"); + ctx.header = packer_header_init(); + set_strdup_fail(4); + TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return"); + memcpy(file + sizeof(i), tmp, sizeof(tmp)); + packer_header_free(ctx.header); + + ctx.header = packer_header_init(); + set_strdup_fail(5); + TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return"); memcpy(file + sizeof(i), tmp, sizeof(tmp)); + packer_header_free(ctx.header); free(file); return TEST_SUCCESS;