Dali 3D User Interface Engine
assert.h
Go to the documentation of this file.
1 #ifndef _ASSERT_H_
2 #define _ASSERT_H_
3 #include <stdio.h>
4 #include <stdlib.h>
5 
6 #define assert(exp) \
7  if (!(exp)) { \
8  fprintf(stderr, \
9  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
10  fprintf(stderr, \
11  "Following expression is not true:\n" \
12  "%s\n", #exp); \
13  return 1; \
14  }
15 
16 #define assert_eq(var, ref) \
17  if (var != ref) { \
18  fprintf(stderr, \
19  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
20  fprintf(stderr, \
21  "Values \"%s\" and \"%s\" are not equal:\n" \
22  "%s == %d, %s == %d\n", \
23  #var, #ref, #var, (int)var, #ref, (int)ref); \
24  return 1; \
25  }
26 
27 #define assert_neq(var, ref) \
28  if (var == ref) { \
29  fprintf(stderr, \
30  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
31  fprintf(stderr, \
32  "Values \"%s\" and \"%s\" are equal:\n" \
33  "%s == %s == %d\n", \
34  #var, #ref, #var, #ref, (int)ref); \
35  return 1; \
36  }
37 
38 #define assert_gt(var, ref) \
39  if (var <= ref) { \
40  fprintf(stderr, \
41  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
42  fprintf(stderr, \
43  "Value \"%s\" is not greater than \"%s\":\n" \
44  "%s == %d, %s == %d\n", \
45  #var, #ref, #var, var, #ref, ref); \
46  return 1; \
47  }
48 
49 #define assert_geq(var, ref) \
50  if (var < ref) { \
51  fprintf(stderr, \
52  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
53  fprintf(stderr, \
54  "Value \"%s\" is not greater or equal to \"%s\":\n" \
55  "%s == %d, %s == %d\n", \
56  #var, #ref, #var, var, #ref, ref); \
57  return 1; \
58  }
59 
60 #define assert_lt(var, ref) \
61  if (var >= ref) { \
62  fprintf(stderr, \
63  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
64  fprintf(stderr, \
65  "Value \"%s\" is not lower than \"%s\":\n" \
66  "%s == %d, %s == %d\n", \
67  #var, #ref, #var, var, #ref, ref); \
68  return 1; \
69  }
70 
71 #define assert_leq(var, ref) \
72  if (var > ref) { \
73  fprintf(stderr, \
74  "Assert fail in %s:%d\n", __FILE__, __LINE__); \
75  fprintf(stderr, \
76  "Value \"%s\" is not lower or equal to \"%s\":\n" \
77  "%s == %d, %s == %d\n", \
78  #var, #ref, #var, var, #ref, ref); \
79  return 1; \
80  }
81 
82 #endif // _ASSERT_H_
Dali Docs Home
Read more about Dali