summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2015-07-19 15:23:36 +0100
committerMichael Drake <tlsa@netsurf-browser.org>2015-08-03 22:30:20 +0100
commit0b624c7fba92d74858746328888548d28b55f84a (patch)
treedef21828c16e8ce57d96c9cf07757c552f50a1de /test
parent5496ba69d866145d2855e06c83c6441640e16231 (diff)
downloadlibnslayout-0b624c7fba92d74858746328888548d28b55f84a.tar.gz
libnslayout-0b624c7fba92d74858746328888548d28b55f84a.tar.bz2
Add basic tests for creating a layout object.
Diffstat (limited to 'test')
-rw-r--r--test/Makefile3
-rw-r--r--test/assert-tests.c38
-rw-r--r--test/basic-layout-tests.c78
-rw-r--r--test/tests.c52
-rw-r--r--test/tests.h19
5 files changed, 190 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..5703e79
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,3 @@
+DIR_TEST_ITEMS := testrunner:tests.c;assert-tests.c;basic-layout-tests.c
+
+include $(NSBUILD)/Makefile.subdir
diff --git a/test/assert-tests.c b/test/assert-tests.c
new file mode 100644
index 0000000..4fca036
--- /dev/null
+++ b/test/assert-tests.c
@@ -0,0 +1,38 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+#include <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+/* TODO: Test for each individual param being NULL. */
+START_TEST (test_nslayout_layout_create_aborts1)
+{
+ nslayout_layout *layout;
+ (void) nslayout_layout_create(NULL, NULL, NULL, NULL, NULL, &layout);
+}
+END_TEST
+
+
+void nslayout_assert_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: API Assert tests");
+ TCase *tc_assert = tcase_create("Creation/Destruction");
+
+ tcase_add_test_raise_signal(
+ tc_assert,
+ test_nslayout_layout_create_aborts1,
+ SIGABRT);
+ suite_add_tcase(s, tc_assert);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/basic-layout-tests.c b/test/basic-layout-tests.c
new file mode 100644
index 0000000..84611a9
--- /dev/null
+++ b/test/basic-layout-tests.c
@@ -0,0 +1,78 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+#include <check.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) (void)(x)
+#endif
+
+int pw;
+
+static nslayout_error nslayout_test_callback(
+ nslayout_request *req,
+ nslayout_layout *layout,
+ void *pw)
+{
+ UNUSED(req);
+ UNUSED(layout);
+ UNUSED(pw);
+ return NSLAYOUT_OK;
+}
+
+START_TEST (test_nslayout_layout_create_ok)
+{
+ nslayout_layout *layout = NULL;
+ nslayout_error error;
+ dom_exception dom_error;
+ css_error css_err;
+ dom_document *doc;
+ css_select_ctx *css_ctx;
+ css_media_type media = CSS_MEDIA_SCREEN;
+
+ /* Create a DOM document */
+ dom_error = dom_implementation_create_document(DOM_IMPLEMENTATION_HTML,
+ NULL, NULL, NULL, NULL, NULL, &doc);
+ ck_assert(dom_error == DOM_NO_ERR);
+
+ /* Create a selection context (with no sheets added) */
+ css_err = css_select_ctx_create(&css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ error = nslayout_layout_create(doc,
+ css_ctx,
+ &media,
+ nslayout_test_callback,
+ &pw,
+ &layout);
+ fail_unless(error == NSLAYOUT_OK,
+ "Unable to create layout");
+ fail_unless(layout != NULL,
+ "Returned OK but str was still NULL");
+
+ css_err = css_select_ctx_destroy(css_ctx);
+ ck_assert(css_err == CSS_OK);
+
+ dom_node_unref(doc);
+}
+END_TEST
+
+
+void nslayout_basic_layout_suite(SRunner *sr)
+{
+ Suite *s = suite_create("libnslayout: basic layout tests");
+ TCase *tc_layout_basic = tcase_create("Creation/Destruction");
+
+ tcase_add_test(tc_layout_basic,
+ test_nslayout_layout_create_ok);
+ suite_add_tcase(s, tc_layout_basic);
+
+ srunner_add_suite(sr, s);
+}
diff --git a/test/tests.c b/test/tests.c
new file mode 100644
index 0000000..a58e038
--- /dev/null
+++ b/test/tests.c
@@ -0,0 +1,52 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <check.h>
+
+#include "tests.h"
+
+#ifndef UNUSED
+#define UNUSED(x) ((x) = (x))
+#endif
+
+#ifndef NDEBUG
+/* This means that assertion failures are silent in tests */
+void __assert_fail(const char *__assertion, const char *__file,
+ unsigned int __line, const char *__function) {
+ (void)__assertion;
+ (void)__file;
+ (void)__line;
+ (void)__function;
+ abort();
+}
+#endif
+
+int main(int argc, char **argv)
+{
+ int number_failed = 0;
+ SRunner *sr;
+
+ UNUSED(argc);
+ UNUSED(argv);
+
+ sr = srunner_create(suite_create("Test suite for libnslayout"));
+
+#ifndef NDEBUG
+ nslayout_assert_suite(sr);
+#endif
+ nslayout_basic_layout_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..4f7795f
--- /dev/null
+++ b/test/tests.h
@@ -0,0 +1,19 @@
+/*
+ * This file is part of LibNSLayout's tests
+ * Licensed under the ISC License, http://opensource.org/licenses/ISC
+ * Copyright 2015 Michael Drake <tlsa@netsurf-browser.org>
+ */
+
+#ifndef nslayout_tests_h_
+#define nslayout_tests_h_
+
+#include <signal.h>
+
+#include <check.h>
+
+#include <libnslayout/nslayout.h>
+
+extern void nslayout_assert_suite(SRunner *);
+extern void nslayout_basic_layout_suite(SRunner *);
+
+#endif