add generated tests

This commit is contained in:
dedoz
2014-08-26 21:10:55 +04:00
committed by Yan Zhulanow
parent a56fa7f192
commit f2ab424c41
45 changed files with 1135 additions and 234 deletions
@@ -0,0 +1,29 @@
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
}
}
}
fun box(): String {
return "OK"
}
@@ -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,8 @@
package org.my.cool
import android.widget.Button
import android.app.Activity
class MyButton(ctx: Activity): Button(ctx) {
override fun toString(): String {return "Button"}
}
@@ -0,0 +1,15 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<view
class="org.my.cool.MyButton"
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,29 @@
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 = Button(this)
override fun findViewById(id: Int): View? {
return when (id) {
R.id.login -> buttonWidget
else -> null
}
}
}
fun box(): String {
return "OK"
}
@@ -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,8 @@
package org.my.cool
import android.widget.Button
import android.content.Context
class MyButton(ctx: Context): Button(ctx) {
override fun toString(): String {return "Button"}
}
@@ -0,0 +1,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<org.my.cool.MyButton
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1 @@
fun box() = "OK"
@@ -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,67 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<ImageView
android:id="@+id/req_who_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="6dip"
android:gravity="left"
android:src="@drawable/icon" />
<TextView
android:id="@+id/req_state_who"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/req_who_icon"
android:textSize="10dip"
android:layout_alignParentRight="false"
android:layout_alignParentTop="false"
android:layout_alignWithParentIfMissing="true"
android:gravity="left"
android:text="who" />
<TextView
android:id="@+id/req_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/req_state_who"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="true"
android:gravity="right"
android:text="No summary"
android:textSize="10dip"
android:textColor="#FFFF00" />
<TextView
android:id="@+id/req_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/req_header"
android:layout_toRightOf="@id/req_state_who"
android:layout_alignParentRight="true"
android:layout_alignWithParentIfMissing="true"
android:gravity="right"
android:textSize="10dip"
android:text="No summary" />
<TextView
android:id="@+id/req_description"
android:layout_below="@id/req_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/req_state_who"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:gravity="right"
android:ellipsize="marquee"
android:text="No description"
android:textSize="10dip" />
<ImageView
android:id="@+id/req_state_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/req_description"
android:layout_marginRight="6dip"/>
</RelativeLayout>
@@ -0,0 +1,37 @@
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
}
}
}
fun box(): String {
return "OK"
}
@@ -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,29 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/passwordCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -0,0 +1,37 @@
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
}
}
}
fun box(): String {
return "OK"
}
@@ -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,59 @@
/*
* Copyright 2010-2014 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.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
import org.jetbrains.jet.JetTestUtils
import java.util.Collections
import com.intellij.util.ArrayUtil
import com.intellij.openapi.util.io.FileUtil
import java.io.File
import java.util.ArrayList
import com.intellij.util.Processor
import org.jetbrains.jet.codegen.CodegenTestFiles
public abstract class AbstractAndroidBoxTest : AbstractBlackBoxCodegenTest() {
fun createEnvironment(path: String) {
val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.ANDROID_API);
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)
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))
}
return true
}
})
Collections.sort(files);
myFiles = CodegenTestFiles.create(myEnvironment!!.getProject(), ArrayUtil.toStringArray(files))
blackBox();
}
}
@@ -0,0 +1,64 @@
/*
* Copyright 2010-2014 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.jet.lang.resolve.android;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
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")
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("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
doTest("compiler/testData/codegen/android/fqNameInAttr/");
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
doTest("compiler/testData/codegen/android/fqNameInTag/");
}
@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/");
}
}
@@ -1,141 +0,0 @@
/*
* Copyright 2010-2014 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.jet.lang.resolve.android;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.testFramework.UsefulTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.*;
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.codegen.GenerationUtils;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.config.CompilerConfiguration;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.test.TestCaseWithTmpdir;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.*;
public class AndroidXmlTest extends UsefulTestCase {
private static final String singleFilePrefix = getTestDataPath() + "/converter/singleFile/";
public static final String singleFileManifestPath = singleFilePrefix + "AndroidManifest.xml";
private final File singleFileDir = new File(singleFilePrefix + "res/layout/");
private final File fakeActivitySrc = new File(getTestDataPath() + "/fakeHelpers/Activity.kt");
private final File fakeViewSrc = new File(getTestDataPath() + "/fakeHelpers/View.kt");
private final File fakeWidgetsSrc = new File(getTestDataPath() + "/fakeHelpers/Widgets.kt");
private final File fakeMyActivitySrc = new File(singleFilePrefix + "MyActivity.kt");
private static final String singleFileResPath = singleFilePrefix + "res/layout/";
@Override
public void setUp() throws Exception {
super.setUp();
}
@NotNull
private static String getTestDataPath() {
return JetTestCaseBuilder.getTestDataPathBase() + "/android";
}
@SuppressWarnings({"ResultOfMethodCallIgnored", "IOResourceOpenedButNotSafelyClosed"})
protected static String loadOrCreate(File file, String data) throws IOException {
try {
return new Scanner(file, "UTF-8" ).useDelimiter("\\A").next();
} catch (IOException e) {
file.createNewFile();
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(data);
fileWriter.close();
fail("Empty expected data, creating from actual");
return data;
}
}
private GenerationState compileManyFilesGetGenerationState(List<File> files, String resPath) throws IOException {
JetCoreEnvironment jetCoreEnvironment = getEnvironment(resPath);
Project project = jetCoreEnvironment.getProject();
List<JetFile> jetFiles = new ArrayList<JetFile>(files.size());
for (File file: files) {
jetFiles.add(JetTestUtils.loadJetFile(project, file));
}
return GenerationUtils.compileManyFilesGetGenerationStateForTest(project, jetFiles);
}
private JetCoreEnvironment getEnvironment(String resPath) {
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL,
TestJdkKind.MOCK_JDK);
configuration.put(JVMConfigurationKeys.ANDROID_RES_PATH, resPath);
configuration.put(JVMConfigurationKeys.ANDROID_MANIFEST, singleFileManifestPath);
return JetCoreEnvironment.createForTests(getTestRootDisposable(),
configuration);
}
public void testCompileResult() throws Exception {
List<File> files = addDefaultFiles();
compileManyFilesGetGenerationState(files, singleFileResPath);
// TODO: why?
Disposer.dispose(getTestRootDisposable());
}
private List<File> addDefaultFiles() {
File fakeRClass = new File(getTestDataPath() + "/converter/singleFile/R.kt");
List<File> files = new ArrayList<File>();
files.add(fakeActivitySrc);
files.add(fakeViewSrc);
files.add(fakeRClass);
files.add(fakeWidgetsSrc);
return files;
}
// TODO: many tests
public void testConverterOneFile() throws Exception {
JetCoreEnvironment jetCoreEnvironment = getEnvironment(singleFileResPath);
AndroidUIXmlProcessor parser = new CliAndroidUIXmlProcessor(jetCoreEnvironment.getProject(),
singleFileDir.getAbsolutePath(),
singleFileManifestPath);
String actual = parser.parseToString();
String expected = loadOrCreate(new File(getTestDataPath() + "/converter/singleFile/layout.kt"), actual);
assertEquals(expected, actual);
}
// todo: unify with box tests
public void testGeneratedByteCode() throws Exception {
String resPath = getTestDataPath() + "/converter/singleFile/res/layout/";
List<File> files = addDefaultFiles();
files.add(fakeMyActivitySrc);
GenerationState state = compileManyFilesGetGenerationState(files, resPath);
ByteArrayClassLoader classLoader = new ByteArrayClassLoader(new URL[] {}, getClass().getClassLoader(), state.getFactory().asList());
classLoader.loadFiles();
Class<?> activity = classLoader.findClass("com.myapp.MyActivity");
String res =(String) activity.getMethod("test").invoke(activity.newInstance());
// todo: why?
Disposer.dispose(getTestRootDisposable());
assertEquals("OK", res);
}
}
@@ -1,84 +0,0 @@
/*
* Copyright 2010-2014 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.jet.lang.resolve.android;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.OutputFile;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
// todo: get rid of this class
public class ByteArrayClassLoader extends URLClassLoader {
private final Queue<OutputFile> q;
private final Map<String, Class> extraClassDefs = new HashMap<String, Class>();
@NotNull
@Override
protected Class<?> findClass(@NotNull String name) throws ClassNotFoundException {
Class aClass = extraClassDefs.get(name);
if (aClass != null) return aClass;
else return super.findClass(name);
}
public ByteArrayClassLoader(URL[] urls, ClassLoader parent, List<OutputFile> files) {
super(urls, parent);
q = new LinkedList<OutputFile>(files);
}
private void loadBytes(OutputFile f) {
try {
byte[] b = f.asByteArray();
String name = relPathToClassName(f.getRelativePath());
Class<?> aClass = defineClass(name, b, 0, b.length);
extraClassDefs.put(name, aClass);
q.remove(f);
} catch (NoClassDefFoundError e) {
OutputFile found = findByClassName(e.getMessage());
if (found == null) throw e;
else {
loadBytes(found);
loadBytes(f);
}
}
}
public void loadFiles() {
OutputFile f = q.peek();
while (f != null) {
loadBytes(f);
f = q.peek();
}
}
private OutputFile findByClassName(String name) {
String path = classNameToRelPath(name);
for (OutputFile file: q)
if (file.getRelativePath().equals(path)) return file;
return null;
}
private static String relPathToClassName(String path) {
return path.replace(".class", "").replace("/", ".");
}
private static String classNameToRelPath(String name) {
return name.replace(".", "/").concat(".class");
}
}
@@ -164,7 +164,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
blackBox();
}
private void blackBox() {
protected void blackBox() {
// If there are many files, the first of them should contain the 'box(): String' function
JetFile firstFile = myFiles.getPsiFiles().get(0);
String fqName = getPackageClassFqName(firstFile.getPackageFqName()).asString();
@@ -143,6 +143,8 @@ import org.jetbrains.kotlin.idea.kdoc.AbstractKDocHighlightingTest
import org.jetbrains.kotlin.addImport.AbstractAddImportTest
import org.jetbrains.kotlin.idea.highlighter.*
import org.jetbrains.jet.lang.resolve.android.AbstractAndroidXml2KConversionTest
import org.jetbrains.jet.android.AbstractCrossParserTest
import org.jetbrains.jet.lang.resolve.android.AbstractAndroidBoxTest
fun main(args: Array<String>) {
System.setProperty("java.awt.headless", "true")
@@ -319,6 +321,10 @@ fun main(args: Array<String>) {
model("android/converter/simple", recursive = false, extension = null)
model("android/converter/exceptions", recursive = false, extension = null, testMethod = "doNoManifestTest")
}
testClass(javaClass<AbstractAndroidBoxTest>()) {
model("codegen/android", recursive = false, extension = null)
}
}
testGroup("idea/tests", "idea/testData") {
@@ -691,6 +697,9 @@ fun main(args: Array<String>) {
testClass(javaClass<AbstractReferenceResolveTest>(), "org.jetbrains.kotlin.idea.kdoc.KdocResolveTestGenerated") {
model("kdoc/resolve")
testClass(javaClass<AbstractCrossParserTest>()) {
model("android/crossParser", recursive = false, extension = null)
}
testClass(javaClass<AbstractKDocHighlightingTest>()) {
@@ -27,13 +27,13 @@ import org.jetbrains.jet.lang.resolve.android.CliAndroidResourceManager
import org.jetbrains.jet.lang.resolve.android.AndroidResourceManager
class IDEAndroidUIXmlProcessor(project: Project) : AndroidUIXmlProcessor(project) {
override val searchPath: String? = if (ApplicationManager.getApplication()!!.isUnitTestMode()) project.getUserData(TestConst.TESTDATA_PATH) + "res/layout/"
override val searchPath: String? = if (ApplicationManager.getApplication()!!.isUnitTestMode()) project.getUserData(TestConst.TESTDATA_PATH) + "layout/"
else project.getBasePath() + "/res/layout/"
override var androidAppPackage: String = ""
get() = resourceManager.readManifest()._package
override val resourceManager: AndroidResourceManager = if (ApplicationManager.getApplication()!!.isUnitTestMode())
CliAndroidResourceManager(project, searchPath, searchPath + "AndroidManifest.xml")
CliAndroidResourceManager(project, searchPath, project.getUserData(TestConst.TESTDATA_PATH) + "AndroidManifest.xml")
else IDEAndroidResourceManager(project, searchPath)
override fun parseSingleFileImpl(file: PsiFile): String {
@@ -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,9 @@
package com.myapp
import android.app.Activity
import android.view.View
import android.widget.*
val Activity.MyButton: org.my.cool.Button
get() = findViewById(0) as org.my.cool.Button
@@ -0,0 +1,15 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<view
class="org.my.cool.Button"
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -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,9 @@
package com.myapp
import android.app.Activity
import android.view.View
import android.widget.*
val Activity.MyButton: org.my.cool.Button
get() = findViewById(0) as org.my.cool.Button
@@ -0,0 +1,14 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<org.my.cool.Button
android:id="@+id/MyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -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,30 @@
package com.myapp
import android.app.Activity
import android.view.View
import android.widget.*
val Activity.item_detail_container: FrameLayout
get() = findViewById(0) as FrameLayout
val Activity.textView1: TextView
get() = findViewById(0) as TextView
val Activity.password: EditText
get() = findViewById(0) as EditText
val Activity.login: Button
get() = findViewById(0) as Button
val Activity.frameLayout: FrameLayout
get() = findViewById(0) as FrameLayout
val Activity.passwordField: TextView
get() = findViewById(0) as TextView
val Activity.passwordCaption: EditText
get() = findViewById(0) as EditText
val Activity.loginButton: Button
get() = findViewById(0) as Button
@@ -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,29 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frameLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:id="@+id/passwordField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:id="@+id/passwordCaption"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -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,6 @@
package com.myapp
import android.app.Activity
import android.view.View
import android.widget.*
@@ -0,0 +1,25 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter your password" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sign in" />
</FrameLayout>
@@ -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,27 @@
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"
}
}
@@ -0,0 +1,14 @@
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,18 @@
package com.myapp
import android.app.Activity
import android.view.View
import android.widget.*
val Activity.item_detail_container: FrameLayout
get() = findViewById(0) as FrameLayout
val Activity.textView1: TextView
get() = findViewById(0) as TextView
val Activity.password: EditText
get() = findViewById(0) as EditText
val Activity.login: Button
get() = findViewById(0) as Button
@@ -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>
@@ -14,26 +14,40 @@
* limitations under the License.
*/
package org.jetbrains.jet.lang.resolve.android
package org.jetbrains.jet.android
import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
import org.jetbrains.jet.lang.resolve.android.CliAndroidUIXmlProcessor
import org.jetbrains.jet.JetTestUtils
import org.jetbrains.jet.ConfigurationKind
import org.jetbrains.jet.TestJdkKind
import org.jetbrains.jet.plugin.android.IDEAndroidUIXmlProcessor
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys
import junit.framework.TestCase
import kotlin.test.assertEquals
import org.jetbrains.jet.plugin.android.TestConst
import com.intellij.testFramework.LightCodeInsightTestCase
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
public abstract class AbstractCrossParserTest : UsefulTestCase() {
public abstract class AbstractCrossParserTest : LightCodeInsightFixtureTestCase() {
public fun doTest(path: String) {
val jetCoreEnvironment = getEnvironment(path)
val project = jetCoreEnvironment.getProject()
project.putUserData(TestConst.TESTDATA_PATH, path)
val cliParser = CliAndroidUIXmlProcessor(jetCoreEnvironment.getProject(), path + "/layout", path + "AndroidManifest.xml")
// val ideParser = IDEAndroidUIXmlProcessor(jetCoreEnvironment.getProject(), path + "/layout", path + "AndroidManifest.xml")
val ideParser = IDEAndroidUIXmlProcessor(jetCoreEnvironment.getProject())
val cliResult = cliParser.parseToPsi(project)!!.getText()
val ideResult = ideParser.parseToPsi(project)!!.getText()
assertEquals(cliResult, ideResult)
}
private fun getEnvironment(testPath: String): JetCoreEnvironment {
val configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.MOCK_JDK)
// configuration.put<String>(JVMConfigurationKeys.ANDROID_RES_PATH, testPath + "/layout")
// configuration.put<String>(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
configuration.put<String>(JVMConfigurationKeys.ANDROID_RES_PATH, testPath + "/layout")
configuration.put<String>(JVMConfigurationKeys.ANDROID_MANIFEST, testPath + "/AndroidManifest.xml")
return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, configuration)
}
}
}
@@ -0,0 +1,64 @@
/*
* Copyright 2010-2014 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.jet.android;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import java.util.regex.Pattern;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import org.jetbrains.jet.android.AbstractCrossParserTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/android/crossParser")
public class CrossParserTestGenerated extends AbstractCrossParserTest {
public void testAllFilesPresentInCrossParser() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/android/crossParser"), Pattern.compile("^([^\\.]+)$"), false);
}
@TestMetadata("fqNameInAttr")
public void testFqNameInAttr() throws Exception {
doTest("idea/testData/android/crossParser/fqNameInAttr/");
}
@TestMetadata("fqNameInTag")
public void testFqNameInTag() throws Exception {
doTest("idea/testData/android/crossParser/fqNameInTag/");
}
@TestMetadata("multiFile")
public void testMultiFile() throws Exception {
doTest("idea/testData/android/crossParser/multiFile/");
}
@TestMetadata("noIds")
public void testNoIds() throws Exception {
doTest("idea/testData/android/crossParser/noIds/");
}
@TestMetadata("singleFile")
public void testSingleFile() throws Exception {
doTest("idea/testData/android/crossParser/singleFile/");
}
}