aboutsummaryrefslogtreecommitdiffstats
path: root/tests/common
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-04 23:58:10 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2016-10-04 23:58:10 +0200
commit13be5bd50238daa2be6b42104ba20aeea427655b (patch)
tree3e66986cd1ebbd98f06f61ff45127745fd54bc01 /tests/common
parent3fff4bb3172f77b292b0c913749e81bedd3545f3 (diff)
downloadblogc-13be5bd50238daa2be6b42104ba20aeea427655b.tar.gz
blogc-13be5bd50238daa2be6b42104ba20aeea427655b.tar.bz2
blogc-13be5bd50238daa2be6b42104ba20aeea427655b.zip
git-receiver: splitted and tested pre-receive input parser
Diffstat (limited to 'tests/common')
-rw-r--r--tests/common/check_stdin.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tests/common/check_stdin.c b/tests/common/check_stdin.c
new file mode 100644
index 0000000..c0d222d
--- /dev/null
+++ b/tests/common/check_stdin.c
@@ -0,0 +1,53 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+#include <string.h>
+#include <stdio.h>
+#include "../../src/common/stdin.h"
+
+
+int
+__wrap_fgetc(FILE *stream)
+{
+ assert_int_equal(fileno(stream), fileno(stdin));
+ return mock_type(int);
+}
+
+
+static void
+test_read(void **state)
+{
+ will_return(__wrap_fgetc, EOF);
+ char *t = bc_stdin_read();
+ assert_non_null(t);
+ assert_string_equal(t, "");
+ free(t);
+ will_return(__wrap_fgetc, 'b');
+ will_return(__wrap_fgetc, 'o');
+ will_return(__wrap_fgetc, 'l');
+ will_return(__wrap_fgetc, 'a');
+ will_return(__wrap_fgetc, EOF);
+ t = bc_stdin_read();
+ assert_non_null(t);
+ assert_string_equal(t, "bola");
+ free(t);
+}
+
+
+int
+main(void)
+{
+ const UnitTest tests[] = {
+ unit_test(test_read),
+ };
+ return run_tests(tests);
+}