#include "acutest.h" #include "vieter_package_internal.h" void test_info_parse() { FILE *f = fopen("./test/package/.PKGINFO", "r"); TEST_ASSERT_(f != NULL, "could not find test .PKGINFO file in ./test/package "); fseek(f, 0L, SEEK_END); size_t size = ftell(f); fflush(stdout); rewind(f); char *pkg_info_str = malloc(size); fread(pkg_info_str, 1, size, f); fclose(f); pkg_info *info = vieter_package_info_init(); vieter_package_info_parse(info, pkg_info_str); TEST_CHECK(!strcmp(info->name, "xcursor-dmz")); TEST_CHECK(!strcmp(info->base, "xcursor-dmz")); TEST_CHECK(!strcmp(info->version, "0.4.5-2")); TEST_CHECK(!strcmp(info->description, "Style neutral, scalable cursor theme")); TEST_CHECK(!strcmp(info->url, "https://packages.debian.org/sid/dmz-cursor-theme")); TEST_CHECK(info->build_date == 1673751613); TEST_CHECK(!strcmp(info->packager, "Unknown Packager")); TEST_CHECK(info->size == 3469584); TEST_CHECK(!strcmp(info->arch, "any")); TEST_CHECK(!strcmp(info->licenses->array[0], "MIT")); TEST_CHECK(!strcmp(info->replaces->array[0], "test1")); TEST_CHECK(!strcmp(info->groups->array[0], "x11")); TEST_CHECK(!strcmp(info->conflicts->array[0], "test2")); TEST_CHECK(!strcmp(info->conflicts->array[1], "test3")); TEST_CHECK(!strcmp(info->provides->array[0], "test4")); TEST_CHECK(!strcmp(info->depends->array[0], "test5")); TEST_CHECK(!strcmp(info->depends->array[1], "test6")); TEST_CHECK(!strcmp(info->optdepends->array[0], "test7")); TEST_CHECK(!strcmp(info->makedepends->array[0], "xorg-xcursorgen")); TEST_CHECK(!strcmp(info->checkdepends->array[0], "test8")); } void test_pkg_read_archive_files() { Pkg *pkg = vieter_package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst"); TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive"); FILE *f = fopen("./test/package/files", "r"); TEST_ASSERT_(f != NULL, "could not find test files file in ./test/package"); char buff[128]; size_t i = 0; while ((fgets(buff, 128, f)) != NULL || i < pkg->files->size) { if (buff[strlen(buff) - 1] == '\n') { buff[strlen(buff) - 1] = '\0'; } TEST_CHECK_(!strcmp(pkg->files->array[i], buff), "%s != %s", pkg->files->array[i], buff); i++; } TEST_CHECK(pkg->compression = 14); } void test_pkg_read_archive_desc() { Pkg *pkg = vieter_package_read_archive("./test/package/xcursor-dmz-0.4.5-2-any.pkg.tar.zst"); TEST_ASSERT_(pkg != NULL, "failure parsing pkg archive"); char *description = vieter_package_to_description(pkg); FILE *f = fopen("./test/package/desc", "r"); TEST_ASSERT_(f != NULL, "could not find test desc file in ./test/package"); fseek(f, 0, SEEK_END); size_t size = ftell(f); rewind(f); char *desc = malloc(size); fread(desc, 1, size, f); fclose(f); TEST_CHECK(!strcmp(description, desc)); } TEST_LIST = { {".PKGINFO parse", test_info_parse}, {"files array creation", test_pkg_read_archive_files}, {"desc file creation", test_pkg_read_archive_desc}, {NULL, NULL} };