-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
• Support other apps sharing data with Cryptool. • Implement user feedback. • Fix stability issues.
- Loading branch information
Showing
46 changed files
with
742 additions
and
234 deletions.
There are no files selected for viewing
119 changes: 119 additions & 0 deletions
119
...androidTest/java/io/github/nfdz/cryptool/shared/message/repository/MessageReceiverTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package io.github.nfdz.cryptool.shared.message.repository | ||
|
||
import io.github.nfdz.cryptool.shared.core.realm.FakeRealmGateway | ||
import io.github.nfdz.cryptool.shared.encryption.entity.AlgorithmVersion | ||
import io.github.nfdz.cryptool.shared.encryption.entity.MessageSource | ||
import io.github.nfdz.cryptool.shared.encryption.entity.serialize | ||
import io.github.nfdz.cryptool.shared.encryption.repository.realm.EncryptionRealm | ||
import io.github.nfdz.cryptool.shared.message.entity.Message | ||
import io.github.nfdz.cryptool.shared.message.entity.MessageOwnership | ||
import io.github.nfdz.cryptool.shared.message.repository.realm.MessageRealm | ||
import io.realm.kotlin.ext.query | ||
import junit.framework.TestCase.assertEquals | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.After | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
class MessageReceiverTest { | ||
|
||
private val encryptionRealmA = EncryptionRealm().also { new -> | ||
new.id = "encryptionId-A" | ||
new.name = "Encryption A" | ||
new.password = "testAA" | ||
new.algorithm = AlgorithmVersion.V2.name | ||
new.source = MessageSource.Manual.serialize() | ||
} | ||
private val messageA = Message( | ||
id = "A", | ||
encryptionId = "encryptionId-A", | ||
message = "Lorem ipsum dolor A", | ||
encryptedMessage = | ||
"LD8azzqjc-e8C90bJ8Ut2bYa7WU.1QVQGS10pFb-LndU.128.idB9lucOGxHPLLusE_h0iumSadSum1AqzZ3fJQfCjl4OvkS-uWMSmfYb9HhAdkOeKvGP5p4vUQ", | ||
timestampInMillis = 100, | ||
isFavorite = false, | ||
ownership = MessageOwnership.OTHER, | ||
) | ||
private lateinit var realm: FakeRealmGateway | ||
|
||
@Before | ||
fun beforeTest() { | ||
realm = FakeRealmGateway() | ||
} | ||
|
||
@After | ||
fun afterTest() { | ||
realm.tearDownTest() | ||
} | ||
|
||
@Test(expected = java.util.NoSuchElementException::class) | ||
fun testReceiveWithInvalidEncryption() = runTest { | ||
val instance = MessageReceiverImpl(realm) | ||
|
||
instance.receive(encryptionId = "Invalid", encryptedMessage = messageA.encryptedMessage, isRead = false) | ||
} | ||
|
||
@Test(expected = java.lang.IllegalStateException::class) | ||
fun testReceiveWithInvalidMessage() = runTest { | ||
realm.instance.write { | ||
copyToRealm(encryptionRealmA) | ||
} | ||
val instance = MessageReceiverImpl(realm) | ||
|
||
instance.receive(encryptionId = messageA.encryptionId, encryptedMessage = "Invalid", isRead = false) | ||
} | ||
|
||
@Test | ||
fun testReceive() = runTest { | ||
realm.instance.write { | ||
copyToRealm(encryptionRealmA) | ||
} | ||
val instance = MessageReceiverImpl(realm) | ||
|
||
instance.receive( | ||
encryptionId = messageA.encryptionId, | ||
encryptedMessage = messageA.encryptedMessage, | ||
isRead = false, | ||
) | ||
|
||
val stored = realm.instance.query<MessageRealm>().find() | ||
assertEquals(1, stored.size) | ||
val storedMessage = stored.first().toEntity() | ||
assertEquals(MessageOwnership.OTHER, storedMessage.ownership) | ||
assertEquals(messageA.message, storedMessage.message) | ||
assertEquals(messageA.encryptedMessage, storedMessage.encryptedMessage) | ||
val storedEncryptions = realm.instance.query<EncryptionRealm>().find() | ||
assertEquals(1, storedEncryptions.size) | ||
val storedEncryption = storedEncryptions.first().toEntity() | ||
assertEquals(1, storedEncryption.unreadMessagesCount) | ||
assertEquals("${encryptionRealmA.name}: ${messageA.encryptedMessage}", storedEncryption.lastMessage) | ||
} | ||
|
||
@Test | ||
fun testReceive2() = runTest { | ||
realm.instance.write { | ||
copyToRealm(encryptionRealmA) | ||
} | ||
val instance = MessageReceiverImpl(realm) | ||
|
||
instance.receive( | ||
encryption = encryptionRealmA.toEntity(), | ||
encryptedMessage = messageA.encryptedMessage, | ||
timestampInMillis = messageA.timestampInMillis, | ||
isRead = false, | ||
) | ||
|
||
val stored = realm.instance.query<MessageRealm>().find() | ||
assertEquals(1, stored.size) | ||
val storedMessage = stored.first().toEntity() | ||
assertEquals(MessageOwnership.OTHER, storedMessage.ownership) | ||
assertEquals(messageA.message, storedMessage.message) | ||
assertEquals(messageA.encryptedMessage, storedMessage.encryptedMessage) | ||
val storedEncryptions = realm.instance.query<EncryptionRealm>().find() | ||
assertEquals(1, storedEncryptions.size) | ||
val storedEncryption = storedEncryptions.first().toEntity() | ||
assertEquals(1, storedEncryption.unreadMessagesCount) | ||
assertEquals("${encryptionRealmA.name}: ${messageA.encryptedMessage}", storedEncryption.lastMessage) | ||
assertEquals(messageA.timestampInMillis, storedEncryption.lastMessageTimestamp) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+1.93 KB
(100%)
...eenshots/31-1080x2340@440dp-en_US/CreateEncryptionDialogScreenshotTest_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.7 KB
(100%)
...enshots/31-1080x2340@440dp-en_US/CreateEncryptionDialogScreenshotTest_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+338 Bytes
(100%)
...creenshots/31-1080x2340@440dp-en_US/CreatePasswordDialogScreenshotTest_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+178 Bytes
(100%)
...reenshots/31-1080x2340@440dp-en_US/CreatePasswordDialogScreenshotTest_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.99 KB
(100%)
...creenshots/31-1080x2340@440dp-en_US/EditEncryptionDialogScreenshotTest_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.81 KB
(100%)
...reenshots/31-1080x2340@440dp-en_US/EditEncryptionDialogScreenshotTest_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+516 Bytes
(100%)
.../screenshots/31-1080x2340@440dp-en_US/EditPasswordDialogScreenshotTest_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+237 Bytes
(100%)
...screenshots/31-1080x2340@440dp-en_US/EditPasswordDialogScreenshotTest_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+44.4 KB
...creenshots/31-1080x2340@440dp-en_US/PickEncryptionDialogScreenshotTest_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45 KB
...reenshots/31-1080x2340@440dp-en_US/PickEncryptionDialogScreenshotTest_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...rc/androidTest/java/io/github/nfdz/cryptool/ui/main/PickEncryptionDialogScreenshotTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.github.nfdz.cryptool.ui.main | ||
|
||
import dev.testify.ComposableScreenshotRule | ||
import dev.testify.annotation.ScreenshotInstrumentation | ||
import io.github.nfdz.cryptool.shared.encryption.entity.AlgorithmVersion | ||
import io.github.nfdz.cryptool.shared.encryption.entity.Encryption | ||
import io.github.nfdz.cryptool.ui.DarkColorScheme | ||
import io.github.nfdz.cryptool.ui.LightColorScheme | ||
import io.github.nfdz.cryptool.ui.test.TestEntry | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class PickEncryptionDialogScreenshotTest { | ||
|
||
@get:Rule | ||
val rule = ComposableScreenshotRule() | ||
|
||
private val incomingData = | ||
"-99Vkg91QTKxpapuXQjqwJ5Mw.fDcHFT5r2nF42S0nq28PQQ.128.rbbgZVnc9f5hE7KHaL_t_pMgmulmWLYl9HrCqb8IhdnasIUmA" | ||
private val encryptions = listOf( | ||
Encryption("", "Conversation 1", "", AlgorithmVersion.V2, null, false, 0, "", 0L), | ||
Encryption("", "Conversation 2", "", AlgorithmVersion.V2, null, false, 0, "", 0L), | ||
Encryption("", "Conversation 3", "", AlgorithmVersion.V2, null, false, 0, "", 0L), | ||
) | ||
|
||
@ScreenshotInstrumentation | ||
@Test | ||
fun light() { | ||
rule.setCompose { | ||
TestEntry(colorScheme = LightColorScheme) { | ||
PickEncryptionDialogContent(incomingData, encryptions) {} | ||
} | ||
}.assertSame() | ||
} | ||
|
||
@ScreenshotInstrumentation | ||
@Test | ||
fun dark() { | ||
rule.setCompose { | ||
TestEntry(colorScheme = DarkColorScheme) { | ||
PickEncryptionDialogContent(incomingData, encryptions) {} | ||
} | ||
}.assertSame() | ||
} | ||
} |
Oops, something went wrong.