Skip to content

Commit

Permalink
Merge pull request #1875 from bugsnag/PLAT-10584_User_can_set_array_m…
Browse files Browse the repository at this point in the history
…etadata_for_NDK_events

NDK should report Array metadata values
  • Loading branch information
SmartbearYing committed Aug 1, 2023
2 parents 467734f + 253228b commit a225ea5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.bugsnag.android.ndk

import com.bugsnag.android.ndk.OpaqueValue.Companion.makeSafe
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
internal class OpaqueValueTest {

@Test
fun testBooleanOpaqueValue() {
val result = makeSafe(true)
assertEquals(true, result)
val result2 = makeSafe(false)
assertEquals(false, result2)
}

@Test
fun testNumberOpaqueValue() {
val result = makeSafe(1.5)
assertEquals(1.5, result)
}

@Test
fun testValidStringOpaqueValue() {
val result = makeSafe("Test")
assertEquals("Test", result)
}

@Test
fun testInvalidStringOpaqueValue() {
val testObject = "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest"
val result = makeSafe(testObject)
assertTrue(result is OpaqueValue)
}

@Test
fun testCollectionOpaqueValue() {
val testObject = listOf("Test1", "Test2")
val result = makeSafe(testObject)
assertTrue(result is OpaqueValue)
}

@Test
fun testMapOpaqueValue() {
val testObject = mapOf(1 to "Test1")
val result = makeSafe(testObject)
assertTrue(result is OpaqueValue)
}

@Test
fun testArrayOpaqueValue() {
val testObject = arrayOf("Test1", "Test2")
val result = makeSafe(testObject)
assertTrue(result is OpaqueValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ internal class OpaqueValue(val json: String) {
value is Boolean -> value
value is Number -> value
value is String && isStringNDKSupported(value) -> value
value is String || value is Map<*, *> || value is Collection<*> -> OpaqueValue(encode(value))
value is String ||
value is Map<*, *> ||
value is Collection<*> ||
value is Array<*> ->
OpaqueValue(encode(value))
else -> null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ private Map<String, Object> createComplexMetadata() {

metadata.put("nestedMap", nestedMap);

metadata.put("array", new String[]{"a", "b", "c"});

return metadata;
}
}
3 changes: 3 additions & 0 deletions features/smoke_tests/04_unhandled.feature
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ Feature: Unhandled smoke tests
And the event "metaData.opaque.nestedList.1" equals "one"
And the event "metaData.opaque.nestedList.2" equals "two"
And the event "metaData.opaque.nestedList.3" equals "three"
And the event "metaData.opaque.array.0" equals "a"
And the event "metaData.opaque.array.1" equals "b"
And the event "metaData.opaque.array.2" equals "c"

@debug-safe
Scenario: C++ exception thrown with overwritten config
Expand Down

0 comments on commit a225ea5

Please sign in to comment.