PortAudio  2.0
paqa_macros.h
Go to the documentation of this file.
1 
2 #ifndef PORTAUDIO_QA_PAQA_MACROS_H
3 #define PORTAUDIO_QA_PAQA_MACROS_H
4 
5 extern int paQaNumPassed;
6 extern int paQaNumFailed;
7 
8 /* You must use this macro exactly once in each test program. */
9 #define PAQA_INSTANTIATE_GLOBALS\
10  int paQaNumPassed = 0;\
11  int paQaNumFailed = 0;
12 
13 /*------------------- Macros ------------------------------*/
14 /* Print ERROR if it fails. Tally success or failure. Odd */
15 /* do-while wrapper seems to be needed for some compilers. */
16 #define ASSERT_TRUE(_exp) \
17  do \
18  { \
19  if (_exp) {\
20  paQaNumPassed++; \
21  } \
22  else { \
23  printf("ERROR at %s:%d, (%s) not true\n", \
24  __FILE__, __LINE__, #_exp ); \
25  paQaNumFailed++; \
26  goto error; \
27  } \
28  } while(0)
29 
30 #define ASSERT_AB(_a, _b, _op, _opn) \
31  do \
32  { \
33  int mA = (int)(_a); \
34  int mB = (int)(_b); \
35  if (mA _op mB) {\
36  paQaNumPassed++; \
37  } \
38  else { \
39  printf("ERROR at %s:%d, (%s) %s (%s), %d %s %d\n", \
40  __FILE__, __LINE__, #_a, #_opn, #_b, mA, #_opn, mB ); \
41  paQaNumFailed++; \
42  goto error; \
43  } \
44  } while(0)
45 
46 #define ASSERT_EQ(_a, _b) ASSERT_AB(_a, _b, ==, !=)
47 #define ASSERT_NE(_a, _b) ASSERT_AB(_a, _b, !=, ==)
48 #define ASSERT_GT(_a, _b) ASSERT_AB(_a, _b, >, <=)
49 #define ASSERT_GE(_a, _b) ASSERT_AB(_a, _b, >=, <)
50 #define ASSERT_LT(_a, _b) ASSERT_AB(_a, _b, <, >=)
51 #define ASSERT_LE(_a, _b) ASSERT_AB(_a, _b, <=, >)
52 
53 #define HOPEFOR(_exp) \
54  do \
55  { \
56  if ((_exp)) {\
57  paQaNumPassed++; \
58  } \
59  else { \
60  printf("\nERROR - 0x%x - %s for %s\n", result, Pa_GetErrorText(result), #_exp ); \
61  paQaNumFailed++; \
62  } \
63  } while(0)
64 
65 #define PAQA_PRINT_RESULT \
66  printf("QA Report: %d passed, %d failed.\n", paQaNumPassed, paQaNumFailed )
67 
68 #define PAQA_EXIT_RESULT \
69  (((paQaNumFailed > 0) || (paQaNumPassed == 0)) ? EXIT_FAILURE : EXIT_SUCCESS)
70 
71 #endif /* PORTAUDIO_QA_PAQA_MACROS_H */
int paQaNumPassed
int paQaNumFailed