backend/tests: Add blackbox tests from Kotlin JVM

Added tests from testData/codegen/box directory. There are blackbox tests
in other directories and they are to be added.
This commit is contained in:
Ilya Matveev
2017-01-12 19:43:20 +07:00
parent d5988297b1
commit 1b553ebfaf
2643 changed files with 66666 additions and 0 deletions
@@ -0,0 +1,37 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
private object NotEmptyMap : MutableMap<Any, Int> {
override fun containsKey(key: Any): Boolean = true
override fun containsValue(value: Int): Boolean = true
// non-special bridges get(Object)Integer -> get(Object)I
override fun get(key: Any): Int = 1
override fun remove(key: Any): Int = 1
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun put(key: Any, value: Int): Int? = throw UnsupportedOperationException()
override fun putAll(from: Map<out Any, Int>): Unit = throw UnsupportedOperationException()
override fun clear(): Unit = throw UnsupportedOperationException()
override val entries: MutableSet<MutableMap.MutableEntry<Any, Int>> get() = null!!
override val keys: MutableSet<Any> get() = null!!
override val values: MutableCollection<Int> get() = null!!
}
fun box(): String {
val n = NotEmptyMap as MutableMap<Any?, Any?>
if (n.get(null) != null) return "fail 1"
if (n.containsKey(null)) return "fail 2"
if (n.containsValue(null)) return "fail 3"
if (n.remove(null) != null) return "fail 4"
if (n.get(1) == null) return "fail 5"
if (!n.containsKey("")) return "fail 6"
if (!n.containsValue(3)) return "fail 7"
if (n.remove("") == null) return "fail 8"
return "OK"
}
@@ -0,0 +1,104 @@
interface A0 {
val size: Int get() = 56
}
class B0 : Collection<String>, A0 {
override fun isEmpty() = throw UnsupportedOperationException()
override fun contains(o: String) = throw UnsupportedOperationException()
override fun iterator() = throw UnsupportedOperationException()
override fun containsAll(c: Collection<String>) = throw UnsupportedOperationException()
override val size: Int
get() = super.size
}
open class A1 {
val size: Int = 56
}
class B1 : Collection<String>, A1() {
override fun isEmpty() = throw UnsupportedOperationException()
override fun contains(o: String) = throw UnsupportedOperationException()
override fun iterator() = throw UnsupportedOperationException()
override fun containsAll(c: Collection<String>) = throw UnsupportedOperationException()
}
interface I2 {
val size: Int
}
val list = ArrayList<String>()
class B2 : ArrayList<String>(list), I2
interface I3<T> {
val size: T
}
class B3 : ArrayList<String>(list), I3<Int>
interface I4<T> {
val size: T get() = 56 as T
}
class B4 : Collection<String>, I4<Int> {
override fun isEmpty() = throw UnsupportedOperationException()
override fun contains(o: String) = throw UnsupportedOperationException()
override fun iterator() = throw UnsupportedOperationException()
override fun containsAll(c: Collection<String>) = throw UnsupportedOperationException()
override val size: Int
get() = super.size
}
interface I5 : Collection<String> {
override val size: Int get() = 56
}
class B5 : I5 {
override fun isEmpty() = throw UnsupportedOperationException()
override fun contains(o: String) = throw UnsupportedOperationException()
override fun iterator() = throw UnsupportedOperationException()
override fun containsAll(c: Collection<String>) = throw UnsupportedOperationException()
}
fun box(): String {
list.add("1")
val b0 = B0()
if (b0.size != 56) return "fail 0: ${b0.size}"
var x: Collection<String> = B0()
if (x.size != 56) return "fail 00: ${x.size}"
val a0: A0 = b0
if (a0.size != 56) return "fail 000: ${a0.size}"
val b1 = B1()
if (b1.size != 56) return "fail 1: ${b1.size}"
x = B1()
if (x.size != 56) return "fail 2: ${x.size}"
val b2 = B2()
if (b2.size != 1) return "fail 3: ${b2.size}"
x = B2()
if (x.size != 1) return "fail 4: ${x.size}"
val i2: I2 = b2
if (i2.size != 1) return "fail 5: ${i2.size}"
val b3 = B3()
if (b3.size != 1) return "fail 6: ${b3.size}"
x = B3()
if (x.size != 1) return "fail 7: ${x.size}"
val i3: I3<Int> = b3
if (i3.size != 1) return "fail 8: ${i3.size}"
val b4 = B4()
if (b4.size != 56) return "fail 9: ${b4.size}"
x = B4()
if (x.size != 56) return "fail 10: ${x.size}"
val b5 = B5()
if (b5.size != 56) return "fail 11: ${b5.size}"
x = B5()
if (x.size != 56) return "fail 12: ${x.size}"
return "OK"
}
@@ -0,0 +1,97 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
class A1 : MutableCollection<String> {
override val size: Int
get() = 56
override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}
override fun contains(o: String): Boolean {
throw UnsupportedOperationException()
}
override fun iterator(): MutableIterator<String> {
throw UnsupportedOperationException()
}
override fun containsAll(c: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun add(e: String): Boolean {
throw UnsupportedOperationException()
}
override fun remove(o: String): Boolean {
throw UnsupportedOperationException()
}
override fun addAll(c: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun removeAll(c: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun retainAll(c: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun clear() {
throw UnsupportedOperationException()
}
}
class A2 : java.util.AbstractCollection<String>() {
override val size: Int
get() = 56
override fun iterator(): MutableIterator<String> {
throw UnsupportedOperationException()
}
}
class A3 : java.util.ArrayList<String>() {
override val size: Int
get() = 56
}
interface Sized {
val size: Int
}
class A4 : java.util.ArrayList<String>(), Sized {
override val size: Int
get() = 56
}
fun check56(x: Collection<String>) {
if (x.size != 56) throw java.lang.RuntimeException("fail ${x.size}")
}
fun box(): String {
val a1 = A1()
if (a1.size != 56) return "fail 1: ${a1.size}"
check56(a1)
val a2 = A2()
if (a2.size != 56) return "fail 2: ${a2.size}"
check56(a2)
val a3 = A3()
if (a3.size != 56) return "fail 3: ${a3.size}"
check56(a3)
val a4 = A4()
if (a4.size != 56) return "fail 4: ${a4.size}"
check56(a4)
val sized: Sized = a4
if (sized.size != 56) return "fail 5: ${a4.size}"
return "OK"
}
@@ -0,0 +1,25 @@
open class Base<Target : DatabaseEntity>() : HashSet<Target>() {
override fun remove(element: Target): Boolean {
return true
}
}
class Derived : Base<Issue>() {
// common "synthetic bridge override fun remove(element: DatabaseEntity): Boolean" should call
// `INVOKEVIRTUAL remove(Issue)`
// instead of `INVOKEVIRTUAL remove(OBJECT)`
override fun remove(element: Issue): Boolean {
return super.remove(element)
}
}
open class DatabaseEntity
class Issue: DatabaseEntity()
fun box(): String {
val sprintIssues = Derived()
if (!sprintIssues.remove(Issue())) return "Fail"
return "OK"
}
@@ -0,0 +1,34 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
private object EmptyList : List<Nothing> {
override fun contains(element: Nothing): Boolean = false
override fun containsAll(elements: Collection<Nothing>): Boolean = elements.isEmpty()
override fun indexOf(element: Nothing): Int = -2
override fun lastIndexOf(element: Nothing): Int = -2
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun iterator(): Iterator<Nothing> = throw UnsupportedOperationException()
override fun get(index: Int): Nothing = throw UnsupportedOperationException()
override fun listIterator(): ListIterator<Nothing> = throw UnsupportedOperationException()
override fun listIterator(index: Int): ListIterator<Nothing> = throw UnsupportedOperationException()
override fun subList(fromIndex: Int, toIndex: Int): List<Nothing> = throw UnsupportedOperationException()
}
fun box(): String {
val n = EmptyList as List<String>
if (n.contains("")) return "fail 1"
if (n.indexOf("") != -1) return "fail 2"
if (n.lastIndexOf("") != -1) return "fail 3"
val nullAny = EmptyList as List<Any?>
if (nullAny.contains(null)) return "fail 4"
if (nullAny.indexOf(null) != -1) return "fail 5"
if (nullAny.lastIndexOf(null) != -1) return "fail 6"
return "OK"
}
@@ -0,0 +1,22 @@
private object EmptyMap : Map<Any, Nothing> {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun containsKey(key: Any): Boolean = false
override fun containsValue(value: Nothing): Boolean = false
override fun get(key: Any): Nothing? = null
override val entries: Set<Map.Entry<String, Nothing>> get() = null!!
override val keys: Set<String> get() = null!!
override val values: Collection<Nothing> get() = null!!
}
fun box(): String {
val n = EmptyMap as Map<Any?, Any?>
if (n.get(null) != null) return "fail 1"
if (n.containsKey(null)) return "fail 2"
if (n.containsValue(null)) return "fail 3"
return "OK"
}
@@ -0,0 +1,21 @@
private object EmptyStringMap : Map<String, Nothing> {
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun containsKey(key: String): Boolean = false
override fun containsValue(value: Nothing): Boolean = false
override fun get(key: String): Nothing? = null
override val entries: Set<Map.Entry<String, Nothing>> get() = null!!
override val keys: Set<String> get() = null!!
override val values: Collection<Nothing> get() = null!!
}
fun box(): String {
val n = EmptyStringMap as Map<Any?, Any?>
if (n.get(null) != null) return "fail 1"
if (n.containsKey(null)) return "fail 2"
if (n.containsValue(null)) return "fail 3"
return "OK"
}
@@ -0,0 +1,14 @@
open class Map1 : HashMap<String, Any?>()
class Map2 : Map1()
fun box(): String {
val m = Map2()
if (m.entries.size != 0) return "fail 1"
m.put("56", "OK")
val x = m.entries.iterator().next()
if (x.key != "56" || x.value != "OK") return "fail 2"
return "OK"
}
@@ -0,0 +1,16 @@
interface Ordinaled {
val ordinal: Int
}
enum class A : Ordinaled {
X
}
fun box(): String {
val result = (A.X as Ordinaled).ordinal
if (result != 0) return "fail 1: $result"
return "OK"
}
@@ -0,0 +1,10 @@
class A : ArrayList<String>() {
override val size: Int get() = super.size + 56
}
fun box(): String {
val a = A()
if (a.size != 56) return "fail: ${a.size}"
return "OK"
}
@@ -0,0 +1,104 @@
interface Container {
fun removeAt(x: Int): String
}
open class ContainerImpl : Container {
override fun removeAt(x: Int) = "abc"
}
class A : ContainerImpl(), MutableList<String> {
override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}
override val size: Int
get() = throw UnsupportedOperationException()
override fun contains(element: String): Boolean {
throw UnsupportedOperationException()
}
override fun containsAll(elements: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun get(index: Int): String {
throw UnsupportedOperationException()
}
override fun indexOf(element: String): Int {
throw UnsupportedOperationException()
}
override fun lastIndexOf(element: String): Int {
throw UnsupportedOperationException()
}
override fun add(element: String): Boolean {
throw UnsupportedOperationException()
}
override fun remove(element: String): Boolean {
throw UnsupportedOperationException()
}
override fun addAll(elements: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun addAll(index: Int, elements: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun removeAll(elements: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun retainAll(elements: Collection<String>): Boolean {
throw UnsupportedOperationException()
}
override fun clear() {
throw UnsupportedOperationException()
}
override fun set(index: Int, element: String): String {
throw UnsupportedOperationException()
}
override fun add(index: Int, element: String) {
throw UnsupportedOperationException()
}
override fun listIterator(): MutableListIterator<String> {
throw UnsupportedOperationException()
}
override fun listIterator(index: Int): MutableListIterator<String> {
throw UnsupportedOperationException()
}
override fun subList(fromIndex: Int, toIndex: Int): MutableList<String> {
throw UnsupportedOperationException()
}
override fun iterator(): MutableIterator<String> {
throw UnsupportedOperationException()
}
}
fun box(): String {
val a = A()
if (a.removeAt(0) != "abc") return "fail 1"
val l: MutableList<String> = a
if (l.removeAt(0) != "abc") return "fail 2"
val anyList: MutableList<Any?> = a as MutableList<Any?>
if (anyList.removeAt(0) != "abc") return "fail 3"
val container: Container = a
if (container.removeAt(0) != "abc") return "fail 4"
return "OK"
}
@@ -0,0 +1,41 @@
class A : Map<String, String> {
override val size: Int get() = 56
override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}
override fun containsKey(key: String): Boolean {
throw UnsupportedOperationException()
}
override fun containsValue(value: String): Boolean {
throw UnsupportedOperationException()
}
override fun get(key: String): String? {
throw UnsupportedOperationException()
}
override val keys: Set<String> get() {
throw UnsupportedOperationException()
}
override val values: Collection<String> get() {
throw UnsupportedOperationException()
}
override val entries: Set<Map.Entry<String, String>> get() {
throw UnsupportedOperationException()
}
}
fun box(): String {
val a = A()
if (a.size != 56) return "fail 1: ${a.size}"
val x: Map<String, String> = a
if (x.size != 56) return "fail 2: ${x.size}"
return "OK"
}
@@ -0,0 +1,59 @@
var result = ""
public abstract class AbstractFoo<K, V> : Map<K, V> {
override operator fun get(key: K): V? {
result = "AbstractFoo"
return null
}
override val size: Int
get() = throw UnsupportedOperationException()
override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}
override fun containsKey(key: K): Boolean {
throw UnsupportedOperationException()
}
override fun containsValue(value: V): Boolean {
throw UnsupportedOperationException()
}
override val keys: Set<K>
get() = throw UnsupportedOperationException()
override val values: Collection<V>
get() = throw UnsupportedOperationException()
override val entries: Set<Map.Entry<K, V>>
get() = throw UnsupportedOperationException()
}
public open class StringFoo<E> : AbstractFoo<String, E>() {
override operator fun get(key: String): E? {
result = "StringFoo"
return null
}
}
public class IntFoo<E> : AbstractFoo<Int, E>() {
override operator fun get(key: Int): E? {
result = "IntFoo"
return null
}
}
public class AnyFoo<E> : AbstractFoo<Any?, E>() {}
fun box(): String {
StringFoo<String>().get("")
if (result != "StringFoo") return "fail 1: $result"
IntFoo<String>().get(1)
if (result != "IntFoo") return "fail 2: $result"
AnyFoo<String>().get(null)
if (result != "AbstractFoo") return "fail 3: $result"
return "OK"
}
@@ -0,0 +1,46 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
private object NotEmptyList : MutableList<Any> {
override fun contains(element: Any): Boolean = true
override fun indexOf(element: Any): Int = 0
override fun lastIndexOf(element: Any): Int = 0
override fun remove(element: Any): Boolean = true
override val size: Int
get() = throw UnsupportedOperationException()
override fun containsAll(elements: Collection<Any>): Boolean = elements.isEmpty()
override fun isEmpty(): Boolean = throw UnsupportedOperationException()
override fun get(index: Int): Any = throw UnsupportedOperationException()
override fun add(element: Any): Boolean = throw UnsupportedOperationException()
override fun addAll(elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
override fun addAll(index: Int, elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
override fun removeAll(elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
override fun retainAll(elements: Collection<Any>): Boolean = throw UnsupportedOperationException()
override fun clear(): Unit = throw UnsupportedOperationException()
override fun set(index: Int, element: Any): Any = throw UnsupportedOperationException()
override fun add(index: Int, element: Any): Unit = throw UnsupportedOperationException()
override fun removeAt(index: Int): Any = throw UnsupportedOperationException()
override fun listIterator(): MutableListIterator<Any> = throw UnsupportedOperationException()
override fun listIterator(index: Int): MutableListIterator<Any> = throw UnsupportedOperationException()
override fun subList(fromIndex: Int, toIndex: Int): MutableList<Any> = throw UnsupportedOperationException()
override fun iterator(): MutableIterator<Any> = throw UnsupportedOperationException()
}
fun box(): String {
val n = NotEmptyList as MutableList<Any?>
if (n.contains(null)) return "fail 1"
if (n.indexOf(null) != -1) return "fail 2"
if (n.lastIndexOf(null) != -1) return "fail 3"
if (!n.contains("")) return "fail 3"
if (n.indexOf("") != 0) return "fail 4"
if (n.lastIndexOf("") != 0) return "fail 5"
if (n.remove(null)) return "fail 6"
if (!n.remove("")) return "fail 7"
return "OK"
}
@@ -0,0 +1,35 @@
// TODO: muted automatically, investigate should it be ran for JS or not
// IGNORE_BACKEND: JS
private object NotEmptyMap : MutableMap<Any, Any> {
override fun containsKey(key: Any): Boolean = true
override fun containsValue(value: Any): Boolean = true
override fun get(key: Any): Any? = Any()
override fun remove(key: Any): Any? = Any()
override val size: Int get() = 0
override fun isEmpty(): Boolean = true
override fun put(key: Any, value: Any): Any? = throw UnsupportedOperationException()
override fun putAll(from: Map<out Any, Any>): Unit = throw UnsupportedOperationException()
override fun clear(): Unit = throw UnsupportedOperationException()
override val entries: MutableSet<MutableMap.MutableEntry<Any, Any>> get() = null!!
override val keys: MutableSet<Any> get() = null!!
override val values: MutableCollection<Any> get() = null!!
}
fun box(): String {
val n = NotEmptyMap as MutableMap<Any?, Any?>
if (n.get(null) != null) return "fail 1"
if (n.containsKey(null)) return "fail 2"
if (n.containsValue(null)) return "fail 3"
if (n.remove(null) != null) return "fail 4"
if (n.get("") == null) return "fail 5"
if (!n.containsKey("")) return "fail 6"
if (!n.containsValue("")) return "fail 7"
if (n.remove("") == null) return "fail 8"
return "OK"
}
@@ -0,0 +1,28 @@
open class A1 {
open val size: Int = 56
}
class A2 : A1(), Collection<String> {
// No 'getSize()' method should be generated in A2
override fun contains(element: String): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun containsAll(elements: Collection<String>): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun isEmpty(): Boolean {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun iterator(): Iterator<String> {
throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
fun box(): String {
if (A2().size != 56) return "fail 1"
return "OK"
}
@@ -0,0 +1,96 @@
open class A0<E> : MutableList<E> {
override fun add(element: E): Boolean {
throw UnsupportedOperationException()
}
override fun add(index: Int, element: E) {
throw UnsupportedOperationException()
}
override fun addAll(index: Int, elements: Collection<E>): Boolean {
throw UnsupportedOperationException()
}
override fun addAll(elements: Collection<E>): Boolean {
throw UnsupportedOperationException()
}
override fun clear() {
throw UnsupportedOperationException()
}
override fun listIterator(): MutableListIterator<E> {
throw UnsupportedOperationException()
}
override fun listIterator(index: Int): MutableListIterator<E> {
throw UnsupportedOperationException()
}
override fun remove(element: E): Boolean {
throw UnsupportedOperationException()
}
override fun removeAll(elements: Collection<E>): Boolean {
throw UnsupportedOperationException()
}
override fun removeAt(index: Int): E = "K" as E
override fun retainAll(elements: Collection<E>): Boolean {
throw UnsupportedOperationException()
}
override fun set(index: Int, element: E): E {
throw UnsupportedOperationException()
}
override fun subList(fromIndex: Int, toIndex: Int): MutableList<E> {
throw UnsupportedOperationException()
}
override val size: Int
get() = throw UnsupportedOperationException()
override fun contains(element: E): Boolean {
throw UnsupportedOperationException()
}
override fun containsAll(elements: Collection<E>): Boolean {
throw UnsupportedOperationException()
}
override fun get(index: Int): E {
throw UnsupportedOperationException()
}
override fun indexOf(element: E): Int {
throw UnsupportedOperationException()
}
override fun isEmpty(): Boolean {
throw UnsupportedOperationException()
}
override fun lastIndexOf(element: E): Int {
throw UnsupportedOperationException()
}
override fun iterator(): MutableIterator<E> {
throw UnsupportedOperationException()
}
}
class A1() : A0<String>() {
override fun removeAt(p0: Int): String = "O"
}
class A2 : A0<String>()
// Basically this test checks that no redundant special bridges were generated (i.e. no VerifyError happens)
fun box(): String {
val a1 = A1()
val a2 = A2()
return a1.removeAt(123) + a2.removeAt(456)
}
@@ -0,0 +1,10 @@
fun box(): String {
try {
throw Throwable("OK", null)
} catch (t: Throwable) {
if (t.cause != null) return "fail 1"
return t.message!!
}
return "fail 2"
}
@@ -0,0 +1,21 @@
class MyThrowable(message: String? = null, cause: Throwable? = null) : Throwable(message, cause) {
override val message: String?
get() = "My message: " + super.message
override val cause: Throwable?
get() = super.cause ?: this
}
fun box(): String {
try {
throw MyThrowable("test")
} catch (t: MyThrowable) {
if (t.cause != t) return "fail t.cause"
if (t.message != "My message: test") return "fail t.message"
return "OK"
}
return "fail: MyThrowable wasn't catched."
}
@@ -0,0 +1,8 @@
enum class Variants {
O, K;
companion object {
val valueStr = values()[0].name + Variants.values()[1].name
}
}
fun box() = Variants.valueStr