@@ -52,42 +52,47 @@ struct Argv { |
52 | 52 | int nr_args_; |
53 | 53 | }; |
54 | 54 |
|
55 | | -extern uv_loop_t current_loop; |
56 | 55 |
|
57 | 56 | class NodeTestFixture : public ::testing::Test { |
58 | 57 | public: |
59 | 58 | static uv_loop_t* CurrentLoop() { return ¤t_loop; } |
60 | 59 |
|
61 | | - node::MultiIsolatePlatform* Platform() const { return platform_; } |
| 60 | + node::MultiIsolatePlatform* Platform() const { return platform.get(); } |
62 | 61 |
|
63 | 62 | protected: |
| 63 | + static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator; |
| 64 | + static std::unique_ptr<node::NodePlatform> platform; |
| 65 | + static v8::Isolate::CreateParams params; |
| 66 | + static uv_loop_t current_loop; |
64 | 67 | v8::Isolate* isolate_; |
65 | 68 |
|
66 | | - virtual void SetUp() { |
| 69 | + static void SetUpTestCase() { |
| 70 | + platform.reset(new node::NodePlatform(4, nullptr)); |
| 71 | + allocator.reset(v8::ArrayBuffer::Allocator::NewDefaultAllocator()); |
| 72 | + params.array_buffer_allocator = allocator.get(); |
67 | 73 | CHECK_EQ(0, uv_loop_init(¤t_loop)); |
68 | | - platform_ = new node::NodePlatform(8, nullptr); |
69 | | - v8::V8::InitializePlatform(platform_); |
| 74 | + v8::V8::InitializePlatform(platform.get()); |
70 | 75 | v8::V8::Initialize(); |
71 | | - v8::Isolate::CreateParams params_; |
72 | | - params_.array_buffer_allocator = allocator_.get(); |
73 | | - isolate_ = v8::Isolate::New(params_); |
74 | 76 | } |
75 | 77 |
|
76 | | - virtual void TearDown() { |
77 | | - platform_->Shutdown(); |
| 78 | + static void TearDownTestCase() { |
| 79 | + platform->Shutdown(); |
78 | 80 | while (uv_loop_alive(¤t_loop)) { |
79 | 81 | uv_run(¤t_loop, UV_RUN_ONCE); |
80 | 82 | } |
81 | 83 | v8::V8::ShutdownPlatform(); |
82 | | - delete platform_; |
83 | | - platform_ = nullptr; |
84 | 84 | CHECK_EQ(0, uv_loop_close(¤t_loop)); |
85 | 85 | } |
86 | 86 |
|
87 | | - private: |
88 | | - node::NodePlatform* platform_ = nullptr; |
89 | | - std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{ |
90 | | - v8::ArrayBuffer::Allocator::NewDefaultAllocator()}; |
| 87 | + virtual void SetUp() { |
| 88 | + isolate_ = v8::Isolate::New(params); |
| 89 | + CHECK_NE(isolate_, nullptr); |
| 90 | + } |
| 91 | + |
| 92 | + virtual void TearDown() { |
| 93 | + isolate_->Dispose(); |
| 94 | + isolate_ = nullptr; |
| 95 | + } |
91 | 96 | }; |
92 | 97 |
|
93 | 98 | #endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_ |