libmpm

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

commit 127ddb84cf4686fb490fbfab2243bd3c18588ad4
parent 913c928f2cbf08b08d2418a43e74721cfd8cec55
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Thu,  6 Apr 2017 18:53:03 +0200

Add(Tests): Add tests for better coverage on the packer:

Fix some bad frees too

Diffstat:
Msrc/packer.c | 6++++--
Atests/packer/wrong_comp_section_1/package.json | 17+++++++++++++++++
Atests/packer/wrong_comp_section_2/package.json | 19+++++++++++++++++++
Atests/packer/wrong_comp_section_3/package.json | 19+++++++++++++++++++
Atests/packer/wrong_comp_section_4/package.json | 19+++++++++++++++++++
Atests/packer/wrong_comp_section_5/package.json | 19+++++++++++++++++++
Atests/packer/wrong_comp_section_6/package.json | 19+++++++++++++++++++
Atests/packer/wrong_comp_section_7/package.json | 20++++++++++++++++++++
Atests/packer/wrong_comp_section_8/package.json | 12++++++++++++
Atests/packer/wrong_deps_section_1/package.json | 16++++++++++++++++
Atests/packer/wrong_deps_section_2/package.json | 18++++++++++++++++++
Atests/packer/wrong_package_section_1/package.json | 24++++++++++++++++++++++++
Atests/packer/wrong_package_section_2/package.json | 24++++++++++++++++++++++++
Atests/packer/wrong_package_section_3/package.json | 24++++++++++++++++++++++++
Atests/packer/wrong_package_section_4/package.json | 25+++++++++++++++++++++++++
Atests/packer/wrong_package_section_5/package.json | 20++++++++++++++++++++
Mtests/test_packer.c | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
17 files changed, 449 insertions(+), 2 deletions(-)

diff --git a/src/packer.c b/src/packer.c @@ -193,7 +193,7 @@ static bool packer_read_config_comp(packer_t *ctx, struct json_object *obj) { assert(ctx != NULL); /* Can't raise an assertion since NULL is a valid type in JSON */ - if (obj == NULL) + if (obj == NULL || json_object_get_type(obj) != json_type_object) return false; it = json_object_iter_begin(obj); @@ -309,7 +309,7 @@ static bool packer_read_config_package(packer_t *ctx, struct json_object *obj) { assert(ctx != NULL); /* Can't raise an assertion since NULL is a valid type in JSON */ - if (obj == NULL) + if (obj == NULL || json_object_get_type(obj) != json_type_object) return false; it = json_object_iter_begin(obj); @@ -347,6 +347,7 @@ static bool packer_read_config_package(packer_t *ctx, struct json_object *obj) { cleanup: packer_header_package_free(ctx->header->package); + ctx->header->package = NULL; return false; } @@ -386,6 +387,7 @@ static bool packer_read_config_file(packer_t *ctx) { cleanup: packer_header_free(ctx->header); + ctx->header = NULL; return false; } diff --git a/tests/packer/wrong_comp_section_1/package.json b/tests/packer/wrong_comp_section_1/package.json @@ -0,0 +1,17 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": "", + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_2/package.json b/tests/packer/wrong_comp_section_2/package.json @@ -0,0 +1,19 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"something": ["not a string"]} + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_3/package.json b/tests/packer/wrong_comp_section_3/package.json @@ -0,0 +1,19 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + ["array wrong"] + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_4/package.json b/tests/packer/wrong_comp_section_4/package.json @@ -0,0 +1,19 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + "yup" + ], + "make": [], + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_5/package.json b/tests/packer/wrong_comp_section_5/package.json @@ -0,0 +1,19 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + "yup" + ], + "make": "", + "test": [], + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_6/package.json b/tests/packer/wrong_comp_section_6/package.json @@ -0,0 +1,19 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + "yup" + ], + "make": "", + "test": "", + "install": [] + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_7/package.json b/tests/packer/wrong_comp_section_7/package.json @@ -0,0 +1,20 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + "yup" + ], + "make": "", + "test": "", + "install": "", + "bs_token": "yy" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_comp_section_8/package.json b/tests/packer/wrong_comp_section_8/package.json @@ -0,0 +1,12 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": ["wi"], + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_deps_section_1/package.json b/tests/packer/wrong_deps_section_1/package.json @@ -0,0 +1,16 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + "yup" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": "Not an array" +} diff --git a/tests/packer/wrong_deps_section_2/package.json b/tests/packer/wrong_deps_section_2/package.json @@ -0,0 +1,18 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + "yup" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + ["not a string"] + ] +} diff --git a/tests/packer/wrong_package_section_1/package.json b/tests/packer/wrong_package_section_1/package.json @@ -0,0 +1,24 @@ +{ + "package": { + "name": [], + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_package_section_2/package.json b/tests/packer/wrong_package_section_2/package.json @@ -0,0 +1,24 @@ +{ + "package": { + "name": "test", + "version": {}, + "description": "This is a description. Yeah I know, mind blowing." + }, + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_package_section_3/package.json b/tests/packer/wrong_package_section_3/package.json @@ -0,0 +1,24 @@ +{ + "package": { + "name": "name", + "version": "2.0", + "description": [] + }, + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_package_section_4/package.json b/tests/packer/wrong_package_section_4/package.json @@ -0,0 +1,25 @@ +{ + "package": { + "name": "test", + "version": "2.0", + "description": "This is a description. Yeah I know, mind blowing.", + "bullshit_token": "" + }, + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/packer/wrong_package_section_5/package.json b/tests/packer/wrong_package_section_5/package.json @@ -0,0 +1,20 @@ +{ + "package": ["wi"], + "compilation": { + "configure": [ + {"mandir": "/usr/share/man"}, + "with-shared", + "without-debug", + "without-normal", + "enable-pc-files", + "enable-widec" + ], + "make": "", + "test": "", + "install": "" + }, + "dependencies": [ + "something-5.5", + "yrdy" + ] +} diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -68,6 +68,141 @@ TEST(packer_right) { return TEST_SUCCESS; } +TEST(packer_wrong_package_section_1) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_1/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_package_section_2) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_2/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_package_section_3) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_3/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_package_section_4) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_4/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_package_section_5) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_package_section_5/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_1) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_1/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_2) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_2/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_3) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_3/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_4) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_4/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_5) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_5/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_6) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_6/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_7) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_7/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_comp_section_8) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_comp_section_8/"); + 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; + + ptr = packer_init_dir("packer/wrong_deps_section_1/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_wrong_deps_section_2) { + packer_t *ptr; + + ptr = packer_init_dir("packer/wrong_deps_section_2/"); + TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised"); + packer_free(ptr); + return TEST_SUCCESS; +} + void register_test_packer(void) { reg_test("packer", packer_init_dir); reg_test("packer", packer_init_archive); @@ -75,4 +210,19 @@ void register_test_packer(void) { reg_test("packer", packer_read_dir_wrong_dir); reg_test("packer", packer_read_dir_no_configuration); reg_test("packer", packer_right); + reg_test("packer", packer_wrong_package_section_1); + reg_test("packer", packer_wrong_package_section_2); + reg_test("packer", packer_wrong_package_section_3); + reg_test("packer", packer_wrong_package_section_4); + reg_test("packer", packer_wrong_package_section_5); + reg_test("packer", packer_wrong_comp_section_1); + reg_test("packer", packer_wrong_comp_section_2); + reg_test("packer", packer_wrong_comp_section_3); + reg_test("packer", packer_wrong_comp_section_4); + reg_test("packer", packer_wrong_comp_section_5); + 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_deps_section_1); + reg_test("packer", packer_wrong_deps_section_2); }