1 #ifndef DEJAGNU_GTEST_H
2 #define DEJAGNU_GTEST_H 1
12 struct dejagnu_gtest_test
16 struct dejagnu_gtest_test
*next
;
18 struct dejagnu_gtest_test
*dejagnu_gtest_test_first
, *dejagnu_gtest_test_last
;
19 int dejagnu_gtest_test_death_num
, dejagnu_gtest_test_death_cur_num
;
21 #define TEST(cond, name) \
22 static void cond##_##name##_fn (void); \
23 static struct dejagnu_gtest_test cond##_##name##_struct \
24 = { #cond "_" #name, cond##_##name##_fn, NULL }; \
25 static __attribute__((__constructor__)) void \
26 cond##_##name##_ctor (void) \
28 if (strncmp (#name, "DISABLED_", 9) == 0) \
30 if (dejagnu_gtest_test_first == NULL) \
31 dejagnu_gtest_test_first = &cond##_##name##_struct; \
33 dejagnu_gtest_test_last->next = &cond##_##name##_struct; \
34 dejagnu_gtest_test_last = &cond##_##name##_struct; \
37 cond##_##name##_fn (void)
40 # define DEJAGNU_GTEST_TOCSTR(regex) (regex)
42 static inline const char *DEJAGNU_GTEST_TOCSTR(const char *x
) { return x
; }
43 static inline const char *DEJAGNU_GTEST_TOCSTR(const std::string
&x
) { return x
.c_str (); }
46 #define EXPECT_DEATH(statement, regex) \
49 ++dejagnu_gtest_test_death_cur_num; \
50 if (dejagnu_gtest_test_death_num == 0) \
52 fprintf (stderr, "DEJAGNU_GTEST_EXPECT_DEATH%d %s " \
53 "DEJAGNU_GTEST_EXPECT_DEATH%d %s " \
54 "DEJAGNU_GTEST_EXPECT_DEATH%d\n", \
55 dejagnu_gtest_test_death_cur_num, #statement, \
56 dejagnu_gtest_test_death_cur_num, \
57 DEJAGNU_GTEST_TOCSTR (regex), \
58 dejagnu_gtest_test_death_cur_num); \
60 else if (dejagnu_gtest_test_death_cur_num \
61 == dejagnu_gtest_test_death_num) \
68 #define EXPECT_TRUE(condition) \
71 fprintf (stderr, "%s", \
72 "EXPECT_TRUE failed: " #condition "\n"); \
75 #define EXPECT_FALSE(condition) EXPECT_TRUE (!condition)
76 #define EXPECT_EQ(expected, actual) EXPECT_TRUE ((expected) == (actual))
77 #define EXPECT_NE(expected, actual) EXPECT_TRUE ((expected) != (actual))
78 #define EXPECT_LT(expected, actual) EXPECT_TRUE ((expected) < (actual))
79 #define EXPECT_LE(expected, actual) EXPECT_TRUE ((expected) <= (actual))
80 #define EXPECT_GT(expected, actual) EXPECT_TRUE ((expected) > (actual))
81 #define EXPECT_GE(expected, actual) EXPECT_TRUE ((expected) >= (actual))
82 #define ASSERT_DEATH(statement, regex) EXPECT_DEATH (statement, regex)
83 #define ASSERT_TRUE(condition) EXPECT_TRUE (condition)
84 #define ASSERT_FALSE(condition) EXPECT_FALSE (condition)
85 #define ASSERT_EQ(expected, actual) EXPECT_EQ (expected, actual)
86 #define ASSERT_NE(expected, actual) EXPECT_NE (expected, actual)
87 #define ASSERT_LT(expected, actual) EXPECT_LT (expected, actual)
88 #define ASSERT_LE(expected, actual) EXPECT_LE (expected, actual)
89 #define ASSERT_GT(expected, actual) EXPECT_GT (expected, actual)
90 #define ASSERT_GE(expected, actual) EXPECT_GE (expected, actual)
93 main (int argc
, const char **argv
)
95 const char *test
= NULL
;
96 struct dejagnu_gtest_test
*t
;
100 test
= getenv ("DEJAGNU_GTEST_ARG");
102 for (t
= dejagnu_gtest_test_first
; t
; t
= t
->next
)
103 fprintf (stderr
, "DEJAGNU_GTEST_TEST %s\n", t
->name
);
106 const char *p
= strchr (test
, ':');
108 dejagnu_gtest_test_death_num
= atoi (p
+ 1);
109 for (t
= dejagnu_gtest_test_first
; t
; t
= t
->next
)
111 ? (strncmp (test
, t
->name
, p
- test
) == 0
112 && t
->name
[p
- test
] == '\0')
113 : (strcmp (test
, t
->name
) == 0))
115 EXPECT_TRUE (t
!= NULL
);