GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../test/cctest/test_platform.cc Lines: 26 26 100.0 %
Date: 2019-01-07 12:15:22 Branches: 14 26 53.8 %

Line Branch Exec Source
1
#include "node_internals.h"
2
#include "libplatform/libplatform.h"
3
4
#include <string>
5
#include "gtest/gtest.h"
6
#include "node_test_fixture.h"
7
8
// This task increments the given run counter and reposts itself until the
9
// repost counter reaches zero.
10
6
class RepostingTask : public v8::Task {
11
 public:
12
3
  explicit RepostingTask(int repost_count,
13
                         int* run_count,
14
                         v8::Isolate* isolate,
15
                         node::NodePlatform* platform)
16
      : repost_count_(repost_count),
17
        run_count_(run_count),
18
        isolate_(isolate),
19
3
        platform_(platform) {}
20
21
  // v8::Task implementation
22
3
  void Run() final {
23
3
    ++*run_count_;
24
3
    if (repost_count_ > 0) {
25
2
      --repost_count_;
26
      platform_->CallOnForegroundThread(isolate_,
27
2
          new RepostingTask(repost_count_, run_count_, isolate_, platform_));
28
    }
29
3
  }
30
31
 private:
32
  int repost_count_;
33
  int* run_count_;
34
  v8::Isolate* isolate_;
35
  node::NodePlatform* platform_;
36
};
37
38
2
class PlatformTest : public EnvironmentTestFixture {};
39
40
5
TEST_F(PlatformTest, SkipNewTasksInFlushForegroundTasks) {
41
1
  v8::Isolate::Scope isolate_scope(isolate_);
42
2
  const v8::HandleScope handle_scope(isolate_);
43
2
  const Argv argv;
44
2
  Env env {handle_scope, argv};
45
1
  int run_count = 0;
46
1
  platform->CallOnForegroundThread(
47
1
      isolate_, new RepostingTask(2, &run_count, isolate_, platform.get()));
48
1
  EXPECT_TRUE(platform->FlushForegroundTasks(isolate_));
49
1
  EXPECT_EQ(1, run_count);
50
1
  EXPECT_TRUE(platform->FlushForegroundTasks(isolate_));
51
1
  EXPECT_EQ(2, run_count);
52
1
  EXPECT_TRUE(platform->FlushForegroundTasks(isolate_));
53
1
  EXPECT_EQ(3, run_count);
54
2
  EXPECT_FALSE(platform->FlushForegroundTasks(isolate_));
55

4
}