aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/androidTest
diff options
context:
space:
mode:
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java41
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java32
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java7
3 files changed, 61 insertions, 19 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
index 19b8b63..385fc0a 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
@@ -42,6 +42,7 @@ public class OlmAccountTest {
private static OlmAccount mOlmAccount;
private static OlmManager mOlmManager;
private boolean mIsAccountCreated;
+ final String FILE_NAME = "SerialTestFile";
@BeforeClass
public static void setUpClass(){
@@ -72,7 +73,11 @@ public class OlmAccountTest {
@Test
public void test01CreateReleaseAccount() {
- mOlmAccount = new OlmAccount();
+ try {
+ mOlmAccount = new OlmAccount();
+ } catch (OlmException e) {
+ e.printStackTrace();
+ }
assertNotNull(mOlmAccount);
mOlmAccount.releaseAccount();
@@ -81,7 +86,11 @@ public class OlmAccountTest {
@Test
public void test02CreateAccount() {
- mOlmAccount = new OlmAccount();
+ try {
+ mOlmAccount = new OlmAccount();
+ } catch (OlmException e) {
+ e.printStackTrace();
+ }
assertNotNull(mOlmAccount);
mIsAccountCreated = true;
}
@@ -198,16 +207,21 @@ public class OlmAccountTest {
public void test13Serialization() {
FileOutputStream fileOutput = null;
ObjectOutputStream objectOutput = null;
- OlmAccount accountRef = new OlmAccount();
+ OlmAccount accountRef = null;
OlmAccount accountDeserial = null;
- OlmException exception;
+
+ try {
+ accountRef = new OlmAccount();
+ } catch (OlmException e) {
+ assertTrue(e.getMessage(),false);
+ }
int retValue = accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
assertTrue(0==retValue);
+ // get keys references
JSONObject identityKeysRef = accountRef.identityKeys();
JSONObject oneTimeKeysRef = accountRef.oneTimeKeys();
- final String FILE_NAME = "testfile";
/*Context context = getInstrumentation().getContext();
SharedPreferences sharedPref = context.getSharedPreferences("TestPref",Context.MODE_PRIVATE);
@@ -217,16 +231,15 @@ public class OlmAccountTest {
try {
Context context = getInstrumentation().getContext();
context.getFilesDir();
- //File serialFile = new File(FILE_NAME);
- //fileOutput = new FileOutputStream(serialFile);
fileOutput = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
+ // serialize
objectOutput = new ObjectOutputStream(fileOutput);
objectOutput.writeObject(accountRef);
objectOutput.flush();
objectOutput.close();
- //FileInputStream fileInput = new FileInputStream(serialFile);
+ // deserialize
FileInputStream fileInput = context.openFileInput(FILE_NAME);
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
accountDeserial = (OlmAccount) objectInput.readObject();
@@ -234,14 +247,20 @@ public class OlmAccountTest {
assertNotNull(accountDeserial);
+ // get de-serialized keys
JSONObject identityKeys2 = accountDeserial.identityKeys();
+ assertNotNull(identityKeys2);
JSONObject oneTimeKeys2 = accountDeserial.oneTimeKeys();
- assertEquals(identityKeysRef, identityKeys2);
- assertEquals(oneTimeKeysRef, oneTimeKeys2);
+ assertNotNull(oneTimeKeys2);
+
+ // compare identity keys
+ assertTrue(identityKeys2.toString().equals(identityKeysRef.toString()));
+
+ // compare onetime keys
+ assertTrue(oneTimeKeys2.toString().equals(oneTimeKeysRef.toString()));
accountRef.releaseAccount();
accountDeserial.releaseAccount();
-
}
catch (FileNotFoundException e) {
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
index 311d6a8..4d7c5b0 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSessionTest.java
@@ -47,10 +47,16 @@ public class OlmSessionTest {
final int ONE_TIME_KEYS_NUMBER = 5;
String bobIdentityKey = null;
String bobOneTimeKey=null;
-
+ OlmAccount bobAccount = null;
+ OlmAccount aliceAccount = null;
// creates alice & bob accounts
- OlmAccount aliceAccount = new OlmAccount();
- OlmAccount bobAccount = new OlmAccount();
+
+ try {
+ aliceAccount = new OlmAccount();
+ bobAccount = new OlmAccount();
+ } catch (OlmException e) {
+ assertTrue(e.getMessage(),false);
+ }
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
@@ -132,10 +138,16 @@ public class OlmSessionTest {
final int ONE_TIME_KEYS_NUMBER = 1;
String bobIdentityKey = null;
String bobOneTimeKey=null;
+ OlmAccount aliceAccount = null;
+ OlmAccount bobAccount = null;
// creates alice & bob accounts
- OlmAccount aliceAccount = new OlmAccount();
- OlmAccount bobAccount = new OlmAccount();
+ try {
+ aliceAccount = new OlmAccount();
+ bobAccount = new OlmAccount();
+ } catch (OlmException e) {
+ assertTrue(e.getMessage(),false);
+ }
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
@@ -226,8 +238,14 @@ public class OlmSessionTest {
@Test
public void test03AliceBobSessionId() {
// creates alice & bob accounts
- OlmAccount aliceAccount = new OlmAccount();
- OlmAccount bobAccount = new OlmAccount();
+ OlmAccount aliceAccount = null;
+ OlmAccount bobAccount = null;
+ try {
+ aliceAccount = new OlmAccount();
+ bobAccount = new OlmAccount();
+ } catch (OlmException e) {
+ assertTrue(e.getMessage(),false);
+ }
// test accounts creation
assertTrue(0!=bobAccount.getOlmAccountId());
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
index b500cdf..030bea7 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
@@ -47,9 +47,14 @@ public class OlmUtilityTest {
String fingerPrintKey = null;
StringBuffer errorMsg = new StringBuffer();
String message = "{\"key1\":\"value1\",\"key2\":\"value2\"};";
+ OlmAccount account = null;
// create account
- OlmAccount account = new OlmAccount();
+ try {
+ account = new OlmAccount();
+ } catch (OlmException e) {
+ assertTrue(e.getMessage(),false);
+ }
assertNotNull(account);
// sign message