From c57a0440ece9d22e8a3fccb1e9bcdeca2510336d Mon Sep 17 00:00:00 2001 From: Natalia Ukhorskaya Date: Tue, 2 Jun 2015 13:56:24 +0300 Subject: [PATCH] Test stdlib with dx #KT-7003 Fixed --- .../jetbrains/kotlin/codegen/DxChecker.java | 31 +++++++++---- .../kotlin/codegen/TestStdlibWithDxTest.kt | 44 +++++++++++++++++++ 2 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 compiler/tests/org/jetbrains/kotlin/codegen/TestStdlibWithDxTest.kt diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/DxChecker.java b/compiler/tests/org/jetbrains/kotlin/codegen/DxChecker.java index 356793a2286..46b59286846 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/DxChecker.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/DxChecker.java @@ -21,6 +21,7 @@ import com.android.dx.cf.direct.StdAttributeFactory; import com.android.dx.command.dexer.Main; import com.android.dx.dex.cf.CfTranslator; import com.android.dx.dex.file.DexFile; +import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.junit.Assert; @@ -46,15 +47,7 @@ public class DxChecker { for (OutputFile file : outputFiles.asList()) { try { byte[] bytes = file.asByteArray(); - DirectClassFile cf = new DirectClassFile(bytes, file.getRelativePath(), true); - cf.setAttributeFactory(StdAttributeFactory.THE_ONE); - CfTranslator.translate( - cf, - bytes, - arguments.cfOptions, - arguments.dexOptions, - new DexFile(arguments.dexOptions) - ); + checkFileWithDx(bytes, file.getRelativePath(), arguments); } catch (Throwable e) { Assert.fail(generateExceptionMessage(e)); @@ -62,6 +55,26 @@ public class DxChecker { } } + public static void checkFileWithDx(byte[] bytes, @NotNull String relativePath) { + Main.Arguments arguments = new Main.Arguments(); + String[] array = new String[1]; + array[0] = "testArgs"; + arguments.parse(array); + checkFileWithDx(bytes, relativePath, arguments); + } + + private static void checkFileWithDx(byte[] bytes, @NotNull String relativePath, @NotNull Main.Arguments arguments) { + DirectClassFile cf = new DirectClassFile(bytes, relativePath, true); + cf.setAttributeFactory(StdAttributeFactory.THE_ONE); + CfTranslator.translate( + cf, + bytes, + arguments.cfOptions, + arguments.dexOptions, + new DexFile(arguments.dexOptions) + ); + } + private static String generateExceptionMessage(Throwable e) { StringWriter writer = new StringWriter(); PrintWriter printWriter = new PrintWriter(writer); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/TestStdlibWithDxTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/TestStdlibWithDxTest.kt new file mode 100644 index 00000000000..3dcc09dd98f --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/codegen/TestStdlibWithDxTest.kt @@ -0,0 +1,44 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.codegen + +import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime +import org.junit.Test +import java.io.File +import java.io.FileInputStream +import java.util.zip.ZipInputStream + +public class TestStdlibWithDxTest { + Test public fun testRuntimeWithDx() { + doTest(ForTestCompileRuntime.runtimeJarForTests()) + } + + Test public fun testReflectWithDx() { + doTest(ForTestCompileRuntime.reflectJarForTests()) + } + + private fun doTest(file: File) { + val zip = ZipInputStream(FileInputStream(file)) + zip.use { + sequence { zip.getNextEntry() }.forEach { + if (it.getName().endsWith(".class")) { + DxChecker.checkFileWithDx(zip.readBytes(), it.getName()) + } + } + } + } +}