libmpm

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

commit 88c829598712b6a9c041e951369bc29c8ed5a500
parent 09d9351bb994f9ecee9aaf7fc91488109252793c
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sat, 15 Apr 2017 18:34:33 +0200

Add(Packer): read_archive function beginning

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

diff --git a/src/packer.c b/src/packer.c @@ -471,3 +471,28 @@ bool packer_create_archive(packer_t *ctx, const char *archive_path) { return true; } +static bool read_package_header(int fd, packer_t *ctx) +{ + (void)ctx; + char *file_content = mpm_read_file_from_fd(fd); + printf("%s\n", file_content); + return true; +} + +bool packer_read_archive(packer_t *ctx) +{ + int fd; + bool ret; + + if (ctx->type != PACKER_TYPE_ARCHIVE) + return false; + + fd = open(ctx->str, O_RDONLY); + if (fd == -1) + return false; + + ret = read_package_header(fd, ctx); + + close(fd); + return ret; +} diff --git a/tests/test_packer.c b/tests/test_packer.c @@ -279,6 +279,7 @@ TEST(packer_create_archive_1) { TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened"); TEST_ASSERT(packer_create_archive(ptr, PACKAGE_OUTPUT_FN) == true, "An error happened"); + packer_free(ptr); return TEST_SUCCESS; } @@ -289,6 +290,7 @@ TEST(packer_create_archive_wrong_fn) { TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened"); TEST_ASSERT(packer_create_archive(ptr, "/non/sense/path") == false, "Error did not raise"); + packer_free(ptr); return TEST_SUCCESS; } @@ -298,6 +300,34 @@ TEST(packer_create_archive_wrong_type) { ptr = packer_init_archive("test"); TEST_ASSERT(packer_create_archive(ptr, "nocare") == false, "Error did not raise") + packer_free(ptr); + return TEST_SUCCESS; +} + +TEST(packer_read_archive_1) { + packer_t *ctx; + + ctx = packer_init_dir("./"); + TEST_ASSERT(packer_read_archive(ctx) == false, "Wrong return"); + packer_free(ctx); + return TEST_SUCCESS; +} + +TEST(packer_read_archive_2) { + packer_t *ctx; + + ctx = packer_init_archive("/non/sense/path"); + TEST_ASSERT(packer_read_archive(ctx) == false, "Wrong return"); + packer_free(ctx); + return TEST_SUCCESS; +} + +TEST(packer_read_archive_3) { + packer_t *ctx; + + ctx = packer_init_archive(PACKAGE_OUTPUT_FN); + TEST_ASSERT(packer_read_archive(ctx) == true, "Wrong return"); + packer_free(ctx); return TEST_SUCCESS; } @@ -340,6 +370,8 @@ void register_test_packer(void) { reg_test("packer", packer_create_archive_1); reg_test("packer", packer_create_archive_wrong_fn); reg_test("packer", packer_create_archive_wrong_type); + reg_test("packer", packer_read_archive_1); + reg_test("packer", packer_read_archive_2); + reg_test("packer", packer_read_archive_3); reg_test("packer", packer_create_archive_cleanup); - }