First update with serialization mechanism
This commit is contained in:
parent
250af95330
commit
867ef94ced
1 changed files with 89 additions and 1 deletions
|
@ -1,5 +1,8 @@
|
||||||
package org.matrix.olm;
|
package org.matrix.olm;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
import android.support.test.runner.AndroidJUnit4;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -15,9 +18,19 @@ import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.MethodSorters;
|
import org.junit.runners.MethodSorters;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.ObjectInputStream;
|
||||||
|
import java.io.ObjectOutputStream;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import static android.support.test.InstrumentationRegistry.getInstrumentation;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
@ -106,7 +119,7 @@ public class OlmAccountTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
//****************************************************
|
//****************************************************
|
||||||
//** ************** One time keys TESTS **************
|
//***************** ONE TIME KEYS TESTS **************
|
||||||
//****************************************************
|
//****************************************************
|
||||||
@Test
|
@Test
|
||||||
public void test06MaxOneTimeKeys() {
|
public void test06MaxOneTimeKeys() {
|
||||||
|
@ -175,4 +188,79 @@ public class OlmAccountTest {
|
||||||
assertNotNull(signedMsg);
|
assertNotNull(signedMsg);
|
||||||
// additional tests are performed in test01VerifyEd25519Signing()
|
// additional tests are performed in test01VerifyEd25519Signing()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ********************************************************
|
||||||
|
// ************* SERIALIZATION TEST ***********************
|
||||||
|
// ********************************************************
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test13Serialization() {
|
||||||
|
FileOutputStream fileOutput = null;
|
||||||
|
ObjectOutputStream objectOutput = null;
|
||||||
|
OlmAccount accountRef = new OlmAccount();
|
||||||
|
OlmAccount accountDeserial = null;
|
||||||
|
OlmException exception;
|
||||||
|
|
||||||
|
int retValue = accountRef.generateOneTimeKeys(GENERATION_ONE_TIME_KEYS_NUMBER);
|
||||||
|
assertTrue(0==retValue);
|
||||||
|
|
||||||
|
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);
|
||||||
|
SharedPreferences.Editor editPref = sharedPref.edit();
|
||||||
|
editPref.putLong();*/
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
objectOutput = new ObjectOutputStream(fileOutput);
|
||||||
|
objectOutput.writeObject(accountRef);
|
||||||
|
objectOutput.flush();
|
||||||
|
objectOutput.close();
|
||||||
|
|
||||||
|
//FileInputStream fileInput = new FileInputStream(serialFile);
|
||||||
|
FileInputStream fileInput = context.openFileInput(FILE_NAME);
|
||||||
|
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
|
||||||
|
accountDeserial = (OlmAccount) objectInput.readObject();
|
||||||
|
objectInput.close();
|
||||||
|
|
||||||
|
assertNotNull(accountDeserial);
|
||||||
|
|
||||||
|
JSONObject identityKeys2 = accountDeserial.identityKeys();
|
||||||
|
JSONObject oneTimeKeys2 = accountDeserial.oneTimeKeys();
|
||||||
|
assertEquals(identityKeysRef, identityKeys2);
|
||||||
|
assertEquals(oneTimeKeysRef, oneTimeKeys2);
|
||||||
|
|
||||||
|
accountRef.releaseAccount();
|
||||||
|
accountDeserial.releaseAccount();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (FileNotFoundException e) {
|
||||||
|
Log.e(LOG_TAG, "## test13Serialization(): Exception FileNotFoundException Msg=="+e.getMessage());
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e) {
|
||||||
|
Log.e(LOG_TAG, "## test13Serialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
Log.e(LOG_TAG, "## test13Serialization(): Exception IOException Msg==" + e.getMessage());
|
||||||
|
}
|
||||||
|
/*catch (OlmException e) {
|
||||||
|
Log.e(LOG_TAG, "## test13Serialization(): Exception OlmException Msg==" + e.getMessage());
|
||||||
|
}*/
|
||||||
|
catch (Exception e) {
|
||||||
|
Log.e(LOG_TAG, "## test13Serialization(): Exception Msg==" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue