implement basic unit testing
This commit is contained in:
9
tests/Makefile
Normal file
9
tests/Makefile
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# Makefile
|
||||
#
|
||||
|
||||
include ../config.mk
|
||||
|
||||
all: unit-tests.c
|
||||
$(CC) unit-tests.c -o test-suite -lcunit -lconfig ../build/libglacier.a -Wall -Wextra
|
||||
./test-suite
|
||||
53
tests/unit-tests.c
Normal file
53
tests/unit-tests.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
CU_ASSERT(is_process_root() == 0);
|
||||
|
||||
uid_t saved_uid = getuid();
|
||||
setuid(0);
|
||||
CU_ASSERT(is_process_root() == 1);
|
||||
|
||||
setuid((int)saved_uid);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
if (CUE_SUCCESS != CU_initialize_registry()) {
|
||||
return CU_get_error();
|
||||
}
|
||||
|
||||
CU_basic_set_mode(CU_BRM_VERBOSE);
|
||||
|
||||
CU_basic_run_tests();
|
||||
return CU_get_error();
|
||||
}
|
||||
Reference in New Issue
Block a user