diff --git a/Makefile.am b/Makefile.am index 51d6d52739fe9e1b6361268cade843014485be81..bd7503879e12873de417d88d089bf80483004bdb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = src +SUBDIRS = src tests ACLOCAL_AMFLAGS = --install -I build-macro diff --git a/configure.ac b/configure.ac index f32e54ea7301d95dd40b4b440f788398a19809a8..750a6221af5a06b6365794d81f07d406a19654a2 100644 --- a/configure.ac +++ b/configure.ac @@ -30,6 +30,7 @@ AC_CHECK_HEADER([string.h]) # Makefiles AC_CONFIG_FILES([Makefile - src/Makefile]) + src/Makefile + tests/Makefile]) AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..4db975ecae41eb155d2ad5493349d06ce691c734 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,19 @@ +## Process this file with automake to produce Makefile.in + +AM_CFLAGS = -Wall -Wextra $(CHECK_CFLAGS) + +TESTS = +TESTS += sefht_cms_test + +check_PROGRAMS = $(TESTS) + +AM_CPPFLAGS = +AM_CPPFLAGS += -I$(top_srcdir)/src + +LDADD = $(CHECK_LIBS) + +sefht_cms_test_SOURCES = test_cms.c +sefht_cms_test_LDADD = +sefht_cms_test_LDADD += $(top_builddir)/src/cms.o +sefht_cms_test_LDADD += $(top_builddir)/src/data.o +sefht_cms_test_LDADD += $(LDADD) diff --git a/tests/test_cms.c b/tests/test_cms.c new file mode 100644 index 0000000000000000000000000000000000000000..1d4f0f5e1cd33689c45e99c26c95dc1c99586095 --- /dev/null +++ b/tests/test_cms.c @@ -0,0 +1,82 @@ +/* + * test_cms.c + * + * Copyright 2022 Jonathan Schöbel <jonathan@Ubermos-2019> + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * + */ + + +#include <check.h> +#include <stdlib.h> + +#include "error.h" +#include "cms.h" + + +START_TEST(test_cms) +{ + struct SH_Error error; + struct SH_Cms * cms; + + cms = SH_Cms_new (NULL); + ck_assert_int_ne ((long int) cms, (long int) NULL); + + SH_Cms_free (cms, NULL); + + cms = SH_Cms_new (&error); + ck_assert_int_ne ((long int) cms, (long int) NULL); + ck_assert_int_eq (error.type, SUCCESS); + + SH_Cms_free (cms, &error); + ck_assert_int_eq (error.type, SUCCESS); +} +END_TEST + +Suite * cms_suite (void) +{ + Suite *s; + TCase *tc_core; + + s = suite_create ("Testsuite SeFHT CMS"); + + /* Core test case */ + tc_core = tcase_create ("Core"); + + tcase_add_test (tc_core, test_cms); + suite_add_tcase (s, tc_core); + + return s; +} + +int main (int argc, char **argv) +{ + int number_failed; + Suite *s; + SRunner *sr; + + s = cms_suite (); + sr = srunner_create (s); + + srunner_run_all (sr, CK_NORMAL); + number_failed = srunner_ntests_failed (sr); + srunner_free (sr); + + return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} +