xml_parser_repomd: More tests
authorTomas Mlcoch <tmlcoch@redhat.com>
Mon, 3 Jun 2013 07:36:41 +0000 (09:36 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Mon, 3 Jun 2013 07:55:12 +0000 (09:55 +0200)
tests/fixtures.h
tests/test_xml_parser_repomd.c
tests/testdata/modified_repo_files/missing_type-repomd.xml [new file with mode: 0644]

index 40c6193..02b46cd 100644 (file)
@@ -54,6 +54,7 @@
 #define TEST_MRF_BAD_TYPE_FIL   TEST_MODIFIED_REPO_FILES_PATH"bad_file_type-filelists.xml"
 #define TEST_MRF_NO_PKGID_FIL   TEST_MODIFIED_REPO_FILES_PATH"no_pkgid-filelists.xml"
 #define TEST_MRF_NO_PKGID_OTH   TEST_MODIFIED_REPO_FILES_PATH"no_pkgid-other.xml"
+#define TEST_MRF_MISSING_TYPE_REPOMD TEST_MODIFIED_REPO_FILES_PATH"missing_type-repomd.xml"
 #define TEST_MRF_UE_PRI_00      TEST_MODIFIED_REPO_FILES_PATH"unknown_element_00-primary.xml"
 #define TEST_MRF_UE_PRI_01      TEST_MODIFIED_REPO_FILES_PATH"unknown_element_01-primary.xml"
 #define TEST_MRF_UE_PRI_02      TEST_MODIFIED_REPO_FILES_PATH"unknown_element_02-primary.xml"
index bb54583..6cd1346 100644 (file)
@@ -82,6 +82,57 @@ test_cr_xml_parse_repomd_00(void)
     cr_repomd_free(repomd);
 }
 
+static void
+test_cr_xml_parse_repomd_01(void)
+{
+    GError *tmp_err = NULL;
+    cr_Repomd *repomd = cr_repomd_new();
+
+    int ret = cr_xml_parse_repomd(TEST_REPO_01_REPOMD, repomd,
+                                  NULL, NULL, &tmp_err);
+    g_assert(tmp_err == NULL);
+    g_assert_cmpint(ret, ==, CRE_OK);
+
+    cr_repomd_free(repomd);
+}
+
+static void
+test_cr_xml_parse_repomd_02(void)
+{
+    GError *tmp_err = NULL;
+    char *warnmsgs;
+    cr_Repomd *repomd = cr_repomd_new();
+    GString *warn_strings = g_string_new(0);
+
+    int ret = cr_xml_parse_repomd(TEST_REPO_02_REPOMD, repomd,
+                                  warningcb, warn_strings, &tmp_err);
+    g_assert(tmp_err == NULL);
+    g_assert_cmpint(ret, ==, CRE_OK);
+
+    cr_repomd_free(repomd);
+
+    warnmsgs = g_string_free(warn_strings, FALSE);
+    g_assert_cmpstr(warnmsgs, ==, "");
+    g_free(warnmsgs);
+}
+
+static void
+test_cr_xml_parse_repomd_warningcb_interrupt(void)
+{
+    int numofwarnings = 0;
+    GError *tmp_err = NULL;
+    cr_Repomd *repomd = cr_repomd_new();
+
+    int ret = cr_xml_parse_repomd(TEST_MRF_MISSING_TYPE_REPOMD, repomd,
+                                  warningcb_interrupt,
+                                  &numofwarnings, &tmp_err);
+    g_assert(tmp_err != NULL);
+    g_error_free(tmp_err);
+    g_assert_cmpint(ret, ==, CRE_CBINTERRUPTED);
+    g_assert_cmpint(numofwarnings, ==, 1);
+    cr_repomd_free(repomd);
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -89,6 +140,12 @@ main(int argc, char *argv[])
 
     g_test_add_func("/xml_parser_filelists/test_cr_xml_parse_repomd_00",
                     test_cr_xml_parse_repomd_00);
+    g_test_add_func("/xml_parser_filelists/test_cr_xml_parse_repomd_01",
+                    test_cr_xml_parse_repomd_01);
+    g_test_add_func("/xml_parser_filelists/test_cr_xml_parse_repomd_02",
+                    test_cr_xml_parse_repomd_02);
+    g_test_add_func("/xml_parser_filelists/test_cr_xml_parse_repomd_warningcb_interrupt",
+                    test_cr_xml_parse_repomd_warningcb_interrupt);
 
     return g_test_run();
 }
diff --git a/tests/testdata/modified_repo_files/missing_type-repomd.xml b/tests/testdata/modified_repo_files/missing_type-repomd.xml
new file mode 100644 (file)
index 0000000..4862416
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<repomd xmlns="http://linux.duke.edu/metadata/repo" xmlns:rpm="http://linux.duke.edu/metadata/rpm">
+ <revision>1334667230</revision>
+<data type="filelists">
+  <checksum type="sha256">c7db035d0e6f1b2e883a7fa3229e2d2be70c05a8b8d2b57dbb5f9c1a67483b6c</checksum>
+  <open-checksum type="sha256">85bc611be5d81ac8da2fe01e98ef741d243d1518fcc46ada70660020803fbf09</open-checksum>
+  <location href="repodata/c7db035d0e6f1b2e883a7fa3229e2d2be70c05a8b8d2b57dbb5f9c1a67483b6c-filelists.xml.gz"/>
+  <timestamp>1334667230</timestamp>
+  <size>273</size>
+  <open-size>389</open-size>
+</data>
+<data> <!-- WARNING: Missing data element type -->
+  <checksum type="sha256">b752a73d9efd4006d740f943db5fb7c2dd77a8324bd99da92e86bd55a2c126ef</checksum>
+  <open-checksum type="sha256">da6096c924349af0c326224a33be0cdb26897fbe3d25477ac217261652449445</open-checksum>
+  <location href="repodata/b752a73d9efd4006d740f943db5fb7c2dd77a8324bd99da92e86bd55a2c126ef-other.xml.gz"/>
+  <timestamp>1334667230</timestamp>
+  <size>332</size>
+  <open-size>530</open-size>
+</data>
+<data type="primary">
+  <checksum type="sha256">6c662d665c24de9a0f62c17d8fa50622307739d7376f0d19097ca96c6d7f5e3e</checksum>
+  <open-checksum type="sha256">0fc6cadf97d515e87491d24dc9712d8ddaf2226a21ae7f131ff42d71a877c496</open-checksum>
+  <location href="repodata/6c662d665c24de9a0f62c17d8fa50622307739d7376f0d19097ca96c6d7f5e3e-primary.xml.gz"/>
+  <timestamp>1334667230</timestamp>
+  <size>782</size>
+  <open-size>2085</open-size>
+</data>
+</repomd>