// Copyright 2020 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "fxjs/gc/container_trace.h" #include #include #include #include #include #include "testing/gtest/include/gtest/gtest.h" #include "v8/include/cppgc/member.h" namespace { class Thing : public cppgc::GarbageCollected { public: void Trace(cppgc::Visitor* visitor) const {} }; class CountingVisitor { public: CountingVisitor() = default; void Trace(const void* that) { ++call_count_; } int call_count() const { return call_count_; } private: int call_count_ = 0; }; } // namespace TEST(ContainerTrace, ActualListTrace) { std::list> thing; thing.emplace_back(nullptr); CountingVisitor cv; ContainerTrace(&cv, thing); EXPECT_EQ(1, cv.call_count()); } TEST(ContainerTrace, ActualMapTraceFirst) { std::map, int> thing; thing[nullptr] = 42; CountingVisitor cv; ContainerTrace(&cv, thing); EXPECT_EQ(1, cv.call_count()); } TEST(ContainerTrace, ActualMapTraceSecond) { std::map> thing; thing[42] = nullptr; CountingVisitor cv; ContainerTrace(&cv, thing); EXPECT_EQ(1, cv.call_count()); } TEST(ContainerTrace, ActualMapTraceBoth) { std::map, cppgc::Member> thing; thing[nullptr] = nullptr; CountingVisitor cv; ContainerTrace(&cv, thing); EXPECT_EQ(2, cv.call_count()); } TEST(ContainerTrace, ActualSetTrace) { std::set> thing; thing.insert(nullptr); CountingVisitor cv; ContainerTrace(&cv, thing); EXPECT_EQ(1, cv.call_count()); } TEST(ContainerTrace, ActualVectorTrace) { std::vector> thing; thing.emplace_back(nullptr); CountingVisitor cv; ContainerTrace(&cv, thing); EXPECT_EQ(1, cv.call_count()); }