diff --git a/.gitignore b/.gitignore index f6bb37b..e238846 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ check_*.trs test-*.log .dirstamp check_jira_plugin +check_packaging \ No newline at end of file diff --git a/Makefile.am b/Makefile.am index 2dbe60a..e4266cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,8 +1,9 @@ ACLOCAL_AMFLAGS = -I m4 EXTRA_DIST = ${top_srcdir}/README.md \ - ${top_srcdir}/LICENSE \ - ${top_srcdir}/common.mk + ${top_srcdir}/LICENSE \ + ${top_srcdir}/common.mk \ + ${top_srcdir}/tests/package.spec NULL = CLEANFILES = diff --git a/common.mk b/common.mk index b68b0a4..72c3a2d 100644 --- a/common.mk +++ b/common.mk @@ -8,6 +8,7 @@ AM_CFLAGS = -fstack-protector -Wall -pedantic \ AM_CPPFLAGS = \ -I $(top_srcdir)/src \ -DDATA_DIRECTORY=\"$(datadir)/cve-check-tool\" \ - -DSITE_PATH=\"$(sysconfdir)\" -DDEFAULT_PATH=\"$(datadir)/defaults/cve-check-tool\" + -DSITE_PATH=\"$(sysconfdir)\" -DDEFAULT_PATH=\"$(datadir)/defaults/cve-check-tool\" \ + -DTOP_DIR=\"$(top_srcdir)\" AUTOMAKE_OPTIONS = color-tests parallel-tests diff --git a/tests/Makefile.am b/tests/Makefile.am index 1fde8e2..e545b55 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,11 +3,13 @@ TESTS = \ check_core \ - check_jira_plugin + check_jira_plugin \ + check_packaging check_PROGRAMS = \ check_core \ - check_jira_plugin + check_jira_plugin \ + check_packaging check_core_SOURCES = \ check-core.c @@ -42,3 +44,18 @@ check_jira_plugin_LDADD = \ $(LIBJSON_GLIB_LIBS) +check_packaging_SOURCES = \ + check-packaging.c + +check_packaging_CFLAGS = \ + $(GLIB_CFLAGS) \ + $(GIO_CFLAGS) \ + $(LIBXML2_CFLAGS) \ + $(AM_CFLAGS) \ + $(CHECK_CFLAGS) + +check_packaging_LDADD = \ + $(GLIB_LIBS) \ + $(GIO_LIBS) \ + $(LIBXML2_LIBS) \ + $(CHECK_LIBS) diff --git a/tests/check-packaging.c b/tests/check-packaging.c new file mode 100644 index 0000000..467369e --- /dev/null +++ b/tests/check-packaging.c @@ -0,0 +1,116 @@ +/* + * This file is part of cve-check-tool + * Copyright (C) 2015 Intel Corporation + * + * cve-check-tool 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. + */ + +#define _GNU_SOURCE +#include +#include +#include + +#include "cve-string.c" +#include "util.h" +#include "util.c" +#include "rpm.c" +#include "eopkg.c" + +#include "config.h" + + +/** + * Kept here as a no-op for now (linking) + */ +void cve_add_package(const char *path) +{ + +} + +/** + * Copy of main.c function + */ +static inline void package_free(void *p) +{ + if (!p) { + return; + } + struct source_package_t *t = p; + if (t->issues) { + g_list_free_full(t->issues, xmlFree); + } + if (t->patched) { + g_list_free_full(t->patched, xmlFree); + } + if (t->path) { + g_free(t->path); + } + if (t->xml) { + xmlFree((xmlChar*)t->name); + xmlFree((xmlChar*)t->version); + } else { + g_free((gchar*)t->name); + g_free((gchar*)t->version); + } + if (t->extra) { + g_strfreev(t->extra); + } + + free(t); +} + +/** + * Ensure parse_xml_date works + */ +START_TEST(cve_rpm_test) +{ + struct source_package_t *pkg = NULL; + + pkg = rpm_inspect_spec(TOP_DIR "/tests/package.spec"); + fail_if(!pkg, "Failed to inspect RPM spec!"); + + fail_if(!g_str_equal(pkg->name, "test-package"), + "Invalid RPM package name"); + fail_if(!g_str_equal(pkg->version, "1.1.0"), + "Invalid RPM package version"); + fail_if(pkg->release != 5, "Invalid RPM package release"); + + package_free(pkg); +} +END_TEST + + +static Suite *core_suite(void) +{ + Suite *s = NULL; + TCase *tc = NULL; + + s = suite_create("cve_packaging"); + tc = tcase_create("cve_packaging_functions"); + tcase_add_test(tc, cve_rpm_test); + suite_add_tcase(s, tc); + + return s; +} + +int main(void) +{ + Suite *s; + SRunner *sr; + int fail; + + s = core_suite(); + sr = srunner_create(s); + srunner_run_all(sr, CK_VERBOSE); + fail = srunner_ntests_failed(sr); + srunner_free(sr); + + if (fail > 0) { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} diff --git a/tests/package.spec b/tests/package.spec new file mode 100644 index 0000000..41b7de7 --- /dev/null +++ b/tests/package.spec @@ -0,0 +1,14 @@ +# Mostly ensuring demacro performs correctly +%define sub package +%define patch 0 +%define minor 1 +%define suffix %{minor}.%{patch} + +# test-package +Name : test-%{sub} +# 1.1.0 +Version : 1.%{suffix} +Release : 5 + +%description +Invalid RPM spec package, provided solely for testing