static int test_native(const struct test* t) {
// First call
const char* arch1 = pakfire_arch_native();
- assert_return(arch1, EXIT_FAILURE);
+ ASSERT(arch1);
// Second call
const char* arch2 = pakfire_arch_native();
- assert_return(arch2, EXIT_FAILURE);
+ ASSERT(arch2);
// Must be the same pointer
- assert_return(arch1 == arch2, EXIT_FAILURE);
+ ASSERT(arch1 == arch2);
return EXIT_SUCCESS;
}
int r;
r = pakfire_arch_supported("x86_64");
- assert_return(r, EXIT_FAILURE);
+ ASSERT(r);
r = pakfire_arch_supported("i686");
- assert_return(r, EXIT_FAILURE);
+ ASSERT(r);
// Check non-existant architecture
r = pakfire_arch_supported("ABC");
- assert_return(!r, EXIT_FAILURE);
+ ASSERT(!r);
return EXIT_SUCCESS;
}
// x86_64 can build i686
r = pakfire_arch_is_compatible("x86_64", "i686");
- assert_return(r, EXIT_FAILURE);
+ ASSERT(r);
// i686 can NOT build i686
r = pakfire_arch_is_compatible("i686", "x86_64");
- assert_return(!r, EXIT_FAILURE);
+ ASSERT(!r);
// x86_64 can build itself
r = pakfire_arch_is_compatible("x86_64", "x86_64");
- assert_return(r, EXIT_FAILURE);
+ ASSERT(r);
// x86_64 can NOT build a non-existant architecture
r = pakfire_arch_is_compatible("x86_64", "ABC");
- assert_return(!r, EXIT_FAILURE);
+ ASSERT(!r);
// A non-existant architecture cannot build anything
r = pakfire_arch_is_compatible("ABC", "x86_64");
- assert_return(!r, EXIT_FAILURE);
+ ASSERT(!r);
return EXIT_SUCCESS;
}
char* machine;
machine = pakfire_arch_machine("x86_64", "ipfire");
- assert_compare(machine, "x86_64-ipfire-linux-gnu", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(machine, "x86_64-ipfire-linux-gnu");
machine = pakfire_arch_machine("x86_64", "IPFIRE");
- assert_compare(machine, "x86_64-ipfire-linux-gnu", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(machine, "x86_64-ipfire-linux-gnu");
return EXIT_SUCCESS;
}
// Open the archive
PakfireArchive archive = pakfire_archive_open(t->pakfire, path);
- assert_return(archive, EXIT_FAILURE);
+ ASSERT(archive);
// Verify the archive
pakfire_archive_verify_status_t verify = pakfire_archive_verify(archive);
- assert_return(verify == PAKFIRE_ARCHIVE_VERIFY_OK, EXIT_FAILURE);
+ ASSERT(verify == PAKFIRE_ARCHIVE_VERIFY_OK);
pakfire_archive_unref(archive);
pakfire_free(path);
// Extract the archive payload
int r = pakfire_archive_extract(archive, NULL, PAKFIRE_ARCHIVE_USE_PAYLOAD);
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// Check if test file from the archive exists
- assert_return(pakfire_access(t->pakfire, pakfire_get_path(t->pakfire),
- TEST_PKG1_FILE, F_OK) == 0, EXIT_FAILURE);
+ ASSERT(pakfire_access(t->pakfire, pakfire_get_path(t->pakfire),
+ TEST_PKG1_FILE, F_OK) == 0);
pakfire_archive_unref(archive);
pakfire_free(path);
PakfireRepo repo = pakfire_repo_create(t->pakfire, "tmp");
- assert_return(repo, EXIT_FAILURE);
+ ASSERT(repo);
PakfirePackage pkg = pakfire_repo_add_archive(repo, archive);
- assert_return(pkg, EXIT_FAILURE);
+ ASSERT(pkg);
pakfire_repo_unref(repo);
pakfire_package_unref(pkg);
const char* cmd = "/usr/bin/does-not-exist";
int r = pakfire_execute(t->pakfire, cmd, NULL, NULL, 0);
- assert_return(r != 0, EXIT_FAILURE);
+ ASSERT(r != 0);
return EXIT_SUCCESS;
}
keys = pakfire_key_list(t->pakfire);
// Must be empty now
- assert_return(keys == NULL, EXIT_FAILURE);
+ ASSERT(keys == NULL);
return EXIT_SUCCESS;
}
PakfireKey* keys = pakfire_key_import(t->pakfire, TEST_KEY_DATA);
// We should have a list with precisely one key object
- assert_return(keys, EXIT_FAILURE);
- assert_return(keys[0] != NULL, EXIT_FAILURE);
- assert_return(keys[1] == NULL, EXIT_FAILURE);
+ ASSERT(keys);
+ ASSERT(keys[0] != NULL);
+ ASSERT(keys[1] == NULL);
// Get the imported key
key = *keys;
// Check the fingerprint
const char* fingerprint = pakfire_key_get_fingerprint(key);
- assert_return(strcmp(fingerprint, TEST_KEY_FINGERPRINT) == 0, EXIT_FAILURE);
+ ASSERT(strcmp(fingerprint, TEST_KEY_FINGERPRINT) == 0);
pakfire_key_unref(key);
static int test_export(const struct test* t) {
PakfireKey key = pakfire_key_get(t->pakfire, TEST_KEY_FINGERPRINT);
- assert_return(key, EXIT_FAILURE);
+ ASSERT(key);
// Dump key description
char* dump = pakfire_key_dump(key);
- assert_return(dump, EXIT_FAILURE);
+ ASSERT(dump);
LOG("%s\n", dump);
pakfire_free(dump);
char* data = pakfire_key_export(key, 0);
- assert_return(data, EXIT_FAILURE);
+ ASSERT(data);
LOG("Exported key:\n%s\n", data);
pakfire_free(data);
# #
#############################################################################*/
-#include <string.h>
-
#include <pakfire/pakfire.h>
#include "../testsuite.h"
static int test_path(const struct test* t) {
const char* path = pakfire_get_path(t->pakfire);
- assert_return(strcmp(path, TEST_ROOTFS) == 0, EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(path, TEST_ROOTFS);
return EXIT_SUCCESS;
}
// Open file
FILE* f = fopen(path, "r");
- assert_return(f, EXIT_FAILURE);
+ ASSERT(f);
PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL);
int r = pakfire_parser_read(parser, f);
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// Try to retrieve some value
char* value = pakfire_parser_get(parser, "sources");
- assert_return(value, EXIT_FAILURE);
+ ASSERT(value);
printf("VALUE: sources = %s\n", value);
pakfire_free(value);
// Retrieve a value that does not exist
value = pakfire_parser_get(parser, "null");
- assert_return(!value, EXIT_FAILURE);
+ ASSERT(!value);
// Set a value
int r = pakfire_parser_set(parser, "a", "a");
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// Retrieve the value again
value = pakfire_parser_get(parser, "a");
- assert_compare(value, "a", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "a");
// Append something to the value
r = pakfire_parser_append(parser, "a", "b");
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// Retrieve the value again
value = pakfire_parser_get(parser, "a");
- assert_compare(value, "a b", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "a b");
// Make a child parser
PakfireParser subparser = pakfire_parser_create_child(parser, "child");
- assert_return(subparser, EXIT_FAILURE);
+ ASSERT(subparser);
// Try to get a again
value = pakfire_parser_get(subparser, "a");
- assert_compare(value, "a b", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "a b");
// Append something to the subparser
r = pakfire_parser_append(subparser, "a", "c");
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// The subparser should return "a b c"
value = pakfire_parser_get(subparser, "a");
- assert_compare(value, "a b c", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "a b c");
// The original parser should remain unchanged
value = pakfire_parser_get(parser, "a");
- assert_compare(value, "a b", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "a b");
// Set another value
r = pakfire_parser_append(subparser, "b", "1");
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// Merge the two parsers
pakfire_parser_merge(parser, subparser);
// Now a should have changed to "a b c"
value = pakfire_parser_get(parser, "a");
- assert_compare(value, "a b c", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "a b c");
// Set a variable
r = pakfire_parser_set(parser, "c", "%{b}");
- assert_return(r == 0, EXIT_FAILURE);
+ ASSERT(r == 0);
// Get the value of c
value = pakfire_parser_get(parser, "c");
- assert_compare(value, "1", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(value, "1");
// Dump the parser
char* s = pakfire_parser_dump(parser);
const char* dir = "/a/b/c";
char* output = pakfire_basename(dir);
- assert_compare(output, "c", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(output, "c");
pakfire_free(output);
return EXIT_SUCCESS;
const char* dir = "/a/b/c";
char* output = pakfire_dirname(dir);
- assert_compare(output, "/a/b", EXIT_FAILURE);
+ ASSERT_STRING_EQUALS(output, "/a/b");
pakfire_free(output);
return EXIT_SUCCESS;
int r;
r = pakfire_string_startswith("ABC", "A");
- assert_return(r, EXIT_FAILURE);
+ ASSERT(r);
r = pakfire_string_startswith("ABC", "B");
- assert_return(!r, EXIT_FAILURE);
+ ASSERT(!r);
return EXIT_SUCCESS;
}
LOG("running %s\n", t->name);
t->pakfire = pakfire_create(TEST_ROOTFS, NULL);
- assert_return(t->pakfire, EXIT_FAILURE);
+ ASSERT(t->pakfire);
// Log to stderr
pakfire_log_set_function(t->pakfire, pakfire_log_stderr);
#define testsuite_add_test(func) __testsuite_add_test(#func, func)
-#define assert_return(expr, r) \
+#define ASSERT(expr) \
do { \
if ((!(expr))) { \
LOG_ERROR("Failed assertion: " #expr " %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return r; \
+ return EXIT_FAILURE; \
} \
} while (0)
-#define assert_compare(string, value, r) \
+#define ASSERT_STRING_EQUALS(string, value) \
do { \
if (strcmp(string, value) != 0) { \
LOG_ERROR("Failed assertion: " #string " != " #value " %s:%d %s\n", \
__FILE__, __LINE__, __PRETTY_FUNCTION__); \
- return r; \
+ return EXIT_FAILURE; \
} \
} while (0)