Commit 26e98f79 authored by Matyáš Latner's avatar Matyáš Latner

#352 Ability to create iTest package for Android platform

parent 40cdc933
......@@ -36,6 +36,12 @@ android {
buildConfigField ASSETS_CHECKSUM_FIELD_TYPE, ASSETS_CHECKSUM_FIELD_NAME, rootProject.ext.assetsChecksumPattern
resValue "string", "app_name", "${tablexiaAppName}"
}
iTest.initWith(buildTypes.debug)
iTest {
applicationIdSuffix rootProject.applicationIdITestSuffix
buildConfigField ASSETS_CHECKSUM_FIELD_TYPE, ASSETS_CHECKSUM_FIELD_NAME, rootProject.ext.assetsChecksumPattern
resValue "string", "app_name", "${tablexiaAppName}"
}
devel.initWith(buildTypes.debug)
devel {
applicationIdSuffix rootProject.applicationIdDevelSuffix
......@@ -46,10 +52,10 @@ android {
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
manifest.srcFile 'src/main/AndroidManifest.xml'
res.srcDirs = ['res/main']
assets.srcDirs = ['assets']
java.srcDir file('src/main/java')
java.srcDirs = ['src/main/java']
jniLibs.srcDirs = ['libs']
}
androidTest {
......@@ -65,12 +71,17 @@ android {
debug {
res.srcDirs = ['res/debug']
}
iTest {
manifest.srcFile 'src/iTest/AndroidManifest.xml'
java.srcDirs = ['src/main/java', 'src/iTest/java']
res.srcDirs = ['res/iTest']
}
devel {
res.srcDirs = ['res/devel']
}
}
assemble.dependsOn = ['assembleRelease', 'assembleDebug']
assemble.dependsOn = ['assembleRelease', 'assembleDebug', 'assembleITest']
applicationVariants.all { variant ->
if (!variant.buildType.name.equals("devel")) {
......
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity
android:name="cz.nic.tablexia.android.AndroidLauncher"
tools:node="remove"/>
<activity
android:name="cz.nic.tablexia.android.AndroidITestLauncher"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
......@@ -49,6 +49,7 @@ public class AndroidITestLauncher extends AndroidApplication {
getResources().getConfiguration().locale,
SQL_CONNECTION_TYPE,
new AndroidConnectionManager(getContext()),
false,
savedInstanceState == null, register), config);
testScenario = new TestScenarioNewUser(register, tablexia);
......
......@@ -26,16 +26,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="cz.nic.tablexia.android.AndroidTestLauncher"
android:label="@string/app_name"
android:screenOrientation="sensorLandscape"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
package cz.nic.tablexia.android;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.net.ConnectivityManager;
import android.os.Bundle;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.flurry.android.FlurryAgent;
import java.io.File;
import java.io.FileOutputStream;
import cz.nic.tablexia.Tablexia;
import cz.nic.tablexia.TablexiaBuildConfig;
import cz.nic.tablexia.TablexiaSettings;
import cz.nic.tablexia.testing.TestComponentRegister;
import cz.nic.tablexia.debug.BuildConfig;
import cz.nic.tablexia.screen.loader.IConnectionManager;
import cz.nic.tablexia.testing.TestScenarioSpecial;
import cz.nic.tablexia.util.Log;
/**
* Created by frantisek on 13.4.16.
*/
public class AndroidTestLauncher extends AndroidApplication {
public static final Tablexia.SQLConnectionType SQL_CONNECTION_TYPE = new Tablexia.SQLConnectionType("org.sqldroid.SQLDroidDriver", "jdbc:sqldroid:");
private static final int MULTI_SAMPLING_2X = 2;
private Tablexia tablexia;
private TestComponentRegister register;
private TestScenarioSpecial specialScenario;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
config.useWakelock = true;
config.numSamples = MULTI_SAMPLING_2X;
register = new TestComponentRegister();
initialize(tablexia = new Tablexia(BuildConfig.BUILD_TYPE,
getResources().getConfiguration().locale,
SQL_CONNECTION_TYPE,
new AndroidConnectionManager(getContext()),
AndroidLauncher.HAS_SOFT_BACK_BUTTON,
savedInstanceState == null, register), config);
specialScenario = new TestScenarioSpecial(register, tablexia);
specialScenario.runTest();
if (TablexiaSettings.getInstance().getBuildType().isBugReport() && TablexiaBuildConfig.FLURRY_KEY != null) {
FlurryAgent.setLogEnabled(false);
FlurryAgent.setVersionName(TablexiaSettings.getInstance().getFullName());
FlurryAgent.init(this, TablexiaBuildConfig.FLURRY_KEY);
}
}
/**
* Method supporting screenshots during UI testing the application using OpenGL
*
* @param file
*/
public void takeScreenshot(final File file) {
tablexia.takeScreenShot(new Tablexia.ScreenshotListener() {
@Override
public void screenshotTaken(int width, int height, int[] screen) {
try {
for (int i = 0; i < screen.length; ++i) {
// The alpha and green channels' positions are preserved while the red and blue are swapped
screen[i] = ((screen[i] & 0xff00ff00)) | ((screen[i] & 0x000000ff) << 16) | ((screen[i] & 0x00ff0000) >> 16);
}
Bitmap sb = Bitmap.createBitmap(screen, width, height, Bitmap.Config.RGB_565);
// flip bitmap vertically
Matrix matrixMirror = new Matrix();
matrixMirror.preScale(1.0f, -1.0f);
sb = Bitmap.createBitmap(sb, 0, 0, sb.getWidth(), sb.getHeight(), matrixMirror, false);
// overwrite file
FileOutputStream fOut = new FileOutputStream(file);
sb.compress(Bitmap.CompressFormat.PNG, 100, fOut);
sb.recycle();
fOut.flush();
fOut.close();
} catch (Exception e) {
e.printStackTrace();
Log.err(this.getClass().getSimpleName(), e.getMessage());
}
}
});
}
private static class AndroidConnectionManager implements IConnectionManager {
private Context androidContext;
public AndroidConnectionManager(Context androidContext) {
this.androidContext = androidContext;
}
@Override
public boolean isUsingMobileData() {
ConnectivityManager conMan = (ConnectivityManager) androidContext.getSystemService(Context.CONNECTIVITY_SERVICE);
//We are not connected to the internet at all...
if(conMan == null || conMan.getActiveNetworkInfo() == null)
return false;
//Is user using any of mobile internet types ? Hope I didn't miss any...
switch (conMan.getActiveNetworkInfo().getType()) {
case ConnectivityManager.TYPE_MOBILE:
case ConnectivityManager.TYPE_MOBILE_DUN:
case ConnectivityManager.TYPE_MOBILE_HIPRI:
case ConnectivityManager.TYPE_MOBILE_MMS:
case ConnectivityManager.TYPE_MOBILE_SUPL:
return true;
default:
return false;
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment