1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef V8_TEST_TEST_UTILS_H_
6 #define V8_TEST_TEST_UTILS_H_
7 
8 #include "include/v8.h"
9 #include "src/base/macros.h"
10 #include "src/zone.h"
11 #include "testing/gtest-support.h"
12 
13 namespace v8 {
14 
15 class TestWithIsolate : public ::testing::Test {
16  public:
17   TestWithIsolate();
18   virtual ~TestWithIsolate();
19 
isolate()20   Isolate* isolate() const { return isolate_; }
21 
22   static void SetUpTestCase();
23   static void TearDownTestCase();
24 
25  private:
26   static Isolate* isolate_;
27   Isolate::Scope isolate_scope_;
28   HandleScope handle_scope_;
29 
30   DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
31 };
32 
33 
34 class TestWithContext : public virtual TestWithIsolate {
35  public:
36   TestWithContext();
37   virtual ~TestWithContext();
38 
context()39   const Local<Context>& context() const { return context_; }
40 
41  private:
42   Local<Context> context_;
43   Context::Scope context_scope_;
44 
45   DISALLOW_COPY_AND_ASSIGN(TestWithContext);
46 };
47 
48 
49 namespace internal {
50 
51 // Forward declarations.
52 class Factory;
53 
54 
55 class TestWithIsolate : public virtual ::v8::TestWithIsolate {
56  public:
TestWithIsolate()57   TestWithIsolate() {}
58   virtual ~TestWithIsolate();
59 
60   Factory* factory() const;
isolate()61   Isolate* isolate() const {
62     return reinterpret_cast<Isolate*>(::v8::TestWithIsolate::isolate());
63   }
64 
65  private:
66   DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
67 };
68 
69 
70 class TestWithZone : public TestWithIsolate {
71  public:
TestWithZone()72   TestWithZone() : zone_(isolate()) {}
73   virtual ~TestWithZone();
74 
zone()75   Zone* zone() { return &zone_; }
76 
77  private:
78   Zone zone_;
79 
80   DISALLOW_COPY_AND_ASSIGN(TestWithZone);
81 };
82 
83 }  // namespace internal
84 }  // namespace v8
85 
86 #endif  // V8_TEST_TEST_UTILS_H_
87