Tom Sepez | eaf9d21 | 2020-07-22 16:24:00 +0000 | [diff] [blame] | 1 | // 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 Sepez | f5397f0 | 2020-07-23 21:22:40 +0000 | [diff] [blame] | 5 | #include "testing/fxgc_unittest.h" |
Tom Sepez | eaf9d21 | 2020-07-22 16:24:00 +0000 | [diff] [blame] | 6 | |
| 7 | #include "fxjs/gc/heap.h" |
| 8 | #include "testing/gtest/include/gtest/gtest.h" |
| 9 | #include "testing/v8_test_environment.h" |
Lei Zhang | dabb206 | 2021-06-07 18:17:25 +0000 | [diff] [blame] | 10 | #include "v8/include/libplatform/libplatform.h" |
Tom Sepez | eaf9d21 | 2020-07-22 16:24:00 +0000 | [diff] [blame] | 11 | |
| 12 | FXGCUnitTest::FXGCUnitTest() = default; |
| 13 | |
| 14 | FXGCUnitTest::~FXGCUnitTest() = default; |
| 15 | |
| 16 | void FXGCUnitTest::SetUp() { |
Tom Sepez | fe28729 | 2022-06-03 21:05:30 +0000 | [diff] [blame] | 17 | ::testing::Test::SetUp(); |
Tom Sepez | 5b2e586 | 2020-09-23 22:03:45 +0000 | [diff] [blame] | 18 | auto* env = V8TestEnvironment::GetInstance(); |
| 19 | FXGC_Initialize(env->platform(), env->isolate()); |
Tom Sepez | eaf9d21 | 2020-07-22 16:24:00 +0000 | [diff] [blame] | 20 | heap_ = FXGC_CreateHeap(); |
| 21 | ASSERT_TRUE(heap_); |
| 22 | } |
| 23 | |
| 24 | void FXGCUnitTest::TearDown() { |
Tom Sepez | fe28729 | 2022-06-03 21:05:30 +0000 | [diff] [blame] | 25 | ForceGCAndPump(); |
Tom Sepez | eaf9d21 | 2020-07-22 16:24:00 +0000 | [diff] [blame] | 26 | heap_.reset(); |
| 27 | FXGC_Release(); |
Tom Sepez | fe28729 | 2022-06-03 21:05:30 +0000 | [diff] [blame] | 28 | ::testing::Test::TearDown(); |
| 29 | } |
| 30 | |
| 31 | void FXGCUnitTest::ForceGCAndPump() { |
| 32 | FXGC_ForceGarbageCollection(heap_.get()); |
| 33 | Pump(); |
| 34 | } |
| 35 | |
| 36 | void FXGCUnitTest::Pump() { |
| 37 | V8TestEnvironment::PumpPlatformMessageLoop( |
| 38 | V8TestEnvironment::GetInstance()->isolate()); |
Tom Sepez | eaf9d21 | 2020-07-22 16:24:00 +0000 | [diff] [blame] | 39 | } |