tests: Add initial packaging tests for RPM functionality

Signed-off-by: Ikey Doherty <michael.i.doherty@intel.com>
This commit is contained in:
Ikey Doherty
2015-04-10 11:25:06 +01:00
parent 1c460e7b87
commit 307f4e2673
6 changed files with 155 additions and 5 deletions
+1
View File
@@ -25,3 +25,4 @@ check_*.trs
test-*.log
.dirstamp
check_jira_plugin
check_packaging
+3 -2
View File
@@ -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 =
+2 -1
View File
@@ -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
+19 -2
View File
@@ -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)
+116
View File
@@ -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 <check.h>
#include <stdlib.h>
#include <stdio.h>
#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;
}
+14
View File
@@ -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