libmpm

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

commit 6953ecc73d35f4f038c99dcb873d0e35c01b78b5
parent 2ab211832775ff8099eb5be79dbbdaa6e9c3ff6d
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun, 28 May 2017 16:56:35 +0200

Add(Tests): Add some test for the Packer

Diffstat:
Minc/packer.h | 2+-
Msrc/packer.c | 6------
Mtests/packer/compilation/package.json | 6+++++-
Atests/packer/wrong_comp_section_10/package.json | 23+++++++++++++++++++++++
Atests/packer/wrong_comp_section_11/package.json | 21+++++++++++++++++++++
Atests/packer/wrong_comp_section_9/package.json | 21+++++++++++++++++++++
Mtests/test_packer.c | 53++++++++++++++++++++++++++++++++++++++++++-----------
7 files changed, 113 insertions(+), 19 deletions(-)

diff --git a/inc/packer.h b/inc/packer.h @@ -97,10 +97,10 @@ typedef struct packer_s { json_object *json; /*!< JSON object */ packer_type_t type; /*!< Type of packer */ packer_header_t *header; /*!< Header of the MPX format */ - mlist_t *files; /*!< Files list, if it's an archive */ char *out_dir;/*!< Output directory, in case of an archive */ } packer_t; + # include <libmpm.h> /*! diff --git a/src/packer.c b/src/packer.c @@ -27,7 +27,6 @@ MPX_STATIC packer_t *packer_init(const char *str) { ret->json = NULL; ret->str = strdup(str); ret->header = NULL; - ret->files = NULL; ret->out_dir = NULL; if (ret->str == NULL) goto cleanup; @@ -189,10 +188,6 @@ void packer_free(packer_t *ptr) { free(ptr->str); packer_header_free(ptr->header); free(ptr->out_dir); - if (ptr->files != NULL) - { - list_free(ptr->files, packer_file_free); - } free(ptr); } } @@ -835,7 +830,6 @@ bool packer_read_archive_header(packer_t *ctx) { } bool packer_extract_archive(packer_t *ctx, const char *dir) { - /*packer_file_t *file = NULL;*/ int fd, t_ctr; bool ret = false; char *archive = NULL; diff --git a/tests/packer/compilation/package.json b/tests/packer/compilation/package.json @@ -11,7 +11,11 @@ ], "make": "", "test": "", - "install": "" + "install": "", + "env": [ + {"TOTO": "TATA"}, + "TRUC" + ] }, "dependencies": [ "something-5.5", diff --git a/tests/packer/wrong_comp_section_10/package.json b/tests/packer/wrong_comp_section_10/package.json @@ -0,0 +1,23 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"something": "value"}, + "single-opt" + ], + "make": "", + "test": "", + "install": "", + "env": [ + {"TOTO": 10} + ] + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_11/package.json b/tests/packer/wrong_comp_section_11/package.json @@ -0,0 +1,21 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"something": "value"}, + "single-opt" + ], + "make": "", + "test": "", + "install": "", + "env": [10] + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_9/package.json b/tests/packer/wrong_comp_section_9/package.json @@ -0,0 +1,21 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"something": "value"}, + "single-opt" + ], + "make": "", + "test": "", + "install": "", + "env": "Not an array" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -210,6 +210,33 @@ TEST(packer_wrong_comp_section_8) { return TEST_SUCCESS; } +TEST(packer_wrong_comp_section_9) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_9/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_10) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_10/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_11) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_11/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + TEST(packer_wrong_deps_section_1) { packer_t *ptr; @@ -381,7 +408,7 @@ TEST(packer_read_package_header_dependencies) { 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"; + char tmp[] = "TEst:123\0Oui\0make\0test\0install\0Test:123"; u32_t i = htonl(2); file = malloc(sizeof(i) + sizeof(tmp)); @@ -396,6 +423,10 @@ TEST(packer_read_package_header_compilation) { TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return"); memcpy(file + sizeof(i), tmp, sizeof(tmp)); + set_malloc_fail(3); + TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return"); + memcpy(file + sizeof(i), tmp, sizeof(tmp)); + set_strdup_fail(0); TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return"); memcpy(file + sizeof(i), tmp, sizeof(tmp)); @@ -519,6 +550,13 @@ TEST(packer_extract_archive_2) { TEST_ASSERT(packer_extract_archive(ctx, NULL) == false, "Error did not raise"); packer_free(ctx); + recursive_delete("/tmp/test-2.0"); + set_mkdir_fail(-1); + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); + set_strdup_fail(20); + TEST_ASSERT(packer_extract_archive(ctx, "/tmp") == false, "Error did not raise"); + packer_free(ctx); + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); set_malloc_fail(0); TEST_ASSERT(packer_extract_archive(ctx, NULL) == false, "Error did not raise"); @@ -532,16 +570,6 @@ TEST(packer_extract_archive_2) { TEST_ASSERT(packer_extract_archive(ctx, "/") == false, "Error did not raise"); packer_free(ctx); - ctx = packer_init_archive(PACKAGE_OUTPUT_FN); - set_malloc_fail(12); - TEST_ASSERT(packer_extract_archive(ctx, "/tmp") == false, "Error did not raise"); - packer_free(ctx); - - ctx = packer_init_archive(PACKAGE_OUTPUT_FN); - set_mkdir_fail(2); - TEST_ASSERT(packer_extract_archive(ctx, "/tmp") == false, "Error did not raise"); - packer_free(ctx); - return TEST_SUCCESS; } @@ -598,6 +626,9 @@ void register_test_packer(void) { reg_test("packer", packer_wrong_comp_section_6); reg_test("packer", packer_wrong_comp_section_7); reg_test("packer", packer_wrong_comp_section_8); + reg_test("packer", packer_wrong_comp_section_9); + reg_test("packer", packer_wrong_comp_section_10); + reg_test("packer", packer_wrong_comp_section_11); reg_test("packer", packer_wrong_deps_section_1); reg_test("packer", packer_wrong_deps_section_2); reg_test("packer", packer_init_1);