Skip to content

Commit fdaa03f

Browse files
committed
Convert tests to Katlin
1 parent 255228d commit fdaa03f

10 files changed

Lines changed: 229 additions & 305 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Tag size: 128
7979

8080
Open the directory with Android Studio.
8181

82-
From command line, to run the tests execute: `./gradlew app:connectedAndroidTest`
82+
From command line, to run the tests, start an emulator (or connect a physical phone) and execute:
83+
`./gradlew app:connectedAndroidTest`
8384

8485
To install the debug build: `./gradlew installDebug`
8586

app/build.gradle

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ android {
3131
buildFeatures {
3232
compose = true
3333
}
34-
35-
useLibrary 'android.test.runner'
36-
useLibrary 'android.test.base'
37-
useLibrary 'android.test.mock'
3834
}
3935

4036
dependencies {
@@ -52,6 +48,7 @@ dependencies {
5248
debugImplementation libs.compose.ui.tooling
5349

5450
testImplementation libs.junit
51+
5552
androidTestImplementation libs.ext.junit
5653
androidTestImplementation libs.espresso.core
5754
androidTestImplementation libs.testRunner

app/src/androidTest/java/com/aidinhut/simpletextcrypt/ApplicationTest.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

app/src/androidTest/java/com/aidinhut/simpletextcrypt/CrypterTest.java

Lines changed: 0 additions & 85 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* This file is part of SimpleTextCrypt.
3+
* Copyright (c) 2015-2026, Aidin Gharibnavaz <aidin@aidinhut.com>
4+
*
5+
* SimpleTextCrypt is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* SimpleTextCrypt is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with SimpleTextCrypt. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.aidinhut.simpletextcrypt
19+
20+
import android.util.Log
21+
import androidx.test.ext.junit.runners.AndroidJUnit4
22+
import org.junit.Assert.assertEquals
23+
import org.junit.Test
24+
import org.junit.runner.RunWith
25+
26+
/**
27+
* Implements stand-alone tests for Crypter class.
28+
*/
29+
@RunWith(AndroidJUnit4::class)
30+
class CrypterTest {
31+
32+
/**
33+
* Tests if encrypting and decrypting a data will result
34+
* in the same data.
35+
*/
36+
@Test
37+
fun testEncryptDecryptValidation() {
38+
val passwords = arrayOf(
39+
"uir43@#89djhncAd.,[]-+091jhdncq`",
40+
"18736",
41+
"❤️😜🙈🙃🍎🍀🍵🍪",
42+
"Me L@ve Ch33se! Double, no triple cream! Gonna have a heart attack.",
43+
"کلید فارسی"
44+
)
45+
val dataList = arrayOf(
46+
"Hi there! I'm a test data that is going to be encrypted.",
47+
"I love you! ❤",
48+
"یک مسیج فارسی سری که برای بقیه بفرستیم",
49+
"A very long message to be secretly send over the network. It's very very very very very very" +
50+
" very very long! And has some UTF-8 characters like یک and マンガが大好きです"
51+
)
52+
53+
for (password in passwords) {
54+
for (data in dataList) {
55+
validateEncryptDecrypt(password, data)
56+
}
57+
}
58+
}
59+
60+
private fun validateEncryptDecrypt(password: String, data: String) {
61+
Log.i("CrypterTest", "password=$password - data=$data")
62+
63+
val encryptedData = Crypter.encrypt(password, data)
64+
val decryptedData = Crypter.decrypt(password, encryptedData)
65+
66+
assertEquals(data, decryptedData)
67+
}
68+
69+
/**
70+
* Tests if we can decrypt messages that are encrypted with an old version of the app.
71+
*/
72+
@Test
73+
fun testLegacyAlgorithm() {
74+
assertEquals(
75+
"Hi! I'm encrypted with the old algorithm.",
76+
Crypter.legacyDecrypt(
77+
"buSD4778@af-bq3299",
78+
"q:*`Bgd|I[2y9#[SRbsqNBNdEb+7gBaGSUylWNcSHQWw+Sq32XDF6N3avTWiBzUyObviPqdTzkFEDd2o"
79+
)
80+
)
81+
assertEquals(
82+
"Another message for testing. 😀🙃",
83+
Crypter.legacyDecrypt(
84+
"1356",
85+
"g4A!>y{%pz}Q4B\u007FRr9Da4/d/y33wGJichEjYy3Z+uRgKaTz4WvsOfcC/h2HJTDoSCktv2WNFRM5gdXEI"
86+
)
87+
)
88+
}
89+
}

app/src/androidTest/java/com/aidinhut/simpletextcrypt/LockActivityTest.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

app/src/androidTest/java/com/aidinhut/simpletextcrypt/SettingsActivityTest.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)