From a1f6c70355a78c4e16307bcea7e7ae2843689fd6 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 20 Jul 2021 13:56:17 +0700 Subject: [PATCH] [K/N][Runtime] Use the objc module in the unit tests Calling initRuntime requires some machinery from the objc module (e.g. adding the toKotlin method to NSObject). Include this module to the tests to allow full runtime initialization in the tests --- kotlin-native/runtime/build.gradle.kts | 18 ++-- .../test_support/cpp/CompilerGenerated.cpp | 40 +++++++ .../test_support/cpp/CompilerGeneratedObjC.mm | 101 ++++++++++++++++++ 3 files changed, 153 insertions(+), 6 deletions(-) diff --git a/kotlin-native/runtime/build.gradle.kts b/kotlin-native/runtime/build.gradle.kts index ccd13541dc0..af5b43ced70 100644 --- a/kotlin-native/runtime/build.gradle.kts +++ b/kotlin-native/runtime/build.gradle.kts @@ -144,7 +144,8 @@ targetList.forEach { targetName -> "${targetName}LegacyMemoryManager", "${targetName}Strict", "${targetName}Release", - "${targetName}StdAlloc" + "${targetName}StdAlloc", + "${targetName}Objc" ) ) { includeRuntime() @@ -160,7 +161,8 @@ targetList.forEach { targetName -> "${targetName}Strict", "${targetName}Release", "${targetName}Mimalloc", - "${targetName}OptAlloc" + "${targetName}OptAlloc", + "${targetName}Objc" ) ) { includeRuntime() @@ -177,7 +179,8 @@ targetList.forEach { targetName -> "${targetName}SameThreadMsGc", "${targetName}Release", "${targetName}Mimalloc", - "${targetName}OptAlloc" + "${targetName}OptAlloc", + "${targetName}Objc" ) ) { headersDirs += files("src/gc/stms/cpp", "src/gc/common/cpp", "src/mm/cpp") @@ -194,7 +197,8 @@ targetList.forEach { targetName -> "${targetName}CommonGc", "${targetName}SameThreadMsGc", "${targetName}Release", - "${targetName}StdAlloc" + "${targetName}StdAlloc", + "${targetName}Objc" ) ) { headersDirs += files("src/gc/stms/cpp", "src/gc/common/cpp", "src/mm/cpp") @@ -212,7 +216,8 @@ targetList.forEach { targetName -> "${targetName}NoopGc", "${targetName}Release", "${targetName}Mimalloc", - "${targetName}OptAlloc" + "${targetName}OptAlloc", + "${targetName}Objc" ) ) { headersDirs += files("src/gc/noop/cpp", "src/gc/common/cpp", "src/mm/cpp") @@ -229,7 +234,8 @@ targetList.forEach { targetName -> "${targetName}CommonGc", "${targetName}NoopGc", "${targetName}Release", - "${targetName}StdAlloc" + "${targetName}StdAlloc", + "${targetName}Objc" ) ) { headersDirs += files("src/gc/noop/cpp", "src/gc/common/cpp", "src/mm/cpp") diff --git a/kotlin-native/runtime/src/test_support/cpp/CompilerGenerated.cpp b/kotlin-native/runtime/src/test_support/cpp/CompilerGenerated.cpp index 1d2ad8b1d94..a4164f906d3 100644 --- a/kotlin-native/runtime/src/test_support/cpp/CompilerGenerated.cpp +++ b/kotlin-native/runtime/src/test_support/cpp/CompilerGenerated.cpp @@ -272,6 +272,46 @@ extern KBox LONG_CACHE[] = { {{}, 1}, }; +OBJ_GETTER(Kotlin_boxByte, KByte value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxShort, KShort value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxInt, KInt value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxLong, KLong value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxUByte, KUByte value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxUShort, KUShort value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxUInt, KUInt value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxULong, KULong value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxFloat, KFloat value) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_boxDouble, KDouble value) { + throw std::runtime_error("Not implemented for tests"); +} + RUNTIME_NORETURN OBJ_GETTER(Kotlin_Throwable_getMessage, KRef throwable) { throw std::runtime_error("Not implemented for tests"); } diff --git a/kotlin-native/runtime/src/test_support/cpp/CompilerGeneratedObjC.mm b/kotlin-native/runtime/src/test_support/cpp/CompilerGeneratedObjC.mm index 6400daf30d7..f49694f4568 100644 --- a/kotlin-native/runtime/src/test_support/cpp/CompilerGeneratedObjC.mm +++ b/kotlin-native/runtime/src/test_support/cpp/CompilerGeneratedObjC.mm @@ -67,6 +67,107 @@ void Kotlin_ObjCExport_resumeContinuationSuccess(KRef continuation, KRef result) throw std::runtime_error("Not implemented for tests"); } +// Declarations from the "objc" module (see ObjCExportCollections.mm). +OBJ_GETTER0(Kotlin_NSArrayAsKList_create) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER0(Kotlin_NSMutableArrayAsKMutableList_create) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER0(Kotlin_NSSetAsKSet_create) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER0(Kotlin_NSDictionaryAsKMap_create) { + throw std::runtime_error("Not implemented for tests"); +} + +KBoolean Kotlin_Iterator_hasNext(KRef iterator) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_Iterator_next, KRef iterator) { + throw std::runtime_error("Not implemented for tests"); +} + +KInt Kotlin_Collection_getSize(KRef collection) { + throw std::runtime_error("Not implemented for tests"); +} + +KBoolean Kotlin_Set_contains(KRef set, KRef element) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_Set_getElement, KRef set, KRef element) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_Set_iterator, KRef set) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableCollection_removeObject(KRef collection, KRef element) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableCollection_addObject(KRef list, KRef obj) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_MutableSet_createWithCapacity, KInt capacity) { + throw std::runtime_error("Not implemented for tests"); +} + +KInt Kotlin_Map_getSize(KRef map) { + throw std::runtime_error("Not implemented for tests"); +} + +KBoolean Kotlin_Map_containsKey(KRef map, KRef key) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_Map_get, KRef map, KRef key) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_Map_keyIterator, KRef map) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_List_get, KRef list, KInt index) { + throw std::runtime_error("Not implemented for tests"); +} + +OBJ_GETTER(Kotlin_MutableMap_createWithCapacity, KInt capacity) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableMap_set(KRef map, KRef key, KRef value) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableMap_remove(KRef map, KRef key) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableList_addObjectAtIndex(KRef list, KInt index, KRef obj) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableList_removeObjectAtIndex(KRef list, KInt index) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableList_removeLastObject(KRef list) { + throw std::runtime_error("Not implemented for tests"); +} + +void Kotlin_MutableList_setObject(KRef list, KInt index, KRef obj) { + throw std::runtime_error("Not implemented for tests"); +} + } // extern "C" #endif // KONAN_OBJC_INTEROP