]> git.ipfire.org Git - pakfire.git/commitdiff
testsuite: Add tests to verify imported key and export a key
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Nov 2017 11:59:07 +0000 (12:59 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 30 Nov 2017 11:59:07 +0000 (12:59 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
tests/libpakfire/key.c

index 2747965944907068b202da9330a49490edfaf42c..6ee8ef3dfccc3a03b3cd3fb9bce7ed0bb7962c5a 100644 (file)
 #                                                                             #
 #############################################################################*/
 
-#include "../testsuite.h"
+#include <string.h>
 
 #include <pakfire/key.h>
+#include <pakfire/util.h>
 
+#include "../testsuite.h"
 #include "key.h"
 #include "pakfire.h"
 
@@ -69,16 +71,43 @@ int test_import(const test_t* t) {
        assert_return(keys[0] != NULL, EXIT_FAILURE);
        assert_return(keys[1] == NULL, EXIT_FAILURE);
 
+       // 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);
+
+       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);
+       assert_return(key, EXIT_FAILURE);
+
+       char* data = pakfire_key_export(key, 0);
+       assert_return(data, EXIT_FAILURE);
+       pakfire_free(data);
+
+       pakfire_unref(pakfire);
+
        return EXIT_SUCCESS;
 }
 
 int main(int argc, char** argv) {
        testsuite_init();
 
-       testsuite_t* ts = testsuite_create(2);
+       testsuite_t* ts = testsuite_create(3);
 
        testsuite_add_test(ts, "test_init", test_init);
        testsuite_add_test(ts, "test_import", test_import);
+       testsuite_add_test(ts, "test_export", test_export);
 
        return testsuite_run(ts);
 }