aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-09-05 20:02:41 +0200
committerTheJackiMonster <thejackimonster@gmail.com>2021-09-05 20:02:41 +0200
commitaec4779ce9030fdf3adb47f7791566a5aacf1a6e (patch)
tree8277b917f9a8a54b6ba0c01f7c5bf98ad0b7fbf1
parenta6d4094851714d3e1406fe9d50f4cc08d8c0ff1a (diff)
downloadlibgnunetchat-aec4779ce9030fdf3adb47f7791566a5aacf1a6e.tar.gz
libgnunetchat-aec4779ce9030fdf3adb47f7791566a5aacf1a6e.zip
Added build target for automatic test cases
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--.gitignore3
-rw-r--r--Makefile16
-rw-r--r--tests/test_gnunet_chat_handle.c68
3 files changed, 86 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 1f8f3a0..fc71951 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,6 @@
6# Binary files: 6# Binary files:
7*.o 7*.o
8*.so 8*.so
9
10# Test files:
11tests/*.test
diff --git a/Makefile b/Makefile
index 20b304b..b124cbf 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
1 1
2TARGET_NAME = gnunetchat
2SOURCE_DIR = src/ 3SOURCE_DIR = src/
3INCLUDE_DIR = include/ 4INCLUDE_DIR = include/
5TESTS_DIR = tests/
4INSTALL_DIR ?= /usr/local/ 6INSTALL_DIR ?= /usr/local/
5 7
6LIBRARY = libgnunetchat.so 8LIBRARY = lib$(TARGET_NAME).so
7SOURCES = gnunet_chat_lib.c\ 9SOURCES = gnunet_chat_lib.c\
8 gnunet_chat_contact.c\ 10 gnunet_chat_contact.c\
9 gnunet_chat_context.c\ 11 gnunet_chat_context.c\
@@ -16,6 +18,8 @@ SOURCES = gnunet_chat_lib.c\
16 18
17HEADERS = gnunet_chat_lib.h 19HEADERS = gnunet_chat_lib.h
18 20
21TESTS = test_gnunet_chat_handle.c
22
19LIBRARIES = gnunetarm\ 23LIBRARIES = gnunetarm\
20 gnunetfs\ 24 gnunetfs\
21 gnunetmessenger\ 25 gnunetmessenger\
@@ -35,7 +39,10 @@ RELEASEFLAGS = -O2 -D NDEBUG
35SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES)) 39SOURCE_FILES = $(addprefix $(SOURCE_DIR), $(SOURCES))
36OBJECT_FILES = $(SOURCE_FILES:%.c=%.o) 40OBJECT_FILES = $(SOURCE_FILES:%.c=%.o)
37HEADER_FILES = $(addprefix $(INCLUDE_DIR), $(HEADERS)) 41HEADER_FILES = $(addprefix $(INCLUDE_DIR), $(HEADERS))
42TEST_FILES = $(addprefix $(TESTS_DIR), $(TESTS))
43TEST_CASES = $(TEST_FILES:%.c=%.test)
38LIBRARY_FLAGS = $(addprefix -l, $(LIBRARIES)) 44LIBRARY_FLAGS = $(addprefix -l, $(LIBRARIES))
45TEST_FLAGS = $(LIBRARY_FLAGS) -lcheck -l$(TARGET_NAME)
39 46
40all: $(LIBRARY) 47all: $(LIBRARY)
41 48
@@ -51,10 +58,17 @@ release: $(LIBRARY)
51$(LIBRARY): $(OBJECT_FILES) 58$(LIBRARY): $(OBJECT_FILES)
52 $(LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS) 59 $(LD) $(LDFLAGS) $^ -o $@ $(LIBRARY_FLAGS)
53 60
61check: $(TEST_CASES)
62 ./$(TEST_CASES)
63
64%.test: %.c
65 $(CC) $(CFLAGS) $< -o $@ -I $(INCLUDE_DIR) $(TEST_FLAGS)
66
54.PHONY: install 67.PHONY: install
55 68
56install: 69install:
57 install -m 755 $(LIBRARY) $(addprefix $(INSTALL_DIR), lib/) 70 install -m 755 $(LIBRARY) $(addprefix $(INSTALL_DIR), lib/)
71 mkdir -p $(addprefix $(INSTALL_DIR), include/gnunet/)
58 install -m 644 $(HEADER_FILES) $(addprefix $(INSTALL_DIR), include/gnunet/) 72 install -m 644 $(HEADER_FILES) $(addprefix $(INSTALL_DIR), include/gnunet/)
59 73
60.PHONY: uninstall 74.PHONY: uninstall
diff --git a/tests/test_gnunet_chat_handle.c b/tests/test_gnunet_chat_handle.c
new file mode 100644
index 0000000..2492590
--- /dev/null
+++ b/tests/test_gnunet_chat_handle.c
@@ -0,0 +1,68 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file test_gnunet_chat_handle.c
23 */
24
25#include <check.h>
26#include <gnunet/gnunet_chat_lib.h>
27
28START_TEST(test_gnunet_chat_handle)
29{
30 struct GNUNET_CHAT_Handle *handle;
31
32 handle = GNUNET_CHAT_start(NULL, "", "Test", NULL, NULL, NULL, NULL);
33 ck_assert_ptr_eq(handle, NULL);
34
35 GNUNET_CHAT_stop(handle);
36}
37END_TEST
38
39Suite* handle_suite(void)
40{
41 Suite *suite;
42 TCase *test_case;
43
44 suite = suite_create("Handle");
45
46 test_case = tcase_create("Start/Stop");
47 tcase_add_test(test_case, test_gnunet_chat_handle);
48 suite_add_tcase(suite, test_case);
49
50 return suite;
51}
52
53int main(void)
54{
55 int tests_failed;
56
57 Suite *suite;
58 SRunner *suite_runner;
59
60 suite = handle_suite();
61 suite_runner = srunner_create(suite);
62
63 srunner_run_all(suite_runner, CK_NORMAL);
64 tests_failed = srunner_ntests_failed(suite_runner);
65 srunner_free(suite_runner);
66
67 return (tests_failed == 0? EXIT_SUCCESS : EXIT_FAILURE);
68}