summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@netsurf-browser.org>2009-02-14 15:56:52 (GMT)
committer Daniel Silverstone <dsilvers@netsurf-browser.org>2009-02-14 15:56:52 (GMT)
commit41124cff3e5e20f7b7542bdfec653ef8e852c306 (patch)
treea73fb0bfe92f66cb127312a31e29cb69980a77a6
parentbe1ffaeca7cdb002d30817383aeb1f47fe9df79b (diff)
downloadlibwapcaplet-41124cff3e5e20f7b7542bdfec653ef8e852c306.tar.gz
libwapcaplet-41124cff3e5e20f7b7542bdfec653ef8e852c306.tar.bz2
100% of tests pass. Ship it.
svn path=/trunk/libwapcaplet/; revision=6497
-rw-r--r--Makefile89
-rw-r--r--include/libwapcaplet/libwapcaplet.h7
-rw-r--r--src/libwapcaplet.c6
-rw-r--r--test/basictests.c35
-rw-r--r--test/testmain.c34
-rw-r--r--test/tests.h20
6 files changed, 187 insertions, 4 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..d15458a
--- a/dev/null
+++ b/Makefile
@@ -0,0 +1,89 @@
+# Simple Makefile for libwapcaplet
+
+LIB := libwapcaplet.a
+
+SRCS := libwapcaplet.c
+HDRS := libwapcaplet/libwapcaplet.h
+
+TESTSRCS := testmain.c basictests.c
+
+TARGET ?= debug
+
+BUILDDIR := build-$(TARGET)
+
+all: $(BUILDDIR)/$(LIB)
+
+test: $(BUILDDIR)/testrunner
+ $(BUILDDIR)/testrunner
+
+CFLAGS := -Iinclude -Wall -Werror
+
+ifeq ($(TARGET),debug)
+CFLAGS += -O0 -g
+else
+CFLAGS += -O2
+endif
+
+
+clean:
+ rm -fr build-*
+
+$(BUILDDIR)/stamp:
+ mkdir -p $(BUILDDIR)
+ touch $(BUILDDIR)/stamp
+
+define srcfile
+src/$1
+endef
+
+define objfile
+$(BUILDDIR)/$(1:.c=.o)
+endef
+
+define depfile
+$(BUILDDIR)/$(1:.c=.d)
+endef
+
+DEPS :=
+OBJS :=
+
+define _depandbuild
+
+$2: $1 $(BUILDDIR)/stamp
+ $(CC) -MMD -MP $($5) -o $2 -c $1
+
+$4 += $2
+DEPS += $3
+
+endef
+
+define depandbuild
+$(call _depandbuild,$(call srcfile,$1),$(call objfile,$1),$(call depfile,$1),OBJS,CFLAGS)
+endef
+
+$(eval $(foreach SOURCE,$(SRCS),$(call depandbuild,$(SOURCE))))
+
+ifneq ($(MAKECMDGOALS),clean)
+-include $(DEPS)
+endif
+
+$(BUILDDIR)/$(LIB): $(BUILDDIR)/stamp $(OBJS)
+ $(AR) cru $@ $^
+
+define testsrc
+test/$1
+endef
+
+define depandbuildtest
+$(call _depandbuild,$(call testsrc,$1),$(call objfile,test-$1),$(call depfile,test-$1),TOBJS,TESTCFLAGS)
+endef
+
+TOBJS :=
+
+TESTCFLAGS := $(CFLAGS) $(shell pkg-config --cflags check)
+TESTLDFLAGS := $(LDFLAGS) $(shell pkg-config --libs check)
+
+$(eval $(foreach TESTSRC,$(TESTSRCS),$(call depandbuildtest,$(TESTSRC))))
+
+$(BUILDDIR)/testrunner: $(BUILDDIR)/stamp $(TOBJS) $(BUILDDIR)/$(LIB)
+ $(CC) -o $@ $(TOBJS) $(BUILDDIR)/$(LIB) $(TESTLDFLAGS)
diff --git a/include/libwapcaplet/libwapcaplet.h b/include/libwapcaplet/libwapcaplet.h
index 0294eec..ded5d58 100644
--- a/include/libwapcaplet/libwapcaplet.h
+++ b/include/libwapcaplet/libwapcaplet.h
@@ -10,6 +10,7 @@
#define libwapcaplet_h_
#include <sys/types.h>
+#include <stdbool.h>
/**
* Memory allocator type
@@ -30,9 +31,9 @@ typedef struct lwc_string_s lwc_string;
* Error codes which libwapcaplet might return.
*/
typedef enum lwc_error_e {
- lwc_error_ok = 0,
- lwc_error_oom = 1,
- lwc_error_range = 2,
+ lwc_error_ok = 0,
+ lwc_error_oom = 1,
+ lwc_error_range = 2,
} lwc_error;
/**
diff --git a/src/libwapcaplet.c b/src/libwapcaplet.c
index 1b5738b..cc80627 100644
--- a/src/libwapcaplet.c
+++ b/src/libwapcaplet.c
@@ -7,6 +7,8 @@
*/
#include <string.h>
+#include <stdint.h>
+#include <assert.h>
#include "libwapcaplet/libwapcaplet.h"
@@ -77,6 +79,8 @@ lwc_error
lwc_create_context(lwc_allocator_fn alloc, void *pw,
lwc_context **ret)
{
+ assert(alloc);
+
*ret = alloc(NULL, sizeof(lwc_context), pw);
if (*ret == NULL)
@@ -193,7 +197,7 @@ lwc_context_intern(lwc_context *ctx,
{
return __lwc_context_intern(ctx, s, slen, ret,
lwc_calculate_hash,
- strncmp, memcpy);
+ strncmp, (lwc_memcpy)memcpy);
}
lwc_error
diff --git a/test/basictests.c b/test/basictests.c
new file mode 100644
index 0000000..1e0a828
--- a/dev/null
+++ b/test/basictests.c
@@ -0,0 +1,35 @@
+/* test/basictests.c
+ *
+ * Basic tests for the test suite for libwapcaplet
+ *
+ * Copyright 2009 The NetSurf Browser Project
+ * Daniel Silverstone <dsilvers@netsurf-browser.org>
+ */
+
+#include <check.h>
+#include <stdlib.h>
+
+#include "tests.h"
+
+START_TEST (test_lwc_context_creation_bad_alloc)
+{
+ lwc_context *ctx = NULL;
+ lwc_error err;
+
+ err = lwc_create_context(NULL, NULL, &ctx);
+}
+END_TEST
+
+
+
+void
+lwc_basic_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libwapcaplet: Basic tests");
+ TCase *tc_basic = tcase_create("Creation/Destruction");
+
+ tcase_add_test_raise_signal(tc_basic, test_lwc_context_creation_bad_alloc, SIGABRT);
+
+ suite_add_tcase(s, tc_basic);
+ srunner_add_suite(sr, s);
+}
diff --git a/test/testmain.c b/test/testmain.c
new file mode 100644
index 0000000..c5fa0b3
--- a/dev/null
+++ b/test/testmain.c
@@ -0,0 +1,34 @@
+/* test/testmain.c
+ *
+ * Core of the test suite for libwapcaplet
+ *
+ * Copyright 2009 The NetSurf Browser Project
+ * Daniel Silverstone <dsilvers@netsurf-browser.org>
+ */
+
+#include <check.h>
+#include <stdlib.h>
+
+#include "tests.h"
+
+/* This means that assertion failures are silent in tests */
+void __assert_fail(void) { abort(); }
+
+int
+main(int argc, char **argv)
+{
+ int number_failed = 0;
+ SRunner *sr;
+
+ sr = srunner_create(suite_create("Test suite for libwapcaplet"));
+
+ lwc_basic_suite(sr);
+
+ srunner_set_fork_status(sr, CK_FORK);
+ srunner_run_all(sr, CK_ENV);
+ number_failed = srunner_ntests_failed(sr);
+
+ srunner_free(sr);
+
+ return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/test/tests.h b/test/tests.h
new file mode 100644
index 0000000..e223ff1
--- a/dev/null
+++ b/test/tests.h
@@ -0,0 +1,20 @@
+/* test/tests.h
+ *
+ * Set of test suites for libwapcaplet
+ *
+ * Copyright 2009 The NetSurf Browser Project
+ * Daniel Silverstone <dsilvers@netsurf-browser.org>
+ */
+
+#ifndef lwc_tests_h_
+#define lwc_tests_h_
+
+#include <signal.h>
+
+#include <check.h>
+
+#include "libwapcaplet/libwapcaplet.h"
+
+extern void lwc_basic_suite(SRunner *);
+
+#endif /* lwc_tests_h_ */