Files
kotlin-fork/kotlin-native/runtime/src/gc/noop/cpp/GCImplTestSupport.cpp
T
Alexander Shabalin 70996035fc [K/N] Move AllocatorImpl.hpp into alloc/ ^KT-60928
- Hide allocator-specific data into Allocator::*::Impl
  like with gc and gcScheduler modules.
- These *::Impl are still owned by specific GCs
- Additionally moved "stateless" allocator APIs into Allocator.hpp
2023-09-01 17:00:59 +00:00

48 lines
1.3 KiB
C++

/*
* Copyright 2010-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the LICENSE file.
*/
#include "GCTestSupport.hpp"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "GCImpl.hpp"
using namespace kotlin;
namespace {
template <typename T>
auto collectCopy(T& iterable) {
std::vector<std::remove_reference_t<decltype(*iterable.begin())>> result;
for (const auto& element : iterable) {
result.push_back(element);
}
return result;
}
template <typename T>
auto collectPointers(T& iterable) {
std::vector<const std::remove_reference_t<decltype(*iterable.begin())>*> result;
for (const auto& element : iterable) {
result.push_back(&element);
}
return result;
}
} // namespace
void gc::AssertClear(GC& gc) noexcept {
#ifdef CUSTOM_ALLOCATOR
auto objects = gc.impl().allocator().heap().GetAllocatedObjects();
EXPECT_THAT(collectCopy(objects), testing::UnorderedElementsAre());
#else
auto objects = gc.impl().allocator().objectFactory().LockForIter();
auto extraObjects = gc.impl().allocator().extraObjectDataFactory().LockForIter();
EXPECT_THAT(collectCopy(objects), testing::UnorderedElementsAre());
EXPECT_THAT(collectPointers(extraObjects), testing::UnorderedElementsAre());
#endif
}