summaryrefslogtreecommitdiffstats
path: root/moon-abe/pbc-0.5.14/include/pbc_test.h
diff options
context:
space:
mode:
Diffstat (limited to 'moon-abe/pbc-0.5.14/include/pbc_test.h')
-rw-r--r--moon-abe/pbc-0.5.14/include/pbc_test.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/moon-abe/pbc-0.5.14/include/pbc_test.h b/moon-abe/pbc-0.5.14/include/pbc_test.h
new file mode 100644
index 00000000..35d6f754
--- /dev/null
+++ b/moon-abe/pbc-0.5.14/include/pbc_test.h
@@ -0,0 +1,42 @@
+// Useful for tests.
+
+#ifndef __PBC_TEST_H__
+#define __PBC_TEST_H__
+
+/*@manual test
+Initializes pairing from file specified as first argument, or from standard
+input if there is no first argument.
+*/
+static inline void pbc_demo_pairing_init(pairing_t pairing, int argc, char **argv) {
+ char s[16384];
+ FILE *fp = stdin;
+
+ if (argc > 1) {
+ fp = fopen(argv[1], "r");
+ if (!fp) pbc_die("error opening %s", argv[1]);
+ }
+ size_t count = fread(s, 1, 16384, fp);
+ if (!count) pbc_die("input error");
+ fclose(fp);
+
+ if (pairing_init_set_buf(pairing, s, count)) pbc_die("pairing init failed");
+}
+
+/*@manual test
+Returns seconds elapsed since the first call to this function.
+Returns 0 the first time.
+*/
+double pbc_get_time(void);
+
+/*@manual test
+Macro: if `condition` evaluates to 0 then print an error.
+*/
+#define EXPECT(condition) \
+ if (condition); else pbc_err_count++, fprintf(stderr, "\n*** FAIL ***\n %s:%d: %s\n\n", __FILE__, __LINE__, #condition)
+
+/*@manual test
+Total number of failed EXPECT checks.
+*/
+int pbc_err_count;
+
+#endif //__PBC_TEST_H__