ASSERT(arch1 == arch2);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_SUCCESS;
}
static int test_supported(const struct test* t) {
ASSERT(!r);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_SUCCESS;
}
static int test_compatible(const struct test* t) {
ASSERT(!r);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_SUCCESS;
}
static int test_machine(const struct test* t) {
ASSERT(r == 0);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_SUCCESS;
}
int main(int argc, char** argv) {
#define TEST_PKG1_FILE "usr/bin/beep"
static int test_open(const struct test* t) {
+ struct pakfire_archive* archive = NULL;
+ int r = EXIT_FAILURE;
+
const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
LOG("Trying to open %s\n", path);
// Open the archive
- struct pakfire_archive* archive;
ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
pakfire_archive_verify_status_t status;
ASSERT(pakfire_archive_verify(archive, &status, NULL) == 0);
ASSERT(status == PAKFIRE_ARCHIVE_VERIFY_OK);
- pakfire_archive_unref(archive);
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (archive)
+ pakfire_archive_unref(archive);
- return EXIT_SUCCESS;
+ return r;
}
static int test_filelist(const struct test* t) {
const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
+ int r = EXIT_FAILURE;
+
+ struct pakfire_archive* archive = NULL;
+ struct pakfire_filelist* list = NULL;
// Open the archive
- struct pakfire_archive* archive;
ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
// Fetch the filelist
- struct pakfire_filelist* list = pakfire_archive_get_filelist(archive);
+ list = pakfire_archive_get_filelist(archive);
ASSERT(list);
// This packages has 7 files
ASSERT(pakfire_filelist_size(list) == 7);
- // Cleanup
- pakfire_filelist_unref(list);
- pakfire_archive_unref(archive);
- return EXIT_SUCCESS;
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (list)
+ pakfire_filelist_unref(list);
+ if (archive)
+ pakfire_archive_unref(archive);
+
+ return r;
}
static int test_extract(const struct test* t) {
const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
+ int r = EXIT_FAILURE;
+
+ struct pakfire_archive* archive = NULL;
- struct pakfire_archive* archive;
ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
// Extract the archive payload
- int r = pakfire_archive_extract(archive, NULL);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_archive_extract(archive, NULL));
#if 0
char file[PATH_MAX];
ASSERT_SUCCESS(access(file, F_OK));
#endif
- pakfire_archive_unref(archive);
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (archive)
+ pakfire_archive_unref(archive);
+
+ return r;
}
static int test_import(const struct test* t) {
const char* path = TEST_SRC_PATH TEST_PKG1_PATH;
+ int r = EXIT_FAILURE;
- struct pakfire_archive* archive;
- ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
-
+ struct pakfire_archive* archive = NULL;
struct pakfire_repo* repo = NULL;
+ struct pakfire_package* package = NULL;
+
+ // Open archive
+ ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
+ ASSERT(archive);
// Create a new repository
ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "tmp"));
ASSERT(repo);
- struct pakfire_package* package = NULL;
-
// Add the package to the repository
ASSERT_SUCCESS(pakfire_repo_add_archive(repo, archive, &package));
ASSERT(package);
- pakfire_repo_unref(repo);
- pakfire_package_unref(package);
- pakfire_archive_unref(archive);
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (repo)
+ pakfire_repo_unref(repo);
+ if (package)
+ pakfire_package_unref(package);
+ if (archive)
+ pakfire_archive_unref(archive);
- return EXIT_SUCCESS;
+ return r;
}
int main(int argc, char** argv) {
);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_attach(const struct test* t) {
);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static void handle_signal(int signum) {
return child_process();
return pid;
+
+FAIL:
+ abort();
}
static int test_killall(const struct test* t) {
);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_cpustat(const struct test* t) {
);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_nice(const struct test* t) {
);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_random_name(const struct test* t) {
ASSERT_STRING_NOT_EQUALS(name1, name2);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
int main(int argc, char** argv) {
static int read_test(const struct test* t,
FILE* (function)(FILE* f, const char* mode), const char* file) {
+ int r = EXIT_FAILURE;
+
+ FILE* f = NULL;
char path[PATH_MAX];
char buffer[1024];
- int r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, file);
+ r = pakfire_string_format(path, "%s/%s", TEST_SRC_PATH, file);
ASSERT(r >= 0);
- FILE* f = fopen(path, "r");
- ASSERT(f);
+ // Open file
+ ASSERT(f = fopen(path, "r"));
// Engage decompressor
f = function(f, "r");
// Buffer should equal the test data
ASSERT(bytes_read >= sizeof(TEST_DATA) - 1);
- ASSERT(memcmp(buffer, TEST_DATA, sizeof(TEST_DATA) - 1) == 0);
+ ASSERT_SUCCESS(memcmp(buffer, TEST_DATA, sizeof(TEST_DATA) - 1));
- fclose(f);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (f)
+ fclose(f);
+
+ return r;
}
static int write_test(const struct test* t, FILE* (function)(FILE* f, const char* mode)) {
+ int r = EXIT_FAILURE;
+
+ FILE* f = NULL;
+
// Create a backend storage file
- FILE* f = test_mktemp();
- ASSERT(f);
+ ASSERT(f = test_mktemp());
// Open compressed file for writing
f = function(f, "w");
ASSERT(bytes_written == sizeof(TEST_DATA) - 1);
}
- fclose(f);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (f)
+ fclose(f);
+
+ return r;
}
static int test_xzfopen_read(const struct test* t) {
}
static int test_xfopen(const struct test* t) {
- ASSERT(read_test(t, pakfire_xfopen, "data/compress/data.xz") == EXIT_SUCCESS);
- ASSERT(read_test(t, pakfire_xfopen, "data/compress/data.zst") == EXIT_SUCCESS);
+ ASSERT_SUCCESS(read_test(t, pakfire_xfopen, "data/compress/data.xz"));
+ ASSERT_SUCCESS(read_test(t, pakfire_xfopen, "data/compress/data.zst"));
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
int main(int argc, char** argv) {
#include "../testsuite.h"
static int test_get_and_set(const struct test* t) {
- struct pakfire_config* config;
+ struct pakfire_config* config = NULL;
+ int r = EXIT_FAILURE;
ASSERT_SUCCESS(pakfire_config_create(&config));
ASSERT(pakfire_config_has_section(config, "section1"));
ASSERT(!pakfire_config_has_section(config, "section3"));
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
pakfire_config_unref(config);
- return EXIT_SUCCESS;
+ return r;
}
static int test_parse(const struct test* t) {
+ int r = EXIT_FAILURE;
char* TEST_INPUT =
"key1 = value1\n"
"\n"
FILE* f = fmemopen(TEST_INPUT, strlen(TEST_INPUT), "r");
ASSERT(f);
- struct pakfire_config* config;
+ struct pakfire_config* config = NULL;
ASSERT_SUCCESS(pakfire_config_create(&config));
ASSERT_SUCCESS(pakfire_config_read(config, f));
ASSERT_STRING_EQUALS(sections[1], "section2");
ASSERT_NULL(sections[2]);
- pakfire_config_unref(config);
+ // Everything passed
+ r = EXIT_SUCCESS;
- fclose(f);
+FAIL:
+ if (f)
+ fclose(f);
+ pakfire_config_unref(config);
- return EXIT_SUCCESS;
+ return r;
}
int main(int argc, char** argv) {
#include "../testsuite.h"
static int test_open_ro(const struct test* t) {
- struct pakfire_db* db;
+ struct pakfire_db* db = NULL;
+ int r = EXIT_FAILURE;
- int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READONLY);
- ASSERT(!r);
+ ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READONLY));
- pakfire_db_unref(db);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return 0;
+FAIL:
+ if (db)
+ pakfire_db_unref(db);
+
+ return r;
}
static int test_open_rw(const struct test* t) {
- struct pakfire_db* db;
+ struct pakfire_db* db = NULL;
+ int r = EXIT_FAILURE;
+
+ ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE));
- int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
- ASSERT(!r);
+ // Everything passed
+ r = EXIT_SUCCESS;
- pakfire_db_unref(db);
+FAIL:
+ if (db)
+ pakfire_db_unref(db);
- return 0;
+ return r;
}
static int test_check(const struct test* t) {
- struct pakfire_db* db;
+ struct pakfire_db* db = NULL;
+ int r = EXIT_FAILURE;
- int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
- ASSERT(!r);
+ ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE));
// Perform check
- ASSERT(!pakfire_db_check(db));
+ ASSERT_SUCCESS(pakfire_db_check(db));
+
+ // Everything passed
+ r = EXIT_SUCCESS;
- pakfire_db_unref(db);
+FAIL:
+ if (db)
+ pakfire_db_unref(db);
- return 0;
+ return r;
}
static int test_add_package(const struct test* t) {
- struct pakfire_db* db;
+ struct pakfire_db* db = NULL;
+ struct pakfire_repo* repo = NULL;
+ struct pakfire_archive* archive = NULL;
+ int r = EXIT_FAILURE;
- struct pakfire_repo* repo = pakfire_get_repo(t->pakfire, "@dummy");
- ASSERT(repo);
+ ASSERT(repo = pakfire_get_repo(t->pakfire, "@dummy"));
- int r = pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE);
- ASSERT(!r);
+ ASSERT_SUCCESS(pakfire_db_open(&db, t->pakfire, PAKFIRE_DB_READWRITE));
// There must be no packages installed
ssize_t packages = pakfire_db_packages(db);
const char* path = TEST_SRC_PATH "/data/beep-1.3-2.ip3.x86_64.pfm";
// Open archive
- struct pakfire_archive* archive;
ASSERT_SUCCESS(pakfire_archive_open(&archive, t->pakfire, path));
ASSERT(archive);
ASSERT(package);
// Try to add the package to the database
- r = pakfire_db_add_package(db, package, archive, 1);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_db_add_package(db, package, archive, 1));
// One package should be installed
- packages = pakfire_db_packages(db);
- ASSERT(packages == 1);
+ ASSERT(pakfire_db_packages(db) == 1);
// Remove the package again
- r = pakfire_db_remove_package(db, package);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_db_remove_package(db, package));
// No packages should be installed any more
- packages = pakfire_db_packages(db);
- ASSERT(packages == 0);
-
- // Cleanup
- pakfire_archive_unref(archive);
- pakfire_db_unref(db);
- pakfire_package_unref(package);
- pakfire_repo_unref(repo);
-
- return 0;
+ ASSERT(pakfire_db_packages(db) == 0);
+
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (archive)
+ pakfire_archive_unref(archive);
+ if (db)
+ pakfire_db_unref(db);
+ if (package)
+ pakfire_package_unref(package);
+ if (repo)
+ pakfire_repo_unref(repo);
+
+ return r;
}
int main(int argc, char** argv) {
#define DOWNLOAD_PATH TEST_ROOTFS "/downloaded.file"
static int test_simple(const struct test* t) {
- struct pakfire_downloader* d;
+ struct pakfire_downloader* d = NULL;
+ int r = EXIT_FAILURE;
// Create downloader
- int r = pakfire_downloader_create(&d, t->pakfire);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire));
// Retrieve a file
- r = pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
- PAKFIRE_DIGEST_NONE, NULL, 0, 0);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(
+ pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
+ PAKFIRE_DIGEST_NONE, NULL, 0, 0)
+ );
- // Cleanup
- pakfire_downloader_unref(d);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (d)
+ pakfire_downloader_unref(d);
+
+ return r;
}
static int test_retrieve_with_pending_transfers(const struct test* t) {
- struct pakfire_downloader* d;
+ struct pakfire_downloader* d = NULL;
+ int r = EXIT_FAILURE;
// Create downloader
- int r = pakfire_downloader_create(&d, t->pakfire);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire));
// Add a transfer
- r = pakfire_downloader_add_transfer(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
- PAKFIRE_DIGEST_NONE, NULL, 0, 0);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(
+ pakfire_downloader_add_transfer(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
+ PAKFIRE_DIGEST_NONE, NULL, 0, 0)
+ );
// Retrieve a file
- r = pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
- PAKFIRE_DIGEST_NONE, NULL, 0, 0);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(
+ pakfire_downloader_retrieve(d, NULL, NULL, NULL, DOWNLOAD_URL, DOWNLOAD_PATH,
+ PAKFIRE_DIGEST_NONE, NULL, 0, 0)
+ );
+
- // Cleanup
- pakfire_downloader_unref(d);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (d)
+ pakfire_downloader_unref(d);
+
+ return r;
}
static int test_retrieve_with_mirrors(const struct test* t) {
- struct pakfire_downloader* d;
- struct pakfire_mirrorlist* m;
+ struct pakfire_downloader* d = NULL;
+ struct pakfire_mirrorlist* m = NULL;
+ int r = EXIT_FAILURE;
// Create downloader
- int r = pakfire_downloader_create(&d, t->pakfire);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_downloader_create(&d, t->pakfire));
// Create mirrorlist
ASSERT_SUCCESS(pakfire_mirrorlist_create(&m, t->pakfire));
ASSERT_SUCCESS(pakfire_downloader_retrieve(d, NULL, m,
NULL, "beep-1.3-2.ip3.x86_64.pfm", DOWNLOAD_PATH, PAKFIRE_DIGEST_NONE, NULL, 0, 0));
- // Cleanup
- ASSERT_NULL(pakfire_mirrorlist_unref(m));
- ASSERT_NULL(pakfire_downloader_unref(d));
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (d)
+ pakfire_downloader_unref(d);
+ if (m)
+ pakfire_mirrorlist_unref(m);
- return 0;
+ return r;
}
int main(int argc, char** argv) {
};
static int test_does_not_exist(const struct test* t) {
- int r = pakfire_execute(t->pakfire, cmd, NULL, 0, NULL, NULL);
- ASSERT(r != 0);
+ ASSERT_FAILURE(pakfire_execute(t->pakfire, cmd, NULL, 0, NULL, NULL));
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
int main(int argc, char** argv) {
static int test_init(const struct test* t) {
struct pakfire_key** keys = NULL;
+ int r = EXIT_FAILURE;
// Try loading any keys & delete them all
ASSERT_SUCCESS(pakfire_list_keys(t->pakfire, &keys));
// Must be empty now
ASSERT(keys == NULL);
- return EXIT_SUCCESS;
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ return r;
}
static int test_import_export(const struct test* t) {
ASSERT_STRING_STARTSWITH(path, TEST_ROOTFS);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
int main(int argc, char** argv) {
ASSERT(r == 0);
for (unsigned int i = 0; i < buffer.gl_pathc; i++) {
- r = pakfire_parser_read_file(parser, buffer.gl_pathv[i], NULL);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(
+ pakfire_parser_read_file(parser, buffer.gl_pathv[i], NULL)
+ );
}
- return 0;
+ return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_parse(const struct test* t) {
+ struct pakfire_parser* parser = NULL;
const char** makefile = makefiles;
char path[PATH_MAX];
+ int r = EXIT_FAILURE;
while (*makefile) {
int r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, *makefile);
FILE* f = fopen(path, "r");
ASSERT(f);
- struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
+ parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
- r = pakfire_parser_read(parser, f, NULL);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_read(parser, f, NULL));
pakfire_parser_unref(parser);
+ parser = NULL;
fclose(f);
// Next file
makefile++;
}
- return EXIT_SUCCESS;
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (parser)
+ pakfire_parser_unref(parser);
+
+ return r;
}
static int test_macros(const struct test* t) {
+ int r = EXIT_FAILURE;
+
struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
ASSERT(parser);
// Load 'em all
- int r = load_macros(parser);
- if (r)
- return r;
+ ASSERT_SUCCESS(load_macros(parser));
- pakfire_parser_unref(parser);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (parser)
+ pakfire_parser_unref(parser);
+
+ return r;
}
static int test_packages(const struct test* t) {
+ struct pakfire_parser* parser = NULL;
struct pakfire_package* pkg = NULL;
struct pakfire_repo* repo = NULL;
+ int r = EXIT_FAILURE;
ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
ASSERT(repo);
- struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL,
+ parser = pakfire_parser_create(t->pakfire, NULL, NULL,
PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
ASSERT(parser);
pakfire_parser_set(parser, NULL, "DISTRO_ARCH", "x86_64", 0);
// Load macros
- int r = load_macros(parser);
- if (r)
- return r;
+ ASSERT_SUCCESS(load_macros(parser));
// Read beep.nm
const char* path = TEST_SRC_PATH "data/beep.nm";
- r = pakfire_parser_read_file(parser, path, NULL);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_read_file(parser, path, NULL));
// Create package
r = pakfire_parser_create_package(parser, &pkg, repo, NULL, NULL);
const char* name = pakfire_package_get_name(pkg);
ASSERT_STRING_EQUALS(name, "beep");
- // Cleanup
- pakfire_parser_unref(parser);
- pakfire_package_unref(pkg);
- pakfire_repo_unref(repo);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (parser)
+ pakfire_parser_unref(parser);
+ if (pkg)
+ pakfire_package_unref(pkg);
+ if (repo)
+ pakfire_repo_unref(repo);
+
+ return r;
}
int main(int argc, char** argv) {
#include "../testsuite.h"
static int test_create(const struct test* t) {
- struct pakfire_packager* packager;
+ struct pakfire_packager* packager = NULL;
+ struct pakfire_package* pkg = NULL;
struct pakfire_repo* repo = NULL;
+ int r = EXIT_FAILURE;
ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
ASSERT(repo);
- struct pakfire_package* pkg = pakfire_package_create(t->pakfire, repo,
+ pkg = pakfire_package_create(t->pakfire, repo,
"test", "1.0-1", "src");
ASSERT(pkg);
// Create packager
- int r = pakfire_packager_create(&packager, pkg);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_packager_create(&packager, pkg));
// Add a file to the package
const char* path = TEST_SRC_PATH "data/beep-1.3-2.ip3.x86_64.pfm";
- r = pakfire_packager_add(packager, path, NULL);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_packager_add(packager, path, NULL));
// Write archive
FILE* f = test_mktemp();
r = pakfire_packager_finish(packager, f);
ASSERT(r == 0);
- // Cleanup
- pakfire_packager_unref(packager);
- pakfire_package_unref(pkg);
- pakfire_repo_unref(repo);
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (packager)
+ pakfire_packager_unref(packager);
+ if (pkg)
+ pakfire_package_unref(pkg);
+ if (repo)
+ pakfire_repo_unref(repo);
return EXIT_SUCCESS;
}
#include "../testsuite.h"
static int test_parser(const struct test* t) {
+ struct pakfire_parser* subparser = NULL;
char* value = NULL;
+ int r = EXIT_FAILURE;
// Create a new parser
struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0);
ASSERT(!value);
// Set a value
- int r = pakfire_parser_set(parser, NULL, "a", "a", 0);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "a", "a", 0));
// Retrieve the value again
value = pakfire_parser_get(parser, NULL, "a");
ASSERT_STRING_EQUALS(value, "a");
// Append something to the value
- r = pakfire_parser_append(parser, NULL, "a", "b");
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_append(parser, NULL, "a", "b"));
// Retrieve the value again
value = pakfire_parser_get(parser, NULL, "a");
ASSERT_STRING_EQUALS(value, "a b");
// Make a child parser
- struct pakfire_parser* subparser = pakfire_parser_create_child(parser, "child");
+ subparser = pakfire_parser_create_child(parser, "child");
ASSERT(subparser);
// Try to get a again
ASSERT_STRING_EQUALS(value, "a b");
// Append something to the subparser
- r = pakfire_parser_append(subparser, NULL, "a", "c");
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_append(subparser, NULL, "a", "c"));
// The subparser should return "a b c"
value = pakfire_parser_get(subparser, NULL, "a");
ASSERT_STRING_EQUALS(value, "a b");
// Set another value
- r = pakfire_parser_append(subparser, NULL, "b", "1");
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_append(subparser, NULL, "b", "1"));
// Merge the two parsers
pakfire_parser_merge(parser, subparser);
// Set a variable
- r = pakfire_parser_set(parser, NULL, "c", "%{b}", 0);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "c", "%{b}", 0));
// Get the value of c
value = pakfire_parser_get(parser, NULL, "c");
char* s = pakfire_parser_dump(parser);
printf("%s\n", s);
- // Cleanup
- pakfire_parser_unref(subparser);
- pakfire_parser_unref(parser);
- free(value);
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (subparser)
+ pakfire_parser_unref(subparser);
+ if (parser)
+ pakfire_parser_unref(parser);
+ if (value)
+ free(value);
+
+ return r;
}
static const char* files[] = {
static int test_parser_files(const struct test* t) {
const char** file = files;
char path[PATH_MAX];
+ int r = EXIT_FAILURE;
while (*file) {
int r = snprintf(path, sizeof(path) - 1, "%s/%s", TEST_SRC_PATH, *file);
file++;
}
- return EXIT_SUCCESS;
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ return r;
}
static int test_parser_command(const struct test* t) {
const char* command = "%(echo \"ABC\")";
+ struct pakfire_parser* parser = NULL;
+ int r = EXIT_FAILURE;
- struct pakfire_parser* parser = pakfire_parser_create(t->pakfire, NULL, NULL,
+ parser = pakfire_parser_create(t->pakfire, NULL, NULL,
PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS);
ASSERT(parser);
- ASSERT(pakfire_parser_set(parser, NULL, "command", command, 0) == 0);
+ ASSERT_SUCCESS(pakfire_parser_set(parser, NULL, "command", command, 0));
// Retrieve the expanded value
char* value = pakfire_parser_get(parser, NULL, "command");
ASSERT_STRING_EQUALS(value, "ABC");
- pakfire_parser_unref(parser);
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (parser)
+ pakfire_parser_unref(parser);
- return EXIT_SUCCESS;
+ return r;
}
int main(int argc, char** argv) {
#include "../testsuite.h"
static int test_run(const struct test* t) {
- struct pakfire_progressbar* p;
+ struct pakfire_progressbar* p = NULL;
+ int r = EXIT_FAILURE;
ASSERT_SUCCESS(pakfire_progressbar_create(&p, NULL));
ASSERT_SUCCESS(pakfire_progressbar_finish(p));
- ASSERT_NULL(pakfire_progressbar_unref(p));
+ // Everything passed
+ r = EXIT_SUCCESS;
- return EXIT_SUCCESS;
+FAIL:
+ if (p)
+ pakfire_progressbar_unref(p);
+
+ return r;
}
int main(int argc, char** argv) {
#include "../testsuite.h"
static int test_scan(const struct test* t) {
+ struct pakfire_repo* repo = NULL;
char baseurl[1024];
- snprintf(baseurl, sizeof(baseurl) - 1, "file://%s/data", TEST_SRC_PATH);
+ int r = EXIT_FAILURE;
- struct pakfire_repo* repo = NULL;
+ pakfire_string_format(baseurl, "file://%s/data", TEST_SRC_PATH);
ASSERT_SUCCESS(pakfire_repo_create(&repo, t->pakfire, "test"));
ASSERT(repo);
- pakfire_repo_set_baseurl(repo, baseurl);
+ ASSERT_SUCCESS(pakfire_repo_set_baseurl(repo, baseurl));
- int r = pakfire_repo_scan(repo, 0);
- ASSERT(r == 0);
+ ASSERT_SUCCESS(pakfire_repo_scan(repo, 0));
// There should be one package in this repository now
ASSERT(pakfire_repo_count(repo) == 1);
- pakfire_repo_unref(repo);
+ // Everything passed
+ r = EXIT_SUCCESS;
+
+FAIL:
+ if (repo)
+ pakfire_repo_unref(repo);
- return 0;
+ return r;
}
int main(int argc, char** argv) {
free(output);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_dirname(const struct test* t) {
free(output);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_string_startswith(const struct test* t) {
- int r;
-
- r = pakfire_string_startswith("ABC", "A");
- ASSERT(r);
-
- r = pakfire_string_startswith("ABC", "B");
- ASSERT(!r);
+ ASSERT_SUCCESS(pakfire_string_startswith("ABC", "A"));
+ ASSERT_FAILURE(pakfire_string_startswith("ABC", "B"));
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_string_partition(const struct test* t) {
free(part2);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_string_replace(const struct test* t) {
ASSERT_STRING_EQUALS(result, "CCCCCCCCCCCC");
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
static int test_string_split(const struct test* t) {
ASSERT_NULL(result[4]);
return EXIT_SUCCESS;
+
+FAIL:
+ return EXIT_FAILURE;
}
int main(int argc, char** argv) {
exit(1);
}
- ASSERT(t->pakfire);
-
// Enable debug logging
pakfire_log_set_priority(t->pakfire, LOG_DEBUG);
if ((!(expr))) { \
LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if (!((expr) == NULL)) { \
LOG_ERROR("Failed assertion: " #expr " == NULL %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if ((expr)) { \
LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if ((expr) > 0) { \
LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if (!(expr)) { \
LOG_ERROR("Failed assertion: " #expr " unexpectedly didn't fail in %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
if (errno != e) { \
LOG_ERROR("Failed assertion: " #expr " failed with (%d - %s) " \
"but was expected to fail with (%d - %s) in %s:%d\n", \
errno, strerror(errno), e, strerror(e), __FILE__, __LINE__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if (strcmp(string, value) != 0) { \
LOG_ERROR("Failed assertion: " #value " (%s) != " #string " %s:%d %s\n", \
value, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if (strcmp(value1, value2) == 0) { \
LOG_ERROR("Failed assertion: " #value1 " (%s) != " #value2 " (%s) %s:%d %s\n", \
value1, value2, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)
if (strncmp(string, start, strlen(start)) != 0) { \
LOG_ERROR("Failed assertion: " #string " does not start with " #start " %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return EXIT_FAILURE; \
+ goto FAIL; \
} \
} while (0)