blob: 1342510b6115263bbf95b5e756ed9338be16f17a [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001// 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
Emily Bernierd0a1eb72015-03-24 16:35:39 -04005#ifndef V8_UNITTESTS_TEST_UTILS_H_
6#define V8_UNITTESTS_TEST_UTILS_H_
Ben Murdochb8a8cc12014-11-26 15:28:44 +00007
8#include "include/v8.h"
9#include "src/base/macros.h"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040010#include "src/base/utils/random-number-generator.h"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000011#include "src/zone.h"
12#include "testing/gtest-support.h"
13
14namespace v8 {
15
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000016class ArrayBufferAllocator;
Emily Bernierd0a1eb72015-03-24 16:35:39 -040017
18
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000019class TestWithIsolate : public virtual ::testing::Test {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000020 public:
21 TestWithIsolate();
22 virtual ~TestWithIsolate();
23
24 Isolate* isolate() const { return isolate_; }
25
26 static void SetUpTestCase();
27 static void TearDownTestCase();
28
29 private:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000030 static ArrayBufferAllocator* array_buffer_allocator_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000031 static Isolate* isolate_;
32 Isolate::Scope isolate_scope_;
33 HandleScope handle_scope_;
34
35 DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
36};
37
38
39class TestWithContext : public virtual TestWithIsolate {
40 public:
41 TestWithContext();
42 virtual ~TestWithContext();
43
44 const Local<Context>& context() const { return context_; }
45
46 private:
47 Local<Context> context_;
48 Context::Scope context_scope_;
49
50 DISALLOW_COPY_AND_ASSIGN(TestWithContext);
51};
52
53
Emily Bernierd0a1eb72015-03-24 16:35:39 -040054namespace base {
55
56class TestWithRandomNumberGenerator : public ::testing::Test {
57 public:
58 TestWithRandomNumberGenerator();
59 virtual ~TestWithRandomNumberGenerator();
60
61 RandomNumberGenerator* rng() { return &rng_; }
62
63 private:
64 RandomNumberGenerator rng_;
65
66 DISALLOW_COPY_AND_ASSIGN(TestWithRandomNumberGenerator);
67};
68
69} // namespace base
70
71
Ben Murdochb8a8cc12014-11-26 15:28:44 +000072namespace internal {
73
74// Forward declarations.
75class Factory;
76
77
78class TestWithIsolate : public virtual ::v8::TestWithIsolate {
79 public:
80 TestWithIsolate() {}
81 virtual ~TestWithIsolate();
82
83 Factory* factory() const;
84 Isolate* isolate() const {
85 return reinterpret_cast<Isolate*>(::v8::TestWithIsolate::isolate());
86 }
Emily Bernierd0a1eb72015-03-24 16:35:39 -040087 base::RandomNumberGenerator* random_number_generator() const;
Ben Murdochb8a8cc12014-11-26 15:28:44 +000088
89 private:
90 DISALLOW_COPY_AND_ASSIGN(TestWithIsolate);
91};
92
93
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000094class TestWithZone : public virtual ::testing::Test {
Ben Murdochb8a8cc12014-11-26 15:28:44 +000095 public:
Ben Murdochda12d292016-06-02 14:46:10 +010096 TestWithZone() : zone_(&allocator_) {}
Ben Murdochb8a8cc12014-11-26 15:28:44 +000097 virtual ~TestWithZone();
98
99 Zone* zone() { return &zone_; }
100
101 private:
Ben Murdochda12d292016-06-02 14:46:10 +0100102 base::AccountingAllocator allocator_;
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000103 Zone zone_;
104
105 DISALLOW_COPY_AND_ASSIGN(TestWithZone);
106};
107
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000108
109class TestWithIsolateAndZone : public virtual TestWithIsolate {
110 public:
Ben Murdochda12d292016-06-02 14:46:10 +0100111 TestWithIsolateAndZone() : zone_(&allocator_) {}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000112 virtual ~TestWithIsolateAndZone();
113
114 Zone* zone() { return &zone_; }
115
116 private:
Ben Murdochda12d292016-06-02 14:46:10 +0100117 base::AccountingAllocator allocator_;
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000118 Zone zone_;
119
120 DISALLOW_COPY_AND_ASSIGN(TestWithIsolateAndZone);
121};
122
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000123} // namespace internal
124} // namespace v8
125
Emily Bernierd0a1eb72015-03-24 16:35:39 -0400126#endif // V8_UNITTESTS_TEST_UTILS_H_