Skip to content

Commit 5504c0d

Browse files
authored
Merge branch 'master' into feature/kotlin-2.0
2 parents a85efaa + f0c0777 commit 5504c0d

File tree

2 files changed

+30
-3
lines changed
  • firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal
  • firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database

2 files changed

+30
-3
lines changed

firebase-common-internal/src/commonMain/kotlin/dev/gitlive/firebase/internal/decoders.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,12 @@ private fun decodeShort(value: Any?) = when(value) {
217217
else -> throw SerializationException("Expected $value to be short")
218218
}
219219

220-
private fun decodeBoolean(value: Any?) = value as Boolean
220+
private fun decodeBoolean(value: Any?) = when (value) {
221+
is Boolean -> value
222+
is Number -> value != 0
223+
is String -> value.toBoolean()
224+
else -> throw SerializationException("Expected $value to be boolean")
225+
}
221226

222227
private fun decodeChar(value: Any?) = when(value) {
223228
is Number -> value.toInt().toChar()

firebase-database/src/commonTest/kotlin/dev/gitlive/firebase/database/database.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import dev.gitlive.firebase.runBlockingTest
88
import dev.gitlive.firebase.runTest
99
import kotlinx.coroutines.Dispatchers
1010
import kotlinx.coroutines.flow.first
11-
import kotlinx.coroutines.flow.map
1211
import kotlinx.coroutines.withContext
1312
import kotlinx.coroutines.withTimeout
1413
import kotlinx.serialization.Serializable
@@ -33,7 +32,7 @@ class FirebaseDatabaseTest {
3332
lateinit var database: FirebaseDatabase
3433

3534
@Serializable
36-
data class FirebaseDatabaseChildTest(val prop1: String? = null, val time: Double = 0.0)
35+
data class FirebaseDatabaseChildTest(val prop1: String? = null, val time: Double = 0.0, val boolean: Boolean = true)
3736

3837
@Serializable
3938
data class DatabaseTest(val title: String, val likes: Int = 0)
@@ -198,6 +197,29 @@ class FirebaseDatabaseTest {
198197
assertFalse(valueEvents.first().exists)
199198
}
200199

200+
@Test
201+
fun testBooleanValue() = runTest {
202+
ensureDatabaseConnected()
203+
val reference = database.reference("FirebaseRealtimeDatabaseBooleanTest")
204+
val falseRef = reference.child("false")
205+
val trueRef = reference.child("true")
206+
falseRef.setValue(false)
207+
trueRef.setValue(true)
208+
val falseValue = falseRef.valueEvents.first().value<Boolean>()
209+
val trueValue = trueRef.valueEvents.first().value<Boolean>()
210+
assertFalse(falseValue)
211+
assertTrue(trueValue)
212+
}
213+
214+
@Test
215+
fun testBooleanValueInChild() = runTest {
216+
ensureDatabaseConnected()
217+
val reference = database.reference("FirebaseRealtimeDatabaseBooleanInChildTest")
218+
reference.setValue(FirebaseDatabaseChildTest())
219+
val value = reference.valueEvents.first().value<FirebaseDatabaseChildTest>()
220+
assertEquals(FirebaseDatabaseChildTest(), value)
221+
}
222+
201223
// Ignoring on Android Instrumented Tests due to bug in Firebase: https://github.com/firebase/firebase-android-sdk/issues/5870
202224
@IgnoreForAndroidTest
203225
@Test

0 commit comments

Comments
 (0)