Commit 867ef94c authored by pedroGitt's avatar pedroGitt
Browse files

First update with serialization mechanism

parent 250af953
package org.matrix.olm;
import android.accounts.Account;
import android.content.Context;
import android.content.SharedPreferences;
import android.support.test.runner.AndroidJUnit4;
import android.text.TextUtils;
import android.util.Log;
......@@ -15,9 +18,19 @@ import org.junit.Test;
import org.junit.runner.RunWith;
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 static android.support.test.InstrumentationRegistry.getInstrumentation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@RunWith(AndroidJUnit4.class)
......@@ -106,7 +119,7 @@ public class OlmAccountTest {
}
//****************************************************
//** ************** One time keys TESTS **************
//***************** ONE TIME KEYS TESTS **************
//****************************************************
@Test
public void test06MaxOneTimeKeys() {
......@@ -175,4 +188,79 @@ public class OlmAccountTest {
assertNotNull(signedMsg);
// 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());
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment