Skip to content

Commit ae965d2

Browse files
authored
Add streaming import union tests (#93)
* Add union to streaming update tests * Fix assertion attempting to change read-only union
1 parent 77d6570 commit ae965d2

8 files changed

Lines changed: 53 additions & 5 deletions

File tree

src/include/ConfigDB/Union.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Union : public Object
5151
*/
5252
void setTag(Tag tag)
5353
{
54+
if(!writeCheck()) {
55+
return;
56+
}
5457
assert(tag < typeinfo().objectCount);
5558
disposeArrays();
5659
memset(getDataPtr(), 0, typeinfo().structSize);
@@ -63,6 +66,9 @@ class Union : public Object
6366
*/
6467
void clear()
6568
{
69+
if(!writeCheck()) {
70+
return;
71+
}
6672
disposeArrays();
6773
memset(getDataPtr(), 0, typeinfo().structSize);
6874
getPropertyData(0)->uint8 = 0;

test/modules/Streaming.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class StreamingTest : public TestGroup
144144
{
145145
// An un-named root object should produce same output (i.e. options are ignored)
146146
String expectedContent =
147-
F("{\"int_array\":[13,28,39,40],\"string_array\":[\"a\",\"b\",\"c\"],\"object_array\":[],\"color\":"
147+
F("{\"simple-union\":{\"obj2\":{\"value\":12}},\"int_array\":[13,28,39,40],\"string_array\":[\"a\","
148+
"\"b\",\"c\"],\"object_array\":[],\"color\":"
148149
"\"red\",\"simple-bool\":true,\"simple-string\":\"donkey\",\"simple-int\":100,\"simple-float\":3."
149150
"1415927}");
150151
TestConfig::Root root(database);

test/resource/array_test_default.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
2+
"simple-union": {
3+
"obj1": {
4+
"value": 0
5+
}
6+
},
27
"int_array": [
38
1,
49
2,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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}
1+
{"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}

test/resource/database1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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":[]}
1+
{"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":[]}

test/resource/root1.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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}
1+
{"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}

test/resource/update1.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
{
22
"simple-bool": true,
3-
"simple-int": 11111110101010
3+
"simple-int": 11111110101010,
4+
"simple-union": {
5+
"obj2": {
6+
"value": 12
7+
}
8+
}
49
}

test/test-config.cfgdb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,37 @@
3030
"default": 3.141592654,
3131
"maximum": 1.2e8
3232
},
33+
"simple-union": {
34+
"oneOf": [
35+
{
36+
"type": "object",
37+
"title": "obj1",
38+
"properties": {
39+
"value": {
40+
"type": "integer"
41+
}
42+
}
43+
},
44+
{
45+
"type": "object",
46+
"title": "obj2",
47+
"properties": {
48+
"value": {
49+
"type": "number"
50+
}
51+
}
52+
},
53+
{
54+
"type": "object",
55+
"title": "obj3",
56+
"properties": {
57+
"value": {
58+
"type": "string"
59+
}
60+
}
61+
}
62+
]
63+
},
3364
"int_array": {
3465
"type": "array",
3566
"items": {

0 commit comments

Comments
 (0)