Fix few compiler warnings + test for xml_parser_repomd
authorTomas Mlcoch <tmlcoch@redhat.com>
Mon, 3 Jun 2013 07:21:38 +0000 (09:21 +0200)
committerTomas Mlcoch <tmlcoch@redhat.com>
Mon, 3 Jun 2013 07:22:00 +0000 (09:22 +0200)
src/checksum.c
src/checksum.h
src/xml_parser_repomd.c
tests/CMakeLists.txt
tests/fixtures.h
tests/test_xml_parser_repomd.c [new file with mode: 0644]

index 925d4b8..ab51234 100644 (file)
@@ -53,9 +53,10 @@ cr_checksum_type(const char *name)
 
     if (!strncmp(name_lower, "md", 2)) {
         // MD* family
-        if (name_lower[2] == '2')
-            return CR_CHECKSUM_MD2;
-        else if (name_lower[2] == '5')
+//        if (name_lower[2] == '2')
+//            return CR_CHECKSUM_MD2;
+//        else if (name_lower[2] == '5')
+        if (name_lower[2] == '5')
             return CR_CHECKSUM_MD5;
     } else if (!strncmp(name_lower, "sha", 3)) {
         // SHA* family
@@ -99,8 +100,9 @@ cr_checksum_name_str(cr_ChecksumType type)
         return "sha384";
     case CR_CHECKSUM_SHA512:
         return "sha512";
+    default:
+        return NULL;
     }
-    return NULL;
 }
 
 char *
@@ -178,7 +180,6 @@ cr_checksum_file(const char *filename,
 cr_ChecksumCtx *
 cr_checksum_new(cr_ChecksumType type, GError **err)
 {
-    int rc;
     EVP_MD_CTX *ctx;
     const EVP_MD *ctx_type;
     cr_ChecksumCtx *cr_ctx;
index 4916372..fc160ff 100644 (file)
@@ -36,7 +36,7 @@ typedef struct _cr_ChecksumCtx cr_ChecksumCtx;
  */
 typedef enum {
     CR_CHECKSUM_UNKNOWN,    /*!< Unknown checksum */
-    CR_CHECKSUM_MD2,        /*!< MD2 checksum */
+//    CR_CHECKSUM_MD2,        /*!< MD2 checksum */
     CR_CHECKSUM_MD5,        /*!< MD5 checksum */
     CR_CHECKSUM_SHA,        /*!< SHA checksum */
     CR_CHECKSUM_SHA1,       /*!< SHA1 checksum */
index 61a2f87..12d5e2d 100644 (file)
@@ -84,7 +84,6 @@ static cr_StatesSwitch stateswitches[] = {
 static void XMLCALL
 cr_start_handler(void *pdata, const char *element, const char **attr)
 {
-    GError *tmp_err = NULL;
     cr_ParserData *pd = pdata;
     cr_StatesSwitch *sw;
 
@@ -215,7 +214,6 @@ static void XMLCALL
 cr_end_handler(void *pdata, const char *element)
 {
     cr_ParserData *pd = pdata;
-    GError *tmp_err = NULL;
     unsigned int state = pd->state;
 
     CR_UNUSED(element);
@@ -241,7 +239,7 @@ cr_end_handler(void *pdata, const char *element)
 
     case STATE_REVISION:
         assert(pd->repomd);
-        assert(pd->repomdrecord);
+        assert(!pd->repomdrecord);
 
         if (pd->lcontent == 0) {
             cr_xml_parser_warning(pd, CR_XML_WARNING_MISSINGVAL,
@@ -257,21 +255,21 @@ cr_end_handler(void *pdata, const char *element)
 
     case STATE_REPO:
         assert(pd->repomd);
-        assert(pd->repomdrecord);
+        assert(!pd->repomdrecord);
 
         cr_repomd_add_repo_tag(pd->repomd, pd->content);
         break;
 
     case STATE_CONTENT:
         assert(pd->repomd);
-        assert(pd->repomdrecord);
+        assert(!pd->repomdrecord);
 
         cr_repomd_add_content_tag(pd->repomd, pd->content);
         break;
 
     case STATE_DISTRO:
         assert(pd->repomd);
-        assert(pd->repomdrecord);
+        assert(!pd->repomdrecord);
 
         cr_repomd_add_distro_tag(pd->repomd, pd->cpeid, pd->content);
         if (pd->cpeid) {
index 576e1d7..e8e9268 100644 (file)
@@ -26,6 +26,10 @@ ADD_EXECUTABLE(test_xml_parser_filelists test_xml_parser_filelists.c)
 TARGET_LINK_LIBRARIES(test_xml_parser_filelists libcreaterepo_c ${GLIB2_LIBRARIES})
 ADD_DEPENDENCIES(tests test_xml_parser_filelists)
 
+ADD_EXECUTABLE(test_xml_parser_repomd test_xml_parser_repomd.c)
+TARGET_LINK_LIBRARIES(test_xml_parser_repomd libcreaterepo_c ${GLIB2_LIBRARIES})
+ADD_DEPENDENCIES(tests test_xml_parser_repomd)
+
 CONFIGURE_FILE("run_gtester.sh.in"  "run_gtester.sh")
 ADD_TEST(test_main run_gtester.sh)
 
index 49edf1e..40c6193 100644 (file)
 
 // Repo files
 
+#define TEST_REPO_00_REPOMD     TEST_REPO_00"repodata/repomd.xml"
 #define TEST_REPO_00_PRIMARY    TEST_REPO_00"repodata/dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz"
 #define TEST_REPO_00_FILELISTS  TEST_REPO_00"repodata/401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz"
 #define TEST_REPO_00_OTHER      TEST_REPO_00"repodata/6bf9672d0862e8ef8b8ff05a2fd0208a922b1f5978e6589d87944c88259cb670-other.xml.gz"
 
+#define TEST_REPO_01_REPOMD     TEST_REPO_01"repodata/repomd.xml"
 #define TEST_REPO_01_PRIMARY    TEST_REPO_01"repodata/6c662d665c24de9a0f62c17d8fa50622307739d7376f0d19097ca96c6d7f5e3e-primary.xml.gz"
 #define TEST_REPO_01_FILELISTS  TEST_REPO_01"repodata/c7db035d0e6f1b2e883a7fa3229e2d2be70c05a8b8d2b57dbb5f9c1a67483b6c-filelists.xml.gz"
 #define TEST_REPO_01_OTHER      TEST_REPO_01"repodata/b752a73d9efd4006d740f943db5fb7c2dd77a8324bd99da92e86bd55a2c126ef-other.xml.gz"
 
+#define TEST_REPO_02_REPOMD     TEST_REPO_02"repodata/repomd.xml"
 #define TEST_REPO_02_PRIMARY    TEST_REPO_02"repodata/bcde64b04916a2a72fdc257d61bc922c70b3d58e953499180585f7a360ce86cf-primary.xml.gz"
 #define TEST_REPO_02_FILELISTS  TEST_REPO_02"repodata/3b7e6ecd01af9cb674aff6458186911d7081bb5676d5562a21a963afc8a8bcc7-filelists.xml.gz"
 #define TEST_REPO_02_OTHER      TEST_REPO_02"repodata/ab5d3edeea50f9b4ec5ee13e4d25c147e318e3a433dbabc94d3461f58ac28255-other.xml.gz"
diff --git a/tests/test_xml_parser_repomd.c b/tests/test_xml_parser_repomd.c
new file mode 100644 (file)
index 0000000..bb54583
--- /dev/null
@@ -0,0 +1,94 @@
+/* createrepo_c - Library of routines for manipulation with repodata
+ * Copyright (C) 2013  Tomas Mlcoch
+ *
+ * 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 2
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+ * USA.
+ */
+
+#include <glib.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "fixtures.h"
+#include "createrepo/error.h"
+#include "createrepo/repomd.h"
+#include "createrepo/misc.h"
+#include "createrepo/xml_parser.h"
+
+// Callbacks
+
+static int
+warningcb(cr_XmlParserWarningType type,
+                    char *msg,
+                    void *cbdata,
+                    GError **err)
+{
+    CR_UNUSED(type);
+    CR_UNUSED(msg);
+    CR_UNUSED(err);
+
+    g_assert(type < CR_XML_WARNING_SENTINEL);
+    g_assert(!err || *err == NULL);
+
+    g_string_append((GString *) cbdata, msg);
+    g_string_append((GString *) cbdata, ";");
+
+    return CR_CB_RET_OK;
+}
+
+static int
+warningcb_interrupt(cr_XmlParserWarningType type,
+                    char *msg,
+                    void *cbdata,
+                    GError **err)
+{
+    CR_UNUSED(type);
+    CR_UNUSED(msg);
+    CR_UNUSED(cbdata);
+    CR_UNUSED(err);
+
+    g_assert(type < CR_XML_WARNING_SENTINEL);
+    g_assert(!err || *err == NULL);
+
+    if (cbdata) *((int *)cbdata) += 1;
+
+    return CR_CB_RET_ERR;
+}
+
+// Tests
+
+static void
+test_cr_xml_parse_repomd_00(void)
+{
+    GError *tmp_err = NULL;
+    cr_Repomd *repomd = cr_repomd_new();
+
+    int ret = cr_xml_parse_repomd(TEST_REPO_00_REPOMD, repomd,
+                                  NULL, NULL, &tmp_err);
+    g_assert(tmp_err == NULL);
+    g_assert_cmpint(ret, ==, CRE_OK);
+
+    cr_repomd_free(repomd);
+}
+
+int
+main(int argc, char *argv[])
+{
+    g_test_init(&argc, &argv, NULL);
+
+    g_test_add_func("/xml_parser_filelists/test_cr_xml_parse_repomd_00",
+                    test_cr_xml_parse_repomd_00);
+
+    return g_test_run();
+}