1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-08 05:27:14 +09:00
ladybird/Tests/LibGC/TestInterop.cpp
Andrew Kaster 8554ee386e LibGC: Teach Swift bindings about Cell and Cell::Visitor
Add the proper annotations for the Cell and Cell::Visitor classes to be
visible in Swift. This lets us remove some OpaquePointer shinangians in
the Swift bindings.
2025-04-03 16:47:48 -06:00

44 lines
987 B
C++

/*
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "TestInterop.h"
#include "TestHeap.h"
#include <AK/TypeCasts.h>
#include <LibGC/ForeignCell.h>
#include <LibGC/Heap.h>
#include <TestGCSwift-Swift.h>
#define COLLECT heap.collect_garbage(GC::Heap::CollectionType::CollectGarbage)
#define COLLECT_ALL heap.collect_garbage(GC::Heap::CollectionType::CollectEverything)
void test_interop()
{
auto& heap = test_gc_heap();
COLLECT_ALL;
auto string = GC::ForeignRef<TestGCSwift::HeapString>::allocate(heap, "Hello, World!");
COLLECT;
auto strings_string = std::string(string->getString());
VERIFY(strings_string == "Hello, World!");
COLLECT;
auto* cell = string->getCell();
VERIFY(cell == static_cast<GC::Cell*>(string.cell()));
COLLECT;
strings_string = std::string(string->getString());
COLLECT;
VERIFY(strings_string == "Hello, World!");
COLLECT_ALL;
}