blob: f7378a9be751c465cdf6e63710ce7c7919e3b87f [file] [log] [blame]
Tom Sepezeaf9d212020-07-22 16:24:00 +00001// Copyright 2020 PDFium 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
Tom Sepezf5397f02020-07-23 21:22:40 +00005#include "testing/fxgc_unittest.h"
Tom Sepezeaf9d212020-07-22 16:24:00 +00006
7#include "fxjs/gc/heap.h"
8#include "testing/gtest/include/gtest/gtest.h"
9#include "testing/v8_test_environment.h"
Lei Zhangdabb2062021-06-07 18:17:25 +000010#include "v8/include/libplatform/libplatform.h"
Tom Sepezeaf9d212020-07-22 16:24:00 +000011
12FXGCUnitTest::FXGCUnitTest() = default;
13
14FXGCUnitTest::~FXGCUnitTest() = default;
15
16void FXGCUnitTest::SetUp() {
Tom Sepezfe287292022-06-03 21:05:30 +000017 ::testing::Test::SetUp();
Tom Sepez5b2e5862020-09-23 22:03:45 +000018 auto* env = V8TestEnvironment::GetInstance();
19 FXGC_Initialize(env->platform(), env->isolate());
Tom Sepezeaf9d212020-07-22 16:24:00 +000020 heap_ = FXGC_CreateHeap();
21 ASSERT_TRUE(heap_);
22}
23
24void FXGCUnitTest::TearDown() {
Tom Sepezfe287292022-06-03 21:05:30 +000025 ForceGCAndPump();
Tom Sepezeaf9d212020-07-22 16:24:00 +000026 heap_.reset();
27 FXGC_Release();
Tom Sepezfe287292022-06-03 21:05:30 +000028 ::testing::Test::TearDown();
29}
30
31void FXGCUnitTest::ForceGCAndPump() {
32 FXGC_ForceGarbageCollection(heap_.get());
33 Pump();
34}
35
36void FXGCUnitTest::Pump() {
37 V8TestEnvironment::PumpPlatformMessageLoop(
38 V8TestEnvironment::GetInstance()->isolate());
Tom Sepezeaf9d212020-07-22 16:24:00 +000039}