add android properties box tests
This commit is contained in:
committed by
Yan Zhulanow
parent
f2ab424c41
commit
08245ffe1c
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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?
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package android.content
|
||||
|
||||
trait Context
|
||||
@@ -0,0 +1,5 @@
|
||||
package android.view
|
||||
|
||||
import android.content.Context
|
||||
|
||||
open class View(ctx: Context)
|
||||
@@ -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"}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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"}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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"}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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()
|
||||
}
|
||||
@@ -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<String> {
|
||||
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<String>? = null) {
|
||||
val files = ArrayList<String>(2)
|
||||
FileUtil.processFilesRecursively(File(path), object : Processor<File> {
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+68
-25
@@ -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/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -323,7 +323,8 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
|
||||
testClass(javaClass<AbstractAndroidBoxTest>()) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<String>(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
|
||||
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration)
|
||||
}
|
||||
override fun getTestDataPath(): String? {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/android/crossParser/"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user