test.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2009 The RE2 Authors. All Rights Reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. #ifndef UTIL_TEST_H_
  5. #define UTIL_TEST_H_
  6. #include "util/util.h"
  7. #include "util/logging.h"
  8. namespace testing {
  9. std::string TempDir();
  10. } // namespace testing
  11. #define TEST(x, y) \
  12. void x##y(void); \
  13. TestRegisterer r##x##y(x##y, # x "." # y); \
  14. void x##y(void)
  15. void RegisterTest(void (*)(void), const char*);
  16. class TestRegisterer {
  17. public:
  18. TestRegisterer(void (*fn)(void), const char *s) {
  19. RegisterTest(fn, s);
  20. }
  21. };
  22. // fatal assertions
  23. #define ASSERT_TRUE CHECK
  24. #define ASSERT_FALSE(x) CHECK(!(x))
  25. #define ASSERT_EQ CHECK_EQ
  26. #define ASSERT_NE CHECK_NE
  27. #define ASSERT_LT CHECK_LT
  28. #define ASSERT_LE CHECK_LE
  29. #define ASSERT_GT CHECK_GT
  30. #define ASSERT_GE CHECK_GE
  31. // nonfatal assertions
  32. // TODO(rsc): Do a better job?
  33. #define EXPECT_TRUE CHECK
  34. #define EXPECT_FALSE(x) CHECK(!(x))
  35. #define EXPECT_EQ CHECK_EQ
  36. #define EXPECT_NE CHECK_NE
  37. #define EXPECT_LT CHECK_LT
  38. #define EXPECT_LE CHECK_LE
  39. #define EXPECT_GT CHECK_GT
  40. #define EXPECT_GE CHECK_GE
  41. #endif // UTIL_TEST_H_