Add compiler tests for support.v4.app.Fragment

This commit is contained in:
Yan Zhulanow
2015-04-08 16:17:12 +03:00
parent 514bc74e9c
commit d7488023d2
16 changed files with 268 additions and 12 deletions
@@ -0,0 +1,33 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-sdk
android:minSdkVersion="18"
android:targetSdkVersion="18" />
<permission android:name="android"></permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.Sample" >
<activity
android:name="com.example.android.basiccontactables.MainActivity"
android:label="@string/app_name"
android:launchMode="singleTop">
<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
@@ -0,0 +1,29 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,50 @@
package kotlinx.android.synthetic.test
import android.app.*
import android.view.*
import android.widget.*
import android.webkit.*
import android.inputmethodservice.*
import android.opengl.*
import android.appwidget.*
import android.support.v4.app.*
import android.support.v4.view.*
import android.support.v4.widget.*
import kotlin.internal.flexible.ft
val android.app.Activity.item_detail_container: ft<FrameLayout, FrameLayout?>
get() = findViewById(0) as? FrameLayout
val android.app.Fragment.item_detail_container: ft<FrameLayout, FrameLayout?>
get() = getView().findViewById(0) as? FrameLayout
val android.support.v4.app.Fragment.item_detail_container: ft<FrameLayout, FrameLayout?>
get() = getView().findViewById(0) as? FrameLayout
val android.app.Activity.textView1: ft<TextView, TextView?>
get() = findViewById(0) as? TextView
val android.app.Fragment.textView1: ft<TextView, TextView?>
get() = getView().findViewById(0) as? TextView
val android.support.v4.app.Fragment.textView1: ft<TextView, TextView?>
get() = getView().findViewById(0) as? TextView
val android.app.Activity.password: ft<EditText, EditText?>
get() = findViewById(0) as? EditText
val android.app.Fragment.password: ft<EditText, EditText?>
get() = getView().findViewById(0) as? EditText
val android.support.v4.app.Fragment.password: ft<EditText, EditText?>
get() = getView().findViewById(0) as? EditText
val android.app.Activity.login: ft<Button, Button?>
get() = findViewById(0) as? Button
val android.app.Fragment.login: ft<Button, Button?>
get() = getView().findViewById(0) as? Button
val android.support.v4.app.Fragment.login: ft<Button, Button?>
get() = getView().findViewById(0) as? Button
@@ -0,0 +1,26 @@
package kotlinx.android.synthetic.test.view
import android.app.*
import android.view.*
import android.widget.*
import android.webkit.*
import android.inputmethodservice.*
import android.opengl.*
import android.appwidget.*
import android.support.v4.app.*
import android.support.v4.view.*
import android.support.v4.widget.*
import kotlin.internal.flexible.ft
val android.view.View.item_detail_container: ft<FrameLayout, FrameLayout?>
get() = findViewById(0) as? FrameLayout
val android.view.View.textView1: ft<TextView, TextView?>
get() = findViewById(0) as? TextView
val android.view.View.password: ft<EditText, EditText?>
get() = findViewById(0) as? EditText
val android.view.View.login: ft<Button, Button?>
get() = findViewById(0) as? Button
@@ -0,0 +1,9 @@
package android.support.v4.app
import android.view.View
import android.app.Activity
abstract class Fragment {
open fun getActivity(): Activity = throw Exception("Function getActivity() is not overridden")
open fun getView(): View = throw Exception("Function getView() is not overridden")
}
@@ -1,20 +1,20 @@
package com.myapp
import android.app.Activity
import android.app.Fragment
import android.os.Bundle
import java.io.File
import kotlinx.android.synthetic.layout.*
public class MyActivity : Activity()
public class MyFragment : Fragment()
fun MyActivity.b() {
fun MyFragment.b() {
val x = login
val y = this.login
}
// 1 public _\$_findCachedViewById
// 1 public _\$_clearFindViewByIdCache
// 1 INVOKEVIRTUAL com/myapp/MyActivity\.findViewById
// 1 INVOKEVIRTUAL com/myapp/MyFragment\.getView
// 2 GETSTATIC com/myapp/R\$id\.login
// 2 INVOKEVIRTUAL com/myapp/MyActivity\._\$_findCachedViewById
// 2 INVOKEVIRTUAL com/myapp/MyFragment\._\$_findCachedViewById
// 2 CHECKCAST android/widget/Button
@@ -0,0 +1,17 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,26 @@
package android.support.v4.app
import android.app.Activity
import android.view.View
import android.os.Bundle
import java.io.File
import kotlinx.android.synthetic.layout.*
open class Fragment {
open fun getActivity(): Activity = throw Exception("Function getActivity() is not overridden")
open fun getView(): View = throw Exception("Function getView() is not overridden")
}
public class MyFragment : Fragment()
fun MyFragment.b() {
val x = login
val y = this.login
}
// 2 public _\$_findCachedViewById
// 2 public _\$_clearFindViewByIdCache
// 1 INVOKEVIRTUAL android/support/v4/app/MyFragment\.getView
// 2 GETSTATIC com/myapp/R\$id\.login
// 2 INVOKEVIRTUAL android/support/v4/app/MyFragment\._\$_findCachedViewById
// 2 CHECKCAST android/widget/Button
@@ -0,0 +1,17 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,22 @@
package android.support.v4.app
import android.app.Activity
import android.view.View
import java.io.File
import kotlinx.android.synthetic.layout.*
open class Fragment {
open fun getActivity(): Activity = throw Exception("Function getActivity() is not overridden")
open fun getView(): View = throw Exception("Function getView() is not overridden")
}
public class MyFragment : Fragment() {
init {login}
}
// 2 public _\$_findCachedViewById
// 2 public _\$_clearFindViewByIdCache
// 1 INVOKEVIRTUAL android/support/v4/app/MyFragment\.getView
// 1 GETSTATIC com/myapp/R\$id\.login
// 1 INVOKEVIRTUAL android/support/v4/app/MyFragment\._\$_findCachedViewById
// 1 CHECKCAST android/widget/Button
@@ -43,7 +43,8 @@ public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
val resPath = path + "layout/"
val manifestPath = path + "AndroidManifest.xml"
myEnvironment = createAndroidTestEnvironment(configuration, resPath, manifestPath)
val supportV4 = File(path).name.startsWith("support")
myEnvironment = createAndroidTestEnvironment(configuration, resPath, manifestPath, supportV4)
}
public fun doCompileAgainstAndroidSdkTest(path: String) {
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.test.ConfigurationKind
import org.jetbrains.kotlin.test.TestJdkKind
import org.jetbrains.kotlin.test.JetTestUtils
import java.io.File
public abstract class AbstractAndroidBytecodeShapeTest : AbstractBytecodeTextTest() {
@@ -31,7 +32,8 @@ public abstract class AbstractAndroidBytecodeShapeTest : AbstractBytecodeTextTes
private fun createEnvironmentForConfiguration(configuration: CompilerConfiguration, path: String) {
val resPath = path + "res/layout/"
val manifestPath = path + "../AndroidManifest.xml"
myEnvironment = createAndroidTestEnvironment(configuration, resPath, manifestPath)
val supportV4 = File(path).name.startsWith("support")
myEnvironment = createAndroidTestEnvironment(configuration, resPath, manifestPath, supportV4)
}
public override fun doTest(path: String) {
@@ -31,12 +31,15 @@ import kotlin.test.*
public abstract class AbstractAndroidXml2KConversionTest : UsefulTestCase() {
public fun doTest(path: String) {
val testDirectory = File(path)
val jetCoreEnvironment = getEnvironment()
val parser = CliAndroidUIXmlProcessor(jetCoreEnvironment.project, path + "AndroidManifest.xml", path + "/res")
parser.supportV4 = testDirectory.name.startsWith("support")
val actual = parser.parse(false).toMap { it.name }
val expectedLayoutFiles = File(path).listFiles {
val expectedLayoutFiles = testDirectory.listFiles {
it.isFile() && it.name.endsWith(".kt")
}?.toMap { it.name.substringBefore(".kt") } ?: mapOf()
@@ -130,4 +130,16 @@ public class AndroidBytecodeShapeTestGenerated extends AbstractAndroidBytecodeSh
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/codegen/bytecodeShape/simpleView/");
doTest(fileName);
}
@TestMetadata("supportExtensionFunctionsFragment")
public void testSupportExtensionFunctionsFragment() throws Exception {
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/codegen/bytecodeShape/supportExtensionFunctionsFragment/");
doTest(fileName);
}
@TestMetadata("supportSimpleFragment")
public void testSupportSimpleFragment() throws Exception {
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/codegen/bytecodeShape/supportSimpleFragment/");
doTest(fileName);
}
}
@@ -90,6 +90,12 @@ public class AndroidXml2KConversionTestGenerated extends AbstractAndroidXml2KCon
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/android/converter/simple/specialTags/");
doTest(fileName);
}
@TestMetadata("supportSingleFile")
public void testSupportSingleFile() throws Exception {
String fileName = JetTestUtils.navigationMetadata("plugins/android-compiler-plugin/testData/android/converter/simple/supportSingleFile/");
doTest(fileName);
}
}
@TestMetadata("plugins/android-compiler-plugin/testData/android/converter/exceptions")
@@ -34,10 +34,12 @@ import org.jetbrains.kotlin.lang.resolve.android.CliAndroidUIXmlProcessor
private class AndroidTestExternalDeclarationsProvider(
val project: Project,
val resPath: String,
val manifestPath: String
val manifestPath: String,
val supportV4: Boolean
) : ExternalDeclarationsProvider {
override fun getExternalDeclarations(moduleInfo: ModuleInfo?): Collection<JetFile> {
val parser = CliAndroidUIXmlProcessor(project, manifestPath, resPath)
parser.supportV4 = supportV4
return parser.parseToPsi() ?: listOf()
}
}
@@ -45,13 +47,14 @@ private class AndroidTestExternalDeclarationsProvider(
fun UsefulTestCase.createAndroidTestEnvironment(
configuration: CompilerConfiguration,
resPath: String,
manifestPath: String): KotlinCoreEnvironment
{
manifestPath: String,
supportV4: Boolean
): KotlinCoreEnvironment {
configuration.put(AndroidConfigurationKeys.ANDROID_RES_PATH, resPath)
configuration.put(AndroidConfigurationKeys.ANDROID_MANIFEST, manifestPath)
val myEnvironment = KotlinCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
val project = myEnvironment.project
ExternalDeclarationsProvider.registerExtension(project, AndroidTestExternalDeclarationsProvider(project, resPath, manifestPath))
ExternalDeclarationsProvider.registerExtension(project, AndroidTestExternalDeclarationsProvider(project, resPath, manifestPath, supportV4))
ExpressionCodegenExtension.registerExtension(project, AndroidExpressionCodegenExtension())
return myEnvironment
}