Move some tests from boxWithStdlib/ to box/
Move those tests which do not require neither stdlib nor reflect
This commit is contained in:
committed by
Alexander Udalov
parent
54a615fcd3
commit
20e36438e2
@@ -0,0 +1,11 @@
|
||||
// FULL_JDK
|
||||
|
||||
import java.nio.CharBuffer
|
||||
|
||||
fun box(): String {
|
||||
val cb = CharBuffer.wrap("OK")
|
||||
cb.position(1)
|
||||
val o = cb[0]
|
||||
val k = (cb as CharSequence).get(0)
|
||||
return o.toString() + k
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// FULL_JDK
|
||||
|
||||
import sun.nio.cs.ext.Big5
|
||||
import sun.net.spi.nameservice.dns.DNSNameService
|
||||
import javax.crypto.Cipher
|
||||
import com.sun.crypto.provider.SunJCE
|
||||
import sun.nio.ByteBuffered
|
||||
|
||||
fun box(): String {
|
||||
val a = Big5() // charsets.jar
|
||||
val c = DNSNameService() // dnsns.ajr
|
||||
val e : Cipher? = null // jce.jar
|
||||
val f : SunJCE? = null // sunjce_provider.jar
|
||||
val j : ByteBuffered? = null // rt.jar
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// FULL_JDK
|
||||
|
||||
fun box() : String {
|
||||
val processors = Runtime.getRuntime()!!.availableProcessors()
|
||||
var threadNum = 1
|
||||
while(threadNum <= 1024) {
|
||||
if(threadNum < 2 * processors)
|
||||
threadNum += 1
|
||||
else
|
||||
threadNum *= 2
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
fun <T> Int.latch(op: CountDownLatch.() -> T) : T {
|
||||
val cdl = CountDownLatch(this)
|
||||
val res = cdl.op()
|
||||
cdl.await()
|
||||
return res
|
||||
}
|
||||
|
||||
fun id(op : ()->Unit) = op()
|
||||
|
||||
fun box() : String {
|
||||
1.latch{
|
||||
id {
|
||||
countDown()
|
||||
}
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// FULL_JDK
|
||||
|
||||
import java.net.*
|
||||
|
||||
fun String.decodeURI(encoding : String) : String? =
|
||||
try {
|
||||
URLDecoder.decode(this, encoding)
|
||||
}
|
||||
catch (e : Throwable) {
|
||||
null
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
return if("hhh".decodeURI("") == null) "OK" else "fail"
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
// FULL_JDK
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
val defaultGetter: Int = 1
|
||||
external get
|
||||
|
||||
var defaultSetter: Int = 1
|
||||
external get
|
||||
external set
|
||||
}
|
||||
|
||||
val defaultGetter: Int = 1
|
||||
external get
|
||||
|
||||
var defaultSetter: Int = 1
|
||||
external get
|
||||
external set
|
||||
}
|
||||
|
||||
val defaultGetter: Int = 1
|
||||
external get
|
||||
|
||||
var defaultSetter: Int = 1
|
||||
external get
|
||||
external set
|
||||
|
||||
fun check(body: () -> Unit, signature: String): String? {
|
||||
try {
|
||||
body()
|
||||
return "Link error expected"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != signature) return "Fail $signature: " + e.message
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return check({defaultGetter}, "NativePropertyAccessorsKt.getDefaultGetter()I")
|
||||
?: check({defaultSetter = 1}, "NativePropertyAccessorsKt.setDefaultSetter(I)V")
|
||||
|
||||
?: check({C.defaultGetter}, "C\$Companion.getDefaultGetter()I")
|
||||
?: check({C.defaultSetter = 1}, "C\$Companion.setDefaultSetter(I)V")
|
||||
|
||||
?: check({C().defaultGetter}, "C.getDefaultGetter()I")
|
||||
?: check({C().defaultSetter = 1}, "C.setDefaultSetter(I)V")
|
||||
|
||||
?: "OK"
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// FULL_JDK
|
||||
|
||||
package foo
|
||||
|
||||
class WithNative {
|
||||
external fun foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
WithNative().foo()
|
||||
return "Link error expected"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// FULL_JDK
|
||||
|
||||
package foo
|
||||
|
||||
external fun bar(l: Long, s: String): Double
|
||||
|
||||
fun box(): String {
|
||||
var d = 0.0
|
||||
|
||||
try {
|
||||
d = bar(1, "")
|
||||
return "Link error expected on object"
|
||||
}
|
||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
||||
if (e.message != "foo.TopLevelKt.bar(JLjava/lang/String;)D") return "Fail 1: " + e.message
|
||||
}
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
// FULL_JDK
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun box(): String {
|
||||
val a = ArrayList<String>() as AbstractList<String>
|
||||
a.add(null)
|
||||
try {
|
||||
val b: String = a[0]
|
||||
return "Fail: an exception should be thrown"
|
||||
} catch (e: IllegalStateException) {
|
||||
val st = (e as java.lang.Throwable).getStackTrace()
|
||||
if (st.size < 5) {
|
||||
return "Fail: very small stack trace, should at least have current function and JUnit reflective calls: ${Arrays.toString(st)}"
|
||||
}
|
||||
val top = st[0]
|
||||
if (!(top.getClassName() == "PlatformTypeAssertionStackTraceKt" && top.getMethodName() == "box")) {
|
||||
return "Fail: top stack trace element should be PlatformTypeAssertionStackTraceKt.box() from default package, but was $top"
|
||||
}
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// FULL_JDK
|
||||
|
||||
import org.w3c.dom.Element
|
||||
import org.xml.sax.InputSource
|
||||
import javax.xml.parsers.DocumentBuilderFactory
|
||||
import java.io.StringReader
|
||||
|
||||
class MyElement(e: Element): Element by e {
|
||||
fun bar() = "OK"
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
val factory = DocumentBuilderFactory.newInstance()!!;
|
||||
val builder = factory.newDocumentBuilder()!!;
|
||||
val source = InputSource(StringReader("<OK></OK>"));
|
||||
val doc = builder.parse(source)!!;
|
||||
val myElement = MyElement(doc.getDocumentElement()!!)
|
||||
return myElement.getTagName()!!
|
||||
}
|
||||
Reference in New Issue
Block a user