From 5bd29e9e9686df5ad72f2e54b1ce4ff03d7167d4 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Wed, 11 Feb 2026 10:54:12 +0000 Subject: [PATCH 1/2] Add union to streaming update tests --- test/modules/Streaming.cpp | 3 ++- test/resource/array_test_default.json | 5 +++++ test/resource/async-update-result.json | 2 +- test/resource/database1.json | 2 +- test/resource/root1.json | 2 +- test/resource/update1.json | 7 +++++- test/test-config.cfgdb | 31 ++++++++++++++++++++++++++ 7 files changed, 47 insertions(+), 5 deletions(-) diff --git a/test/modules/Streaming.cpp b/test/modules/Streaming.cpp index 6d083d90..74804436 100644 --- a/test/modules/Streaming.cpp +++ b/test/modules/Streaming.cpp @@ -144,7 +144,8 @@ class StreamingTest : public TestGroup { // An un-named root object should produce same output (i.e. options are ignored) String expectedContent = - F("{\"int_array\":[13,28,39,40],\"string_array\":[\"a\",\"b\",\"c\"],\"object_array\":[],\"color\":" + F("{\"simple-union\":{\"obj2\":{\"value\":12}},\"int_array\":[13,28,39,40],\"string_array\":[\"a\"," + "\"b\",\"c\"],\"object_array\":[],\"color\":" "\"red\",\"simple-bool\":true,\"simple-string\":\"donkey\",\"simple-int\":100,\"simple-float\":3." "1415927}"); TestConfig::Root root(database); diff --git a/test/resource/array_test_default.json b/test/resource/array_test_default.json index 4cb50a74..e874501f 100644 --- a/test/resource/array_test_default.json +++ b/test/resource/array_test_default.json @@ -1,4 +1,9 @@ { + "simple-union": { + "obj1": { + "value": 0 + } + }, "int_array": [ 1, 2, diff --git a/test/resource/async-update-result.json b/test/resource/async-update-result.json index a931c203..d7975670 100644 --- a/test/resource/async-update-result.json +++ b/test/resource/async-update-result.json @@ -1 +1 @@ -{"int_array":[100,1],"string_array":["go","away"],"object_array":[{"intval":1,"stringval":"biscuit"},{"intval":2,"stringval":"cake"}],"color":"green","simple-bool":true,"simple-string":"gorilla","simple-int":100,"simple-float":1.2e8} \ No newline at end of file +{"simple-union":{"obj1":{"value":0}},"int_array":[100,1],"string_array":["go","away"],"object_array":[{"intval":1,"stringval":"biscuit"},{"intval":2,"stringval":"cake"}],"color":"green","simple-bool":true,"simple-string":"gorilla","simple-int":100,"simple-float":1.2e8} \ No newline at end of file diff --git a/test/resource/database1.json b/test/resource/database1.json index ef09a408..d1be0f86 100644 --- a/test/resource/database1.json +++ b/test/resource/database1.json @@ -1 +1 @@ -{"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927,"array-store":[],"object-array-store":[]} \ No newline at end of file +{"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927,"array-store":[],"object-array-store":[]} \ No newline at end of file diff --git a/test/resource/root1.json b/test/resource/root1.json index 78b76a42..2f694ee9 100644 --- a/test/resource/root1.json +++ b/test/resource/root1.json @@ -1 +1 @@ -{"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927} \ No newline at end of file +{"simple-union":{"obj2":{"value":12}},"int_array":[13,28,39,40],"string_array":["a","b","c"],"object_array":[],"color":"red","simple-bool":true,"simple-string":"donkey","simple-int":100,"simple-float":3.1415927} \ No newline at end of file diff --git a/test/resource/update1.json b/test/resource/update1.json index deadcde2..fc407af7 100644 --- a/test/resource/update1.json +++ b/test/resource/update1.json @@ -1,4 +1,9 @@ { "simple-bool": true, - "simple-int": 11111110101010 + "simple-int": 11111110101010, + "simple-union": { + "obj2": { + "value": 12 + } + } } \ No newline at end of file diff --git a/test/test-config.cfgdb b/test/test-config.cfgdb index 0b15c910..e15d49a4 100644 --- a/test/test-config.cfgdb +++ b/test/test-config.cfgdb @@ -30,6 +30,37 @@ "default": 3.141592654, "maximum": 1.2e8 }, + "simple-union": { + "oneOf": [ + { + "type": "object", + "title": "obj1", + "properties": { + "value": { + "type": "integer" + } + } + }, + { + "type": "object", + "title": "obj2", + "properties": { + "value": { + "type": "number" + } + } + }, + { + "type": "object", + "title": "obj3", + "properties": { + "value": { + "type": "string" + } + } + } + ] + }, "int_array": { "type": "array", "items": { From 4a8dc67a1a4b25167b8bfa2cbedeeb54de140834 Mon Sep 17 00:00:00 2001 From: mikee47 Date: Wed, 11 Feb 2026 19:28:20 +0000 Subject: [PATCH 2/2] Fix assertion attempting to change read-only union --- src/include/ConfigDB/Union.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/include/ConfigDB/Union.h b/src/include/ConfigDB/Union.h index d3c4359a..357a709d 100644 --- a/src/include/ConfigDB/Union.h +++ b/src/include/ConfigDB/Union.h @@ -51,6 +51,9 @@ class Union : public Object */ void setTag(Tag tag) { + if(!writeCheck()) { + return; + } assert(tag < typeinfo().objectCount); disposeArrays(); memset(getDataPtr(), 0, typeinfo().structSize); @@ -63,6 +66,9 @@ class Union : public Object */ void clear() { + if(!writeCheck()) { + return; + } disposeArrays(); memset(getDataPtr(), 0, typeinfo().structSize); getPropertyData(0)->uint8 = 0;