Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
move_unittest.cpp
Go to the documentation of this file.
1// Copyright 2020 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <utility>
6
7#include "fxjs/gc/heap.h"
8#include "testing/fxgc_unittest.h"
9#include "testing/gtest/include/gtest/gtest.h"
10#include "v8/include/cppgc/member.h"
11#include "v8/include/cppgc/persistent.h"
12
13namespace {
14
15class HeapObject : public cppgc::GarbageCollected<HeapObject> {
16 public:
18
19 void Trace(cppgc::Visitor* visitor) const {
20 visitor->Trace(frick_);
21 visitor->Trace(frack_);
22 }
23
24 cppgc::Member<HeapObject> frick_;
25 cppgc::Member<HeapObject> frack_;
26
27 private:
28 HeapObject() = default;
29};
30
31class CppObject {
32 public:
33 CppObject() = default;
34
35 cppgc::Persistent<HeapObject> click_;
36 cppgc::Persistent<HeapObject> clack_;
37};
38
39} // namespace
40
41class MoveUnitTest : public FXGCUnitTest {};
42
44 // Moving a Member<> leaves the moved-from object as null.
45 auto* obj =
46 cppgc::MakeGarbageCollected<HeapObject>(heap()->GetAllocationHandle());
47 obj->frick_ = obj;
48 obj->frack_ = std::move(obj->frick_);
49 EXPECT_FALSE(obj->frick_);
50 EXPECT_EQ(obj, obj->frack_);
51}
52
54 // Moving a Persistent<> leaves the moved-from object as null.
55 auto* obj =
56 cppgc::MakeGarbageCollected<HeapObject>(heap()->GetAllocationHandle());
57 CppObject outsider;
58 outsider.click_ = obj;
59 outsider.clack_ = std::move(outsider.click_);
60 EXPECT_FALSE(outsider.click_);
61 EXPECT_EQ(obj, outsider.clack_);
62}
#define CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED
Definition heap.h:32
TEST_F(MoveUnitTest, Member)