forked from vieter-v/libvieter
				
			fix: Somehow, test file changed line endings to CRLF. Changed it back to LF.
							parent
							
								
									fbbc15cf73
								
							
						
					
					
						commit
						d0914adbb5
					
				| 
						 | 
				
			
			@ -1,86 +1,84 @@
 | 
			
		|||
#include "acutest.h"
 | 
			
		||||
#include "package.h"
 | 
			
		||||
 | 
			
		||||
void test_pkg_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);
 | 
			
		||||
	PkgInfo *pkg_info = package_info_init();
 | 
			
		||||
	package_info_parse(pkg_info, pkg_info_str);
 | 
			
		||||
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->name, "xcursor-dmz"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->base, "xcursor-dmz"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->version, "0.4.5-2"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->description, "Style neutral, scalable cursor theme"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->url, "https://packages.debian.org/sid/dmz-cursor-theme"));
 | 
			
		||||
	TEST_CHECK(pkg_info->build_date == 1673751613);
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->packager, "Unknown Packager"));
 | 
			
		||||
	TEST_CHECK(pkg_info->size == 3469584);
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->arch, "any"));
 | 
			
		||||
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->licenses->array[0], "MIT"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->replaces->array[0], "test1"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->groups->array[0], "x11"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->conflicts->array[0], "test2"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->conflicts->array[1], "test3"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->provides->array[0], "test4"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->depends->array[0], "test5"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->depends->array[1], "test6"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->optdepends->array[0], "test7"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->makedepends->array[0], "xorg-xcursorgen"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->checkdepends->array[0], "test8"));
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_pkg_read_archive_files() {
 | 
			
		||||
	Pkg *pkg = 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 = malloc(sizeof(char) * 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 = 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 = 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 = {
 | 
			
		||||
	{"pkg_info_valid_parse", test_pkg_info_parse},
 | 
			
		||||
	{"pkg_read_archive_files", test_pkg_read_archive_files},
 | 
			
		||||
	{"pkg_read_archive_desc", test_pkg_read_archive_desc},
 | 
			
		||||
	{NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
#include "acutest.h"
 | 
			
		||||
#include "package.h"
 | 
			
		||||
 | 
			
		||||
void test_pkg_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);
 | 
			
		||||
	PkgInfo *pkg_info = package_info_init();
 | 
			
		||||
	package_info_parse(pkg_info, pkg_info_str);
 | 
			
		||||
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->name, "xcursor-dmz"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->base, "xcursor-dmz"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->version, "0.4.5-2"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->description, "Style neutral, scalable cursor theme"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->url, "https://packages.debian.org/sid/dmz-cursor-theme"));
 | 
			
		||||
	TEST_CHECK(pkg_info->build_date == 1673751613);
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->packager, "Unknown Packager"));
 | 
			
		||||
	TEST_CHECK(pkg_info->size == 3469584);
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->arch, "any"));
 | 
			
		||||
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->licenses->array[0], "MIT"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->replaces->array[0], "test1"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->groups->array[0], "x11"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->conflicts->array[0], "test2"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->conflicts->array[1], "test3"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->provides->array[0], "test4"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->depends->array[0], "test5"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->depends->array[1], "test6"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->optdepends->array[0], "test7"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->makedepends->array[0], "xorg-xcursorgen"));
 | 
			
		||||
	TEST_CHECK(!strcmp(pkg_info->checkdepends->array[0], "test8"));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void test_pkg_read_archive_files() {
 | 
			
		||||
	Pkg *pkg = 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 = 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 = 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 = {
 | 
			
		||||
	{"pkg_info_valid_parse", test_pkg_info_parse},
 | 
			
		||||
	{"pkg_read_archive_files", test_pkg_read_archive_files},
 | 
			
		||||
	{"pkg_read_archive_desc", test_pkg_read_archive_desc},
 | 
			
		||||
	{NULL, NULL}
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue