GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — test: introduce SetUpTestCase/TearDownTestCase · nodejs/node@743cf33

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/cctest
    • node_test_fixture.cc
    • node_test_fixture.h
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/cctest/node_test_fixture.cc‎

Copy file name to clipboard
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#include "node_test_fixture.h"
22

3-
uv_loop_t current_loop;
3+
uv_loop_t NodeTestFixture::current_loop;
4+
std::unique_ptr<node::NodePlatform> NodeTestFixture::platform;
5+
std::unique_ptr<v8::ArrayBuffer::Allocator> NodeTestFixture::allocator;
6+
v8::Isolate::CreateParams NodeTestFixture::params;
Collapse file

‎test/cctest/node_test_fixture.h‎

Copy file name to clipboardExpand all lines: test/cctest/node_test_fixture.h
+21-16Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,42 +52,47 @@ struct Argv {
5252
int nr_args_;
5353
};
5454

55-
extern uv_loop_t current_loop;
5655

5756
class NodeTestFixture : public ::testing::Test {
5857
public:
5958
static uv_loop_t* CurrentLoop() { return &current_loop; }
6059

61-
node::MultiIsolatePlatform* Platform() const { return platform_; }
60+
node::MultiIsolatePlatform* Platform() const { return platform.get(); }
6261

6362
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;
6467
v8::Isolate* isolate_;
6568

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();
6773
CHECK_EQ(0, uv_loop_init(&current_loop));
68-
platform_ = new node::NodePlatform(8, nullptr);
69-
v8::V8::InitializePlatform(platform_);
74+
v8::V8::InitializePlatform(platform.get());
7075
v8::V8::Initialize();
71-
v8::Isolate::CreateParams params_;
72-
params_.array_buffer_allocator = allocator_.get();
73-
isolate_ = v8::Isolate::New(params_);
7476
}
7577

76-
virtual void TearDown() {
77-
platform_->Shutdown();
78+
static void TearDownTestCase() {
79+
platform->Shutdown();
7880
while (uv_loop_alive(&current_loop)) {
7981
uv_run(&current_loop, UV_RUN_ONCE);
8082
}
8183
v8::V8::ShutdownPlatform();
82-
delete platform_;
83-
platform_ = nullptr;
8484
CHECK_EQ(0, uv_loop_close(&current_loop));
8585
}
8686

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+
}
9196
};
9297

9398
#endif // TEST_CCTEST_NODE_TEST_FIXTURE_H_

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.