aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-19 16:45:20 -0300
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2015-04-19 16:45:20 -0300
commit329ef39c0fe382498dde48b5822b041a3804f618 (patch)
treec03815c65098339ee161139634d66a1cb827b959
parentd5ae7feec228e88f2c728a1fec2d331c88789a1b (diff)
downloadblogc-329ef39c0fe382498dde48b5822b041a3804f618.tar.gz
blogc-329ef39c0fe382498dde48b5822b041a3804f618.tar.bz2
blogc-329ef39c0fe382498dde48b5822b041a3804f618.zip
error: added tests
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am18
-rw-r--r--tests/check_error.c65
-rw-r--r--tests/check_loader.c1
-rw-r--r--tests/check_source_parser.c1
-rw-r--r--tests/check_template_parser.c1
6 files changed, 87 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 64014b2..c0943f3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -40,6 +40,7 @@ Makefile.in
/blogc
# tests
+/tests/check_error
/tests/check_loader
/tests/check_source_parser
/tests/check_template_parser
diff --git a/Makefile.am b/Makefile.am
index 71747dc..0988b5f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -81,12 +81,30 @@ blogc_LDADD = \
if USE_CMOCKA
check_PROGRAMS += \
+ tests/check_error \
tests/check_loader \
tests/check_source_parser \
tests/check_template_parser \
tests/check_utils \
$(NULL)
+tests_check_error_SOURCES = \
+ tests/check_error.c \
+ $(NULL)
+
+tests_check_error_CFLAGS = \
+ $(CMOCKA_CFLAGS) \
+ $(NULL)
+
+tests_check_error_LDFLAGS = \
+ -no-install \
+ $(NULL)
+
+tests_check_error_LDADD = \
+ $(CMOCKA_LIBS) \
+ libblogc.la \
+ $(NULL)
+
tests_check_loader_SOURCES = \
tests/check_loader.c \
$(NULL)
diff --git a/tests/check_error.c b/tests/check_error.c
new file mode 100644
index 0000000..59ac2f9
--- /dev/null
+++ b/tests/check_error.c
@@ -0,0 +1,65 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file COPYING.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <string.h>
+#include "../src/error.h"
+#include "../src/utils/utils.h"
+
+
+static void
+test_error_new(void **state)
+{
+ blogc_error_t *error = blogc_error_new(1, "bola %s");
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg, "bola %s");
+ blogc_error_free(error);
+}
+
+
+static void
+test_error_new_printf(void **state)
+{
+ blogc_error_t *error = blogc_error_new_printf(2, "bola %s", "guda");
+ assert_non_null(error);
+ assert_int_equal(error->type, 2);
+ assert_string_equal(error->msg, "bola guda");
+ blogc_error_free(error);
+}
+
+
+static void
+test_error_parser(void **state)
+{
+ const char *a = "bola\nguda\nchunda\n";
+ blogc_error_t *error = blogc_error_parser(1, a, strlen(a), 11, "asd %d", 10);
+ assert_non_null(error);
+ assert_int_equal(error->type, 1);
+ assert_string_equal(error->msg, "asd 10\nError occurred near to \"hunda\".");
+ blogc_error_free(error);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_error_new),
+ unit_test(test_error_new_printf),
+ unit_test(test_error_parser),
+ };
+ return run_tests(tests);
+}
diff --git a/tests/check_loader.c b/tests/check_loader.c
index c9f1432..08c5acc 100644
--- a/tests/check_loader.c
+++ b/tests/check_loader.c
@@ -16,6 +16,7 @@
#include <cmocka.h>
#include <string.h>
#include "../src/loader.h"
+#include "../src/utils/utils.h"
static void
diff --git a/tests/check_source_parser.c b/tests/check_source_parser.c
index ede1f5e..90ebcc1 100644
--- a/tests/check_source_parser.c
+++ b/tests/check_source_parser.c
@@ -17,6 +17,7 @@
#include <string.h>
#include "../src/source-parser.h"
#include "../src/error.h"
+#include "../src/utils/utils.h"
static void
diff --git a/tests/check_template_parser.c b/tests/check_template_parser.c
index b7ebd1c..9d67fe3 100644
--- a/tests/check_template_parser.c
+++ b/tests/check_template_parser.c
@@ -17,6 +17,7 @@
#include <string.h>
#include "../src/template-parser.h"
#include "../src/error.h"
+#include "../src/utils/utils.h"
static void