Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
867ef94c
Commit
867ef94c
authored
8 years ago
by
pedroGitt
Browse files
Options
Downloads
Patches
Plain Diff
First update with serialization mechanism
parent
250af953
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
+89
-1
89 additions, 1 deletion
...k/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
with
89 additions
and
1 deletion
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmAccountTest.java
+
89
−
1
View file @
867ef94c
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 {
}
//****************************************************
//**
************** O
ne time keys
TESTS **************
//**
*
************** O
NE 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
());
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment