This reduces the amount of code that is to be written for each test.
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
$(TESTSUITE_CPPFLAGS) \
-DABS_TOP_BUILDDIR=\"$(abs_top_builddir)\"
-EXTRA_DIST += \
- tests/libpakfire/pakfire.h
-
TESTSUITE_CPPFLAGS = \
$(AM_CPPFLAGS) \
$(PAKFIRE_CPPFLAGS)
#include "../testsuite.h"
#include "key.h"
-#include "pakfire.h"
int test_init(const test_t* t) {
- Pakfire pakfire = init_pakfire();
- if (!pakfire)
- return EXIT_FAILURE;
-
// Try loading any keys & delete them all
- PakfireKey* keys = pakfire_key_list(pakfire);
+ PakfireKey* keys = pakfire_key_list(t->pakfire);
while (keys && *keys) {
PakfireKey key = *keys++;
}
// Load list of keys again
- keys = pakfire_key_list(pakfire);
+ keys = pakfire_key_list(t->pakfire);
// Must be empty now
assert_return(keys == NULL, EXIT_FAILURE);
}
int test_import(const test_t* t) {
- Pakfire pakfire = init_pakfire();
- if (!pakfire)
- return EXIT_FAILURE;
-
// Try to delete the key just in case it
// has been imported before
- PakfireKey key = pakfire_key_get(pakfire, TEST_KEY_FINGERPRINT);
+ PakfireKey key = pakfire_key_get(t->pakfire, TEST_KEY_FINGERPRINT);
if (key) {
pakfire_key_delete(key);
pakfire_key_unref(key);
}
// Import a key
- PakfireKey* keys = pakfire_key_import(pakfire, TEST_KEY_DATA);
+ 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);
const char* fingerprint = pakfire_key_get_fingerprint(key);
assert_return(strcmp(fingerprint, TEST_KEY_FINGERPRINT) == 0, EXIT_FAILURE);
- pakfire_unref(pakfire);
-
return EXIT_SUCCESS;
}
int test_export(const test_t* t) {
- Pakfire pakfire = init_pakfire();
- if (!pakfire)
- return EXIT_FAILURE;
-
- PakfireKey key = pakfire_key_get(pakfire, TEST_KEY_FINGERPRINT);
+ PakfireKey key = pakfire_key_get(t->pakfire, TEST_KEY_FINGERPRINT);
assert_return(key, EXIT_FAILURE);
char* data = pakfire_key_export(key, 0);
assert_return(data, EXIT_FAILURE);
- pakfire_free(data);
- pakfire_unref(pakfire);
+ LOG("Exported key:\n%s\n", data);
+
+ pakfire_free(data);
return EXIT_SUCCESS;
}
#include "../testsuite.h"
-#include "pakfire.h"
-
static int test_init(const test_t* t) {
- Pakfire pakfire = init_pakfire();
- if (!pakfire)
- return EXIT_FAILURE;
-
- LOG("Allocated at %p\n", pakfire);
-
- pakfire_unref(pakfire);
+ LOG("Allocated at %p\n", t->pakfire);
return EXIT_SUCCESS;
}
static int test_path(const test_t* t) {
- Pakfire pakfire = init_pakfire();
- if (!pakfire)
- return EXIT_FAILURE;
-
- const char* path = pakfire_get_path(pakfire);
+ const char* path = pakfire_get_path(t->pakfire);
assert_return(strcmp(path, TEST_PATH) == 0, EXIT_FAILURE);
- pakfire_unref(pakfire);
-
return EXIT_SUCCESS;
}
+++ /dev/null
-/*#############################################################################
-# #
-# Pakfire - The IPFire package management system #
-# Copyright (C) 2017 Pakfire development team #
-# #
-# This program is free software: you can redistribute it and/or modify #
-# it under the terms of the GNU General Public License as published by #
-# the Free Software Foundation, either version 3 of the License, or #
-# (at your option) any later version. #
-# #
-# This program is distributed in the hope that it will be useful, #
-# but WITHOUT ANY WARRANTY; without even the implied warranty of #
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
-# GNU General Public License for more details. #
-# #
-# You should have received a copy of the GNU General Public License #
-# along with this program. If not, see <http://www.gnu.org/licenses/>. #
-# #
-#############################################################################*/
-
-#include <pakfire/pakfire.h>
-
-#include "../testsuite.h"
-
-static Pakfire init_pakfire() {
- const char* path = TEST_PATH;
-
- return pakfire_create(path, NULL);
-}
return 0;
}
-static int test_run(const test_t* t) {
+static int test_run(test_t* t) {
LOG("running %s\n", t->name);
+ t->pakfire = pakfire_create(TEST_PATH, NULL);
+ assert_return(t->pakfire, EXIT_FAILURE);
+
int r = t->func(t);
if (r)
LOG("Test failed with error code: %d\n", r);
+ // Release pakfire
+ pakfire_unref(t->pakfire);
+
return r;
}
#include <stdlib.h>
#include <stdio.h>
+#include <pakfire/pakfire.h>
+
extern const char* TEST_PATH;
// Forward declaration
typedef struct test {
const char* name;
test_function_t func;
+ Pakfire pakfire;
} test_t;
typedef struct testsuite {