2024-11-16 14:58:28 -07:00
|
|
|
/*
|
|
|
|
|
* 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>
|
2025-03-22 19:01:41 -06:00
|
|
|
#include <TestGCSwift-Swift.h>
|
2024-11-16 14:58:28 -07:00
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
|
2025-03-22 19:01:41 -06:00
|
|
|
auto string = GC::ForeignRef<TestGCSwift::HeapString>::allocate(heap, "Hello, World!");
|
2024-11-16 14:58:28 -07:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|