-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from RomanTsisyk/add-qa-code-handling-functiona…
…lity Add Unit and Instrumentation Tests for QR Code Features
- Loading branch information
Showing
12 changed files
with
221 additions
and
71 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
24 changes: 0 additions & 24 deletions
24
cryptolib/src/androidTest/java/io/github/romantsisyk/cryptolib/ExampleInstrumentedTest.kt
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
cryptolib/src/androidTest/java/io/github/romantsisyk/cryptolib/qr/QRCodeGeneratorTest.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,20 @@ | ||
package io.github.romantsisyk.cryptolib.qr | ||
|
||
import android.graphics.Bitmap | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.github.romantsisyk.cryptolib.crypto.qr.QRCodeGenerator | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class QRCodeGeneratorTest { | ||
|
||
@Test | ||
fun testGenerateQRCode() { | ||
val bitmap: Bitmap = QRCodeGenerator.generateQRCode("Test") | ||
assertNotNull(bitmap) | ||
assertEquals(300, bitmap.width) // Ensure the QR code is 300x300 pixels | ||
assertEquals(300, bitmap.height) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
cryptolib/src/androidTest/java/io/github/romantsisyk/cryptolib/qr/QRCodeScannerTest.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,28 @@ | ||
package io.github.romantsisyk.cryptolib.qr | ||
|
||
import android.graphics.Bitmap | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.github.romantsisyk.cryptolib.crypto.qr.QRCodeGenerator | ||
import io.github.romantsisyk.cryptolib.crypto.qr.QRCodeScanner | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNull | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class QRCodeScannerTest { | ||
|
||
@Test | ||
fun testDecodeQRCodeValid() { | ||
val bitmap = QRCodeGenerator.generateQRCode("Valid QR Code") | ||
val result = QRCodeScanner.decodeQRCode(bitmap) | ||
assertEquals("Valid QR Code", result) | ||
} | ||
|
||
@Test | ||
fun testDecodeQRCodeInvalid() { | ||
val bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888) | ||
val result = QRCodeScanner.decodeQRCode(bitmap) | ||
assertNull(result) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
cryptolib/src/androidTest/java/io/github/romantsisyk/cryptolib/qr/QRUtilsTest.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,27 @@ | ||
package io.github.romantsisyk.cryptolib.qr | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.github.romantsisyk.cryptolib.crypto.qr.QRKeyManager | ||
import io.github.romantsisyk.cryptolib.crypto.qr.QRUtils | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertNotNull | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class QRUtilsTest { | ||
|
||
@Test | ||
fun testEncryptDecryptWithRealKey() { | ||
val key = QRKeyManager.generateKey() | ||
assertNotNull(key) | ||
|
||
val data = "Test Data" | ||
val (encryptedData, iv) = QRUtils.encryptData(data, key) | ||
assertNotNull(encryptedData) | ||
assertNotNull(iv) | ||
|
||
val decryptedData = QRUtils.decryptData(encryptedData, key, iv) | ||
assertEquals(data, decryptedData) | ||
} | ||
} |
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
17 changes: 0 additions & 17 deletions
17
cryptolib/src/test/java/io/github/romantsisyk/cryptolib/ExampleUnitTest.kt
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
...olib/src/test/java/io/github/romantsisyk/cryptolib/crypto/qr/BitmapLuminanceSourceTest.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,22 @@ | ||
package io.github.romantsisyk.cryptolib.crypto.qr | ||
|
||
import android.graphics.Bitmap | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.robolectric.RobolectricTestRunner | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class BitmapLuminanceSourceTest { | ||
|
||
@Test | ||
fun testGetMatrix() { | ||
val bitmap = Bitmap.createBitmap(2, 2, Bitmap.Config.ARGB_8888) | ||
bitmap.setPixel(0, 0, 0xFF000000.toInt()) // Black | ||
bitmap.setPixel(0, 1, 0xFFFFFFFF.toInt()) // White | ||
|
||
val source = BitmapLuminanceSource(bitmap) | ||
val matrix = source.matrix | ||
assertEquals(4, matrix.size) | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
cryptolib/src/test/java/io/github/romantsisyk/cryptolib/crypto/qr/QRKeyManagerTest.kt
This file was deleted.
Oops, something went wrong.