aboutsummaryrefslogtreecommitdiffstats
path: root/example
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2018-09-03 23:01:26 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2018-09-03 23:01:26 +0200
commit3635952ae9fa28100a781f4c854f1d16eda8422b (patch)
treee3c8c117a29d20b0b5728eeea052f1f26a6d5325 /example
parent738bea6b99237477433b70d148e31491afbfc3f4 (diff)
downloadmtest-3635952ae9fa28100a781f4c854f1d16eda8422b.tar.gz
mtest-3635952ae9fa28100a781f4c854f1d16eda8422b.tar.bz2
mtest-3635952ae9fa28100a781f4c854f1d16eda8422b.zip
add: missing named-tests examples
Diffstat (limited to 'example')
-rw-r--r--example/named-tests.c50
-rw-r--r--example/named-tests.h11
2 files changed, 61 insertions, 0 deletions
diff --git a/example/named-tests.c b/example/named-tests.c
new file mode 100644
index 0000000..191c154
--- /dev/null
+++ b/example/named-tests.c
@@ -0,0 +1,50 @@
+/* ==========================================================================
+ Licensed under BSD 2clause license. See LICENSE file for more information
+ Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
+ ========================================================================== */
+
+
+#include "../mtest.h"
+#include "sub-tests.h"
+#include "calc.h"
+
+
+mt_defs_ext();
+static int a, b;
+
+
+/* ==========================================================================
+ test to run, mt_run_named takes functions without parameters, so we have
+ to use global variables as parameters
+ ========================================================================== */
+
+
+static void add_test(void)
+{
+ mt_fail(add(a, b) == a + b);
+}
+
+
+/* ==========================================================================
+ run single test with different parameters in a loop
+ ========================================================================== */
+
+
+void named_test_in_loop(void)
+{
+ for (a = 0; a != 3; ++a)
+ {
+ for (b = 0; b != 3; ++b)
+ {
+ char test_name[32];
+
+ /*
+ * mt_run_named takes "const char *" as parameter,
+ * so we have to construct name by ourselfs
+ */
+
+ sprintf(test_name, "test add(%d, %d)", a, b);
+ mt_run_named(add_test, test_name);
+ }
+ }
+}
diff --git a/example/named-tests.h b/example/named-tests.h
new file mode 100644
index 0000000..88ef9a7
--- /dev/null
+++ b/example/named-tests.h
@@ -0,0 +1,11 @@
+/* ==========================================================================
+ Licensed under BSD 2clause license. See LICENSE file for more information
+ Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
+ ========================================================================== */
+
+#ifndef NAMED_TESTS_H
+#define NAMED_TESTS_H 1
+
+void named_test_in_loop(void);
+
+#endif