summaryrefslogtreecommitdiffstats
path: root/moon-abe/pbc-0.5.14/include/pbc_test.h
blob: 35d6f7540d135be230eb97f742315c729c465f45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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__