From d961a32145a2ebce42d632cfdcf36a05f13f6b44 Mon Sep 17 00:00:00 2001
From: Edouard Tisserant
Date: Mon, 12 Dec 2016 23:49:29 +0100
Subject: [PATCH] re-commited arturo's changes in one single clean commit,
again stripped leftover mess - 'update test app, update hgignore' also, this
commit updates adapter's buildToolsVersion to 25.0.0.
---
.hgignore | 11 +-
android/build.gradle | 4 +-
androidTests/app/build.gradle | 7 +-
.../androidTest/java/com/pep/k9/PEpTest.java | 10 +
androidTests/app/src/main/AndroidManifest.xml | 12 +-
.../main/java/com/pep/k9/MainActivity.java | 1849 ++++++++++++++---
.../main/java/com/pep/k9/PEpUnitaryStuff.java | 46 +
.../main/java/com/pep/k9/UnitActivity.java | 280 +++
.../app/src/main/res/layout/activity_main.xml | 417 +++-
.../app/src/main/res/layout/activity_unit.xml | 13 +
.../app/src/main/res/menu/menu_main.xml | 4 +-
.../java/com/pep/k9/MainActivityTest.java | 10 +
.../src/test/java/com/pep/k9/UnitaryTest.java | 49 +
androidTests/build.gradle | 2 +-
14 files changed, 2380 insertions(+), 334 deletions(-)
create mode 100644 androidTests/app/src/androidTest/java/com/pep/k9/PEpTest.java
create mode 100644 androidTests/app/src/main/java/com/pep/k9/PEpUnitaryStuff.java
create mode 100644 androidTests/app/src/main/java/com/pep/k9/UnitActivity.java
create mode 100644 androidTests/app/src/main/res/layout/activity_unit.xml
create mode 100644 androidTests/app/src/test/java/com/pep/k9/MainActivityTest.java
create mode 100644 androidTests/app/src/test/java/com/pep/k9/UnitaryTest.java
diff --git a/.hgignore b/.hgignore
index 83a0d09..7bc6a3e 100644
--- a/.hgignore
+++ b/.hgignore
@@ -51,7 +51,16 @@ androidTests/build
androidTests/.idea
androidTests/androidTests.iml
androidTests/app/app.iml
-
+.gradle
+android/.externalNativeBuild
+android/android.iml
+android/gradle/wrapper/gradle-wrapper.properties
+android/gradlew
+android/gradlew.bat
+androidTests/gradle/wrapper/gradle-wrapper.properties
+androidTests/gradlew
+androidTests/gradlew.bat
+src/org.tar.gz
syntax: regexp
android/external/[^.]*
diff --git a/android/build.gradle b/android/build.gradle
index ee0856d..c209d9b 100644
--- a/android/build.gradle
+++ b/android/build.gradle
@@ -18,7 +18,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.2'
+ classpath 'com.android.tools.build:gradle:2.2.0'
}
}
@@ -32,7 +32,7 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 21
- buildToolsVersion '23.0.3'
+ buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 15
diff --git a/androidTests/app/build.gradle b/androidTests/app/build.gradle
index ccfc7a8..da4b5ce 100644
--- a/androidTests/app/build.gradle
+++ b/androidTests/app/build.gradle
@@ -2,11 +2,11 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 23
- buildToolsVersion "23.0.0"
+ buildToolsVersion '25.0.0'
defaultConfig {
applicationId "pep.android.k9"
- minSdkVersion 15
+ minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
@@ -28,5 +28,8 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.0'
compile project(':pEpJNIAdapter')
+ testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:7.0.1'
+ compile 'com.karumi:dexter:2.3.1'
+ compile group: 'net.lingala.zip4j', name: 'zip4j', version: '1.3.1'
}
diff --git a/androidTests/app/src/androidTest/java/com/pep/k9/PEpTest.java b/androidTests/app/src/androidTest/java/com/pep/k9/PEpTest.java
new file mode 100644
index 0000000..fd76450
--- /dev/null
+++ b/androidTests/app/src/androidTest/java/com/pep/k9/PEpTest.java
@@ -0,0 +1,10 @@
+package com.pep.k9;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by arturo on 15/11/16.
+ */
+public class PEpTest {
+
+}
\ No newline at end of file
diff --git a/androidTests/app/src/main/AndroidManifest.xml b/androidTests/app/src/main/AndroidManifest.xml
index f82184d..ab266f6 100644
--- a/androidTests/app/src/main/AndroidManifest.xml
+++ b/androidTests/app/src/main/AndroidManifest.xml
@@ -1,23 +1,27 @@
+ package="com.pep.k9">
+
+
+
+ android:theme="@style/AppTheme">
+ android:label="@string/app_name">
+
-
+
\ No newline at end of file
diff --git a/androidTests/app/src/main/java/com/pep/k9/MainActivity.java b/androidTests/app/src/main/java/com/pep/k9/MainActivity.java
index 1287b67..bf539a3 100644
--- a/androidTests/app/src/main/java/com/pep/k9/MainActivity.java
+++ b/androidTests/app/src/main/java/com/pep/k9/MainActivity.java
@@ -1,28 +1,74 @@
package com.pep.k9;
+import android.Manifest;
import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.Intent;
import android.content.res.AssetManager;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Environment;
+import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
+import android.view.ViewGroup;
import android.widget.Button;
-import butterknife.Bind;
-import butterknife.ButterKnife;
-import butterknife.OnClick;
-import org.pEp.jniadapter.*;
-
+import android.widget.EditText;
+import android.widget.Toast;
+
+import com.karumi.dexter.Dexter;
+import com.karumi.dexter.PermissionToken;
+import com.karumi.dexter.listener.PermissionDeniedResponse;
+import com.karumi.dexter.listener.PermissionGrantedResponse;
+import com.karumi.dexter.listener.PermissionRequest;
+import com.karumi.dexter.listener.single.CompositePermissionListener;
+import com.karumi.dexter.listener.single.PermissionListener;
+import com.karumi.dexter.listener.single.SnackbarOnDeniedPermissionListener;
+
+import net.lingala.zip4j.core.ZipFile;
+import net.lingala.zip4j.model.ZipParameters;
+import net.lingala.zip4j.util.Zip4jConstants;
+
+import org.pEp.jniadapter.AndroidHelper;
+import org.pEp.jniadapter.Blob;
+import org.pEp.jniadapter.Engine;
+import org.pEp.jniadapter.Identity;
+import org.pEp.jniadapter.Message;
+import org.pEp.jniadapter.Pair;
+import org.pEp.jniadapter.Rating;
+import org.pEp.jniadapter.pEpException;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.Vector;
+import butterknife.Bind;
+import butterknife.ButterKnife;
+import butterknife.OnClick;
+
public class MainActivity extends AppCompatActivity {
+ private StringBuilder text;
+ private Integer testingTimes;
+ private List generatedIdentities;
+
+ @Bind(R.id.content) ViewGroup rootView;
+ private long outgoingColorAcumulative = 0L;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -30,13 +76,246 @@ public class MainActivity extends AppCompatActivity {
ButterKnife.bind(this);
Context c = getApplicationContext();
- Log.d("PEPTEST", "Helper Setup");
+ Dexter.initialize(getApplication());
+ PermissionListener feedbackViewPermissionListener = new PermissionListener() {
+ @Override
+ public void onPermissionGranted(PermissionGrantedResponse response) {
+
+ }
+
+ @Override
+ public void onPermissionDenied(PermissionDeniedResponse response) {
+
+ }
+
+ @Override
+ public void onPermissionRationaleShouldBeShown(PermissionRequest permission, PermissionToken token) {
+
+ }
+ };
+
+ CompositePermissionListener storagePermissionListener = new CompositePermissionListener(feedbackViewPermissionListener,
+ SnackbarOnDeniedPermissionListener.Builder.with(rootView, R.string.hello_world)
+ .withOpenSettingsButton("SETTINGS")
+ .build());
+ Dexter.checkPermission(storagePermissionListener, Manifest.permission.WRITE_EXTERNAL_STORAGE);
+
+ generatedIdentities = new ArrayList<>();
+ text = new StringBuilder();
+ log("PEPTEST", "Helper Setup");
AndroidHelper.setup(c);
}
+ private void writeToFile(String data) {
+ text.append(data);
+ text.append("\n");
+ }
+
+ public void generateNoteOnSD(String filename) {
+ try {
+ File rootParent = new File(Environment.getExternalStorageDirectory(), "pEpTest");
+ if (!rootParent.exists()) {
+ rootParent.mkdirs();
+ }
+
+ File root = new File(rootParent.getAbsolutePath(), String.valueOf(new Date()));
+ if (!root.exists()) {
+ root.mkdirs();
+ }
+
+ File file = new File(getApplicationInfo().dataDir);
+ copyDirectory(file, root);
+
+ Log.d("file", root.getAbsolutePath());
+ File filepath = new File(root, filename + ".txt"); // file path to save
+ filepath.createNewFile();
+ Log.d("file", filepath.getAbsolutePath());
+ FileWriter writer = new FileWriter(filepath);
+ writer.append(text.toString());
+ writer.flush();
+ writer.close();
+ archiveDir(root.getAbsolutePath(), root.getName());
+ removeDirectory(root);
+ Toast.makeText(this, "Dump generated", Toast.LENGTH_SHORT).show();
+ } catch (IOException e) {
+ Toast.makeText(this, "Dump not generated, give storage permissions", Toast.LENGTH_LONG).show();
+ }
+ }
+
+ private void removeDirectory(File directory) {
+ if (directory.isDirectory()) {
+ String[] children = directory.list();
+ for (int i = 0; i < children.length; i++) {
+ File file = new File(directory, children[i]);
+ if (file.isDirectory()) {
+ removeDirectory(file);
+ } else {
+ file.delete();
+ }
+ }
+ }
+ directory.delete();
+ }
+
+ private void archiveDir(String path, String filename) {
+ try {
+ // Initiate ZipFile object with the path/name of the zip file.
+ ZipFile zipFile = new ZipFile(path + "_" + filename + ".zip");
+
+ // Folder to add
+ String folderToAdd = path;
+
+ // Initiate Zip Parameters which define various properties such
+ // as compression method, etc.
+ ZipParameters parameters = new ZipParameters();
+
+ // set compression method to store compression
+ parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
+
+ // Set the compression level
+ parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
+
+ // Add folder to the zip file
+ zipFile.addFolder(folderToAdd, parameters);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void copyDirectory(File sourceLocation, File targetLocation)
+ throws IOException {
+
+ if (sourceLocation.isDirectory()) {
+ if (!targetLocation.exists() && !targetLocation.mkdirs()) {
+ throw new IOException("Cannot create dir " + targetLocation.getAbsolutePath());
+ }
+
+ String[] children = sourceLocation.list();
+ for (int i = 0; i < children.length; i++) {
+ copyDirectory(new File(sourceLocation, children[i]),
+ new File(targetLocation, children[i]));
+ }
+ } else {
+
+ // make sure the directory we plan to store the recording in exists
+ File directory = targetLocation.getParentFile();
+ if (directory != null && !directory.exists() && !directory.mkdirs()) {
+ throw new IOException("Cannot create dir " + directory.getAbsolutePath());
+ }
+
+ InputStream in = new FileInputStream(sourceLocation);
+ OutputStream out = new FileOutputStream(targetLocation);
+
+ // Copy the bits from instream to outstream
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+ }
+
+ public void copy(File src, File dst) throws IOException {
+ InputStream in = new FileInputStream(src);
+ OutputStream out = new FileOutputStream(dst);
+
+ // Transfer bytes from in to out
+ byte[] buf = new byte[1024];
+ int len;
+ while ((len = in.read(buf)) > 0) {
+ out.write(buf, 0, len);
+ }
+ in.close();
+ out.close();
+ }
+
+ private void log(String tag, String added) {
+ Log.d(tag, added);
+ writeToFile(tag + " " + added);
+ }
+
+ private void logStart(String tag, String added) {
+ added = "started at " + added;
+ Log.d(tag, added);
+ writeToFile(tag + " " + added);
+ }
+
+ private void logEnd(String tag, String added) {
+ added = "completed in " + added;
+ Log.d(tag, added);
+ writeToFile(tag + " " + added);
+ }
+
+ @Bind(R.id.bRunTypes) Button runTypes;
+ @Bind(R.id.bRunAliceBob) Button runIntegration;
+ @Bind(R.id.bRunServerLookup) Button runLookup;
@Bind(R.id.bRunGenKey) Button runGenKey;
- @OnClick(R.id.bRunGenKey) public void runGenKey() {
- new RunTestTask().execute();
+ @Bind(R.id.encrypt_and_decrypt) Button runEncryptAndDecrypt;
+ @Bind(R.id.encrypt_and_decrypt_without_key) Button runEncryptAndDecryptWithoutKey;
+ @Bind(R.id.ratings) Button runRatings;
+ @Bind(R.id.black_list) Button runBlackList;
+ @Bind(R.id.black_list_and_send) Button runBlackListAndSendMessage;
+ @Bind(R.id.black_list_and_delete) Button runBlackListAndDelete;
+ @Bind(R.id.unencrypted_subject) Button runUnencryptedSubject;
+ @Bind(R.id.passive_mode) Button runPassiveMode;
+ @Bind(R.id.message_from_me_green) Button runMessageFromMeIsGreen;
+ @Bind(R.id.message_me) Button runMessageMe;
+ @Bind(R.id.times_to_test) EditText timesToTest;
+ @Bind(R.id.outgoing_color) Button runOutgoingColor;
+ @Bind(R.id.identity_rating) Button runIdentityRating;
+ @Bind(R.id.deblacklist) Button runDeblacklist;
+
+ @OnClick(R.id.bRunTypes)
+ public void runTypes() {
+ runTypes.setText("TESTING");
+ new RunTestTask().execute(1);
+ }
+ @OnClick(R.id.bRunAliceBob)
+ public void runIntegration() {
+ runIntegration.setText("TESTING");
+ new RunTestTask().execute(6);
+ }
+ @OnClick(R.id.bRunServerLookup)
+ public void runLookup() {
+ runLookup.setText("TESTING");
+ new RunTestTask().execute(2);
+ }
+ @OnClick(R.id.bRunGenKey)
+ public void runGenKey() {
+ runGenKey.setText("TESTING");
+ new RunTestTask().execute(0);
+ }
+ @OnClick(R.id.encrypt_and_decrypt)
+ public void runEncryptAndDecrypt() {
+ runEncryptAndDecrypt.setText("TESTING");
+ new RunTestTask().execute(3);
+ }
+ @OnClick(R.id.encrypt_and_decrypt_without_key)
+ public void runEncryptAndDecryptWithoutKey() {
+ runEncryptAndDecryptWithoutKey.setText("TESTING");
+ new RunTestTask().execute(4);
+ }
+ @OnClick(R.id.ratings)
+ public void runRatings() {
+ runRatings.setText("TESTING");
+ new RunTestTask().execute(5);
+ }
+
+ @OnClick(R.id.deblacklist)
+ public void runDeblack() {
+ runDeblacklist.setText("TESTING");
+ new RunTestTask().execute(16);
+ }
+
+ @OnClick(R.id.test_everything)
+ public void runAllTests() {
+ Toast.makeText(this, "Testing started. Please, don't touch anything ò.ó", Toast.LENGTH_LONG).show();
+ testingTimes = Integer.valueOf(timesToTest.getText().toString());
+ runGenKey.setText("TESTING");
+ new RunAllTestsTask().execute(0);
}
@Override
@@ -52,23 +331,86 @@ public class MainActivity extends AppCompatActivity {
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
- new RunTestTask().execute();
+ finish();
+ startActivity(getIntent());
+ return true;
+ }
+
+ if (id == R.id.action_unitary) {
+ Intent intent = new Intent(this, UnitActivity.class);
+ startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
- private void runTest() {
- try {
- //testPEpTypes();
- //testPEpAliceBobJohn();
- //testKeyserverLookup();
- testKeyGen();
- }
- catch (Exception ex) {
- Log.e("PEPTEST", "##################### TEST Exception ####################", ex);
- }
+ private void runIntegrationTest() throws IOException, pEpException {
+ integrationTest();
+ }
+
+ private void runEncryptAndDecryptTest() throws IOException, pEpException {
+ encryptAndDecryptAMessage();
+ }
+
+ private void runDeblacklistRatingTest() throws IOException, pEpException {
+ deblacklistRating();
+ }
+
+ private void runEncryptAndDecryptAMessageFromMyselft() throws IOException, pEpException {
+ encryptAndDecryptAMessageFromMyselfTest();
+ }
+
+ private void runMessageForMeIsAlwaysGreenTest() throws IOException, pEpException {
+ messageForMeIsAlwaysGreen();
+ }
+
+ private void runUnencryptedSubjectTest() throws IOException, pEpException {
+ unencryptedSubjectTest();
+ }
+
+ private void runEncryptAndDecryptWithoutKeyTest() throws IOException, pEpException {
+ encryptAndDecryptAMessageWithoutKey();
+ }
+
+ private void runColorRatingsTest() throws IOException, pEpException {
+ ratingsTest();
+ }
+
+ private void runTestPEpTypes() throws IOException, pEpException {
+ testPEpTypes();
+ }
+
+ private void runTestKeyserverLookup() throws pEpException, InterruptedException, IOException {
+ testKeyserverLookup();
+ }
+
+ private void runTestKeyGen() throws pEpException, InterruptedException, IOException {
+ testKeyGen();
+ }
+
+ private void runAddToBlacklistTest() throws pEpException, InterruptedException, IOException {
+ addToBlacklistTest();
+ }
+
+ private void runAddToBlacklistAndSendMessageTest() throws pEpException, InterruptedException, IOException {
+ addToBlacklistAndSendMessageTest();
+ }
+
+ private void runAddAndRemoveFromBlacklistTest() throws pEpException, InterruptedException, IOException {
+ addAndRemoveFromBlacklistTest();
+ }
+
+ private void runPassiveModeTest() throws pEpException, InterruptedException, IOException {
+ passiveModeTest();
+ }
+
+ private void runOutgoingColorTest() throws pEpException, InterruptedException, IOException {
+ testOutgoingColor();
+ }
+
+ private void runIdetntityRatingTest() throws pEpException, InterruptedException, IOException {
+ testIdetntityRating();
}
private byte[] LoadAssetAsBuffer(String fname) throws IOException {
@@ -91,13 +433,15 @@ public class MainActivity extends AppCompatActivity {
// byte buffer into a string
return new String(LoadAssetAsBuffer(fname));
}
- public void testPEpTypes() throws pEpException, IOException, AssertionError {
-
- Engine e;
- Log.d("PEPTEST", "Test loaded");
+ /*
+ Just checks the correct creation of an email
+ */
+ public void testPEpTypes() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test pep types loaded");
+ Engine engine;
- e = new Engine();
+ engine = new Engine();
Message msg = new Message();
@@ -105,43 +449,43 @@ public class MainActivity extends AppCompatActivity {
// TEST : Call getter before call to getter
- if(!(msg.getDir() == Message.Direction.Incoming)) throw new AssertionError();
- if(!(msg.getId()==null)) throw new AssertionError();
- if(!(msg.getLongmsg()==null)) throw new AssertionError();
- if(!(msg.getLongmsgFormatted()==null)) throw new AssertionError();
- if(!(msg.getAttachments()==null)) throw new AssertionError();
- if(!(msg.getSent()==null)) throw new AssertionError();
- if(!(msg.getRecv()==null)) throw new AssertionError();
- if(!(msg.getFrom()==null)) throw new AssertionError();
- if(!(msg.getTo()==null)) throw new AssertionError();
- if(!(msg.getRecvBy()==null)) throw new AssertionError();
- if(!(msg.getCc()==null)) throw new AssertionError();
- if(!(msg.getBcc()==null)) throw new AssertionError();
- if(!(msg.getInReplyTo()==null)) throw new AssertionError();
- if(!(msg.getReferences()==null)) throw new AssertionError();
- if(!(msg.getKeywords()==null)) throw new AssertionError();
- if(!(msg.getComments()==null)) throw new AssertionError();
- if(!(msg.getOptFields()==null)) throw new AssertionError();
- if(!(msg.getEncFormat()==Message.EncFormat.None)) throw new AssertionError();
+ if (!(msg.getDir() == Message.Direction.Incoming)) throw new AssertionError();
+ if (!(msg.getId() == null)) throw new AssertionError();
+ if (!(msg.getLongmsg() == null)) throw new AssertionError();
+ if (!(msg.getLongmsgFormatted() == null)) throw new AssertionError();
+ if (!(msg.getAttachments() == null)) throw new AssertionError();
+ if (!(msg.getSent() == null)) throw new AssertionError();
+ if (!(msg.getRecv() == null)) throw new AssertionError();
+ if (!(msg.getFrom() == null)) throw new AssertionError();
+ if (!(msg.getTo() == null)) throw new AssertionError();
+ if (!(msg.getRecvBy() == null)) throw new AssertionError();
+ if (!(msg.getCc() == null)) throw new AssertionError();
+ if (!(msg.getBcc() == null)) throw new AssertionError();
+ if (!(msg.getInReplyTo() == null)) throw new AssertionError();
+ if (!(msg.getReferences() == null)) throw new AssertionError();
+ if (!(msg.getKeywords() == null)) throw new AssertionError();
+ if (!(msg.getComments() == null)) throw new AssertionError();
+ if (!(msg.getOptFields() == null)) throw new AssertionError();
+ if (!(msg.getEncFormat() == Message.EncFormat.None)) throw new AssertionError();
// TEST : Call setter with non-null
// and check getter returns the same
msg.setDir(Message.Direction.Outgoing);
- if(!(msg.getDir()==Message.Direction.Outgoing)) throw new AssertionError();
+ if (!(msg.getDir() == Message.Direction.Outgoing)) throw new AssertionError();
msg.setId("1234ID");
- if(!(msg.getId().equals("1234ID"))) throw new AssertionError();
+ if (!(msg.getId().equals("1234ID"))) throw new AssertionError();
msg.setShortmsg("ShrtMsg");
- if(!(msg.getShortmsg().equals("ShrtMsg"))) throw new AssertionError();
+ if (!(msg.getShortmsg().equals("ShrtMsg"))) throw new AssertionError();
msg.setLongmsg("Loooooooooooooonger Message");
- if(!(msg.getLongmsg().equals("Loooooooooooooonger Message"))) throw new AssertionError();
+ if (!(msg.getLongmsg().equals("Loooooooooooooonger Message"))) throw new AssertionError();
msg.setLongmsgFormatted("");
- if(!(msg.getLongmsgFormatted().equals(""))) throw new AssertionError();
+ if (!(msg.getLongmsgFormatted().equals("
"))) throw new AssertionError();
{
Vector attachments = new Vector();
@@ -152,8 +496,8 @@ public class MainActivity extends AppCompatActivity {
msg.setAttachments(attachments);
Vector detach = msg.getAttachments();
Blob dblb = detach.firstElement();
- if(!(dblb.filename.equals(blb.filename))) throw new AssertionError();
- if(!(Arrays.equals(dblb.data, blb.data))) throw new AssertionError();
+ if (!(dblb.filename.equals(blb.filename))) throw new AssertionError();
+ if (!(Arrays.equals(dblb.data, blb.data))) throw new AssertionError();
}
{
@@ -162,7 +506,8 @@ public class MainActivity extends AppCompatActivity {
msg.setSent(now);
Date res = msg.getSent();
// Conversion rounds to the second, java's Date is in millisecond.
- if(!(java.lang.Math.abs(res.getTime() - now.getTime()) < 1000)) throw new AssertionError();
+ if (!(java.lang.Math.abs(res.getTime() - now.getTime()) < 1000))
+ throw new AssertionError();
}
{
@@ -171,7 +516,8 @@ public class MainActivity extends AppCompatActivity {
msg.setRecv(now);
Date res = msg.getRecv();
// Conversion rounds to the second, java's Date is in millisecond.
- if(!(java.lang.Math.abs(res.getTime() - now.getTime()) < 1000)) throw new AssertionError();
+ if (!(java.lang.Math.abs(res.getTime() - now.getTime()) < 1000))
+ throw new AssertionError();
}
{
@@ -185,11 +531,12 @@ public class MainActivity extends AppCompatActivity {
msg.setFrom(alice);
Identity _alice = msg.getFrom();
- if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
- if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
- if(!(_alice.user_id.equals("111"))) throw new AssertionError();
- if(!(_alice.me == true)) throw new AssertionError();
- if(!(_alice.fpr == null)) throw new AssertionError();
+ if (!(_alice.username.equals("Alice Test"))) throw new AssertionError();
+ if (!(_alice.address.equals("pep.test.alice@pep-project.org")))
+ throw new AssertionError();
+ if (!(_alice.user_id.equals("111"))) throw new AssertionError();
+ if (!(_alice.me == true)) throw new AssertionError();
+ if (!(_alice.fpr == null)) throw new AssertionError();
}
{
@@ -206,11 +553,12 @@ public class MainActivity extends AppCompatActivity {
Vector _rcpts = msg.getTo();
Identity _alice = _rcpts.firstElement();
- if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
- if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
- if(!(_alice.user_id.equals("111"))) throw new AssertionError();
- if(!(_alice.me == true)) throw new AssertionError();
- if(!(_alice.fpr == null)) throw new AssertionError();
+ if (!(_alice.username.equals("Alice Test"))) throw new AssertionError();
+ if (!(_alice.address.equals("pep.test.alice@pep-project.org")))
+ throw new AssertionError();
+ if (!(_alice.user_id.equals("111"))) throw new AssertionError();
+ if (!(_alice.me == true)) throw new AssertionError();
+ if (!(_alice.fpr == null)) throw new AssertionError();
}
{
@@ -224,11 +572,12 @@ public class MainActivity extends AppCompatActivity {
msg.setRecvBy(alice);
Identity _alice = msg.getRecvBy();
- if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
- if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
- if(!(_alice.user_id.equals("111"))) throw new AssertionError();
- if(!(_alice.me == true)) throw new AssertionError();
- if(!(_alice.fpr == null)) throw new AssertionError();
+ if (!(_alice.username.equals("Alice Test"))) throw new AssertionError();
+ if (!(_alice.address.equals("pep.test.alice@pep-project.org")))
+ throw new AssertionError();
+ if (!(_alice.user_id.equals("111"))) throw new AssertionError();
+ if (!(_alice.me == true)) throw new AssertionError();
+ if (!(_alice.fpr == null)) throw new AssertionError();
}
{
@@ -245,11 +594,12 @@ public class MainActivity extends AppCompatActivity {
Vector _rcpts = msg.getCc();
Identity _alice = _rcpts.firstElement();
- if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
- if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
- if(!(_alice.user_id.equals("111"))) throw new AssertionError();
- if(!(_alice.me == true)) throw new AssertionError();
- if(!(_alice.fpr == null)) throw new AssertionError();
+ if (!(_alice.username.equals("Alice Test"))) throw new AssertionError();
+ if (!(_alice.address.equals("pep.test.alice@pep-project.org")))
+ throw new AssertionError();
+ if (!(_alice.user_id.equals("111"))) throw new AssertionError();
+ if (!(_alice.me == true)) throw new AssertionError();
+ if (!(_alice.fpr == null)) throw new AssertionError();
}
{
@@ -266,11 +616,12 @@ public class MainActivity extends AppCompatActivity {
Vector _rcpts = msg.getBcc();
Identity _alice = _rcpts.firstElement();
- if(!(_alice.username.equals("Alice Test"))) throw new AssertionError();
- if(!(_alice.address.equals("pep.test.alice@pep-project.org"))) throw new AssertionError();
- if(!(_alice.user_id.equals("111"))) throw new AssertionError();
- if(!(_alice.me == true)) throw new AssertionError();
- if(!(_alice.fpr == null)) throw new AssertionError();
+ if (!(_alice.username.equals("Alice Test"))) throw new AssertionError();
+ if (!(_alice.address.equals("pep.test.alice@pep-project.org")))
+ throw new AssertionError();
+ if (!(_alice.user_id.equals("111"))) throw new AssertionError();
+ if (!(_alice.me == true)) throw new AssertionError();
+ if (!(_alice.fpr == null)) throw new AssertionError();
}
{
@@ -280,7 +631,7 @@ public class MainActivity extends AppCompatActivity {
msg.setInReplyTo(strvec);
Vector _strvec = msg.getInReplyTo();
- if(!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
+ if (!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
}
{
@@ -290,7 +641,7 @@ public class MainActivity extends AppCompatActivity {
msg.setReferences(strvec);
Vector _strvec = msg.getReferences();
- if(!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
+ if (!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
}
{
@@ -300,151 +651,688 @@ public class MainActivity extends AppCompatActivity {
msg.setKeywords(strvec);
Vector _strvec = msg.getKeywords();
- if(!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
+ if (!(_strvec.firstElement().equals("Blub"))) throw new AssertionError();
}
msg.setComments("No comment.");
- if(!(msg.getComments().equals("No comment."))) throw new AssertionError();
+ if (!(msg.getComments().equals("No comment."))) throw new AssertionError();
{
ArrayList> pairs = new ArrayList>();
- Pair pair = new Pair("left","right");
+ Pair pair = new Pair("left", "right");
pairs.add(pair);
msg.setOptFields(pairs);
ArrayList> _pairs = msg.getOptFields();
- Pair _pair = _pairs.get(0);
- if(!(_pair.first.equals("left"))) throw new AssertionError();
- if(!(_pair.second.equals("right"))) throw new AssertionError();
+ Pair _pair = _pairs.get(0);
+ if (!(_pair.first.equals("left"))) throw new AssertionError();
+ if (!(_pair.second.equals("right"))) throw new AssertionError();
}
msg.setEncFormat(Message.EncFormat.PEP);
- if(!(msg.getEncFormat()==Message.EncFormat.PEP)) throw new AssertionError();
+ if (!(msg.getEncFormat() == Message.EncFormat.PEP)) throw new AssertionError();
// TEST : Call setter with null and then call getter
msg.setDir(null);
- if(!(msg.getDir() == Message.Direction.Incoming)) throw new AssertionError();
+ if (!(msg.getDir() == Message.Direction.Incoming)) throw new AssertionError();
msg.setId(null);
- if(!(msg.getId()==null)) throw new AssertionError();
+ if (!(msg.getId() == null)) throw new AssertionError();
msg.setShortmsg(null);
- if(!(msg.getShortmsg()==null)) throw new AssertionError();
+ if (!(msg.getShortmsg() == null)) throw new AssertionError();
msg.setLongmsg(null);
- if(!(msg.getLongmsg()==null)) throw new AssertionError();
+ if (!(msg.getLongmsg() == null)) throw new AssertionError();
msg.setLongmsgFormatted(null);
- if(!(msg.getLongmsgFormatted()==null)) throw new AssertionError();
+ if (!(msg.getLongmsgFormatted() == null)) throw new AssertionError();
msg.setAttachments(null);
- if(!(msg.getAttachments()==null)) throw new AssertionError();
+ if (!(msg.getAttachments() == null)) throw new AssertionError();
msg.setSent(null);
- if(!(msg.getSent()==null)) throw new AssertionError();
+ if (!(msg.getSent() == null)) throw new AssertionError();
msg.setRecv(null);
- if(!(msg.getRecv()==null)) throw new AssertionError();
+ if (!(msg.getRecv() == null)) throw new AssertionError();
msg.setFrom(null);
- if(!(msg.getFrom()==null)) throw new AssertionError();
+ if (!(msg.getFrom() == null)) throw new AssertionError();
msg.setTo(null);
- if(!(msg.getTo()==null)) throw new AssertionError();
+ if (!(msg.getTo() == null)) throw new AssertionError();
msg.setRecvBy(null);
- if(!(msg.getRecvBy()==null)) throw new AssertionError();
+ if (!(msg.getRecvBy() == null)) throw new AssertionError();
msg.setCc(null);
- if(!(msg.getCc()==null)) throw new AssertionError();
+ if (!(msg.getCc() == null)) throw new AssertionError();
msg.setBcc(null);
- if(!(msg.getBcc()==null)) throw new AssertionError();
+ if (!(msg.getBcc() == null)) throw new AssertionError();
msg.setInReplyTo(null);
- if(!(msg.getInReplyTo()==null)) throw new AssertionError();
+ if (!(msg.getInReplyTo() == null)) throw new AssertionError();
msg.setReferences(null);
- if(!(msg.getReferences()==null)) throw new AssertionError();
+ if (!(msg.getReferences() == null)) throw new AssertionError();
msg.setKeywords(null);
- if(!(msg.getKeywords()==null)) throw new AssertionError();
+ if (!(msg.getKeywords() == null)) throw new AssertionError();
msg.setComments(null);
- if(!(msg.getComments()==null)) throw new AssertionError();
+ if (!(msg.getComments() == null)) throw new AssertionError();
msg.setOptFields(null);
- if(!(msg.getOptFields()==null)) throw new AssertionError();
+ if (!(msg.getOptFields() == null)) throw new AssertionError();
msg.setEncFormat(null);
- if(!(msg.getEncFormat()== Message.EncFormat.None)) throw new AssertionError();
+ if (!(msg.getEncFormat() == Message.EncFormat.None)) throw new AssertionError();
- Log.d("PEPTEST", "Test finished");
+ engine.close();
+ log("TEST: ", "Test pep types finished");
+ }
- e.close();
+ /*
+ Tests the Ratings and Encrypts-Decrypts message
+ */
+ public void integrationTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "integration test loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ // trustwords
+ testTrustwords(engine);
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ Identity john = loadJohnFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ setupRatingToMyself(engine, msg);
+
+ testRatingStatuses(engine, bob, msg);
+
+ //Vector bcc = new Vector<>();
+ //bcc.add(john);
+ //msg.setBcc(bcc);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ byte[] gif = LoadAssetAsBuffer("spinner.gif");
+ byte[] png = LoadAssetAsBuffer("pep.png");
+ byte[] tbz = LoadAssetAsBuffer("yml2.tar.bz2");
+
+ attachToMessage(msg, gif, png, tbz);
+
+ encrypAndDecryptMessage(engine, msg);
+
+ detachFromMessage(msg, gif, png, tbz);
+
+ engine.close();
+ log("TEST: ", "integration test finished");
}
- public void testPEpAliceBobJohn() throws pEpException, IOException, AssertionError {
- Engine e;
+ public void addToBlacklistTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "blacklist test started");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
- // load
- e = new Engine();
+ // trustwords
+ testTrustwords(engine);
+
+ Identity alice = loadAliceFromEngine(engine);
- Log.d("PEPTEST", "Test loaded");
+ String fingerprint = alice.fpr;
+ addToBlacklistInEngine(engine, fingerprint);
+
+ alice = myselfInEngine(engine, alice);
+
+ if (!fingerprint.equals(alice.fpr)) {
+ throw new AssertionError();
+ }
+
+ removeFromBlacklistOnEngine(engine, alice.fpr);
+ engine.close();
+ log("TEST: ", "blacklist test finished");
+ }
+
+ public void testOutgoingColor() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "testOutgoingColor start");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
// trustwords
+ testTrustwords(engine);
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ setupRatingToMyself(engine, msg);
+
+ testRatingStatuses(engine, bob, msg);
+
+ long time = System.currentTimeMillis();
+ logStart("outgoing_message_rating", String.valueOf(time));
+ engine.outgoing_message_rating(msg);
+ long outgoingColorCalculus = System.currentTimeMillis() - time;
+ outgoingColorAcumulative +=outgoingColorCalculus;
+ logEnd("outgoing_message_rating", String.valueOf(outgoingColorCalculus));
+
+ engine.close();
+ log("TEST: ", "testOutgoingColor finished");
+ }
+
+ public void testIdetntityRating() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "testIdetntityRating start");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ // trustwords
+ testTrustwords(engine);
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ long time = System.currentTimeMillis();
+ logStart("identity_rating", String.valueOf(time));
+ engine.identity_rating(bob);
+ long identityRatingCalculus = System.currentTimeMillis() - time;
+ logEnd("identity_rating", String.valueOf(identityRatingCalculus));
+
+ engine.close();
+ log("TEST: ", "testIdetntityRating finished");
+ }
+
+ public void addToBlacklistAndSendMessageTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "blacklist + send message test started");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ // trustwords
+ testTrustwords(engine);
+
+ Identity alice = loadAliceFromEngine(engine);
+ Identity bob = loadBobFromEngine(engine);
+
+ String fingerprint = bob.fpr;
+ addToBlacklistInEngine(engine, fingerprint);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ byte[] gif = LoadAssetAsBuffer("spinner.gif");
+ byte[] png = LoadAssetAsBuffer("pep.png");
+ byte[] tbz = LoadAssetAsBuffer("yml2.tar.bz2");
+
+ attachToMessage(msg, gif, png, tbz);
+
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
+
+ if (encriptedMessage != null) throw new AssertionError();
+
+ //if (!(encriptedMessage.getShortmsg().equals("pEp"))) throw new AssertionError();
+ //if (!(encriptedMessage.getLongmsg().contains("pEp-project.org")))
+ // throw new AssertionError();
+
+ removeFromBlacklistOnEngine(engine, fingerprint);
+
+ engine.close();
+ log("TEST: ", "blacklist + send message test finished");
+ }
+
+ public void addAndRemoveFromBlacklistTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "blacklist + delete from blacklist test started");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ // trustwords
+ testTrustwords(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ String fingerprint = bob.fpr;
+ addToBlacklistInEngine(engine, fingerprint);
+
+ removeFromBlacklistOnEngine(engine, fingerprint);
+
+ Boolean isBlacklisted = isBlacklistedOnEngine(engine, bob);
+
+ if (isBlacklisted) {
+ throw new AssertionError();
+ }
+ // message
+
+ getBlacklist(engine);
+
+ engine.close();
+ log("TEST: ", "blacklist + delete from blacklist finished");
+ }
+
+ private Vector getBlacklist(Engine engine) throws pEpException {
+ long lastTime = System.currentTimeMillis();
+ logStart("blacklist_retrieve", String.valueOf(lastTime));
+ Vector blacklist = engine.blacklist_retrieve();
+ logEnd("blacklist_retrieve", String.valueOf(System.currentTimeMillis() - lastTime));
+ return blacklist;
+ }
+
+ private Boolean isBlacklistedOnEngine(Engine engine, Identity bob) {
+ long lastTime = System.currentTimeMillis();
+ logStart("blacklist_is_listed", String.valueOf(lastTime));
+ Boolean isBlacklisted = engine.blacklist_is_listed(bob.fpr);
+ logEnd("blacklist_is_listed", String.valueOf(System.currentTimeMillis() - lastTime));
+ return isBlacklisted;
+ }
+
+ private void removeFromBlacklistOnEngine(Engine engine, String fingerprint) {
+ long lastTime = System.currentTimeMillis();
+ logStart("blacklist_delete", String.valueOf(lastTime));
+ engine.blacklist_delete(fingerprint);
+ logEnd("backlist_delete", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
+
+ private Identity myselfInEngine(Engine engine, Identity identity) {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.addToBlacklist", String.valueOf(lastTime));
+ Identity myself = engine.myself(identity);
+ logEnd("engine.addToBlacklist", String.valueOf(System.currentTimeMillis() - lastTime));
+ return myself;
+ }
+
+ private void addToBlacklistInEngine(Engine engine, String fingerprint) {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.addToBlacklist", String.valueOf(lastTime));
+ engine.blacklist_add(fingerprint);
+ logEnd("engine.addToBlacklist", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
+
+ private void ratingsTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test ratings loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ // trustwords
+ testTrustwords(engine);
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ setupRatingToMyself(engine, msg);
+
+ testRatingStatuses(engine, bob, msg);
+
+ engine.close();
+ log("TEST: ", "Test ratings finished");
+ }
+
+ public void encryptAndDecryptAMessage() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test encrypt and decrypt loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ encrypAndDecryptMessage(engine, msg);
+
+ engine.close();
+ log("TEST: ", "Test encrypt and decrypt finished");
+ }
+
+ public void deblacklistRating() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test deblacklistRating loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ removeFromBlacklistOnEngine(engine, bob.fpr);
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ log("Test deblacklistRating after remove blacklist", getOutgoingMessageRatingFromEngine(engine, msg).name());
+
+ if (!(getOutgoingMessageRatingFromEngine(engine, msg).equals(Rating.pEpRatingReliable))) {
+ throw new AssertionError();
+ }
+
+ String fingerprint = bob.fpr;
+ addToBlacklistInEngine(engine, fingerprint);
+
+ Message msgBlacklisted = setupMessage(alice, bob);
+
+ log("Test deblacklistRating after blacklist", getOutgoingMessageRatingFromEngine(engine, msgBlacklisted).name());
+
+ if (getOutgoingMessageRatingFromEngine(engine, msgBlacklisted).value > 4) {
+ throw new AssertionError();
+ }
+
+ removeFromBlacklistOnEngine(engine, fingerprint);
+
+ Message msgDeBlacklisted = setupMessage(alice, bob);
+
+ log("Test deblacklistRating after remove blacklist", getOutgoingMessageRatingFromEngine(engine, msg).name());
+ if (!(getOutgoingMessageRatingFromEngine(engine, msgDeBlacklisted).equals(Rating.pEpRatingReliable))) {
+ throw new AssertionError();
+ }
+
+ engine.close();
+ log("TEST: ", "Test deblacklistRating finished");
+ }
+
+ public void encryptAndDecryptAMessageFromMyselfTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test encrypt and decrypt from myself loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, alice);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
+
+ if (!(encriptedMessage != null)) throw new AssertionError();
+
+ if (!(encriptedMessage.getShortmsg().equals("pEp"))) throw new AssertionError();
+ if (!(encriptedMessage.getLongmsg().contains("pEp-project.org")))
+ throw new AssertionError();
+
+ Vector attachments = encriptedMessage.getAttachments();
+ if (!(engine.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----")))
+ throw new AssertionError();
+
+ Engine.decrypt_message_Return result = null;
+ decryptMessageOnEngine(engine, encriptedMessage);
+
+ engine.close();
+ log("TEST: ", "Test encrypt and decrypt from myself finished");
+ }
+
+ public void messageForMeIsAlwaysGreen() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test message from me is green loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, alice);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ Engine.decrypt_message_Return decrypt_message_return = encrypAndDecryptMessage(engine, msg);
+
+ if(decrypt_message_return.rating.value < 6) {
+ throw new AssertionError();
+ }
+
+ engine.close();
+ log("TEST: ", "Test message from me is green finished");
+ }
+
+ public void unencryptedSubjectTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test unencrypted subject loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ long time = System.currentTimeMillis();
+ logStart("config_unencrypted_subject", String.valueOf(time));
+ engine.config_unencrypted_subject(true);
+ logEnd("config_unencrypted_subject", String.valueOf(System.currentTimeMillis() - time));
+
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
+
+ if (!encriptedMessage.getShortmsg().equals(msg.getShortmsg())) throw new AssertionError();
+
+ engine.close();
+ log("TEST: ", "Test unencrypted subject finished");
+ }
+
+ public void passiveModeTest() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test passive mode loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ long time = System.currentTimeMillis();
+ logStart("config_passive_mode", String.valueOf(time));
+ engine.config_passive_mode(true);
+ logEnd("config_passive_mode", String.valueOf(System.currentTimeMillis()));
+
+ if (msg.getAttachments() != null) throw new AssertionError();
+
+ engine.close();
+ log("TEST: ", "Test passive mode finished");
+ }
+
+ public void encryptAndDecryptAMessageWithoutKey() throws pEpException, IOException, AssertionError {
+ log("TEST: ", "Test encrypt and decrypt without key loaded");
+ long lastTime = System.currentTimeMillis();
+ Engine engine;
+ engine = new Engine();
+ log("engine.new Engine()", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngineWithoutKey(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ encrypAndDecryptMessage(engine, msg);
+
+ if (msg.getAttachments() == null) {
+ throw new AssertionError();
+ }
+
+ engine.close();
+ log("TEST: ", "Test encrypt and decrypt without key finished");
+ }
+
+ private void testTrustwords(Engine engine) {
Identity vb = new Identity();
vb.fpr = "DB4713183660A12ABAFA7714EBE90D44146F62F4";
- String t = e.trustwords(vb);
- if(!(t.equals("BAPTISMAL BERTRAND DIVERSITY SCOTSWOMAN TRANSDUCER MIGNONNE CETACEAN AUSTRAL BIPARTISAN JINNAH"))) throw new AssertionError();
+ String t = engine.trustwords(vb);
+ if (!(t.equals("BAPTISMAL BERTRAND DIVERSITY SCOTSWOMAN TRANSDUCER MIGNONNE CETACEAN AUSTRAL BIPARTISAN JINNAH")))
+ throw new AssertionError();
+ }
- // Our test user :
- // pEp Test Alice (test key don't use)
- // 6FF00E97
- // A9411D176FF00E97
- e.importKey(LoadAssetAsString("6FF00E97_sec.asc"));
+ @NonNull
+ private Identity loadJohnFromEngine(Engine engine) throws IOException {
+ //
+ // pEp Test John (test key, don't use)
+ // 70DCF575
+ // 135CD6D170DCF575
+ importKeyFromEngine(engine, "0x70DCF575.asc");
- Identity alice = new Identity();
- alice.username = "Alice Test";
- alice.address = "pep.test.alice@pep-project.org";
- alice.user_id = "111";
- alice.me = true;
- alice.fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
- e.myself(alice);
+ Identity john = new Identity();
+ john.username = "john Test";
+ john.address = "pep.test.john@pep-project.org";
+ john.user_id = "113";
+ john.fpr = "AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575";
+ updateIdentityOnEngine(engine, john);
+ return john;
+ }
+ @NonNull
+ private Identity loadBobFromEngine(Engine engine) throws IOException {
//
// Other peers :
// pEp Test Bob (test key, don't use)
// C9C2EE39
// 59BFF488C9C2EE39
- e.importKey(LoadAssetAsString("0xC9C2EE39.asc"));
+ importKeyFromEngine(engine, "0xC9C2EE39.asc");
Identity bob = new Identity();
bob.username = "bob Test";
bob.address = "pep.test.bob@pep-project.org";
bob.user_id = "112";
bob.fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
- e.updateIdentity(bob);
+ updateIdentityOnEngine(engine, bob);
+ return bob;
+ }
+
+ @NonNull
+ private Identity loadBobFromEngineWithoutKey(Engine engine) throws IOException {
//
- // pEp Test John (test key, don't use)
- // 70DCF575
- // 135CD6D170DCF575
- e.importKey(LoadAssetAsString("0x70DCF575.asc"));
+ // Other peers :
+ // pEp Test Bob (test key, don't use)
+ // C9C2EE39
+ // 59BFF488C9C2EE39
+ Identity bob = new Identity();
+ bob.username = "bob Test";
+ bob.address = "pep.test.bob@pep-project.org";
+ bob.user_id = "112";
- Identity john = new Identity();
- john.username = "john Test";
- john.address = "pep.test.john@pep-project.org";
- john.user_id = "113";
- john.fpr = "AA2E4BEB93E5FE33DEFD8BE1135CD6D170DCF575";
- e.updateIdentity(john);
+ updateIdentityOnEngine(engine, bob);
+ return bob;
+ }
- // message
+ private void updateIdentityOnEngine(Engine engine, Identity identity) {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.updateIdentity", String.valueOf(lastTime));
+ engine.updateIdentity(identity);
+ logEnd("engine.updateIdentity", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
+
+ private void importKeyFromEngine(Engine engine, String filename) throws IOException {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.importKey", String.valueOf(lastTime));
+ engine.importKey(LoadAssetAsString(filename));
+ logEnd("engine.importKey", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
+
+ @NonNull
+ private Identity loadAliceFromEngine(Engine engine) throws IOException {
+ // Our test user :
+ // pEp Test Alice (test key don't use)
+ // 6FF00E97
+ // A9411D176FF00E97
+ importKeyFromEngine(engine, "6FF00E97_sec.asc");
+
+ Identity alice = new Identity();
+ alice.username = "Alice Test";
+ alice.address = "pep.test.alice@pep-project.org";
+ alice.user_id = "pEp_own_userId";
+ alice.me = true;
+ alice.fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
+
+ long lastTime = System.currentTimeMillis();
+ myselfInEngine(engine, alice);
+ log("engine.myself", String.valueOf(System.currentTimeMillis() - lastTime));
+
+ return alice;
+ }
+
+ @NonNull
+ private Message setupMessage(Identity alice, Identity bob) {
Message msg = new Message();
msg.setFrom(alice);
- Vector to = new Vector();
+ Vector to = new Vector<>();
to.add(bob);
msg.setTo(to);
@@ -453,144 +1341,173 @@ public class MainActivity extends AppCompatActivity {
msg.setDir(Message.Direction.Outgoing);
- Color aclr = e.outgoing_message_color(msg);
- if(!(aclr.equals(Color.pEpRatingReliable))) throw new AssertionError();
+ Vector cc = new Vector<>();
+ cc.add(alice);
+ msg.setCc(cc);
- e.trustPersonalKey(bob);
- Color bclr = e.outgoing_message_color(msg);
- if(!(bclr.equals(Color.pEpRatingTrusted))) throw new AssertionError();
+ return msg;
+ }
- e.keyResetTrust(bob);
- Color cclr = e.outgoing_message_color(msg);
- if(!(cclr.equals(Color.pEpRatingReliable))) throw new AssertionError();
+ private void setupRatingToMyself(Engine engine, Message msg) throws pEpException {
+ Rating aliceRating = getOutgoingMessageRatingFromEngine(engine, msg);
+ if (!(aliceRating.equals(Rating.pEpRatingReliable))) throw new AssertionError();
+ }
- e.keyCompromized(bob);
- Color dclr = e.outgoing_message_color(msg);
- if(!(dclr.equals(Color.pEpRatingUnencrypted))) throw new AssertionError();
+ private synchronized Rating getOutgoingMessageRatingFromEngine(Engine engine, Message msg) throws pEpException {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.outgoing", String.valueOf(lastTime));
+ Rating rating = engine.outgoing_message_rating(msg);
+ logEnd("engine.outgoing", String.valueOf(System.currentTimeMillis() - lastTime));
+ return rating;
+ }
- e.keyResetTrust(bob);
- Color oclr = e.outgoing_message_color(msg);
- if(!(oclr.equals(Color.pEpRatingReliable))) throw new AssertionError();
+ private void testRatingStatuses(Engine engine, Identity bob, Message msg) throws pEpException {
+ trustKeyOnEngine(engine, bob);
+ Rating bobTrustRating = getOutgoingMessageRatingFromEngine(engine, msg);
+ if (!(bobTrustRating.equals(Rating.pEpRatingTrusted))) throw new AssertionError();
- Vector cc = new Vector();
- cc.add(alice);
- msg.setCc(cc);
+ resetKeyOnEngine(engine, bob);
+ Rating bobResetRating = getOutgoingMessageRatingFromEngine(engine, msg);
+ if (!(bobResetRating.equals(Rating.pEpRatingReliable))) throw new AssertionError();
- Vector bcc = new Vector();
- bcc.add(john);
- msg.setBcc(bcc);
+ mistrustJeyOnEngine(engine, bob);
+ Rating bobMistrustRating = getOutgoingMessageRatingFromEngine(engine, msg);
+ if (!(bobMistrustRating.equals(Rating.pEpRatingUnencrypted))) throw new AssertionError();
- {
- ArrayList> pairs = new ArrayList>();
- pairs.add(new Pair("Received","in time"));
- pairs.add(new Pair("X-Foobaz","of course"));
+ resetKeyOnEngine(engine, bob);
+ Rating bobResetTrustAgain = getOutgoingMessageRatingFromEngine(engine, msg);
+ if (!(bobResetTrustAgain.equals(Rating.pEpRatingReliable))) throw new AssertionError();
+ }
- msg.setOptFields(pairs);
- }
+ private void mistrustJeyOnEngine(Engine engine, Identity bob) {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.keyMistrusted", String.valueOf(lastTime));
+ engine.keyMistrusted(bob);
+ logEnd("engine.keyMistrusted", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
- byte[] gif = LoadAssetAsBuffer("spinner.gif");
- byte[] png = LoadAssetAsBuffer("pep.png");
- byte[] tbz = LoadAssetAsBuffer("yml2.tar.bz2");
- {
- Vector attachments = new Vector();
- {
- Blob b = new Blob();
- b.data = png;
- b.filename = "pep.png";
- b.mime_type = "image/png";
- attachments.add(b);
- }
- {
- Blob b = new Blob();
- b.data = gif;
- b.filename = "spinner.gif";
- b.mime_type = "image/gif";
- attachments.add(b);
- }
- {
- Blob b = new Blob();
- b.data = tbz;
- b.filename = "yml2.tar.bz2";
- b.mime_type = "application/octet-stream";
- attachments.add(b);
- }
- msg.setAttachments(attachments);
- }
+ private void resetKeyOnEngine(Engine engine, Identity bob) {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.keyResetTrust", String.valueOf(lastTime));
+ engine.keyResetTrust(bob);
+ logEnd("engine.keyResetTrust", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
- if(!(e.outgoing_message_color(msg).equals(Color.pEpRatingReliable))) throw new AssertionError();
+ private void trustKeyOnEngine(Engine engine, Identity bob) {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.trustPersonalKey", String.valueOf(lastTime));
+ engine.trustPersonalKey(bob);
+ logEnd("engine.trustPersonalKey", String.valueOf(System.currentTimeMillis() - lastTime));
+ }
- Message enc = null;
- enc = e.encrypt_message(msg, null);
+ @NonNull
+ private Engine.decrypt_message_Return encrypAndDecryptMessage(Engine engine, Message msg) throws pEpException {
+ if (!(getOutgoingMessageRatingFromEngine(engine, msg).equals(Rating.pEpRatingReliable)))
+ throw new AssertionError();
- if(!(enc != null)) throw new AssertionError();
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
- if(!(enc.getShortmsg().equals("pEp"))) throw new AssertionError();
- if(!(enc.getLongmsg().contains("pEp-project.org"))) throw new AssertionError();
+ if (!(encriptedMessage != null)) throw new AssertionError();
- Vector attachments = enc.getAttachments();
- if(!(e.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----"))) throw new AssertionError();
+ if (!(encriptedMessage.getShortmsg().equals("pEp"))) throw new AssertionError();
+ if (!(encriptedMessage.getLongmsg().contains("pEp-project.org")))
+ throw new AssertionError();
+
+ Vector attachments = encriptedMessage.getAttachments();
+ if (!(engine.toUTF16(attachments.get(1).data).startsWith("-----BEGIN PGP MESSAGE-----")))
+ throw new AssertionError();
Engine.decrypt_message_Return result = null;
- result = e.decrypt_message(enc);
+ result = decryptMessageOnEngine(engine, encriptedMessage);
- if(!(result.dst.getShortmsg().equals("hello, world"))) throw new AssertionError();
- if(!(result.dst.getLongmsg().equals("this is a test"))) throw new AssertionError();
+ if (!(result.dst.getShortmsg().equals("hello, world"))) throw new AssertionError();
+ if (!(result.dst.getLongmsg().equals("this is a test"))) throw new AssertionError();
+ return result;
+ }
- ArrayList> _pairs = result.dst.getOptFields();
- /* FIXME ?
- {
- byte msk = 0;
- for (Pair _pair : _pairs) {
- if (_pair.first.equals("Received")) {
- if(!(_pair.second.equals("in time"))) throw new AssertionError();
- msk |= 1;
- }else if (_pair.first.equals("X-Foobaz")) {
- if(!(_pair.second.equals("of course"))) throw new AssertionError();
- msk |= 2;
- }
+ private Engine.decrypt_message_Return decryptMessageOnEngine(Engine engine, Message encriptedMessage) throws pEpException {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.decrypt_message", String.valueOf(lastTime));
+ Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage);
+ logEnd("engine.decrypt_message", String.valueOf(System.currentTimeMillis() - lastTime));
+ return decrypt_message_return;
+ }
+
+ private Message encryptMessageOnEngine(Engine engine, Message msg) throws pEpException {
+ long lastTime = System.currentTimeMillis();
+ logStart("engine.encrypt_message", String.valueOf(lastTime));
+ Message message = engine.encrypt_message(msg, null);
+ logEnd("engine.encrypt_message", String.valueOf(System.currentTimeMillis() - lastTime));
+ return message;
+ }
+
+ private void detachFromMessage(Message msg, byte[] gif, byte[] png, byte[] tbz) {
+ Vector detach = msg.getAttachments();
+ byte msk = 0;
+ for (Blob dblb : detach) {
+ if (dblb.filename.equals("pep.png")) {
+ if (!(Arrays.equals(dblb.data, png))) throw new AssertionError();
+ if (!(dblb.mime_type.equals("image/png"))) throw new AssertionError();
+ msk |= 1;
+ } else if (dblb.filename.equals("spinner.gif")) {
+ if (!(Arrays.equals(dblb.data, gif))) throw new AssertionError();
+ if (!(dblb.mime_type.equals("image/gif"))) throw new AssertionError();
+ msk |= 2;
+ } else if (dblb.filename.equals("yml2.tar.bz2")) {
+ if (!(Arrays.equals(dblb.data, tbz))) throw new AssertionError();
+ if (!(dblb.mime_type.equals("application/octet-stream")))
+ throw new AssertionError();
+ msk |= 4;
}
- if(!(msk == 3)) throw new AssertionError();
}
- */
+ if (!(msk == 7)) throw new AssertionError();
+ }
+ private void attachToMessage(Message msg, byte[] gif, byte[] png, byte[] tbz) {
+ Vector attachments = new Vector();
{
- Vector detach = msg.getAttachments();
- byte msk = 0;
- for (Blob dblb : detach) {
- if (dblb.filename.equals("pep.png")) {
- if(!(Arrays.equals(dblb.data, png))) throw new AssertionError();
- if(!(dblb.mime_type.equals("image/png"))) throw new AssertionError();
- msk |= 1;
- }else if (dblb.filename.equals("spinner.gif")) {
- if(!(Arrays.equals(dblb.data, gif))) throw new AssertionError();
- if(!(dblb.mime_type.equals("image/gif"))) throw new AssertionError();
- msk |= 2;
- }else if (dblb.filename.equals("yml2.tar.bz2")) {
- if(!(Arrays.equals(dblb.data, tbz))) throw new AssertionError();
- if(!(dblb.mime_type.equals("application/octet-stream"))) throw new AssertionError();
- msk |= 4;
- }
- }
- if(!(msk == 7)) throw new AssertionError();
+ Blob b = new Blob();
+ b.data = png;
+ b.filename = "pep.png";
+ b.mime_type = "image/png";
+ attachments.add(b);
}
- e.close();
+ {
+ Blob b = new Blob();
+ b.data = gif;
+ b.filename = "spinner.gif";
+ b.mime_type = "image/gif";
+ attachments.add(b);
+ }
+ {
+ Blob b = new Blob();
+ b.data = tbz;
+ b.filename = "yml2.tar.bz2";
+ b.mime_type = "application/octet-stream";
+ attachments.add(b);
+ }
+ msg.setAttachments(attachments);
}
+ /*
+ tests its possible to find the fingerprint on server
+ */
public void testKeyserverLookup() throws pEpException, IOException, AssertionError, InterruptedException {
-
+ log("TEST: ", "Test keyserver lookup loaded");
Engine e;
- Log.d("PEPTEST", "Test keyserver lookup loaded");
-
e = new Engine();
+ long lastTime = System.currentTimeMillis();
e.startKeyserverLookup();
+ log("engine.startLookup", String.valueOf(System.currentTimeMillis() - lastTime));
Identity vb = new Identity();
vb.username = "pEpDontAssert";
vb.address = "vb@ulm.ccc.de";
vb.user_id = "SsI6H9";
- e.updateIdentity(vb);
+ updateIdentityOnEngine(e, vb);
int count = 0;
while (count++ < 5000) {
@@ -599,21 +1516,27 @@ public class MainActivity extends AppCompatActivity {
String fpr = e.updateIdentity(vb).fpr;
- Log.d("PEPTEST", "keyserver test fpr");
- Log.d("PEPTEST", fpr != null ? fpr : "NULL");
- if(!(fpr != null)) throw new AssertionError();
+ log("PEPTEST", "keyserver test fpr");
+ log("PEPTEST", fpr != null ? fpr : "NULL");
+ if (fpr == null) throw new AssertionError();
+ lastTime = System.currentTimeMillis();
e.stopKeyserverLookup();
+ log("engine.stopLookup", String.valueOf(System.currentTimeMillis() - lastTime));
+ lastTime = System.currentTimeMillis();
e.close();
+ log("engine.close", String.valueOf(System.currentTimeMillis() - lastTime));
+ log("TEST: ", "Test keyserver lookup finished");
}
+ /*
+ tests I can get my own fingerprint
+ */
public void testKeyGen() throws pEpException, IOException, AssertionError, InterruptedException {
+ log("TEST: ", "Test key generation loaded");
Engine e;
-
- Log.d("PEPTEST", "Test gen key loaded");
-
e = new Engine();
Identity newid = new Identity();
@@ -621,37 +1544,441 @@ public class MainActivity extends AppCompatActivity {
newid.address = "test.gen.key@pep-project.org";
newid.user_id = "P0l1231";
- String fpr = e.myself(newid).fpr;
+ int count = 0;
+ while (count++ < 5000) {
+ Thread.sleep(1);
+ }
+
+ Identity identity = myselfInEngine(e, newid);
+ generatedIdentities.add(identity);
+
+ String fpr = identity.fpr;
- Log.d("PEPTEST", "keygen test fpr");
- Log.d("PEPTEST", fpr != null ? fpr : "NULL");
- if(!(fpr != null)) throw new AssertionError();
+ log("PEPTEST", "keygen test fpr");
+ log("PEPTEST", fpr != null ? fpr : "NULL");if (fpr == null) throw new AssertionError();
e.close();
+ log("TEST: ", "Test key generation finished");
}
+ private Set executedTasks = new HashSet<>();
- private class RunTestTask extends AsyncTask {
+ private class RunAllTestsTask extends AsyncTask {
@Override
- protected Void doInBackground(Void... params) {
- runTest();
- return null;
+ protected Integer doInBackground(Integer... integers) {
+ Integer integer = integers[0];
+ try {
+ switch (integer) {
+ case 0:
+ if (!executedTasks.contains(0)) {
+ for (int i = 0; i< testingTimes; i++) {
+ //runTestKeyGen();
+ }
+ executedTasks.add(0);
+ return 0;
+ }
+ break;
+ case 1:
+ if (!executedTasks.contains(1)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runTestPEpTypes();
+ }
+ executedTasks.add(1);
+ return 1;
+ }
+ break;
+ case 2:
+ if (!executedTasks.contains(2)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runTestPEpTypes();
+ }
+ executedTasks.add(2);
+ return 2;
+ }
+ break;
+ case 3:
+ if (!executedTasks.contains(3)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runEncryptAndDecryptTest();
+ }
+ executedTasks.add(3);
+ return 3;
+ }
+ break;
+ case 4:
+ if (!executedTasks.contains(4)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runEncryptAndDecryptWithoutKeyTest();
+ }
+ executedTasks.add(4);
+ return 4;
+ }
+ break;
+ case 5:
+ if (!executedTasks.contains(5)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runColorRatingsTest();
+ }
+ executedTasks.add(5);
+ return 5;
+ }
+ break;
+ case 6:
+ if (!executedTasks.contains(6)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runIntegrationTest();
+ }
+ executedTasks.add(6);
+ return 6;
+ }
+ break;
+ case 7:
+ if (!executedTasks.contains(7)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runAddToBlacklistTest();
+ }
+ executedTasks.add(7);
+ return 7;
+ }
+ break;
+ case 8:
+ if (!executedTasks.contains(8)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runAddToBlacklistAndSendMessageTest();
+ }
+ executedTasks.add(8);
+ return 8;
+ }
+ break;
+ case 9:
+ if (!executedTasks.contains(9)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runAddAndRemoveFromBlacklistTest();
+ }
+ executedTasks.add(9);
+ return 9;
+ }
+ break;
+ case 10:
+ if (!executedTasks.contains(10)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runUnencryptedSubjectTest();
+ }
+ executedTasks.add(10);
+ return 10;
+ }
+ break;
+ case 11:
+ if (!executedTasks.contains(11)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runPassiveModeTest();
+ }
+ executedTasks.add(11);
+ return 11;
+ }
+ break;
+ case 12:
+ if (!executedTasks.contains(12)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runEncryptAndDecryptAMessageFromMyselft();
+ }
+ executedTasks.add(12);
+ return 12;
+ }
+ break;
+ case 13:
+ if (!executedTasks.contains(13)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runMessageForMeIsAlwaysGreenTest();
+ }
+ executedTasks.add(13);
+ return 13;
+ }
+ break;
+ case 14:
+ if (!executedTasks.contains(14)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runOutgoingColorTest();
+ }
+ log("outgoing average", String.valueOf(outgoingColorAcumulative/testingTimes));
+ executedTasks.add(14);
+ return 14;
+ }
+ break;
+ case 15:
+ if (!executedTasks.contains(15)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runIdetntityRatingTest();
+ }
+ executedTasks.add(15);
+ return 15;
+ }
+ break;
+ case 16:
+ if (!executedTasks.contains(16)) {
+ for (int i = 0; i< testingTimes; i++) {
+ runDeblacklistRatingTest();
+ }
+ executedTasks.add(16);
+ return 16;
+ }
+ break;
+ }
+ } catch (AssertionError | Exception ex) {
+ Log.e("PEPTEST", "##################### TEST Exception ####################", ex);
+ publishProgress(integers);
+ }
+ return -1;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
- Log.i("RunTestTask", "onPreExecute " + "Starting test");
- runGenKey.setText("Running");
+ Log.i("RunAllTestsTask", "onPreExecute " + "Starting test");
+ }
+
+ @Override
+ protected void onPostExecute(Integer integer) {
+ super.onPostExecute(integer);
+ switch (integer) {
+ case 0:
+ runGenKey.setText("NOT TESTED");
+ runTypes.setText("TESTING");
+ new RunAllTestsTask().execute(1);
+ break;
+ case 1:
+ runTypes.setText("PASSED");
+ runLookup.setText("TESTING");
+ new RunAllTestsTask().execute(2);
+ break;
+ case 2:
+ runLookup.setText("PASSED");
+ runEncryptAndDecrypt.setText("TESTING");
+ new RunAllTestsTask().execute(3);
+ break;
+ case 3:
+ runEncryptAndDecrypt.setText("PASSED");
+ runEncryptAndDecryptWithoutKey.setText("TESTING");
+ new RunAllTestsTask().execute(4);
+ break;
+ case 4:
+ runEncryptAndDecryptWithoutKey.setText("PASSED");
+ runRatings.setText("TESTING");
+ new RunAllTestsTask().execute(5);
+ break;
+ case 5:
+ runRatings.setText("PASSED");
+ runIntegration.setText("TESTING");
+ new RunAllTestsTask().execute(6);
+ break;
+ case 6:
+ runIntegration.setText("PASSED");
+ runBlackList.setText("TESTING");
+ new RunAllTestsTask().execute(7);
+ break;
+ case 7:
+ runBlackList.setText("PASSED");
+ runBlackListAndSendMessage.setText("TESTING");
+ new RunAllTestsTask().execute(8);
+ break;
+ case 8:
+ runBlackListAndSendMessage.setText("PASSED");
+ runBlackListAndDelete.setText("TESTING");
+ new RunAllTestsTask().execute(9);
+ break;
+ case 9:
+ runBlackListAndDelete.setText("PASSED");
+ runUnencryptedSubject.setText("TESTING");
+ new RunAllTestsTask().execute(10);
+ break;
+ case 10:
+ runUnencryptedSubject.setText("PASSED");
+ runPassiveMode.setText("TESTING");
+ new RunAllTestsTask().execute(11);
+ break;
+ case 11:
+ runPassiveMode.setText("PASSED");
+ runMessageMe.setText("TESTING");
+ new RunAllTestsTask().execute(12);
+ break;
+ case 12:
+ runMessageMe.setText("PASSED");
+ runMessageFromMeIsGreen.setText("TESTING");
+ new RunAllTestsTask().execute(13);
+ break;
+ case 13:
+ runMessageFromMeIsGreen.setText("PASSED");
+ runOutgoingColor.setText("TESTING");
+ new RunAllTestsTask().execute(14);
+ break;
+ case 14:
+ runOutgoingColor.setText("PASSED");
+ runIdentityRating.setText("TESTING");
+ new RunAllTestsTask().execute(15);
+ break;
+ case 15:
+ runIdentityRating.setText("PASSED");
+ runDeblacklist.setText("TESTING");
+ new RunAllTestsTask().execute(16);
+ break;
+ case 16:
+ runDeblacklist.setText("PASSED");
+ generateNoteOnSD("dump_test_engine");
+ break;
+ }
+ Log.i("RunAllTestsTask", "onPostExecute " + "Ended test");
}
@Override
- protected void onPostExecute(Void aVoid) {
- super.onPostExecute(aVoid);
- Log.i("RunTestTask", "onPostExecute " + "Ended test");
- runGenKey.setText("Done");
+ protected void onProgressUpdate(Integer... values) {
+ super.onProgressUpdate(values);
+ switch (values[0]) {
+ case 0:
+ runGenKey.setText("FAILED");
+ new RunAllTestsTask().execute(1);
+ break;
+ case 1:
+ runLookup.setText("FAILED");
+ new RunAllTestsTask().execute(2);
+ break;
+ case 2:
+ runLookup.setText("FAILED");
+ new RunAllTestsTask().execute(3);
+ break;
+ case 3:
+ runEncryptAndDecryptWithoutKey.setText("FAILED");
+ new RunAllTestsTask().execute(4);
+ break;
+ case 4:
+ runEncryptAndDecrypt.setText("FAILED");
+ new RunAllTestsTask().execute(5);
+ break;
+ case 5:
+ runEncryptAndDecryptWithoutKey.setText("FAILED");
+ new RunAllTestsTask().execute(6);
+ case 6:
+ runRatings.setText("FAILED");
+ new RunAllTestsTask().execute(7);
+ break;
+ case 7:
+ runBlackList.setText("FAILED");
+ new RunAllTestsTask().execute(8);
+ break;
+ case 8:
+ runBlackListAndSendMessage.setText("FAILED");
+ new RunAllTestsTask().execute(9);
+ break;
+ case 9:
+ runBlackListAndDelete.setText("FAILED");
+ new RunAllTestsTask().execute(10);
+ break;
+ case 10:
+ runUnencryptedSubject.setText("FAILED");
+ new RunAllTestsTask().execute(11);
+ break;
+ case 11:
+ runMessageMe.setText("FAILED");
+ new RunAllTestsTask().execute(12);
+ break;
+ case 12:
+ runMessageMe.setText("FAILED");
+ new RunAllTestsTask().execute(13);
+ break;
+ case 13:
+ runMessageFromMeIsGreen.setText("FAILED");
+ new RunAllTestsTask().execute(14);
+ break;
+ case 14:
+ runMessageFromMeIsGreen.setText("FAILED");
+ new RunAllTestsTask().execute(14);
+ break;
+ case 15:
+ runIdentityRating.setText("FAILED");
+ new RunAllTestsTask().execute(15);
+ break;
+ case 16:
+ runDeblacklist.setText("FAILED");
+ generateNoteOnSD("dump_test_engine");
+ break;
+ }
+ }
+ }
+ private class RunTestTask extends AsyncTask {
+
+ @Override
+ protected Integer doInBackground(Integer... integers) {
+ Integer integer = integers[0];
+ try {
+ switch (integer) {
+ case 0:
+ runTestKeyGen();
+ return 0;
+ case 1:
+ runTestPEpTypes();
+ return 1;
+ case 2:
+ runTestKeyserverLookup();
+ return 2;
+ case 3:
+ runEncryptAndDecryptTest();
+ return 3;
+ case 4:
+ runEncryptAndDecryptWithoutKeyTest();
+ return 4;
+ case 5:
+ runColorRatingsTest();
+ return 5;
+ case 6:
+ runIntegrationTest();
+ return 6;
+ case 16:
+ runDeblacklistRatingTest();
+ return 6;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return -1;
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ Log.i("RunAllTestsTask", "onPreExecute " + "Starting test");
+ }
+
+ @Override
+ protected void onPostExecute(Integer integer) {
+ super.onPostExecute(integer);
+ switch (integer) {
+ case 0:
+ runGenKey.setText("TESTED");
+ break;
+ case 1:
+ runTypes.setText("TESTED");
+ break;
+ case 2:
+ runLookup.setText("TESTED");
+ break;
+ case 3:
+ runEncryptAndDecrypt.setText("TESTED");
+ break;
+ case 4:
+ runEncryptAndDecryptWithoutKey.setText("TESTED");
+ break;
+ case 5:
+ runRatings.setText("TESTED");
+ break;
+ case 6:
+ runIntegration.setText("TESTED");
+ break;
+ case 16:
+ runDeblacklist.setText("TESTED");
+ break;
+ }
+ Log.i("RunAllTestsTask", "onPostExecute " + "Ended test");
}
@Override
diff --git a/androidTests/app/src/main/java/com/pep/k9/PEpUnitaryStuff.java b/androidTests/app/src/main/java/com/pep/k9/PEpUnitaryStuff.java
new file mode 100644
index 0000000..ff58a8a
--- /dev/null
+++ b/androidTests/app/src/main/java/com/pep/k9/PEpUnitaryStuff.java
@@ -0,0 +1,46 @@
+package com.pep.k9;
+
+import org.pEp.jniadapter.Engine;
+import org.pEp.jniadapter.Identity;
+import org.pEp.jniadapter.Message;
+
+import java.util.Vector;
+
+public class PEpUnitaryStuff {
+ public static void main (String args[]) {
+ try {
+ shouldDoSomeStuff();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void shouldDoSomeStuff() throws Exception {
+ Engine engine;
+ engine = new Engine();
+
+ Message msg = new Message();
+ msg.setFrom(new Identity());
+
+ Vector to = new Vector<>();
+ to.add(new Identity());
+ msg.setTo(to);
+
+ msg.setShortmsg("hello, world");
+ String message = "this is a test";
+ msg.setLongmsg(message);
+
+ msg.setDir(Message.Direction.Outgoing);
+
+ Vector cc = new Vector<>();
+ cc.add(new Identity());
+ msg.setCc(cc);
+
+ Message encriptedMessage = engine.encrypt_message(msg, null);
+ Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage);
+
+ if (!decrypt_message_return.dst.getLongmsg().equals(message)) {
+ throw new RuntimeException("FAILED");
+ }
+ }
+}
diff --git a/androidTests/app/src/main/java/com/pep/k9/UnitActivity.java b/androidTests/app/src/main/java/com/pep/k9/UnitActivity.java
new file mode 100644
index 0000000..552825b
--- /dev/null
+++ b/androidTests/app/src/main/java/com/pep/k9/UnitActivity.java
@@ -0,0 +1,280 @@
+package com.pep.k9;
+
+import android.content.res.AssetManager;
+import android.support.annotation.NonNull;
+import android.support.v7.app.AppCompatActivity;
+import android.os.Bundle;
+
+import org.pEp.jniadapter.Blob;
+import org.pEp.jniadapter.Engine;
+import org.pEp.jniadapter.Identity;
+import org.pEp.jniadapter.Message;
+import org.pEp.jniadapter.Pair;
+import org.pEp.jniadapter.Rating;
+import org.pEp.jniadapter.pEpException;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Vector;
+
+public class UnitActivity extends AppCompatActivity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_unit);
+
+ try {
+ messageAfterDecriptionShouldBeTheSame();
+ messageAfterDecriptionWithoutKeyShouldKeepBreaks();
+ messageAfterDecriptionShouldKeepBreaks();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void messageAfterDecriptionWithoutKeyShouldKeepBreaks() throws Exception {
+ Engine engine;
+ engine = new Engine();
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadDummyBobFromEngine(engine);
+
+ // message
+ Message msg = new Message();
+ msg.setFrom(alice);
+
+ Vector to = new Vector<>();
+ to.add(bob);
+ msg.setTo(to);
+
+ msg.setShortmsg("hello, world");
+ msg.setLongmsg("thisis\nastest");
+
+ msg.setDir(Message.Direction.Outgoing);
+
+ Vector cc = new Vector<>();
+ cc.add(alice);
+ msg.setCc(cc);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
+
+ Vector attachments = encriptedMessage.getAttachments();
+
+ Engine.decrypt_message_Return result = null;
+ result = decryptMessageOnEngine(engine, encriptedMessage);
+
+ engine.close();
+
+ if (!result.dst.getLongmsg().equals(msg.getLongmsg())) {
+ throw new RuntimeException("FAILED: " +result.dst.getLongmsg()+" not equals to "+msg.getLongmsg());
+ }
+ }
+
+ public void messageAfterDecriptionShouldKeepBreaks() throws Exception {
+ Engine engine;
+ engine = new Engine();
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = new Message();
+ msg.setFrom(alice);
+
+ Vector to = new Vector<>();
+ to.add(bob);
+ msg.setTo(to);
+
+ msg.setShortmsg("hello, world");
+ msg.setLongmsg("thisis\nastest");
+
+ msg.setDir(Message.Direction.Outgoing);
+
+ Vector cc = new Vector<>();
+ cc.add(alice);
+ msg.setCc(cc);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
+
+ Vector attachments = encriptedMessage.getAttachments();
+
+ Engine.decrypt_message_Return result = null;
+ result = decryptMessageOnEngine(engine, encriptedMessage);
+
+ engine.close();
+
+ if (!result.dst.getLongmsg().equals(msg.getLongmsg())) {
+ throw new RuntimeException("FAILED: " +result.dst.getLongmsg()+" not equals to "+msg.getLongmsg());
+ }
+ }
+
+ public void messageAfterDecriptionShouldBeTheSame() throws Exception {
+ Engine engine;
+ engine = new Engine();
+
+ Identity alice = loadAliceFromEngine(engine);
+
+ Identity bob = loadBobFromEngine(engine);
+
+ // message
+ Message msg = setupMessage(alice, bob);
+
+ ArrayList> pairs = new ArrayList<>();
+ pairs.add(new Pair<>("Received", "in time"));
+ pairs.add(new Pair<>("X-Foobaz", "of course"));
+ msg.setOptFields(pairs);
+
+ Message encriptedMessage = null;
+ encriptedMessage = encryptMessageOnEngine(engine, msg);
+
+ Vector attachments = encriptedMessage.getAttachments();
+
+ Engine.decrypt_message_Return result = null;
+ result = decryptMessageOnEngine(engine, encriptedMessage);
+
+ engine.close();
+
+ if (!result.dst.getLongmsg().equals(msg.getLongmsg())) {
+ throw new RuntimeException("FAILED: " +result.dst.getLongmsg()+" not equals to "+msg.getLongmsg());
+ }
+ }
+
+ private Message setupMessage(Identity alice, Identity bob) {
+ Message msg = new Message();
+ msg.setFrom(alice);
+
+ Vector to = new Vector<>();
+ to.add(bob);
+ msg.setTo(to);
+
+ msg.setShortmsg("hello, world");
+ msg.setLongmsg("this is a test");
+
+ msg.setDir(Message.Direction.Outgoing);
+
+ Vector cc = new Vector<>();
+ cc.add(alice);
+ msg.setCc(cc);
+
+ return msg;
+ }
+
+ private Engine.decrypt_message_Return decryptMessageOnEngine(Engine engine, Message encriptedMessage) throws pEpException {
+ long lastTime = System.currentTimeMillis();
+ Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage);
+ return decrypt_message_return;
+ }
+
+ private Message encryptMessageOnEngine(Engine engine, Message msg) throws pEpException {
+ long lastTime = System.currentTimeMillis();
+ Message message = engine.encrypt_message(msg, null);
+ return message;
+ }
+
+ private Identity loadBobFromEngine(Engine engine) throws IOException {
+ //
+ // Other peers :
+ // pEp Test Bob (test key, don't use)
+ // C9C2EE39
+ // 59BFF488C9C2EE39
+ importKeyFromEngine(engine, "0xC9C2EE39.asc");
+
+ Identity bob = new Identity();
+ bob.username = "bob Test";
+ bob.address = "pep.test.bob@pep-project.org";
+ bob.user_id = "112";
+ bob.fpr = "BFCDB7F301DEEEBBF947F29659BFF488C9C2EE39";
+
+ updateIdentityOnEngine(engine, bob);
+ return bob;
+ }
+
+ private Identity loadDummyBobFromEngine(Engine engine) throws IOException {
+ //
+ // Other peers :
+ // pEp Test Bob (test key, don't use)
+ // C9C2EE39
+ // 59BFF488C9C2EE39
+
+ Identity bob = new Identity();
+ bob.username = "bob Test";
+ bob.address = "pep.test.bob@pep-project.org";
+ bob.user_id = "112";
+
+ updateIdentityOnEngine(engine, bob);
+ return bob;
+ }
+
+ private void updateIdentityOnEngine(Engine engine, Identity identity) {
+ long lastTime = System.currentTimeMillis();
+ engine.updateIdentity(identity);
+ }
+
+ @NonNull
+ private Identity loadAliceFromEngine(Engine engine) throws IOException {
+ // Our test user :
+ // pEp Test Alice (test key don't use)
+ // 6FF00E97
+ // A9411D176FF00E97
+ importKeyFromEngine(engine, "6FF00E97_sec.asc");
+
+ Identity alice = new Identity();
+ alice.username = "Alice Test";
+ alice.address = "pep.test.alice@pep-project.org";
+ alice.user_id = "pEp_own_userId";
+ alice.me = true;
+ alice.fpr = "4ABE3AAF59AC32CFE4F86500A9411D176FF00E97";
+
+ long lastTime = System.currentTimeMillis();
+ myselfInEngine(engine, alice);
+
+ return alice;
+ }
+
+ private void importKeyFromEngine(Engine engine, String filename) throws IOException {
+ long lastTime = System.currentTimeMillis();
+ engine.importKey(LoadAssetAsString(filename));
+ }
+
+ private String LoadAssetAsString(String fname) throws IOException {
+ // byte buffer into a string
+ return new String(LoadAssetAsBuffer(fname));
+ }
+
+ private byte[] LoadAssetAsBuffer(String fname) throws IOException {
+ AssetManager assetManager = getAssets();
+ InputStream input;
+
+ input = assetManager.open(fname);
+
+ int size = input.available();
+ byte[] buffer = new byte[size];
+ input.read(buffer);
+ input.close();
+
+ // byte buffer
+ return buffer;
+
+ }
+
+ private Identity myselfInEngine(Engine engine, Identity identity) {
+ Identity myself = engine.myself(identity);
+ return myself;
+ }
+}
diff --git a/androidTests/app/src/main/res/layout/activity_main.xml b/androidTests/app/src/main/res/layout/activity_main.xml
index d25e225..25726c4 100644
--- a/androidTests/app/src/main/res/layout/activity_main.xml
+++ b/androidTests/app/src/main/res/layout/activity_main.xml
@@ -1,103 +1,396 @@
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+ android:layout_alignParentStart="true"
+ android:orientation="vertical">
-
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
-
+ android:textAppearance="?android:attr/textAppearanceMedium" />
-
-
-
+
+
+
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
-
+ android:layout_weight="1"
+ android:text="Server Lookup"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+ style="?android:attr/buttonStyleSmall"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:text="Run" />
+
-
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
-
+ android:layout_weight="1"
+ android:text="Add to blacklist + new key"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
-
-
-
+
+
+
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
-
+ android:layout_weight="1"
+ android:text="Blacklist + send"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
-
-
+ android:layout_weight="1"
+ android:text="Run" />
+
-
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/androidTests/app/src/main/res/layout/activity_unit.xml b/androidTests/app/src/main/res/layout/activity_unit.xml
new file mode 100644
index 0000000..a2aa395
--- /dev/null
+++ b/androidTests/app/src/main/res/layout/activity_unit.xml
@@ -0,0 +1,13 @@
+
+
+
+
diff --git a/androidTests/app/src/main/res/menu/menu_main.xml b/androidTests/app/src/main/res/menu/menu_main.xml
index b1cb908..ed7f9ff 100644
--- a/androidTests/app/src/main/res/menu/menu_main.xml
+++ b/androidTests/app/src/main/res/menu/menu_main.xml
@@ -1,6 +1,8 @@
diff --git a/androidTests/app/src/test/java/com/pep/k9/MainActivityTest.java b/androidTests/app/src/test/java/com/pep/k9/MainActivityTest.java
new file mode 100644
index 0000000..a80b9e8
--- /dev/null
+++ b/androidTests/app/src/test/java/com/pep/k9/MainActivityTest.java
@@ -0,0 +1,10 @@
+package com.pep.k9;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by arturo on 15/11/16.
+ */
+public class MainActivityTest {
+
+}
\ No newline at end of file
diff --git a/androidTests/app/src/test/java/com/pep/k9/UnitaryTest.java b/androidTests/app/src/test/java/com/pep/k9/UnitaryTest.java
new file mode 100644
index 0000000..75a6de0
--- /dev/null
+++ b/androidTests/app/src/test/java/com/pep/k9/UnitaryTest.java
@@ -0,0 +1,49 @@
+package com.pep.k9;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.pEp.jniadapter.Engine;
+import org.pEp.jniadapter.Identity;
+import org.pEp.jniadapter.Message;
+
+import java.util.Vector;
+
+/**
+ * Created by arturo on 15/11/16.
+ */
+public class UnitaryTest {
+
+ @Before
+ public void setUp() throws Exception {
+
+ }
+
+ @Test
+ public void shouldDoSomeStuff() throws Exception {
+ Engine engine;
+ engine = new Engine();
+
+ Message msg = new Message();
+ msg.setFrom(new Identity());
+
+ Vector to = new Vector<>();
+ to.add(new Identity());
+ msg.setTo(to);
+
+ msg.setShortmsg("hello, world");
+ String message = "this is a test";
+ msg.setLongmsg(message);
+
+ msg.setDir(Message.Direction.Outgoing);
+
+ Vector cc = new Vector<>();
+ cc.add(new Identity());
+ msg.setCc(cc);
+
+ Message encriptedMessage = engine.encrypt_message(msg, null);
+ Engine.decrypt_message_Return decrypt_message_return = engine.decrypt_message(encriptedMessage);
+
+ Assert.assertTrue(decrypt_message_return.dst.getLongmsg().equals(message));
+ }
+}
\ No newline at end of file
diff --git a/androidTests/build.gradle b/androidTests/build.gradle
index e220f0b..e220da4 100644
--- a/androidTests/build.gradle
+++ b/androidTests/build.gradle
@@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
- classpath 'com.android.tools.build:gradle:2.1.2'
+ classpath 'com.android.tools.build:gradle:2.3.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files