15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright 2009 The RE2 Authors.  All Rights Reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// license that can be found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef RE2_UTIL_TEST_H__
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define RE2_UTIL_TEST_H__
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "util/util.h"
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "util/flags.h"
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define TEST(x, y) \
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	void x##y(void); \
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	TestRegisterer r##x##y(x##y, # x "." # y); \
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)	void x##y(void)
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RegisterTest(void (*)(void), const char*);
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class TestRegisterer {
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  TestRegisterer(void (*fn)(void), const char *s) {
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    RegisterTest(fn, s);
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(rsc): Do a better job.
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_EQ CHECK_EQ
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_TRUE CHECK
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_LT CHECK_LT
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_GT CHECK_GT
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_LE CHECK_LE
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_GE CHECK_GE
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_FALSE(x) CHECK(!(x))
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ARRAYSIZE arraysize
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_TRUE_M(x, y) CHECK(x) << (y)
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_FALSE_M(x, y) CHECK(!(x)) << (y)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASSERT_TRUE_M(x, y) CHECK(x) << (y)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define ASSERT_EQUALS(x, y) CHECK_EQ(x, y)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const bool UsingMallocCounter = false;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace testing {
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MallocCounter {
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  MallocCounter(int x) { }
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  static const int THIS_THREAD_ONLY = 0;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  long long HeapGrowth() { return 0; }
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  long long PeakHeapGrowth() { return 0; }
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void Reset() { }
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace testing
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace re2 {
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)int64 VirtualProcessSize();
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace re2
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // RE2_UTIL_TEST_H__
58