Files
cve-check-tool/tests/check-packaging.c
T
2015-04-10 14:15:25 +01:00

137 lines
3.1 KiB
C

/*
* 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(__attribute__((unused)) 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);
}
/**
* RPM .spec check
*/
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
/**
* Solus Project pspec.xml check
*/
START_TEST(cve_eopkg_test)
{
struct source_package_t *pkg = NULL;
pkg = eopkg_inspect_pspec(TOP_DIR "/tests/pspec.xml");
fail_if(!pkg, "Failed to inspect eopkg spec!");
fail_if(!g_str_equal(pkg->name, "budgie-desktop"),
"Invalid eopkg package name");
fail_if(!g_str_equal(pkg->version, "8.1"),
"Invalid eopkg package version");
fail_if(pkg->release != 41, "Invalid eopkg 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);
tcase_add_test(tc, cve_eopkg_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;
}