mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-24 02:51:34 -08:00
Fix PWDate and blocks
This commit is contained in:
1 parent
d4a09ed569
commit
be6f01dc99
25 files changed
+703
-787
No files matched your search
+11
-8
@@ -27,7 +27,6 @@ import java.util.Random
|
||||
|
||||
import junit.framework.TestCase
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwDate
|
||||
import com.kunzisoft.keepass.stream.LEDataInputStream
|
||||
import com.kunzisoft.keepass.stream.LEDataOutputStream
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
@@ -168,27 +167,31 @@ class DatabaseInputOutputUtilsTest : TestCase() {
|
||||
val expected = Calendar.getInstance()
|
||||
expected.set(2008, 1, 2, 3, 4, 5)
|
||||
|
||||
val buf = PwDate.writeTime(expected.time, cal)
|
||||
val actual = Calendar.getInstance()
|
||||
actual.time = PwDate.readTime(buf, 0, cal)
|
||||
DatabaseInputOutputUtils.writeCDate(expected.time, cal)?.let { buf ->
|
||||
actual.time = DatabaseInputOutputUtils.readCDate(buf, 0, cal).date
|
||||
}
|
||||
|
||||
assertEquals("Year mismatch: ", 2008, actual.get(Calendar.YEAR))
|
||||
assertEquals("Month mismatch: ", 1, actual.get(Calendar.MONTH))
|
||||
assertEquals("Day mismatch: ", 1, actual.get(Calendar.DAY_OF_MONTH))
|
||||
assertEquals("Day mismatch: ", 2, actual.get(Calendar.DAY_OF_MONTH))
|
||||
assertEquals("Hour mismatch: ", 3, actual.get(Calendar.HOUR_OF_DAY))
|
||||
assertEquals("Minute mismatch: ", 4, actual.get(Calendar.MINUTE))
|
||||
assertEquals("Second mismatch: ", 5, actual.get(Calendar.SECOND))
|
||||
}
|
||||
|
||||
fun testUUID() {
|
||||
val rnd = Random()
|
||||
val bUUID = ByteArray(16)
|
||||
rnd.nextBytes(bUUID)
|
||||
Random().nextBytes(bUUID)
|
||||
|
||||
val uuid = DatabaseInputOutputUtils.bytestoUUID(bUUID)
|
||||
val eUUID = DatabaseInputOutputUtils.UUIDtoBytes(uuid)
|
||||
val uuid = DatabaseInputOutputUtils.bytesToUuid(bUUID)
|
||||
val eUUID = DatabaseInputOutputUtils.uuidToBytes(uuid)
|
||||
|
||||
val lUUID = LEDataInputStream.readUuid(bUUID, 0)
|
||||
val leUUID = DatabaseInputOutputUtils.uuidToBytes(lUUID)
|
||||
|
||||
assertArrayEquals("UUID match failed", bUUID, eUUID)
|
||||
assertArrayEquals("UUID match failed", bUUID, leUUID)
|
||||
}
|
||||
|
||||
@Throws(Exception::class)
|
||||
|
||||
@@ -22,6 +22,7 @@ package com.kunzisoft.keepass.tests
|
||||
import junit.framework.TestCase
|
||||
|
||||
import com.kunzisoft.keepass.database.element.PwDate
|
||||
import com.kunzisoft.keepass.utils.DatabaseInputOutputUtils
|
||||
import org.junit.Assert
|
||||
|
||||
class PwDateTest : TestCase() {
|
||||
@@ -29,9 +30,9 @@ class PwDateTest : TestCase() {
|
||||
fun testDate() {
|
||||
val jDate = PwDate(System.currentTimeMillis())
|
||||
val intermediate = PwDate(jDate)
|
||||
val cDate = PwDate(intermediate.byteArrayDate!!, 0)
|
||||
val cDate = DatabaseInputOutputUtils.readCDate(DatabaseInputOutputUtils.writeCDate(intermediate.date)!!, 0)
|
||||
|
||||
Assert.assertTrue("jDate and intermediate not equal", jDate == intermediate)
|
||||
Assert.assertTrue("jDate and cDate not equal", cDate == jDate)
|
||||
Assert.assertTrue("jDate $jDate and cDate $cDate not equal", cDate == jDate)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user