libmpm

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

commit 4d8ff0f93e287bf325283c1f4e684f45687c66fc
parent b5774662aecead422950434300a4bf248872dc0e
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  9 May 2017 18:52:46 +0200

Add(Tests): Add test for error cases in read_file_from_binary

Diffstat:
Mtests/test_packer.c | 17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -522,6 +522,22 @@ TEST(packer_extract_archive_1) { return TEST_SUCCESS; } +TEST(read_packer_file_from_binary) { + char *content = "Test123\0Nocare"; + off_t ctr = 0; + + set_malloc_fail(0); + TEST_ASSERT(read_packer_file_from_binary(content, &ctr) == NULL, "Error did not raise"); + + + set_strdup_fail(0); + TEST_ASSERT(read_packer_file_from_binary(content, &ctr) == NULL, "Error did not raise"); + + set_malloc_fail(1); + TEST_ASSERT(read_packer_file_from_binary(content, &ctr) == NULL, "Error did not raise"); + return TEST_SUCCESS; +} + TEST(packer_create_archive_cleanup) { unlink(PACKAGE_OUTPUT_FN); return TEST_SUCCESS; @@ -574,5 +590,6 @@ void register_test_packer(void) { reg_test("packer", packer_read_package_header); reg_test("packer", packer_file_init); reg_test("packer", packer_extract_archive_1); + reg_test("packer", read_packer_file_from_binary); reg_test("packer", packer_create_archive_cleanup); }