forked from JetBrains/kotlin-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for using multiple Kotlin frameworks in single application
- Loading branch information
1 parent
9180bef
commit 4d7f39b
Showing
7 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
backend.native/tests/framework/multiple/framework1/first.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2010-2019 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. | ||
*/ | ||
|
||
@file:Suppress("UNUSED") | ||
|
||
package multiple | ||
|
||
interface I1 { | ||
fun getFortyTwo(): Int | ||
} | ||
|
||
class I1Impl : I1 { | ||
override fun getFortyTwo(): Int = 42 | ||
} | ||
|
||
class C | ||
|
||
fun getUnit(): Unit? = Unit |
10 changes: 10 additions & 0 deletions
10
backend.native/tests/framework/multiple/framework1/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2010-2019 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. | ||
*/ | ||
|
||
@file:Suppress("UNUSED") | ||
|
||
package multiple | ||
|
||
val name = "first" |
18 changes: 18 additions & 0 deletions
18
backend.native/tests/framework/multiple/framework2/second.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2010-2019 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. | ||
*/ | ||
|
||
@file:Suppress("UNUSED") | ||
|
||
package multiple | ||
|
||
interface I2 { | ||
fun getFortyTwo(): Int | ||
} | ||
|
||
fun getFortyTwoFrom(i2: I2): Int = i2.getFortyTwo() | ||
|
||
class C | ||
|
||
fun isUnit(obj: Any?): Boolean = (obj === Unit) |
10 changes: 10 additions & 0 deletions
10
backend.native/tests/framework/multiple/framework2/test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2010-2019 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. | ||
*/ | ||
|
||
@file:Suppress("UNUSED") | ||
|
||
package multiple | ||
|
||
val name = "second" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2010-2019 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. | ||
*/ | ||
|
||
import First | ||
import Second | ||
|
||
func testClashingNames() throws { | ||
try assertEquals(actual: "first", expected: First.TestKt.name) | ||
try assertEquals(actual: "second", expected: Second.TestKt.name) | ||
|
||
let c1 = First.C() | ||
let c2 = Second.C() | ||
try assertTrue(type(of: c1) == First.C.self) | ||
try assertTrue(type(of: c2) == Second.C.self) | ||
try assertTrue(First.C.self != Second.C.self) | ||
try assertTrue(objc_getClass(class_getName(First.C.self)) as AnyObject === First.C.self) | ||
try assertTrue(objc_getClass(class_getName(Second.C.self)) as AnyObject === Second.C.self) | ||
} | ||
|
||
extension I1Impl : I2 {} | ||
|
||
func testInteraction() throws { | ||
try assertEquals(actual: SecondKt.getFortyTwoFrom(i2: I1Impl()), expected: 42) | ||
} | ||
|
||
func testIsolation() throws { | ||
try assertFalse(SecondKt.isUnit(obj: FirstKt.getUnit())) | ||
|
||
// Ensure frameworks don't share the same runtime (state): | ||
try assertFalse(First.RuntimeState().consumeChange()) | ||
try assertFalse(Second.RuntimeState().consumeChange()) | ||
Second.RuntimeState().produceChange() | ||
try assertFalse(First.RuntimeState().consumeChange()) | ||
try assertTrue(Second.RuntimeState().consumeChange()) | ||
} | ||
|
||
class MultipleFrameworksTests : TestProvider { | ||
var tests: [TestCase] = [] | ||
|
||
init() { | ||
tests = [ | ||
TestCase(name: "TestClashingNames", method: withAutorelease(testClashingNames)), | ||
TestCase(name: "TestInteraction", method: withAutorelease(testInteraction)), | ||
TestCase(name: "TestIsolation", method: withAutorelease(testIsolation)), | ||
] | ||
providers.append(self) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import kotlin.native.concurrent.Worker | ||
|
||
object RuntimeState { | ||
fun produceChange() { | ||
Worker.current.executeAfter {} | ||
} | ||
|
||
fun consumeChange(): Boolean { | ||
return Worker.current.processQueue() | ||
} | ||
} |