diff --git a/compiler/testData/android/converter/simple/singleFile/MyActivity.kt b/compiler/testData/android/converter/simple/singleFile/MyActivity.kt deleted file mode 100644 index 3d61c9fb897..00000000000 --- a/compiler/testData/android/converter/simple/singleFile/MyActivity.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.myapp - -import android.app.Activity -import android.view.View -import android.widget.* - -class MyActivity(): Activity() { - val textViewWidget = TextView() - val editTextWidget = EditText() - val buttonWidget = Button() - - override fun findViewById(id: Int): View? { - return when (id) { - R.id.textView1 -> textViewWidget - R.id.password -> editTextWidget - R.id.login -> buttonWidget - else -> null - } - } - - fun test(): String { - return if (password.toString() == "EditText" && - textView1.toString() == "TextView" && - login.toString() == "Button" ) - "OK" else "NOTOK" - } -} \ No newline at end of file diff --git a/compiler/testData/android/converter/simple/singleFile/R.kt b/compiler/testData/android/converter/simple/singleFile/R.kt deleted file mode 100644 index 3e9f1eb1b9f..00000000000 --- a/compiler/testData/android/converter/simple/singleFile/R.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.myapp - -class R { - class id { - class object { - val item_detail_container = 0 - val textView1 = 1 - val password = 2 - val textView2 = 3 - val passwordConfirmation = 4 - val login = 5 - } - } -} \ No newline at end of file diff --git a/compiler/testData/codegen/android/FakeActivity.kt b/compiler/testData/codegen/android/FakeActivity.kt new file mode 100644 index 00000000000..0c1c5236a95 --- /dev/null +++ b/compiler/testData/codegen/android/FakeActivity.kt @@ -0,0 +1,8 @@ +package android.app + +import android.view.View +import android.content.Context + +abstract class Activity: Context { + abstract fun findViewById(id: Int): View? +} diff --git a/compiler/testData/codegen/android/FakeContext.kt b/compiler/testData/codegen/android/FakeContext.kt new file mode 100644 index 00000000000..1fe9df2d12f --- /dev/null +++ b/compiler/testData/codegen/android/FakeContext.kt @@ -0,0 +1,3 @@ +package android.content + +trait Context diff --git a/compiler/testData/codegen/android/FakeView.kt b/compiler/testData/codegen/android/FakeView.kt new file mode 100644 index 00000000000..8a4dc0f9577 --- /dev/null +++ b/compiler/testData/codegen/android/FakeView.kt @@ -0,0 +1,5 @@ +package android.view + +import android.content.Context + +open class View(ctx: Context) diff --git a/compiler/testData/codegen/android/FakeWidgets.kt b/compiler/testData/codegen/android/FakeWidgets.kt new file mode 100644 index 00000000000..65aea060728 --- /dev/null +++ b/compiler/testData/codegen/android/FakeWidgets.kt @@ -0,0 +1,11 @@ +package android.widget + +import android.view.View +import android.content.Context + +open class Button(ctx: Context): View(ctx) {override fun toString() = "Button"} +open class EditText(ctx: Context): View(ctx) {override fun toString() = "EditText"} +open class TextView(ctx: Context): View(ctx) {override fun toString() = "TextView"} +open class FrameLayout(ctx: Context): View(ctx) {override fun toString() = "FrameLayout"} +open class RelativeLayout(ctx: Context): View(ctx) {override fun toString() = "RelativeLayout"} +open class ImageView(ctx: Context): View(ctx) {override fun toString() = "ImageView"} diff --git a/compiler/testData/codegen/android/fqNameInAttr/0.kt b/compiler/testData/codegen/android/fqNameInAttr/0.kt new file mode 100644 index 00000000000..bd9ef5426c0 --- /dev/null +++ b/compiler/testData/codegen/android/fqNameInAttr/0.kt @@ -0,0 +1,33 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* +import org.my.cool.MyButton + +class R { + class id { + class object { + val login = 5 + } + } +} + +class MyActivity(): Activity() { + val buttonWidget = MyButton(this) + + override fun findViewById(id: Int): View? { + return when (id) { + R.id.login -> buttonWidget + else -> null + } + } + + public fun box(): String { + return if (login.toString() == "MyButton") "OK" else "" + } +} + +fun box(): String { + return MyActivity().box() +} diff --git a/compiler/testData/codegen/android/fqNameInAttr/CustomWidgets.kt b/compiler/testData/codegen/android/fqNameInAttr/CustomWidgets.kt index cf15bfe703e..273ca931899 100644 --- a/compiler/testData/codegen/android/fqNameInAttr/CustomWidgets.kt +++ b/compiler/testData/codegen/android/fqNameInAttr/CustomWidgets.kt @@ -4,5 +4,5 @@ import android.widget.Button import android.app.Activity class MyButton(ctx: Activity): Button(ctx) { - override fun toString(): String {return "Button"} + override fun toString(): String {return "MyButton"} } diff --git a/compiler/testData/codegen/android/fqNameInTag/0.kt b/compiler/testData/codegen/android/fqNameInTag/0.kt new file mode 100644 index 00000000000..bd9ef5426c0 --- /dev/null +++ b/compiler/testData/codegen/android/fqNameInTag/0.kt @@ -0,0 +1,33 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* +import org.my.cool.MyButton + +class R { + class id { + class object { + val login = 5 + } + } +} + +class MyActivity(): Activity() { + val buttonWidget = MyButton(this) + + override fun findViewById(id: Int): View? { + return when (id) { + R.id.login -> buttonWidget + else -> null + } + } + + public fun box(): String { + return if (login.toString() == "MyButton") "OK" else "" + } +} + +fun box(): String { + return MyActivity().box() +} diff --git a/compiler/testData/codegen/android/fqNameInTag/1.kt b/compiler/testData/codegen/android/fqNameInTag/1.kt index 9f597fb6c3e..d7202aa8c72 100644 --- a/compiler/testData/codegen/android/fqNameInTag/1.kt +++ b/compiler/testData/codegen/android/fqNameInTag/1.kt @@ -14,7 +14,7 @@ class R { } class MyActivity(): Activity() { - val buttonWidget = Button(this) + val buttonWidget = MyButton(this) override fun findViewById(id: Int): View? { return when (id) { diff --git a/compiler/testData/codegen/android/fqNameInTag/CustomWidgets.kt b/compiler/testData/codegen/android/fqNameInTag/CustomWidgets.kt index 59c3b9ff5be..ddd174f0bc7 100644 --- a/compiler/testData/codegen/android/fqNameInTag/CustomWidgets.kt +++ b/compiler/testData/codegen/android/fqNameInTag/CustomWidgets.kt @@ -4,5 +4,5 @@ import android.widget.Button import android.content.Context class MyButton(ctx: Context): Button(ctx) { - override fun toString(): String {return "Button"} + override fun toString(): String {return "MyButton"} } diff --git a/compiler/testData/codegen/android/multiFile/0.kt b/compiler/testData/codegen/android/multiFile/0.kt new file mode 100644 index 00000000000..05a1550c321 --- /dev/null +++ b/compiler/testData/codegen/android/multiFile/0.kt @@ -0,0 +1,57 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* + +class R { + class id { + class object { + val item_detail_container = 0 + val textView1 = 1 + val password = 2 + val textView2 = 3 + val passwordConfirmation = 4 + val login = 5 + val passwordField = 6 + val passwordCaption = 7 + val loginButton = 8 + } + } +} + +class MyActivity(): Activity() { + val textViewWidget = TextView(this) + val editTextWidget = EditText(this) + val buttonWidget = Button(this) + val textViewWidget2 = TextView(this) + val editTextWidget2 = EditText(this) + val buttonWidget2 = Button(this) + + override fun findViewById(id: Int): View? { + return when (id) { + R.id.textView1 -> textViewWidget + R.id.password -> editTextWidget + R.id.login -> buttonWidget + R.id.passwordField -> textViewWidget2 + R.id.passwordCaption -> editTextWidget2 + R.id.loginButton -> buttonWidget2 + else -> null + } + } + + + public fun box(): String{ + return if (textView1.toString() == "TextView" && + password.toString() == "EditText" && + login.toString() == "Button" && + passwordField.toString() == "TextView" && + passwordCaption.toString() == "EditText" && + loginButton.toString() == "Button") + "OK" else "" + } +} + +fun box(): String { + return MyActivity().box() +} diff --git a/compiler/testData/codegen/android/singleFile/0.kt b/compiler/testData/codegen/android/singleFile/0.kt new file mode 100644 index 00000000000..d6d69263b8d --- /dev/null +++ b/compiler/testData/codegen/android/singleFile/0.kt @@ -0,0 +1,44 @@ +package com.myapp + +import android.app.Activity +import android.view.View +import android.widget.* + +class R { + class id { + class object { + val item_detail_container = 0 + val textView1 = 1 + val password = 2 + val textView2 = 3 + val passwordConfirmation = 4 + val login = 5 + } + } +} + +class MyActivity(): Activity() { + val textViewWidget = TextView(this) + val editTextWidget = EditText(this) + val buttonWidget = Button(this) + + override fun findViewById(id: Int): View? { + return when (id) { + R.id.textView1 -> textViewWidget + R.id.password -> editTextWidget + R.id.login -> buttonWidget + else -> null + } + } + + public fun box(): String{ + return if (textView1.toString() == "TextView" && + password.toString() == "EditText" && + login.toString() == "Button") + "OK" else "" + } +} + +fun box(): String { + return MyActivity().box() +} diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/android/AbstractAndroidBoxTest.kt b/compiler/tests/org/jetbrains/jet/lang/resolve/android/AbstractAndroidBoxTest.kt index e3513cb0f44..75d1aa0e127 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/android/AbstractAndroidBoxTest.kt +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/android/AbstractAndroidBoxTest.kt @@ -18,7 +18,6 @@ package org.jetbrains.jet.lang.resolve.android import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest import org.jetbrains.jet.ConfigurationKind -import com.intellij.compiler.CompilerConfiguration import org.jetbrains.jet.TestJdkKind import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment @@ -30,30 +29,62 @@ import java.io.File import java.util.ArrayList import com.intellij.util.Processor import org.jetbrains.jet.codegen.CodegenTestFiles +import java.util.regex.Pattern +import org.jetbrains.jet.config.CompilerConfiguration public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() { - fun createEnvironment(path: String) { - val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API); + private fun createAndroidAPIEnvironment(path: String) { + return createEnvironmentForConfiguration(JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API), path) + } + + private fun createFakeAndroidEnvironment(path: String) { + return createEnvironmentForConfiguration(JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK), path) + } + + private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) { configuration.put(JVMConfigurationKeys.ANDROID_RES_PATH, path + "layout/"); configuration.put(JVMConfigurationKeys.ANDROID_MANIFEST, path + "AndroidManifest.xml"); myEnvironment = JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration); } - override fun doTest(path: String) { - createEnvironment(path) + public fun doCompileAgainstAndroidSdkTest(path: String) { + createAndroidAPIEnvironment(path) + doMultiFileTest(path) + } + + public fun doFakeInvocationTest(path: String) { + if (needsInvocationTest(path)) { + createFakeAndroidEnvironment(path) + doMultiFileTest(path, getFakeFiles(path)) + } + } + + private fun getFakeFiles(path: String): Collection { + return FileUtil.findFilesByMask(Pattern.compile("^Fake.*\\.kt$"), File(path.replace(getTestName(true), ""))) map { relativePath(it) } + } + + private fun needsInvocationTest(path: String): Boolean { + return !FileUtil.findFilesByMask(Pattern.compile("^0.kt$"), File(path)).empty + } + + private fun doMultiFileTest(path: String, additionalFiles: Collection? = null) { val files = ArrayList(2) FileUtil.processFilesRecursively(File(path), object : Processor { override fun process(file: File?): Boolean { - if (file!!.getName().endsWith(".kt")) { - files.add(relativePath(file)) + when (file!!.getName()) { + "1.kt" -> { if (additionalFiles == null) files.add(relativePath(file)) } + "0.kt" -> { if (additionalFiles != null) files.add(relativePath(file)) } + else -> { if (file.getName().endsWith(".kt")) files.add(relativePath(file)) } } return true } }) Collections.sort(files); + if (additionalFiles != null) { + files.addAll(additionalFiles) + } myFiles = CodegenTestFiles.create(myEnvironment!!.getProject(), ArrayUtil.toStringArray(files)) blackBox(); } - } diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidBoxTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidBoxTestGenerated.java index 40545700c9a..d0d22c22e14 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidBoxTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/android/AndroidBoxTestGenerated.java @@ -30,35 +30,78 @@ import org.jetbrains.jet.lang.resolve.android.AbstractAndroidBoxTest; /** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") -@TestMetadata("compiler/testData/codegen/android") +@InnerTestClasses({AndroidBoxTestGenerated.Android.class, AndroidBoxTestGenerated.Invoke.class}) public class AndroidBoxTestGenerated extends AbstractAndroidBoxTest { - public void testAllFilesPresentInAndroid() throws Exception { - JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/android"), Pattern.compile("^([^\\.]+)$"), false); + @TestMetadata("compiler/testData/codegen/android") + public static class Android extends AbstractAndroidBoxTest { + public void testAllFilesPresentInAndroid() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/android"), Pattern.compile("^([^\\.]+)$"), false); + } + + @TestMetadata("fqNameInAttr") + public void testFqNameInAttr() throws Exception { + doCompileAgainstAndroidSdkTest("compiler/testData/codegen/android/fqNameInAttr/"); + } + + @TestMetadata("fqNameInTag") + public void testFqNameInTag() throws Exception { + doCompileAgainstAndroidSdkTest("compiler/testData/codegen/android/fqNameInTag/"); + } + + @TestMetadata("manyWidgets") + public void testManyWidgets() throws Exception { + doCompileAgainstAndroidSdkTest("compiler/testData/codegen/android/manyWidgets/"); + } + + @TestMetadata("multiFile") + public void testMultiFile() throws Exception { + doCompileAgainstAndroidSdkTest("compiler/testData/codegen/android/multiFile/"); + } + + @TestMetadata("singleFile") + public void testSingleFile() throws Exception { + doCompileAgainstAndroidSdkTest("compiler/testData/codegen/android/singleFile/"); + } + } - @TestMetadata("fqNameInAttr") - public void testFqNameInAttr() throws Exception { - doTest("compiler/testData/codegen/android/fqNameInAttr/"); + @TestMetadata("compiler/testData/codegen/android") + public static class Invoke extends AbstractAndroidBoxTest { + public void testAllFilesPresentInInvoke() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/android"), Pattern.compile("^([^\\.]+)$"), false); + } + + @TestMetadata("fqNameInAttr") + public void testFqNameInAttr() throws Exception { + doFakeInvocationTest("compiler/testData/codegen/android/fqNameInAttr/"); + } + + @TestMetadata("fqNameInTag") + public void testFqNameInTag() throws Exception { + doFakeInvocationTest("compiler/testData/codegen/android/fqNameInTag/"); + } + + @TestMetadata("manyWidgets") + public void testManyWidgets() throws Exception { + doFakeInvocationTest("compiler/testData/codegen/android/manyWidgets/"); + } + + @TestMetadata("multiFile") + public void testMultiFile() throws Exception { + doFakeInvocationTest("compiler/testData/codegen/android/multiFile/"); + } + + @TestMetadata("singleFile") + public void testSingleFile() throws Exception { + doFakeInvocationTest("compiler/testData/codegen/android/singleFile/"); + } + } - @TestMetadata("fqNameInTag") - public void testFqNameInTag() throws Exception { - doTest("compiler/testData/codegen/android/fqNameInTag/"); + public static Test suite() { + TestSuite suite = new TestSuite("AndroidBoxTestGenerated"); + suite.addTestSuite(Android.class); + suite.addTestSuite(Invoke.class); + return suite; } - - @TestMetadata("manyWidgets") - public void testManyWidgets() throws Exception { - doTest("compiler/testData/codegen/android/manyWidgets/"); - } - - @TestMetadata("multiFile") - public void testMultiFile() throws Exception { - doTest("compiler/testData/codegen/android/multiFile/"); - } - - @TestMetadata("singleFile") - public void testSingleFile() throws Exception { - doTest("compiler/testData/codegen/android/singleFile/"); - } - } diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 19fca3dd8ae..e603c8739df 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -323,7 +323,8 @@ fun main(args: Array) { } testClass(javaClass()) { - model("codegen/android", recursive = false, extension = null) + model("codegen/android", recursive = false, extension = null, testMethod = "doCompileAgainstAndroidSdkTest") + model("codegen/android", recursive = false, extension = null, testMethod = "doFakeInvocationTest", testClassName = "Invoke") } } diff --git a/idea/tests/org/jetbrains/jet/android/AbstractCrossParserTest.kt b/idea/tests/org/jetbrains/jet/android/AbstractCrossParserTest.kt index 9f2b7ab39b9..8343baf6820 100644 --- a/idea/tests/org/jetbrains/jet/android/AbstractCrossParserTest.kt +++ b/idea/tests/org/jetbrains/jet/android/AbstractCrossParserTest.kt @@ -29,20 +29,33 @@ import kotlin.test.assertEquals import org.jetbrains.jet.plugin.android.TestConst import com.intellij.testFramework.LightCodeInsightTestCase import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase +import org.jetbrains.jet.plugin.PluginTestCaseBase +import org.jetbrains.jet.test.TestMetadata +import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase +import com.intellij.ide.startup.impl.StartupManagerImpl +import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess +import org.jetbrains.jet.JetTestCaseBuilder +import com.intellij.openapi.startup.StartupManager public abstract class AbstractCrossParserTest : LightCodeInsightFixtureTestCase() { public fun doTest(path: String) { - val jetCoreEnvironment = getEnvironment(path) - val project = jetCoreEnvironment.getProject() + val project = myFixture.getProject() project.putUserData(TestConst.TESTDATA_PATH, path) - val cliParser = CliAndroidUIXmlProcessor(jetCoreEnvironment.getProject(), path + "/layout", path + "AndroidManifest.xml") - val ideParser = IDEAndroidUIXmlProcessor(jetCoreEnvironment.getProject()) + myFixture.copyDirectoryToProject(getTestName(true), "") + val cliParser = CliAndroidUIXmlProcessor(project, path + "/layout", path + "AndroidManifest.xml") + val ideParser = IDEAndroidUIXmlProcessor(project) val cliResult = cliParser.parseToPsi(project)!!.getText() val ideResult = ideParser.parseToPsi(project)!!.getText() assertEquals(cliResult, ideResult) } + override fun setUp() { + super.setUp() + myFixture.setTestDataPath(PluginTestCaseBase.getTestDataPathBase() + "/android/crossParser") + (StartupManager.getInstance(getProject()) as StartupManagerImpl).runPostStartupActivities() + VfsRootAccess.allowRootAccess(JetTestCaseBuilder.getHomeDirectory()) + } private fun getEnvironment(testPath: String): JetCoreEnvironment { val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK) @@ -50,4 +63,7 @@ public abstract class AbstractCrossParserTest : LightCodeInsightFixtureTestCase( configuration.put(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml") return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration) } + override fun getTestDataPath(): String? { + return PluginTestCaseBase.getTestDataPathBase() + "/android/crossParser/" + } } \ No newline at end of file