diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2013-11-12 20:43:54 +0100 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2013-11-12 20:43:54 +0100 |
commit | 4ce7e5b3397836320288e8c6dd38b54d73c6d860 (patch) | |
tree | 00573624aac742b4d5043a03785a78390ac5c196 | |
parent | 1297035b32982ddc0832064a65ad9d15ee0d6d39 (diff) |
build: add symbol tests
Add some minor tests for symbol tables. Also build libtsm twice, once as
static library so we can access internal symbols from within the tests.
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile.am | 21 | ||||
-rw-r--r-- | test/test_common.h | 1 | ||||
-rw-r--r-- | test/test_symbol.c | 75 |
4 files changed, 97 insertions, 1 deletions
@@ -26,4 +26,5 @@ m4/ stamp-h1 test-suite.log test_htable +test_symbol test_valgrind diff --git a/Makefile.am b/Makefile.am index 311e933..64e538a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -109,6 +109,7 @@ libshl_la_LIBADD = $(AM_LIBADD) # lib_LTLIBRARIES += libtsm.la +noinst_LTLIBRARIES += libtsm_test.la include_HEADERS += src/libtsm.h pkgconfig_DATA += docs/libtsm.pc @@ -122,17 +123,26 @@ libtsm_la_SOURCES = \ external/wcwidth.h \ external/wcwidth.c \ external/xkbcommon-keysyms.h +libtsm_test_la_SOURCES = $(libtsm_la_SOURCES) libtsm_la_CPPFLAGS = $(AM_CPPFLAGS) +libtsm_test_la_CPPFLAGS = $(AM_CPPFLAGS) + libtsm_la_LIBADD = libshl.la +libtsm_test_la_LIBADD = libshl.la + EXTRA_libtsm_la_DEPENDENCIES = $(top_srcdir)/docs/libtsm.sym + libtsm_la_LDFLAGS = \ $(AM_LDFLAGS) \ -version-info $(LIBTSM_CURRENT):$(LIBTSM_REVISION):$(LIBTSM_AGE) \ -Wl,--version-script="$(top_srcdir)/docs/libtsm.sym" +libtsm_test_la_LDFLAGS = \ + $(AM_LDFLAGS) if BUILD_HAVE_XKBCOMMON libtsm_la_CPPFLAGS += $(XKBCOMMON_CFLAGS) +libtsm_test_la_CPPFLAGS += $(XKBCOMMON_CFLAGS) endif # @@ -148,18 +158,22 @@ endif if BUILD_HAVE_CHECK check_PROGRAMS += \ test_htable \ + test_symbol \ test_valgrind TESTS += \ test_htable \ + test_symbol \ test_valgrind MEMTESTS += \ - test_htable + test_htable \ + test_symbol endif test_sources = \ test/test_common.h test_libs = \ libshl.la \ + libtsm_test.la \ $(CHECK_LIBS) test_cflags = \ $(AM_CPPFLAGS) \ @@ -172,6 +186,11 @@ test_htable_CPPFLAGS = $(test_cflags) test_htable_LDADD = $(test_libs) test_htable_LDFLAGS = $(test_lflags) +test_symbol_SOURCES = test/test_symbol.c $(test_sources) +test_symbol_CPPFLAGS = $(test_cflags) +test_symbol_LDADD = $(test_libs) +test_symbol_LDFLAGS = $(test_lflags) + test_valgrind_SOURCES = test/test_valgrind.c $(test_sources) test_valgrind_CPPFLAGS = $(test_cflags) test_valgrind_LDADD = $(test_libs) diff --git a/test/test_common.h b/test/test_common.h index 75d5072..902020c 100644 --- a/test/test_common.h +++ b/test/test_common.h @@ -38,6 +38,7 @@ #define TEST_COMMON_H #include <check.h> +#include <errno.h> #include <inttypes.h> #include <stdarg.h> #include <stdbool.h> diff --git a/test/test_symbol.c b/test/test_symbol.c new file mode 100644 index 0000000..d5efb64 --- /dev/null +++ b/test/test_symbol.c @@ -0,0 +1,75 @@ +/* + * TSM - Symbol Table Tests + * + * Copyright (c) 2012-2013 David Herrmann <dh.herrmann@gmail.com> + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files + * (the "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "test_common.h" + +START_TEST(test_symbol_null) +{ + int r; + tsm_symbol_t sym = 0, s; + const tsm_symbol_t *sp; + unsigned int n; + + r = tsm_symbol_table_new(NULL); + ck_assert(r == -EINVAL); + + tsm_symbol_table_ref(NULL); + tsm_symbol_table_unref(NULL); + + sp = tsm_symbol_get(NULL, &sym, NULL); + ck_assert(sp == &sym); + + s = tsm_symbol_append(NULL, sym, 'a'); + ck_assert(s == sym); + + n = tsm_symbol_get_width(NULL, sym); + ck_assert(!n); +} +END_TEST + +START_TEST(test_symbol_init) +{ + struct tsm_symbol_table *t; + int r; + + r = tsm_symbol_table_new(&t); + ck_assert(!r); + + tsm_symbol_table_unref(t); + t = NULL; +} +END_TEST + +TEST_DEFINE_CASE(misc) + TEST(test_symbol_null) + TEST(test_symbol_init) +TEST_END_CASE + +TEST_DEFINE( + TEST_SUITE(symbol, + TEST_CASE(misc), + TEST_END + ) +) |