libmpm

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

test_packer.c (22916B)


      1 #include "test.h"
      2 
      3 TEST(packer_tests_init) {
      4     /* Cleaning tests directory */
      5     recursive_delete("/tmp/test-2.0");
      6     return TEST_SUCCESS;
      7 }
      8 
      9 TEST(packer_init_dir) {
     10     packer_t    *ptr = NULL;
     11 
     12     set_strdup_fail(1);
     13     set_malloc_fail(1);
     14     ptr = packer_init_dir("Test 123");
     15     TEST_ASSERT(ptr != NULL, "Function failed");
     16     TEST_ASSERT(strcmp(ptr->str, "Test 123") == 0, "Directory name is wrong");
     17     packer_free(ptr);
     18     ptr = packer_init_dir("Test 123");
     19     TEST_ASSERT(ptr == NULL, "Error not raised");
     20     ptr = packer_init_dir("Test 123");
     21     TEST_ASSERT(ptr == NULL, "Error not raised");
     22     return TEST_SUCCESS;
     23 }
     24 
     25 TEST(packer_init_archive) {
     26     packer_t    *ptr = NULL;
     27 
     28     set_strdup_fail(1);
     29     set_malloc_fail(1);
     30     ptr = packer_init_archive("Test 123");
     31     TEST_ASSERT(ptr != NULL, "Function failed");
     32     TEST_ASSERT(strcmp(ptr->str, "Test 123") == 0, "Directory name is wrong");
     33     packer_free(ptr);
     34     ptr = packer_init_archive("Test 123");
     35     TEST_ASSERT(ptr == NULL, "Error not raised");
     36     ptr = packer_init_archive("Test 123");
     37     TEST_ASSERT(ptr == NULL, "Error not raised");
     38     return TEST_SUCCESS;
     39 }
     40 
     41 TEST(packer_read_dir_wrong_type) {
     42     packer_t    *ptr;
     43 
     44     ptr = packer_init_archive("Test");
     45     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
     46     packer_free(ptr);
     47     return TEST_SUCCESS;
     48 }
     49 
     50 TEST(packer_read_dir_wrong_dir) {
     51     packer_t    *ptr;
     52 
     53     ptr = packer_init_dir("Test/non/existing");
     54     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
     55     packer_free(ptr);
     56     return TEST_SUCCESS;
     57 }
     58 
     59 TEST(packer_read_dir_no_configuration) {
     60     packer_t    *ptr;
     61 
     62     ptr = packer_init_dir("packer/wrong/");
     63     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
     64     packer_free(ptr);
     65     return TEST_SUCCESS;
     66 }
     67 
     68 TEST(packer_wrong_main_1) {
     69     packer_t    *ptr;
     70 
     71     ptr = packer_init_dir("packer/wrong_main_1/");
     72     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
     73     packer_free(ptr);
     74     return TEST_SUCCESS;
     75 }
     76 
     77 TEST(packer_right) {
     78     packer_t    *ptr;
     79 
     80     ptr = packer_init_dir("packer/right/");
     81     TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened");
     82     packer_free(ptr);
     83     return TEST_SUCCESS;
     84 }
     85 
     86 TEST(packer_right_1) {
     87     packer_t    *ptr;
     88 
     89     ptr = packer_init_dir("packer/right_1/");
     90     TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened");
     91     packer_free(ptr);
     92     return TEST_SUCCESS;
     93 }
     94 
     95 
     96 TEST(packer_wrong_package_section_1) {
     97     packer_t    *ptr;
     98 
     99     ptr = packer_init_dir("packer/wrong_package_section_1/");
    100     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    101     packer_free(ptr);
    102     return TEST_SUCCESS;
    103 }
    104 
    105 TEST(packer_wrong_package_section_2) {
    106     packer_t    *ptr;
    107 
    108     ptr = packer_init_dir("packer/wrong_package_section_2/");
    109     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    110     packer_free(ptr);
    111     return TEST_SUCCESS;
    112 }
    113 
    114 TEST(packer_wrong_package_section_3) {
    115     packer_t    *ptr;
    116 
    117     ptr = packer_init_dir("packer/wrong_package_section_3/");
    118     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    119     packer_free(ptr);
    120     return TEST_SUCCESS;
    121 }
    122 
    123 TEST(packer_wrong_package_section_4) {
    124     packer_t    *ptr;
    125 
    126     ptr = packer_init_dir("packer/wrong_package_section_4/");
    127     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    128     packer_free(ptr);
    129     return TEST_SUCCESS;
    130 }
    131 
    132 TEST(packer_wrong_package_section_5) {
    133     packer_t    *ptr;
    134 
    135     ptr = packer_init_dir("packer/wrong_package_section_5/");
    136     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    137     packer_free(ptr);
    138     return TEST_SUCCESS;
    139 }
    140 
    141 TEST(packer_wrong_package_section_6) {
    142     packer_t    *ptr;
    143 
    144     ptr = packer_init_dir("packer/wrong_package_section_6/");
    145     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    146     packer_free(ptr);
    147     return TEST_SUCCESS;
    148 }
    149 
    150 TEST(packer_wrong_package_section_7) {
    151     packer_t    *ptr;
    152 
    153     ptr = packer_init_dir("packer/wrong_package_section_7/");
    154     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    155     packer_free(ptr);
    156     return TEST_SUCCESS;
    157 }
    158 
    159 TEST(packer_wrong_package_section_8) {
    160     packer_t    *ptr;
    161 
    162     ptr = packer_init_dir("packer/wrong_package_section_8/");
    163     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    164     packer_free(ptr);
    165     return TEST_SUCCESS;
    166 }
    167 
    168 TEST(packer_wrong_comp_section_1) {
    169     packer_t    *ptr;
    170 
    171     ptr = packer_init_dir("packer/wrong_comp_section_1/");
    172     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    173     packer_free(ptr);
    174     return TEST_SUCCESS;
    175 }
    176 
    177 TEST(packer_wrong_comp_section_2) {
    178     packer_t    *ptr;
    179 
    180     ptr = packer_init_dir("packer/wrong_comp_section_2/");
    181     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    182     packer_free(ptr);
    183     return TEST_SUCCESS;
    184 }
    185 
    186 TEST(packer_wrong_comp_section_3) {
    187     packer_t    *ptr;
    188 
    189     ptr = packer_init_dir("packer/wrong_comp_section_3/");
    190     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    191     packer_free(ptr);
    192     return TEST_SUCCESS;
    193 }
    194 
    195 TEST(packer_wrong_comp_section_4) {
    196     packer_t    *ptr;
    197 
    198     ptr = packer_init_dir("packer/wrong_comp_section_4/");
    199     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    200     packer_free(ptr);
    201     return TEST_SUCCESS;
    202 }
    203 
    204 TEST(packer_wrong_comp_section_5) {
    205     packer_t    *ptr;
    206 
    207     ptr = packer_init_dir("packer/wrong_comp_section_5/");
    208     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    209     packer_free(ptr);
    210     return TEST_SUCCESS;
    211 }
    212 
    213 TEST(packer_wrong_comp_section_6) {
    214     packer_t    *ptr;
    215 
    216     ptr = packer_init_dir("packer/wrong_comp_section_6/");
    217     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    218     packer_free(ptr);
    219     return TEST_SUCCESS;
    220 }
    221 
    222 TEST(packer_wrong_comp_section_7) {
    223     packer_t    *ptr;
    224 
    225     ptr = packer_init_dir("packer/wrong_comp_section_7/");
    226     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    227     packer_free(ptr);
    228     return TEST_SUCCESS;
    229 }
    230 
    231 TEST(packer_wrong_comp_section_8) {
    232     packer_t    *ptr;
    233 
    234     ptr = packer_init_dir("packer/wrong_comp_section_8/");
    235     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    236     packer_free(ptr);
    237     return TEST_SUCCESS;
    238 }
    239 
    240 TEST(packer_wrong_comp_section_9) {
    241     packer_t    *ptr;
    242 
    243     ptr = packer_init_dir("packer/wrong_comp_section_9/");
    244     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    245     packer_free(ptr);
    246     return TEST_SUCCESS;
    247 }
    248 
    249 TEST(packer_wrong_comp_section_10) {
    250     packer_t    *ptr;
    251 
    252     ptr = packer_init_dir("packer/wrong_comp_section_10/");
    253     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    254     packer_free(ptr);
    255     return TEST_SUCCESS;
    256 }
    257 
    258 TEST(packer_wrong_comp_section_11) {
    259     packer_t    *ptr;
    260 
    261     ptr = packer_init_dir("packer/wrong_comp_section_11/");
    262     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    263     packer_free(ptr);
    264     return TEST_SUCCESS;
    265 }
    266 
    267 TEST(packer_wrong_deps_section_1) {
    268     packer_t    *ptr;
    269 
    270     ptr = packer_init_dir("packer/wrong_deps_section_1/");
    271     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    272     packer_free(ptr);
    273     return TEST_SUCCESS;
    274 }
    275 
    276 TEST(packer_wrong_deps_section_2) {
    277     packer_t    *ptr;
    278 
    279     ptr = packer_init_dir("packer/wrong_deps_section_2/");
    280     TEST_ASSERT(packer_read_dir(ptr) == false, "Error not raised");
    281     packer_free(ptr);
    282     return TEST_SUCCESS;
    283 }
    284 
    285 MPX_STATIC packer_t *packer_init(const char *str);
    286 TEST(packer_init_1) {
    287     set_malloc_fail(0);
    288     TEST_ASSERT(packer_init("Yup.") == NULL, "Error not raised");
    289     return TEST_SUCCESS;
    290 }
    291 
    292 TEST(packer_init_2) {
    293     set_strdup_fail(0);
    294     TEST_ASSERT(packer_init("Yup.") == NULL, "Error not raised");
    295     return TEST_SUCCESS;
    296 }
    297 
    298 MPX_STATIC packer_header_t *packer_header_init(void);
    299 TEST(packer_header_init) {
    300     set_malloc_fail(0);
    301     TEST_ASSERT(packer_header_init() == NULL, "Error not raised");
    302     return TEST_SUCCESS;
    303 }
    304 
    305 #define PACKAGE_OUTPUT_FN "package" PACKER_DEF_EXT
    306 
    307 TEST(packer_create_archive_1) {
    308     packer_t        *ptr;
    309 
    310     ptr = packer_init_dir("packer/right/");
    311     TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened");
    312     TEST_ASSERT(packer_create_archive(ptr, PACKAGE_OUTPUT_FN) == true,
    313                     "An error happened");
    314 
    315     packer_free(ptr);
    316     return TEST_SUCCESS;
    317 }
    318 
    319 TEST(packer_create_archive_wrong_fn) {
    320     packer_t    *ptr;
    321 
    322     ptr = packer_init_dir("packer/right/");
    323     TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened");
    324     TEST_ASSERT(packer_create_archive(ptr, "/non/sense/path") == false,
    325                     "Error did not raise");
    326     packer_free(ptr);
    327     return TEST_SUCCESS;
    328 }
    329 
    330 TEST(packer_create_archive_wrong_type) {
    331     packer_t    *ptr;
    332 
    333     ptr = packer_init_archive("test");
    334     TEST_ASSERT(packer_create_archive(ptr, "nocare") == false,
    335                     "Error did not raise")
    336     packer_free(ptr);
    337     return TEST_SUCCESS;
    338 }
    339 
    340 TEST(packer_create_archive_2) {
    341     packer_t    *ptr;
    342 
    343     ptr = packer_init_dir("packer/right/");
    344     TEST_ASSERT(packer_read_dir(ptr) == true, "An error happened");
    345     packer_free(ptr);
    346     unlink("tests/package_2.mpx");
    347     return TEST_SUCCESS;
    348 }
    349 
    350 TEST(packer_create_archive_3) {
    351     packer_t *ptr;
    352 
    353     ptr = packer_init_dir("packer/right_1/");
    354     packer_read_dir(ptr);
    355     TEST_ASSERT(packer_create_archive(ptr, "package_2.mpx") == true,
    356         "An error happened");
    357     packer_free(ptr);
    358     return TEST_SUCCESS;
    359 }
    360 
    361 TEST(packer_create_archive_4) {
    362     packer_t *ptr;
    363 
    364     ptr = packer_init_dir("packer/right/");
    365     packer_read_dir(ptr);
    366 
    367     set_stat_fail(0);
    368     TEST_ASSERT(packer_create_archive(ptr, "package_2.mpx") == false,
    369         "An error happened");
    370 
    371     set_stat_fail(2);
    372     TEST_ASSERT(packer_create_archive(ptr, "package_2.mpx") == false,
    373         "An error happened");
    374 
    375     set_stat_fail(4);
    376     TEST_ASSERT(packer_create_archive(ptr, "package_2.mpx") == false,
    377         "An error happened");
    378     packer_free(ptr);
    379     return TEST_SUCCESS;
    380 }
    381 
    382 
    383 MPX_STATIC bool write_packer_sources(FILE *fd, packer_t *ctx, const char *dir_name);
    384 TEST(packer_write_packer_sources) {
    385     FILE        *fd = fopen("package_2.mpx", "w+");
    386     packer_t    *ptr;
    387 
    388     ptr = packer_init_dir("packer/right/");
    389 
    390     set_calloc_fail(0);
    391     TEST_ASSERT(write_packer_sources(fd, ptr, "srcs/") == false, "Error did not raise");
    392     packer_free(ptr);
    393     fclose(fd);
    394     unlink("package_2.mpx");
    395     return TEST_SUCCESS;
    396 }
    397 
    398 MPX_STATIC int read_package_header_dependencies(const char *file, packer_t *ctx);
    399 TEST(packer_read_package_header_dependencies) {
    400     char file[10], *tmp;
    401     u32_t i = htonl(3);
    402 
    403     memcpy(file, &i, sizeof(i));
    404     tmp = strdup("Test");
    405     file[4] = tmp;
    406     set_strdup_fail(0);
    407     TEST_ASSERT(read_package_header_dependencies(file, NULL) == 0, "Wrong return");
    408     free(tmp);
    409     return TEST_SUCCESS;
    410 }
    411 
    412 MPX_STATIC void packer_header_free(packer_header_t *ptr);
    413 MPX_STATIC int read_package_header_compilation(char *file, packer_t *ctx);
    414 TEST(packer_read_package_header_compilation) {
    415     char        *file;
    416     char        tmp[] = "TEst:123\0Oui\0make\0test\0install\0Test:123";
    417     u32_t       i = htonl(1);
    418     packer_t    ctx;
    419 
    420     set_malloc_fail(-1);
    421 
    422     file = malloc(sizeof(i) + sizeof(tmp));
    423     memcpy(file, &i, sizeof(i));
    424     memcpy(file + sizeof(i), tmp, sizeof(tmp));
    425 
    426     TEST_ASSERT(read_package_header_compilation(file, NULL) == 0, "Wrong return");
    427 
    428     ctx.header = packer_header_init();
    429     set_strdup_fail(2);
    430     TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return");
    431     memcpy(file + sizeof(i), tmp, sizeof(tmp));
    432     packer_header_free(ctx.header);
    433 
    434     ctx.header = packer_header_init();
    435     set_strdup_fail(3);
    436     TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return");
    437     memcpy(file + sizeof(i), tmp, sizeof(tmp));
    438     packer_header_free(ctx.header);
    439 
    440     ctx.header = packer_header_init();
    441     set_strdup_fail(4);
    442     TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return");
    443     memcpy(file + sizeof(i), tmp, sizeof(tmp));
    444     packer_header_free(ctx.header);
    445 
    446     ctx.header = packer_header_init();
    447     set_strdup_fail(5);
    448     TEST_ASSERT(read_package_header_compilation(file, &ctx) == 0, "Wrong return");
    449     memcpy(file + sizeof(i), tmp, sizeof(tmp));
    450     packer_header_free(ctx.header);
    451 
    452     free(file);
    453     return TEST_SUCCESS;
    454 }
    455 
    456 MPX_STATIC int read_package_header_package(const char *file, packer_t *ctx);
    457 TEST(packer_read_package_header_package) {
    458     set_malloc_fail(-1);
    459     set_strdup_fail(-1);
    460 
    461     char tmp[] = "Name\0Version\0Desc\0";
    462     packer_t *ctx = packer_init_archive("Test");
    463 
    464     TEST_ASSERT(ctx != NULL, "Can't init archive");
    465 
    466     ctx->header = packer_header_init();
    467 
    468     TEST_ASSERT(read_package_header_package(tmp, NULL) == 0, "Wrong return");
    469 
    470     set_strdup_fail(0);
    471     TEST_ASSERT(read_package_header_package(tmp, ctx) == 0, "Wrong return");
    472 
    473     set_strdup_fail(1);
    474     TEST_ASSERT(read_package_header_package(tmp, ctx) == 0, "Wrong return");
    475 
    476     set_strdup_fail(2);
    477     TEST_ASSERT(read_package_header_package(tmp, ctx) == 0, "Wrong return");
    478 
    479     set_strdup_fail(3);
    480     TEST_ASSERT(read_package_header_package(tmp, ctx) == 0, "Wrong return");
    481 
    482     set_malloc_fail(-1);
    483     packer_free(ctx);
    484     return TEST_SUCCESS;
    485 }
    486 MPX_STATIC bool read_package_header(char *file_content, packer_t *ctx, int *s_ret);
    487 TEST(packer_read_package_header) {
    488     packer_t *ctx = packer_init_archive("Test");
    489     char    *file = mpm_read_file_from_fn(PACKAGE_OUTPUT_FN);
    490     int     ret = 0;
    491 
    492     TEST_ASSERT(read_package_header(NULL, ctx, &ret) == false, "Wrong return");
    493     TEST_ASSERT(read_package_header("pasmpx", ctx, &ret) == false, "Wrong return");
    494     packer_free(ctx);
    495 
    496     ctx = packer_init_archive("Test");
    497     set_malloc_fail(0);
    498     TEST_ASSERT(read_package_header(file, ctx, &ret) == false, "Wrong return");
    499     packer_free(ctx);
    500     free(file);
    501 
    502     ctx = packer_init_archive("Test");
    503     file = mpm_read_file_from_fn(PACKAGE_OUTPUT_FN);
    504     set_strdup_fail(0);
    505     TEST_ASSERT(read_package_header(file, ctx, &ret) == false, "Wrong return");
    506     packer_free(ctx);
    507     free(file);
    508 
    509     ctx = packer_init_archive("Test");
    510     file = mpm_read_file_from_fn(PACKAGE_OUTPUT_FN);
    511     set_strdup_fail(8);
    512     TEST_ASSERT(read_package_header(file, ctx, &ret) == false, "Wrong return");
    513     packer_free(ctx);
    514     free(file);
    515 
    516     ctx = packer_init_archive("Test");
    517     file = mpm_read_file_from_fn(PACKAGE_OUTPUT_FN);
    518     set_strdup_fail(15);
    519     TEST_ASSERT(read_package_header(file, ctx, &ret) == false, "Wrong return");
    520     packer_free(ctx);
    521     free(file);
    522 
    523     return TEST_SUCCESS;
    524 }
    525 
    526 MPX_STATIC packer_file_t *packer_file_init(const char *file, const char *dir);
    527 TEST(packer_file_init) {
    528     char    *file = "truc";
    529     char    *dir = "machin";
    530 
    531     set_calloc_fail(0);
    532     TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise");
    533     set_malloc_fail(0);
    534     TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise");
    535     set_strcpy_fail(0);
    536     TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise");
    537     set_strcat_fail(0);
    538     TEST_ASSERT(packer_file_init(file, dir) == NULL, "Error did not raise");
    539     return TEST_SUCCESS;
    540 }
    541 
    542 TEST(packer_extract_archive_1) {
    543     set_strdup_fail(-1);
    544 
    545     packer_t    *ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    546 
    547     SET_ERR_STR("");
    548     TEST_ASSERT_FMT(packer_extract_archive(ctx, "/tmp") == true, "Wrong return: %s\n", GET_ERR_STR());
    549     packer_free(ctx);
    550     return TEST_SUCCESS;
    551 }
    552 
    553 TEST(packer_read_archive_header) {
    554     packer_t *ctx = NULL;
    555 
    556     TEST_ASSERT(packer_read_archive_header(NULL) == false, "Error did not raise");
    557 
    558     ctx = packer_init_dir("test/");
    559     TEST_ASSERT(packer_read_archive_header(ctx) == false, "Error did not raise");
    560     packer_free(ctx);
    561 
    562     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    563     set_malloc_fail(0);
    564     TEST_ASSERT(packer_read_archive_header(ctx) == false, "Error did not raise");
    565 
    566     TEST_ASSERT(packer_read_archive_header(ctx) != false, "Something happend");
    567     TEST_ASSERT(strcmp(ctx->header->package.name, "test") == 0, "Name is wrong");
    568     TEST_ASSERT(strcmp(ctx->header->package.version, "2.0") == 0, "Name is wrong");
    569 
    570     packer_free(ctx);
    571     return TEST_SUCCESS;
    572 }
    573 
    574 TEST(packer_extract_archive_2) {
    575     packer_t    *ctx = NULL;
    576 
    577     recursive_delete("/tmp/test-2.0");
    578     TEST_ASSERT(packer_extract_archive(NULL, NULL) == false, "Error did not raise");
    579 
    580     ctx = packer_init_dir("Test");
    581     TEST_ASSERT(packer_extract_archive(ctx, NULL) == false, "Error did not raise");
    582     packer_free(ctx);
    583 
    584     ctx = packer_init_archive("Not a valid file");
    585     TEST_ASSERT(packer_extract_archive(ctx, NULL) == false, "Error did not raise");
    586     packer_free(ctx);
    587     recursive_delete("/tmp/test-2.0");
    588 
    589     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    590     TEST_ASSERT(packer_extract_archive(ctx, "/tmp/somedir/") == true, "Error did not raise");
    591     packer_free(ctx);
    592     recursive_delete("/tmp/somedir");
    593 
    594     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    595     set_malloc_fail(0);
    596     TEST_ASSERT(packer_extract_archive(ctx, NULL) == false, "Error did not raise");
    597     packer_free(ctx);
    598     recursive_delete("/tmp/test-2.0");
    599 
    600     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    601     set_chdir_fail(0);
    602     TEST_ASSERT(packer_extract_archive(ctx, "/tmp/") == false, "Error did not raise");
    603     packer_free(ctx);
    604     recursive_delete("/tmp/test-2.0");
    605 
    606     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    607     set_mkdir_fail(0);
    608     TEST_ASSERT(packer_extract_archive(ctx, "/tmp/some_non_existent_dir") == false, "Error did not raise");
    609     packer_free(ctx);
    610     recursive_delete("/tmp/some_non_existent_dir");
    611 
    612     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    613     set_mkdir_fail(0);
    614     TEST_ASSERT(packer_extract_archive(ctx, "/tmp/") == false, "Error did not raise");
    615     packer_free(ctx);
    616     recursive_delete("/tmp/test-2.0");
    617 
    618     ctx = packer_init_archive(PACKAGE_OUTPUT_FN);
    619     set_fchmod_fail(0);
    620     TEST_ASSERT(packer_extract_archive(ctx, "/tmp/") == false, "Error did not raise");
    621     packer_free(ctx);
    622     recursive_delete("/tmp/test-2.0");
    623 
    624     return TEST_SUCCESS;
    625 }
    626 
    627 TEST(packer_file_from_binary_to_disk) {
    628     off_t       ctr = 0;
    629 
    630     set_strdup_fail(0);
    631     TEST_ASSERT(packer_file_from_binary_to_disk("Content", &ctr) == false, "Error did not raise");
    632 
    633     set_strdup_fail(1);
    634     TEST_ASSERT(packer_file_from_binary_to_disk("/tmp/somedir/somefile", &ctr) == false, "Error did not raise");
    635 
    636     return TEST_SUCCESS;
    637 }
    638 
    639 TEST(get_file_information) {
    640     packer_file_t   *file;
    641 
    642     file = malloc(sizeof(*file));
    643     TEST_ASSERT(file != NULL, "Malloc failed");
    644     file->fn = strdup(PACKAGE_OUTPUT_FN);
    645 
    646     set_stat_fail(0);
    647     TEST_ASSERT(get_file_information(file) == false, "Error did not raise");
    648     free(file->fn);
    649     free(file);
    650 
    651     return TEST_SUCCESS;
    652 }
    653 
    654 MPX_STATIC bool read_conf_opt(char *file, mlist_t **list, int *ret);
    655 TEST(read_conf_opt) {
    656     char        file[250];
    657     int         ptr = 0;
    658     mlist_t     *head = NULL;
    659     u32_t       size = htonl(1);
    660 
    661     memcpy(file, &size, sizeof(size));
    662     memcpy(file + sizeof(size), "test:something", sizeof("test:something"));
    663     set_malloc_fail(0);
    664     TEST_ASSERT(read_conf_opt(file, &head, &ptr) == false, "Error did not raise");
    665     return TEST_SUCCESS;
    666 }
    667 
    668 TEST(packer_inlines_frees) {
    669     vector_string_t     *str = NULL, *str2 = NULL;
    670 
    671     str = vector_string_init("one", "two");
    672     str2 = vector_string_init("one", "two");
    673 
    674     packer_header_package_free(NULL);
    675     packer_header_comp_free(NULL);
    676     packer_header_package_free(NULL);
    677     packer_header_deps_free(NULL);
    678 
    679     packer_header_t     ptr;
    680 
    681 
    682     packer_header_comp_init(&ptr);
    683 
    684     list_add(ptr.compilation.configure, str, sizeof(*str));
    685     list_add(ptr.compilation.env, str2, sizeof(*str2));
    686 
    687     packer_header_comp_free(&ptr);
    688     free(str);
    689     free(str2);
    690 
    691     return TEST_SUCCESS;
    692 }
    693 
    694 TEST(packer_create_archive_cleanup) {
    695     recursive_delete("/tmp/test-2.0");
    696     set_malloc_fail(-1);
    697     unlink(PACKAGE_OUTPUT_FN);
    698     return TEST_SUCCESS;
    699 }
    700 
    701 void register_test_packer(void) {
    702     reg_test("packer", packer_tests_init);
    703     reg_test("packer", packer_init_dir);
    704     reg_test("packer", packer_init_archive);
    705     reg_test("packer", packer_read_dir_wrong_type);
    706     reg_test("packer", packer_read_dir_wrong_dir);
    707     reg_test("packer", packer_read_dir_no_configuration);
    708     reg_test("packer", packer_wrong_main_1);
    709     reg_test("packer", packer_right);
    710     reg_test("packer", packer_right_1);
    711     reg_test("packer", packer_wrong_package_section_1);
    712     reg_test("packer", packer_wrong_package_section_2);
    713     reg_test("packer", packer_wrong_package_section_3);
    714     reg_test("packer", packer_wrong_package_section_4);
    715     reg_test("packer", packer_wrong_package_section_5);
    716     reg_test("packer", packer_wrong_package_section_6);
    717     reg_test("packer", packer_wrong_package_section_7);
    718     reg_test("packer", packer_wrong_package_section_8);
    719     reg_test("packer", packer_wrong_comp_section_1);
    720     reg_test("packer", packer_wrong_comp_section_2);
    721     reg_test("packer", packer_wrong_comp_section_3);
    722     reg_test("packer", packer_wrong_comp_section_4);
    723     reg_test("packer", packer_wrong_comp_section_5);
    724     reg_test("packer", packer_wrong_comp_section_6);
    725     reg_test("packer", packer_wrong_comp_section_7);
    726     reg_test("packer", packer_wrong_comp_section_8);
    727     reg_test("packer", packer_wrong_comp_section_9);
    728     reg_test("packer", packer_wrong_comp_section_10);
    729     reg_test("packer", packer_wrong_comp_section_11);
    730     reg_test("packer", packer_wrong_deps_section_1);
    731     reg_test("packer", packer_wrong_deps_section_2);
    732     reg_test("packer", packer_init_1);
    733     reg_test("packer", packer_init_2);
    734     reg_test("packer", packer_header_init);
    735     reg_test("packer", packer_create_archive_1);
    736     reg_test("packer", packer_create_archive_2);
    737     reg_test("packer", packer_create_archive_3);
    738     reg_test("packer", packer_create_archive_4);
    739     reg_test("packer", packer_write_packer_sources);
    740     reg_test("packer", packer_create_archive_wrong_fn);
    741     reg_test("packer", packer_create_archive_wrong_type);
    742     reg_test("packer", packer_read_package_header_dependencies);
    743     reg_test("packer", packer_read_package_header_compilation);
    744     reg_test("packer", packer_read_package_header_package);
    745     reg_test("packer", packer_read_package_header);
    746     reg_test("packer", packer_file_init);
    747     reg_test("packer", packer_extract_archive_1);
    748     reg_test("packer", packer_extract_archive_2);
    749     reg_test("packer", packer_read_archive_header);
    750     reg_test("packer", packer_file_from_binary_to_disk);
    751     reg_test("packer", get_file_information);
    752     reg_test("packer", read_conf_opt);
    753     reg_test("packer", packer_inlines_frees);
    754     reg_test("packer", packer_create_archive_cleanup);
    755 }