dcavalca / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

Blame SOURCES/0030-Update-unittest-to-test-the-new-private-dnf-solvfile.patch

1a8671
From 1e0f8f66f6ff30e177c41be7d72330d5eccf2ff8 Mon Sep 17 00:00:00 2001
1a8671
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
1a8671
Date: Wed, 9 Feb 2022 13:24:06 +0100
1a8671
Subject: [PATCH 30/34] Update unittest to test the new private dnf solvfile
1a8671
 API
1a8671
1a8671
---
1a8671
 tests/hawkey/test_iutil.cpp | 34 ++++++++++++++++++++++------------
1a8671
 1 file changed, 22 insertions(+), 12 deletions(-)
1a8671
1a8671
diff --git a/tests/hawkey/test_iutil.cpp b/tests/hawkey/test_iutil.cpp
1a8671
index 8d00cc94..f3c04782 100644
1a8671
--- a/tests/hawkey/test_iutil.cpp
1a8671
+++ b/tests/hawkey/test_iutil.cpp
1a8671
@@ -24,6 +24,8 @@
1a8671
 
1a8671
 
1a8671
 #include <solv/pool.h>
1a8671
+#include <solv/repo.h>
1a8671
+#include <solv/repo_write.h>
1a8671
 
1a8671
 
1a8671
 #include "libdnf/hy-util.h"
1a8671
@@ -97,28 +99,36 @@ START_TEST(test_checksum)
1a8671
 }
1a8671
 END_TEST
1a8671
 
1a8671
-START_TEST(test_checksum_write_read)
1a8671
+START_TEST(test_dnf_solvfile_userdata)
1a8671
 {
1a8671
     char *new_file = solv_dupjoin(test_globals.tmpdir,
1a8671
-                                  "/test_checksum_write_read", NULL);
1a8671
+                                  "/test_dnf_solvfile_userdata", NULL);
1a8671
     build_test_file(new_file);
1a8671
 
1a8671
     unsigned char cs_computed[CHKSUM_BYTES];
1a8671
-    unsigned char cs_read[CHKSUM_BYTES];
1a8671
-    FILE *fp = fopen(new_file, "r");
1a8671
+    FILE *fp = fopen(new_file, "r+");
1a8671
     checksum_fp(cs_computed, fp);
1a8671
-    // fails, file opened read-only:
1a8671
-    fail_unless(checksum_write(cs_computed, fp) == 1);
1a8671
-    fclose(fp);
1a8671
-    fp = fopen(new_file, "r+");
1a8671
-    fail_if(checksum_write(cs_computed, fp));
1a8671
+
1a8671
+    SolvUserdata solv_userdata;
1a8671
+    fail_if(solv_userdata_fill(&solv_userdata, cs_computed, NULL));
1a8671
+
1a8671
+    Pool *pool = pool_create();
1a8671
+    Repo *repo = repo_create(pool, "test_repo");
1a8671
+    Repowriter *writer = repowriter_create(repo);
1a8671
+    repowriter_set_userdata(writer, &solv_userdata, solv_userdata_size);
1a8671
+    fail_if(repowriter_write(writer, fp));
1a8671
+    repowriter_free(writer);
1a8671
     fclose(fp);
1a8671
+
1a8671
     fp = fopen(new_file, "r");
1a8671
-    fail_if(checksum_read(cs_read, fp));
1a8671
-    fail_if(checksum_cmp(cs_computed, cs_read));
1a8671
+    std::unique_ptr<SolvUserdata> dnf_solvfile = solv_userdata_read(fp);
1a8671
+    fail_unless(dnf_solvfile);
1a8671
+    fail_unless(solv_userdata_verify(dnf_solvfile.get(), cs_computed));
1a8671
     fclose(fp);
1a8671
 
1a8671
     g_free(new_file);
1a8671
+    repo_free(repo, 0);
1a8671
+    pool_free(pool);
1a8671
 }
1a8671
 END_TEST
1a8671
 
1a8671
@@ -181,7 +191,7 @@ iutil_suite(void)
1a8671
     TCase *tc = tcase_create("Main");
1a8671
     tcase_add_test(tc, test_abspath);
1a8671
     tcase_add_test(tc, test_checksum);
1a8671
-    tcase_add_test(tc, test_checksum_write_read);
1a8671
+    tcase_add_test(tc, test_dnf_solvfile_userdata);
1a8671
     tcase_add_test(tc, test_mkcachedir);
1a8671
     tcase_add_test(tc, test_version_split);
1a8671
     suite_add_tcase(s, tc);
1a8671
-- 
1a8671
2.31.1
1a8671