dcavalca / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

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

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