libglacier/tests/unit-tests.c

84 lines
2.0 KiB
C

/*
* unit-tests.c - Unit tests for libglacier
*
* This file is part of Glacier.
*
* Glacier 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 3 of the License, or (at your option) any later version.
*
* Glacier 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 Glacier. If
* not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <libconfig.h>
#include <unistd.h>
#include "../include/config.h"
#include "../include/log.h"
#include "../include/pkgops.h"
#include "../include/runtime.h"
#include "../include/security.h"
#include <CUnit/Basic.h>
void
test_is_process_root(void)
{
if (is_process_root() != 0) {
CU_FAIL("is_process_root() with UID != 0 failed");
}
else if (is_process_root() == 0) {
CU_PASS("is_process_root() with UID != 0 passed");
}
}
void
test_init_config(void)
{
CU_ASSERT_TRUE(init_config());
}
int
main(void)
{
if (CUE_SUCCESS != CU_initialize_registry()) {
return CU_get_error();
}
CU_basic_set_mode(CU_BRM_VERBOSE);
CU_pSuite runtime_tests = CU_add_suite("Runtime Functions Suite", NULL, NULL);
if (! runtime_tests) {
CU_cleanup_registry();
return CU_get_error();
}
CU_pSuite config_tests = CU_add_suite("Configuration Functions Suite", NULL, NULL);
if (! config_tests) {
CU_cleanup_registry();
return CU_get_error();
}
if (! CU_add_test(runtime_tests, "test of is_process_root()", test_is_process_root)) {
CU_cleanup_registry();
return CU_get_error();
}
if (! CU_add_test(config_tests, "test of init_config()", test_init_config)) {
CU_cleanup_registry();
return CU_get_error();
}
CU_basic_run_tests();
CU_cleanup_registry();
return CU_get_error();
}