1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include <gtest/gtest.h>
23 #include <OCRepresentation.h>
26 #include <ocpayload.h>
27 #include <ocpayloadcbor.h>
28 #include <oic_malloc.h>
29 #include <oic_string.h>
30 #include "payload_logging.h"
32 bool operator==(const OCByteString& lhs, const OCByteString& rhs)
34 bool result = (lhs.len == rhs.len);
37 result = (memcmp(lhs.bytes, rhs.bytes, lhs.len) == 0);
44 bool operator==(const OC::NullType&, const OC::NullType&)
49 bool operator==(const OC::OCRepresentation& lhs, const OC::OCRepresentation& rhs)
51 return lhs.getUri() == rhs.getUri() &&
52 lhs.getChildren() == rhs.getChildren() &&
53 lhs.getResourceInterfaces() == rhs.getResourceInterfaces() &&
54 lhs.getResourceTypes() == rhs.getResourceTypes() &&
55 lhs.m_values == rhs.m_values;
58 // these tests validate the OCRepresentation->OCPayload, OCPayload->CBOR,
59 // CBOR->OCPayload and OCPayload->OCRepresentation conversions
60 namespace OCRepresentationEncodingTest
62 static const char sid1[] = "646F6F72-4465-7669-6365-555549443030";
63 static const char devicename1[] = "device name";
64 static const char specver1[] = "spec version";
65 static const char dmver1[] = "res.1.1.0";
66 static OCStringLL *types = NULL;
68 TEST(DeviceDiscoveryEncoding, Normal)
70 OCResourcePayloadAddStringLL(&types, "oic.wk.d");
71 OCResourcePayloadAddStringLL(&types, "oic.d.tv");
73 OCDevicePayload* device = OCDevicePayloadCreate(
80 EXPECT_STREQ(sid1, device->sid);
81 EXPECT_STREQ(devicename1, device->deviceName);
82 EXPECT_STREQ(specver1, device->specVersion);
83 EXPECT_TRUE(device->dataModelVersions);
84 EXPECT_STREQ("res.1.1.0", device->dataModelVersions->value);
85 EXPECT_FALSE(device->dataModelVersions->next);
86 EXPECT_EQ(PAYLOAD_TYPE_DEVICE, ((OCPayload *)device)->type);
87 EXPECT_STREQ("oic.wk.d", device->types->value);
88 EXPECT_STREQ("oic.d.tv", device->types->next->value);
92 OCPayload* parsedDevice;
93 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)device, &cborData, &cborSize));
94 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_DEVICE,
98 EXPECT_STREQ(device->sid, ((OCDevicePayload*)parsedDevice)->sid);
99 EXPECT_STREQ(device->deviceName, ((OCDevicePayload*)parsedDevice)->deviceName);
100 EXPECT_STREQ(device->specVersion, ((OCDevicePayload*)parsedDevice)->specVersion);
101 EXPECT_STREQ(device->dataModelVersions->value, ((OCDevicePayload*)parsedDevice)->dataModelVersions->value);
102 EXPECT_STREQ("oic.wk.d", ((OCDevicePayload*)parsedDevice)->types->value);
103 EXPECT_STREQ("oic.d.tv", ((OCDevicePayload*)parsedDevice)->types->next->value);
104 EXPECT_EQ(device->base.type, ((OCDevicePayload*)parsedDevice)->base.type);
106 OCPayloadDestroy((OCPayload*)device);
108 OC::MessageContainer mc1;
109 mc1.setPayload(parsedDevice);
110 EXPECT_EQ(1u, mc1.representations().size());
111 const OC::OCRepresentation &r1 = mc1.representations()[0];
112 EXPECT_STREQ(sid1, r1.getValue<std::string>(OC_RSRVD_DEVICE_ID).c_str());
113 EXPECT_STREQ(devicename1, r1.getValue<std::string>(OC_RSRVD_DEVICE_NAME).c_str());
114 EXPECT_STREQ(specver1, r1.getValue<std::string>(OC_RSRVD_SPEC_VERSION).c_str());
115 EXPECT_STREQ("res.1.1.0", r1.getDataModelVersions()[0].c_str());
117 OCPayloadDestroy(parsedDevice);
119 static const char dmver2[] = "res.1.1.0,sh.1.1.0";
120 device = OCDevicePayloadCreate(
127 EXPECT_STREQ("res.1.1.0", device->dataModelVersions->value);
128 EXPECT_TRUE(device->dataModelVersions->next);
129 EXPECT_STREQ("sh.1.1.0", device->dataModelVersions->next->value);
130 EXPECT_FALSE(device->dataModelVersions->next->next);
131 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)device, &cborData, &cborSize));
132 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_DEVICE,
133 cborData, cborSize));
135 EXPECT_STREQ(device->dataModelVersions->value,
136 ((OCDevicePayload *)parsedDevice)->dataModelVersions->value);
137 EXPECT_STREQ(device->dataModelVersions->next->value,
138 ((OCDevicePayload *)parsedDevice)->dataModelVersions->next->value);
139 OCPayloadDestroy((OCPayload *)device);
140 OC::MessageContainer mc2;
141 mc2.setPayload(parsedDevice);
142 EXPECT_EQ(1u, mc2.representations().size());
143 const OC::OCRepresentation r2 = mc2.representations()[0];
144 EXPECT_STREQ("res.1.1.0", r2.getDataModelVersions()[0].c_str());
145 EXPECT_STREQ("sh.1.1.0", r2.getDataModelVersions()[1].c_str());
147 OCPayloadDestroy(parsedDevice);
150 static const char uri1[] = "/testuri";
151 static char pfid1[] = "pfid";
152 static char mfgnm1[] = "mfgnm";
153 static char mfgurl1[] = "mfgurl";
154 static char modelnum1[] = "modelnum";
155 static char dom1[] = "dom";
156 static char pfver1[] = "pfver";
157 static char osver1[] = "osver";
158 static char hwver1[] = "hwver";
159 static char fwver1[] = "fwver";
160 static char url1[] = "url";
161 static char time1[] = "time";
164 TEST(PlatformDiscoveryEncoding, Normal)
166 OCPlatformInfo info {pfid1, mfgnm1, mfgurl1, modelnum1, dom1, pfver1, osver1, hwver1,
167 fwver1, url1, time1};
168 OCPlatformPayload* platform = OCPlatformPayloadCreate(&info);
169 EXPECT_EQ(PAYLOAD_TYPE_PLATFORM, ((OCPayload*)platform)->type);
170 EXPECT_STREQ(pfid1, platform->info.platformID);
171 EXPECT_STREQ(mfgnm1, platform->info.manufacturerName);
172 EXPECT_STREQ(mfgurl1, platform->info.manufacturerUrl);
173 EXPECT_STREQ(modelnum1, platform->info.modelNumber);
174 EXPECT_STREQ(dom1, platform->info.dateOfManufacture);
175 EXPECT_STREQ(pfver1, platform->info.platformVersion);
176 EXPECT_STREQ(osver1, platform->info.operatingSystemVersion);
177 EXPECT_STREQ(hwver1, platform->info.hardwareVersion);
178 EXPECT_STREQ(fwver1, platform->info.firmwareVersion);
179 EXPECT_STREQ(url1, platform->info.supportUrl);
180 EXPECT_STREQ(time1, platform->info.systemTime);
181 EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, platform->interfaces->value);
182 EXPECT_STREQ(OC_RSRVD_INTERFACE_READ, platform->interfaces->next->value);
183 EXPECT_STREQ(OC_RSRVD_RESOURCE_TYPE_PLATFORM, platform->rt->value);
187 OCPayload* parsedPlatform;
188 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)platform, &cborData, &cborSize));
189 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedPlatform, PAYLOAD_TYPE_PLATFORM,
190 cborData, cborSize));
193 EXPECT_EQ(platform->base.type, ((OCPlatformPayload*)parsedPlatform)->base.type);
194 OCPlatformPayload* platform2 = (OCPlatformPayload*)parsedPlatform;
195 EXPECT_STREQ(platform->info.platformID, platform2->info.platformID);
196 EXPECT_STREQ(platform->info.manufacturerName, platform->info.manufacturerName);
197 EXPECT_STREQ(platform->info.manufacturerUrl, platform->info.manufacturerUrl);
198 EXPECT_STREQ(platform->info.modelNumber, platform->info.modelNumber);
199 EXPECT_STREQ(platform->info.dateOfManufacture, platform->info.dateOfManufacture);
200 EXPECT_STREQ(platform->info.platformVersion, platform->info.platformVersion);
201 EXPECT_STREQ(platform->info.operatingSystemVersion, platform->info.operatingSystemVersion);
202 EXPECT_STREQ(platform->info.hardwareVersion, platform->info.hardwareVersion);
203 EXPECT_STREQ(platform->info.firmwareVersion, platform->info.firmwareVersion);
204 EXPECT_STREQ(platform->info.supportUrl, platform->info.supportUrl);
205 EXPECT_STREQ(platform->info.systemTime, platform2->info.systemTime);
206 EXPECT_STREQ(platform->interfaces->value, platform2->interfaces->value);
207 EXPECT_STREQ(platform->rt->value, platform2->rt->value);
209 OCPayloadDestroy((OCPayload*)platform);
211 OC::MessageContainer mc;
212 mc.setPayload(parsedPlatform);
213 EXPECT_EQ(1u, mc.representations().size());
214 const OC::OCRepresentation& r = mc.representations()[0];
215 EXPECT_STREQ(pfid1, r.getValue<std::string>(OC_RSRVD_PLATFORM_ID).c_str());
216 EXPECT_STREQ(mfgnm1, r.getValue<std::string>(OC_RSRVD_MFG_NAME).c_str());
217 EXPECT_STREQ(mfgurl1, r.getValue<std::string>(OC_RSRVD_MFG_URL).c_str());
218 EXPECT_STREQ(modelnum1, r.getValue<std::string>(OC_RSRVD_MODEL_NUM).c_str());
219 EXPECT_STREQ(dom1, r.getValue<std::string>(OC_RSRVD_MFG_DATE).c_str());
220 EXPECT_STREQ(pfver1, r.getValue<std::string>(OC_RSRVD_PLATFORM_VERSION).c_str());
221 EXPECT_STREQ(osver1, r.getValue<std::string>(OC_RSRVD_OS_VERSION).c_str());
222 EXPECT_STREQ(hwver1, r.getValue<std::string>(OC_RSRVD_HARDWARE_VERSION).c_str());
223 EXPECT_STREQ(fwver1, r.getValue<std::string>(OC_RSRVD_FIRMWARE_VERSION).c_str());
224 EXPECT_STREQ(url1, r.getValue<std::string>(OC_RSRVD_SUPPORT_URL).c_str());
225 EXPECT_STREQ(time1, r.getValue<std::string>(OC_RSRVD_SYSTEM_TIME).c_str());
227 OCPayloadDestroy(parsedPlatform);
229 TEST(PresencePayload, Normal)
232 uint32_t sequenceNumber = 0;
233 OCPresenceTrigger trigger = OC_PRESENCE_TRIGGER_CREATE;
234 OCPresencePayload *presence = OCPresencePayloadCreate(sequenceNumber, maxAge, trigger, uri1);
239 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)presence, &cborData, &cborSize));
240 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_PRESENCE,
241 cborData, cborSize));
242 OCPayloadDestroy((OCPayload*)presence);
245 OCPresencePayload* parsed = ((OCPresencePayload*)cparsed);
246 EXPECT_EQ(sequenceNumber, parsed->sequenceNumber);
247 EXPECT_EQ(maxAge, parsed->maxAge);
248 EXPECT_EQ(trigger, parsed->trigger);
249 EXPECT_STREQ(uri1, parsed->resourceType);
251 OCPayloadDestroy(cparsed);
253 // Representation Payloads
254 TEST(RepresentationEncoding, BaseAttributeTypes)
256 OC::OCRepresentation startRep;
257 startRep.setNULL("NullAttr");
258 startRep.setValue("IntAttr", 77);
259 startRep.setValue("DoubleAttr", 3.333);
260 startRep.setValue("BoolAttr", true);
261 startRep.setValue("StringAttr", std::string("String attr"));
263 uint8_t binval[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
264 0x9, 0x0, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
266 OCByteString byteString = {binval, sizeof(binval)};
267 startRep.setValue("ByteStringAttr", byteString);
269 OC::MessageContainer mc1;
270 mc1.addRepresentation(startRep);
272 OCRepPayload* cstart = mc1.getPayload();
273 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
278 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
279 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
280 cborData, cborSize));
281 OCPayloadDestroy((OCPayload*)cstart);
284 OC::MessageContainer mc2;
285 mc2.setPayload(cparsed);
286 EXPECT_EQ(1u, mc2.representations().size());
287 const OC::OCRepresentation& r = mc2.representations()[0];
289 EXPECT_TRUE(r.isNULL("NullAttr"));
290 EXPECT_EQ(77, r.getValue<int>("IntAttr"));
291 EXPECT_EQ(3.333, r.getValue<double>("DoubleAttr"));
292 EXPECT_EQ(true, r.getValue<bool>("BoolAttr"));
293 EXPECT_STREQ("String attr", r.getValue<std::string>("StringAttr").c_str());
294 const char *expectedByteString = "\\x1\\x2\\x3\\x4\\x5\\x6\\x7\\x8\\x9\\x0\\xa\\xb\\xc\\xd\\xe\\xf";
295 EXPECT_STREQ(expectedByteString, r.getValueToString("ByteStringAttr").c_str());
297 OCPayloadDestroy(cparsed);
300 TEST(RepresentationEncoding, RepAttributeEmpty)
302 OC::OCRepresentation startRep;
303 std::vector<int> iarr {};
304 std::vector<double> darr {};
305 std::vector<bool> barr {};
306 std::vector<std::string> strarr {};
307 std::vector<OC::OCRepresentation> objarr {};
308 std::vector<OCByteString> bytestrarr {{NULL, 0}};
309 startRep.setValue("StringAttr", std::string(""));
310 startRep["iarr"] = iarr;
311 startRep["darr"] = darr;
312 startRep["barr"] = barr;
313 startRep["strarr"] = strarr;
314 startRep["objarr"] = objarr;
315 startRep["bytestrarr"] = bytestrarr;
316 startRep.setValue("StringAttr2", std::string("String attr"));
318 OC::MessageContainer mc1;
319 mc1.addRepresentation(startRep);
320 OCRepPayload* cstart = mc1.getPayload();
321 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
323 uint8_t *cborData = NULL;
325 OCPayload *cparsed = NULL;
326 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
327 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
328 cborData, cborSize));
329 OCPayloadDestroy((OCPayload*)cstart);
332 OC::MessageContainer mc2;
333 mc2.setPayload(cparsed);
334 EXPECT_EQ(1u, mc2.representations().size());
335 const OC::OCRepresentation& r = mc2.representations()[0];
337 EXPECT_STREQ("", r.getValue<std::string>("StringAttr").c_str());
338 std::vector<int> iarr2 = r["iarr"];
339 EXPECT_EQ(iarr, iarr2);
340 std::vector<double> darr2 = r["darr"];
341 EXPECT_EQ(darr, darr2);
342 std::vector<bool> barr2 = r["barr"];
343 EXPECT_EQ(barr, barr2);
344 std::vector<std::string> strarr2 = r["strarr"];
345 EXPECT_EQ(strarr, strarr2);
346 std::vector<OC::OCRepresentation> objarr2 = r["objarr"];
347 EXPECT_EQ(objarr, objarr2);
348 std::vector<uint8_t> binAttr = r.getValue<std::vector<uint8_t>>("BinaryAttr");
349 EXPECT_EQ(bytestrarr[0].len, binAttr.size());
350 EXPECT_STREQ("String attr", r.getValue<std::string>("StringAttr2").c_str());
351 OIC_LOG_PAYLOAD(DEBUG, cparsed);
352 OCPayloadDestroy(cparsed);
355 TEST(RepresentationEncoding, RepAttribute)
357 OC::OCRepresentation startRep;
358 OC::OCRepresentation subRep;
359 subRep.setNULL("NullAttr");
360 subRep.setValue("IntAttr", 77);
361 subRep.setValue("DoubleAttr", 3.333);
362 subRep.setValue("BoolAttr", true);
363 subRep.setValue("StringAttr", std::string("String attr"));
364 std::vector<uint8_t> bin_data {5,3,4,5,6,0,34,2,4,5,6,3};
365 subRep.setValue("BinaryAttr", bin_data);
366 startRep.setValue("Sub", subRep);
368 OC::MessageContainer mc1;
369 mc1.addRepresentation(startRep);
371 OCRepPayload* cstart = mc1.getPayload();
372 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
376 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
378 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
379 cborData, cborSize));
380 OCPayloadDestroy((OCPayload*)cstart);
383 OC::MessageContainer mc2;
384 mc2.setPayload(cparsed);
385 EXPECT_EQ(1u, mc2.representations().size());
386 const OC::OCRepresentation& r = mc2.representations()[0];
388 OC::OCRepresentation newSubRep = r["Sub"];
390 EXPECT_TRUE(newSubRep.isNULL("NullAttr"));
391 EXPECT_EQ(77, newSubRep.getValue<int>("IntAttr"));
392 EXPECT_EQ(3.333, newSubRep.getValue<double>("DoubleAttr"));
393 EXPECT_EQ(true, newSubRep.getValue<bool>("BoolAttr"));
394 EXPECT_STREQ("String attr", newSubRep.getValue<std::string>("StringAttr").c_str());
396 newSubRep.getValue<std::vector<uint8_t>>("BinaryAttr"));
397 OCPayloadDestroy(cparsed);
400 TEST(RepresentationEncoding, OneDVectors)
403 OC::OCRepresentation startRep;
405 OC::OCRepresentation subRep1;
406 OC::OCRepresentation subRep2;
407 OC::OCRepresentation subRep3;
408 subRep1.setNULL("NullAttr");
409 subRep1.setValue("IntAttr", 77);
410 subRep2.setValue("DoubleAttr", 3.333);
411 subRep2.setValue("BoolAttr", true);
412 subRep3.setValue("StringAttr", std::string("String attr"));
414 std::vector<int> iarr {1,2,3,4,5,6,7,8,9};
415 std::vector<double> darr {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
416 std::vector<bool> barr {false, true, false, false, true, true};
417 std::vector<std::string> strarr {"item1", "item2", "item3", "item4"};
418 std::vector<OC::OCRepresentation> objarr {subRep1, subRep2, subRep3};
420 uint8_t binval1[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8};
421 OCByteString byteStringRef1 {binval1, sizeof(binval1)};
422 OCByteString byteString1 {NULL,0};
423 EXPECT_TRUE(OCByteStringCopy(&byteString1, &byteStringRef1));
424 uint8_t binval2[] = {0x9, 0x0, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF};
425 OCByteString byteStringRef2 {binval2, sizeof(binval2)};
426 OCByteString byteString2 {NULL,0};
427 EXPECT_TRUE(OCByteStringCopy(&byteString2, &byteStringRef2));
428 std::vector<OCByteString> bytestrarrRef {byteStringRef1, byteStringRef2 };
429 std::vector<OCByteString> bytestrarr {byteString1, byteString2 };
431 startRep["iarr"] = iarr;
432 startRep["darr"] = darr;
433 startRep["barr"] = barr;
434 startRep["strarr"] = strarr;
435 startRep["objarr"] = objarr;
436 startRep["bytestrarr"] = bytestrarr;
439 OC::MessageContainer mc1;
440 mc1.addRepresentation(startRep);
442 OCRepPayload* cstart = mc1.getPayload();
443 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
448 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize));
449 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
450 cborData, cborSize));
451 OCPayloadDestroy((OCPayload *)cstart);
454 OC::MessageContainer mc2;
455 mc2.setPayload(cparsed);
456 EXPECT_EQ(1u, mc2.representations().size());
457 const OC::OCRepresentation &r = mc2.representations()[0];
460 std::vector<int> iarr2 = r["iarr"];
461 std::vector<double> darr2 = r["darr"];
462 std::vector<bool> barr2 = r["barr"];
463 std::vector<std::string> strarr2 = r["strarr"];
464 std::vector<OC::OCRepresentation> objarr2 = r["objarr"];
465 std::vector<OCByteString> bytestrarr2 = r["bytestrarr"];
467 EXPECT_EQ(iarr, iarr2);
468 EXPECT_EQ(darr, darr2);
469 EXPECT_EQ(barr, barr2);
470 EXPECT_EQ(strarr, strarr2);
471 EXPECT_EQ(objarr, objarr2);
473 EXPECT_EQ(bytestrarrRef, bytestrarr2);
474 OCPayloadDestroy(cparsed);
477 TEST(RepresentationEncoding, TwoDVectors)
480 OC::OCRepresentation startRep;
482 OC::OCRepresentation subRep1;
483 OC::OCRepresentation subRep2;
484 OC::OCRepresentation subRep3;
485 subRep1.setNULL("NullAttr");
486 subRep1.setValue("IntAttr", 77);
487 subRep2.setValue("DoubleAttr", 3.333);
488 subRep2.setValue("BoolAttr", true);
489 subRep3.setValue("StringAttr", std::string("String attr"));
491 std::vector<std::vector<int>> iarr {{1,2,3},{4,5,6},{7,8,9}};
492 std::vector<std::vector<double>> darr {{1.1,2.2,3.3},{4.4,5.5,6.6},{7.7,8.8,9.9}};
493 std::vector<std::vector<bool>> barr {{false, true}, {false, false}, {true, true}};
494 std::vector<std::vector<std::string>> strarr {{"item1", "item2"}, {"item3", "item4"}};
495 std::vector<std::vector<OC::OCRepresentation>> objarr
496 {{subRep1, subRep2, subRep3}, {subRep3, subRep2, subRep1}};
498 uint8_t binval1[] = {0x1, 0x2, 0x3, 0x4};
499 OCByteString byteStringRef1 {binval1, sizeof(binval1) };
500 OCByteString byteString1 {NULL,0};
501 EXPECT_TRUE(OCByteStringCopy(&byteString1, &byteStringRef1));
502 uint8_t binval2[] = {0x5, 0x6, 0x7, 0x8};
503 OCByteString byteStringRef2 {binval2, sizeof(binval2) };
504 OCByteString byteString2 {NULL,0};
505 EXPECT_TRUE(OCByteStringCopy(&byteString2, &byteStringRef2));
506 uint8_t binval3[] = {0x9, 0x0, 0xA, 0xB};
507 OCByteString byteStringRef3 {binval3, sizeof(binval3) };
508 OCByteString byteString3 {NULL,0};
509 EXPECT_TRUE(OCByteStringCopy(&byteString3, &byteStringRef3));
510 uint8_t binval4[] = {0xC, 0xD, 0xE, 0xF};
511 OCByteString byteStringRef4 {binval4, sizeof(binval4) };
512 OCByteString byteString4 {NULL,0};
513 EXPECT_TRUE(OCByteStringCopy(&byteString4, &byteStringRef4));
514 std::vector<std::vector<OCByteString>> bytestrarrRef
516 {byteStringRef1, byteStringRef2}, {byteStringRef3, byteStringRef4}
518 std::vector<std::vector<OCByteString>> bytestrarr
520 {byteString1, byteString2}, {byteString3, byteString4}
523 startRep["iarr"] = iarr;
524 startRep["darr"] = darr;
525 startRep["barr"] = barr;
526 startRep["strarr"] = strarr;
527 startRep["objarr"] = objarr;
528 startRep["bytestrarr"] = bytestrarr;
531 OC::MessageContainer mc1;
532 mc1.addRepresentation(startRep);
534 OCRepPayload *cstart = mc1.getPayload();
535 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
540 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize));
541 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
542 cborData, cborSize));
543 OCPayloadDestroy((OCPayload *)cstart);
546 OC::MessageContainer mc2;
547 mc2.setPayload(cparsed);
548 EXPECT_EQ(1u, mc2.representations().size());
549 const OC::OCRepresentation &r = mc2.representations()[0];
552 std::vector<std::vector<int>> iarr2 = r["iarr"];
553 std::vector<std::vector<double>> darr2 = r["darr"];
554 std::vector<std::vector<bool>> barr2 = r["barr"];
555 std::vector<std::vector<std::string>> strarr2 = r["strarr"];
556 std::vector<std::vector<OC::OCRepresentation>> objarr2 = r["objarr"];
557 std::vector<std::vector<OCByteString>> bytestrarr2 = r["bytestrarr"];
559 EXPECT_EQ(iarr, iarr2);
560 EXPECT_EQ(darr, darr2);
561 EXPECT_EQ(barr, barr2);
562 EXPECT_EQ(strarr, strarr2);
563 EXPECT_EQ(objarr, objarr2);
565 EXPECT_EQ(bytestrarrRef, bytestrarr2);
567 OCPayloadDestroy(cparsed);
570 TEST(RepresentationEncoding, TwoDVectorsJagged)
573 OC::OCRepresentation startRep;
575 OC::OCRepresentation subRep1;
576 OC::OCRepresentation subRep2;
577 OC::OCRepresentation subRep3;
578 subRep1.setNULL("NullAttr");
579 subRep1.setValue("IntAttr", 77);
580 subRep2.setValue("DoubleAttr", 3.333);
581 subRep2.setValue("BoolAttr", true);
582 subRep3.setValue("StringAttr", std::string("String attr"));
584 std::vector<std::vector<int>> iarr {{1,2,3},{4,6},{7,8,9}};
585 std::vector<std::vector<double>> darr {{1.1,2.2,3.3},{4.4,5.5,6.6},{8.8,9.9}};
586 std::vector<std::vector<bool>> barr {{false, true}, {false}, {true, true}};
587 std::vector<std::vector<std::string>> strarr {{"item1"}, {"item3", "item4"}};
588 std::vector<std::vector<OC::OCRepresentation>> objarr
589 {{subRep1, subRep3}, {subRep3, subRep2, subRep1}};
591 uint8_t binval1[] = {0x1};
592 OCByteString byteStringRef1 {binval1, sizeof(binval1) };
593 OCByteString byteString1 {NULL,0};
594 EXPECT_TRUE(OCByteStringCopy(&byteString1, &byteStringRef1));
595 uint8_t binval3[] = {0x2, 0x3, 0x4};
596 OCByteString byteStringRef3 {binval3, sizeof(binval3) };
597 OCByteString byteString3 {NULL,0};
598 EXPECT_TRUE(OCByteStringCopy(&byteString3, &byteStringRef3));
599 uint8_t binval4[] = {0x5, 0x6, 0x7, 0x8};
600 OCByteString byteStringRef4 {binval4, sizeof(binval4) };
601 OCByteString byteString4 {NULL,0};
602 EXPECT_TRUE(OCByteStringCopy(&byteString4, &byteStringRef4));
604 std::vector<std::vector<OCByteString>> bytestrarrRef
606 {byteStringRef1}, {byteStringRef3, byteStringRef4}
609 std::vector<std::vector<OCByteString>> bytestrarr
611 {byteString1}, {byteString3, byteString4}
614 startRep["iarr"] = iarr;
615 startRep["darr"] = darr;
616 startRep["barr"] = barr;
617 startRep["strarr"] = strarr;
618 startRep["objarr"] = objarr;
620 startRep["bytestrarr"] = bytestrarr;
622 EXPECT_STREQ("[[\\x1 ] [\\x2\\x3\\x4 \\x5\\x6\\x7\\x8 ] ]",
623 startRep.getValueToString("bytestrarr").c_str());
625 OC::MessageContainer mc1;
626 mc1.addRepresentation(startRep);
628 OCRepPayload *cstart = mc1.getPayload();
629 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
634 OCStackResult result = OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize);
635 EXPECT_EQ(OC_STACK_OK, result);
636 result = OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
638 EXPECT_EQ(OC_STACK_OK, result);
640 OCPayloadDestroy((OCPayload *)cstart);
643 OC::MessageContainer mc2;
644 mc2.setPayload(cparsed);
645 EXPECT_EQ(1u, mc2.representations().size());
646 const OC::OCRepresentation &r = mc2.representations()[0];
649 std::vector<std::vector<int>> iarr2 = r["iarr"];
650 std::vector<std::vector<double>> darr2 = r["darr"];
651 std::vector<std::vector<bool>> barr2 = r["barr"];
652 std::vector<std::vector<std::string>> strarr2 = r["strarr"];
653 std::vector<std::vector<OC::OCRepresentation>> objarr2 = r["objarr"];
655 std::vector<std::vector<OCByteString>> bytestrarr2 = r["bytestrarr"];
657 // Note: due to the way that the CSDK works, all 2d arrays need to be rectangular.
658 // Since std::vector doesn't require this, items received on the other side end up
659 // being backfilled. This section removes the backfilling
663 strarr2[0].pop_back();
664 objarr2[0].pop_back();
665 bytestrarr2[0].pop_back();
667 EXPECT_EQ(iarr, iarr2);
668 EXPECT_EQ(darr, darr2);
669 EXPECT_EQ(barr, barr2);
670 EXPECT_EQ(strarr, strarr2);
671 EXPECT_EQ(objarr, objarr2);
672 EXPECT_EQ(bytestrarr.size(), bytestrarr2.size());
673 EXPECT_EQ(bytestrarrRef, bytestrarr2);
675 OCPayloadDestroy(cparsed);
678 TEST(RepresentationEncoding, ThreeDVectors)
681 OC::OCRepresentation startRep;
683 OC::OCRepresentation subRep1;
684 OC::OCRepresentation subRep2;
685 OC::OCRepresentation subRep3;
686 subRep1.setNULL("NullAttr");
687 subRep1.setValue("IntAttr", 77);
688 subRep2.setValue("DoubleAttr", 3.333);
689 subRep2.setValue("BoolAttr", true);
690 subRep3.setValue("StringAttr", std::string("String attr"));
692 std::vector<std::vector<std::vector<int>>> iarr
693 {{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}},{{13,14,15},{16,17,18}}};
694 std::vector<std::vector<std::vector<double>>> darr
695 {{{1.1,2.2,3.3},{4.4,5.5,6.6}},
696 {{7.7,8.7,9.7},{10.7,11.7,12.7}},
697 {{13.7,14.7,15.7},{16.7,17.7,18.7}}};
698 std::vector<std::vector<std::vector<bool>>> barr
699 {{{false, true},{true, false}},{{false, true},{true, false}}};
700 std::vector<std::vector<std::vector<std::string>>> strarr
702 {{"item1", "item2"},{"item3", "item4"}},
703 {{"item5", "item6"},{"item7", "item8"}},
704 {{"item9", "item10"},{"item11", ""}}
706 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr
708 {{subRep1, subRep2},{subRep3, subRep1}},
709 {{subRep2, subRep3},{subRep2, subRep1}},
710 {{subRep3, subRep2},{subRep1, subRep2}}
713 uint8_t binval1[] = {0x1, 0x2, 0x3, 0x4};
714 OCByteString byteStringRef1 {binval1, sizeof(binval1)};
715 OCByteString byteString1 {NULL,0};
716 EXPECT_TRUE(OCByteStringCopy(&byteString1, &byteStringRef1));
717 uint8_t binval2[] = {0x5, 0x6, 0x7, 0x8};
718 OCByteString byteStringRef2 {binval2, sizeof(binval2)};
719 OCByteString byteString2 {NULL,0};
720 EXPECT_TRUE(OCByteStringCopy(&byteString2, &byteStringRef2));
721 uint8_t binval3[] = {0x9, 0x0, 0xA, 0xB};
722 OCByteString byteStringRef3 {binval3, sizeof(binval3)};
723 OCByteString byteString3 {NULL,0};
724 EXPECT_TRUE(OCByteStringCopy(&byteString3, &byteStringRef3));
725 uint8_t binval4[] = {0xC, 0xD, 0xE, 0xF};
726 OCByteString byteStringRef4 {binval4, sizeof(binval4)};
727 OCByteString byteString4 {NULL,0};
728 EXPECT_TRUE(OCByteStringCopy(&byteString4, &byteStringRef4));
729 uint8_t binval5[] = {0x11, 0x12, 0x13, 0x14};
730 OCByteString byteStringRef5 {binval5, sizeof(binval5)};
731 OCByteString byteString5 {NULL,0};
732 EXPECT_TRUE(OCByteStringCopy(&byteString5, &byteStringRef5));
733 uint8_t binval6[] = {0x15, 0x16, 0x17, 0x18};
734 OCByteString byteStringRef6 {binval6, sizeof(binval6)};
735 OCByteString byteString6 {NULL,0};
736 EXPECT_TRUE(OCByteStringCopy(&byteString6, &byteStringRef6));
737 uint8_t binval7[] = {0x19, 0x10, 0x1A, 0x1B};
738 OCByteString byteStringRef7 {binval7, sizeof(binval7)};
739 OCByteString byteString7 {NULL,0};
740 EXPECT_TRUE(OCByteStringCopy(&byteString7, &byteStringRef7));
741 uint8_t binval8[] = {0x1C, 0x1D, 0x1E, 0x1F};
742 OCByteString byteStringRef8 {binval8, sizeof(binval8)};
743 OCByteString byteString8 {NULL,0};
744 EXPECT_TRUE(OCByteStringCopy(&byteString8, &byteStringRef8));
745 uint8_t binval9[] = {0x21, 0x22, 0x23, 0x24};
746 OCByteString byteStringRef9 {binval9, sizeof(binval9)};
747 OCByteString byteString9 {NULL,0};
748 EXPECT_TRUE(OCByteStringCopy(&byteString9, &byteStringRef9));
749 uint8_t binval10[] = {0x25, 0x26, 0x27, 0x28};
750 OCByteString byteStringRef10 {binval10, sizeof(binval10)};
751 OCByteString byteString10 {NULL,0};
752 EXPECT_TRUE(OCByteStringCopy(&byteString10, &byteStringRef10));
753 uint8_t binval11[] = {0x29, 0x20, 0x2A, 0x2B};
754 OCByteString byteStringRef11 {binval11, sizeof(binval11)};
755 OCByteString byteString11 {NULL,0};
756 EXPECT_TRUE(OCByteStringCopy(&byteString11, &byteStringRef11));
757 uint8_t binval12[] = {0xFF};
758 OCByteString byteStringRef12 {binval12, sizeof(binval12)};
759 OCByteString byteString12 {NULL,0};
760 EXPECT_TRUE(OCByteStringCopy(&byteString12, &byteStringRef12));
762 std::vector<std::vector<std::vector<OCByteString>>> bytestrarrRef
764 {{byteStringRef1, byteStringRef2}, {byteStringRef3, byteStringRef4}},
765 {{byteStringRef5, byteStringRef6}, {byteStringRef7, byteStringRef8}},
766 {{byteStringRef9, byteStringRef10}, {byteStringRef11, byteStringRef12}}
769 std::vector<std::vector<std::vector<OCByteString>>> bytestrarr
771 {{byteString1, byteString2}, {byteString3, byteString4}},
772 {{byteString5, byteString6}, {byteString7, byteString8}},
773 {{byteString9, byteString10}, {byteString11, byteString12}}
776 startRep["iarr"] = iarr;
777 startRep["darr"] = darr;
778 startRep["barr"] = barr;
779 startRep["strarr"] = strarr;
780 startRep["objarr"] = objarr;
781 startRep["bytestrarr"] = bytestrarr;
784 OC::MessageContainer mc1;
785 mc1.addRepresentation(startRep);
787 OCRepPayload *cstart = mc1.getPayload();
788 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
793 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize));
794 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
795 cborData, cborSize));
796 OCPayloadDestroy((OCPayload *)cstart);
799 OC::MessageContainer mc2;
800 mc2.setPayload(cparsed);
801 EXPECT_EQ(1u, mc2.representations().size());
802 const OC::OCRepresentation &r = mc2.representations()[0];
805 std::vector<std::vector<std::vector<int>>> iarr2 = r["iarr"];
806 std::vector<std::vector<std::vector<double>>> darr2 = r["darr"];
807 std::vector<std::vector<std::vector<bool>>> barr2 = r["barr"];
808 std::vector<std::vector<std::vector<std::string>>> strarr2 = r["strarr"];
809 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr2 = r["objarr"];
810 std::vector<std::vector<std::vector<OCByteString>>> bytestrarr2 = r["bytestrarr"];
812 EXPECT_EQ(iarr, iarr2);
813 EXPECT_EQ(darr, darr2);
814 EXPECT_EQ(barr, barr2);
815 EXPECT_EQ(strarr, strarr2);
816 EXPECT_EQ(objarr, objarr2);
817 EXPECT_EQ(bytestrarrRef, bytestrarr2);
818 OCPayloadDestroy(cparsed);
821 TEST(RepresentationEncoding, ThreeDVectorsJagged)
824 OC::OCRepresentation startRep;
826 OC::OCRepresentation subRep1;
827 OC::OCRepresentation subRep2;
828 OC::OCRepresentation subRep3;
829 subRep1.setNULL("NullAttr");
830 subRep1.setValue("IntAttr", 77);
831 subRep2.setValue("DoubleAttr", 3.333);
832 subRep2.setValue("BoolAttr", true);
833 subRep3.setValue("StringAttr", std::string("String attr"));
835 std::vector<std::vector<std::vector<int>>> iarr
839 {{13,14,15},{16,17,18}}
841 std::vector<std::vector<std::vector<double>>> darr
843 {{1.1,2.2,3.3},{4.4,5.5,6.6}},
844 {{7.7,8.7,9.7},{10.7,12.7}},
845 {{13.7,14.7,15.7},{16.7,17.7,18.7}}
847 std::vector<std::vector<std::vector<bool>>> barr
849 {{false, true},{true}},
850 {{false, true},{true, false}}
852 std::vector<std::vector<std::vector<std::string>>> strarr
854 {{"item1", "item2"},{"item3", "item4"}},
855 {{"item5", "item6"},{"item8"}},
856 {{"item9", "item10"},{"item11", ""}}
858 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr
860 {{subRep1, subRep2},{subRep3, subRep1}},
861 {{subRep2, subRep3},{subRep2}},
865 uint8_t binval1[] = {0x1, 0x2, 0x3, 0x4};
866 OCByteString byteStringRef1 {binval1, sizeof(binval1)};
867 OCByteString byteString1 {NULL,0};
868 EXPECT_TRUE(OCByteStringCopy(&byteString1, &byteStringRef1));
869 uint8_t binval2[] = {0x5, 0x6, 0x7, 0x8};
870 OCByteString byteStringRef2 {binval2, sizeof(binval2)};
871 OCByteString byteString2 {NULL,0};
872 EXPECT_TRUE(OCByteStringCopy(&byteString2, &byteStringRef2));
873 uint8_t binval3[] = {0x9, 0x0, 0xA, 0xB};
874 OCByteString byteStringRef3 {binval3, sizeof(binval3)};
875 OCByteString byteString3 {NULL,0};
876 EXPECT_TRUE(OCByteStringCopy(&byteString3, &byteStringRef3));
877 uint8_t binval4[] = {0xC, 0xD, 0xE, 0xF};
878 OCByteString byteStringRef4 {binval4, sizeof(binval4)};
879 OCByteString byteString4 {NULL,0};
880 EXPECT_TRUE(OCByteStringCopy(&byteString4, &byteStringRef4));
881 uint8_t binval5[] = {0x11, 0x12, 0x13, 0x14};
882 OCByteString byteStringRef5 {binval5, sizeof(binval5)};
883 OCByteString byteString5 {NULL,0};
884 EXPECT_TRUE(OCByteStringCopy(&byteString5, &byteStringRef5));
885 uint8_t binval6[] = {0x15, 0x16, 0x17, 0x18};
886 OCByteString byteStringRef6 {binval6, sizeof(binval6)};
887 OCByteString byteString6 {NULL,0};
888 EXPECT_TRUE(OCByteStringCopy(&byteString6, &byteStringRef6));
889 uint8_t binval8[] = {0x1C, 0x1D, 0x1E, 0x1F};
890 OCByteString byteStringRef8 {binval8, sizeof(binval8)};
891 OCByteString byteString8 {NULL,0};
892 EXPECT_TRUE(OCByteStringCopy(&byteString8, &byteStringRef8));
893 uint8_t binval9[] = {0x21, 0x22, 0x23, 0x24};
894 OCByteString byteStringRef9 {binval9, sizeof(binval9)};
895 OCByteString byteString9 {NULL,0};
896 EXPECT_TRUE(OCByteStringCopy(&byteString9, &byteStringRef9));
897 uint8_t binval10[] = {0x25, 0x26, 0x27, 0x28};
898 OCByteString byteStringRef10 {binval10, sizeof(binval10)};
899 OCByteString byteString10 {NULL,0};
900 EXPECT_TRUE(OCByteStringCopy(&byteString10, &byteStringRef10));
901 uint8_t binval11[] = {0x29, 0x20, 0x2A, 0x2B};
902 OCByteString byteStringRef11 {binval11, sizeof(binval11)};
903 OCByteString byteString11 {NULL,0};
904 EXPECT_TRUE(OCByteStringCopy(&byteString11, &byteStringRef11));
905 uint8_t binval12[] = {0xFF};
906 OCByteString byteStringRef12 {binval12, sizeof(binval12)};
907 OCByteString byteString12 {NULL,0};
908 EXPECT_TRUE(OCByteStringCopy(&byteString12, &byteStringRef12));
910 std::vector<std::vector<std::vector<OCByteString>>> bytestrarrRef
912 {{byteStringRef1, byteStringRef2}, {byteStringRef3, byteStringRef4}},
913 {{byteStringRef5, byteStringRef6}, {byteStringRef8}},
914 {{byteStringRef9, byteStringRef10}, {byteStringRef11, byteStringRef12}}
917 std::vector<std::vector<std::vector<OCByteString>>> bytestrarr
919 {{byteString1, byteString2}, {byteString3, byteString4}},
920 {{byteString5, byteString6}, {byteString8}},
921 {{byteString9, byteString10}, {byteString11, byteString12}}
924 startRep["iarr"] = iarr;
925 startRep["darr"] = darr;
926 startRep["barr"] = barr;
927 startRep["strarr"] = strarr;
928 startRep["objarr"] = objarr;
929 startRep["bytestrarr"] = bytestrarr;
932 OC::MessageContainer mc1;
933 mc1.addRepresentation(startRep);
935 OCRepPayload *cstart = mc1.getPayload();
936 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
941 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize));
942 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
943 cborData, cborSize));
944 OCPayloadDestroy((OCPayload *)cstart);
947 OC::MessageContainer mc2;
948 mc2.setPayload(cparsed);
949 EXPECT_EQ(1u, mc2.representations().size());
950 const OC::OCRepresentation &r = mc2.representations()[0];
953 std::vector<std::vector<std::vector<int>>> iarr2 = r["iarr"];
954 std::vector<std::vector<std::vector<double>>> darr2 = r["darr"];
955 std::vector<std::vector<std::vector<bool>>> barr2 = r["barr"];
956 std::vector<std::vector<std::vector<std::string>>> strarr2 = r["strarr"];
957 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr2 = r["objarr"];
958 std::vector<std::vector<std::vector<OCByteString>>> bytestrarr2 = r["bytestrarr"];
960 // Note: due to the way that the CSDK works, all 3d arrays need to be cuboidal.
961 // Since std::vector doesn't require this, items received on the other side end up
962 // being backfilled. This section removes the backfilling
963 iarr2[1][1].pop_back();
964 darr2[1][1].pop_back();
965 barr2[0][1].pop_back();
966 strarr2[1][1].pop_back();
967 objarr2[1][1].pop_back();
968 objarr2[2].pop_back();
969 bytestrarr2[1][1].pop_back();
971 EXPECT_EQ(iarr, iarr2);
972 EXPECT_EQ(darr, darr2);
973 EXPECT_EQ(barr, barr2);
974 EXPECT_EQ(strarr, strarr2);
975 EXPECT_EQ(objarr, objarr2);
976 EXPECT_EQ(bytestrarrRef, bytestrarr2);
977 OCPayloadDestroy(cparsed);
980 TEST(DiscoveryRTandIF, SingleItemNormal)
982 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
983 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
984 payload->sid = OICStrdup(sid1);
985 payload->resources = resource;
987 EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem"));
988 EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->interfaces, "if.singleitem"));
990 resource->uri = OICStrdup("/uri/thing");
996 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
997 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
998 cborData, cborSize));
1000 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1001 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1003 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1004 EXPECT_EQ(NULL, parsedResource->next);
1005 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
1006 EXPECT_EQ(NULL, parsedResource->types->next);
1007 EXPECT_EQ(NULL, parsedResource->interfaces->next);
1008 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
1011 OCPayloadDestroy(cparsed);
1012 OCDiscoveryPayloadDestroy(payload);
1015 TEST(DiscoveryRTandIF, SingleItemFrontTrim)
1017 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1018 payload->sid = OICStrdup(sid1);
1019 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1020 payload->resources = resource;
1022 EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, " rt.singleitem"));
1023 EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->interfaces, " if.singleitem"));
1024 resource->uri = OICStrdup("/uri/thing");
1030 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1031 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1032 cborData, cborSize));
1034 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1035 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1037 EXPECT_EQ(NULL, parsedResource->next);
1038 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1039 EXPECT_EQ(NULL, parsedResource->types->next);
1040 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
1041 EXPECT_EQ(NULL, parsedResource->interfaces->next);
1042 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
1045 OCPayloadDestroy(cparsed);
1046 OCDiscoveryPayloadDestroy(payload);
1049 TEST(DiscoveryRTandIF, SingleItemBackTrim)
1051 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1052 payload->sid = OICStrdup(sid1);
1053 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1054 payload->resources = resource;
1056 OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem ");
1057 OCResourcePayloadAddStringLL(&resource->interfaces, "if.singleitem ");
1058 resource->uri = OICStrdup("/uri/thing");
1064 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1065 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1066 cborData, cborSize));
1068 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1069 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1071 EXPECT_EQ(NULL, parsedResource->next);
1072 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1073 EXPECT_EQ(NULL, parsedResource->types->next);
1074 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
1075 EXPECT_EQ(NULL, parsedResource->interfaces->next);
1076 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
1079 OCPayloadDestroy(cparsed);
1080 OCDiscoveryPayloadDestroy(payload);
1082 TEST(DiscoveryRTandIF, SingleItemBothTrim)
1084 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1085 payload->sid = OICStrdup(sid1);
1086 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1087 payload->resources = resource;
1089 OCResourcePayloadAddStringLL(&resource->types, " rt.singleitem ");
1090 OCResourcePayloadAddStringLL(&resource->interfaces, " if.singleitem ");
1091 resource->uri = OICStrdup("/uri/thing");
1097 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1098 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1099 cborData, cborSize));
1101 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1102 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1104 EXPECT_EQ(NULL, parsedResource->next);
1105 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1106 EXPECT_EQ(NULL, parsedResource->types->next);
1107 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
1108 EXPECT_EQ(NULL, parsedResource->interfaces->next);
1109 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
1112 OCPayloadDestroy(cparsed);
1113 OCDiscoveryPayloadDestroy(payload);
1115 TEST(DiscoveryRTandIF, MultiItemsNormal)
1117 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1118 payload->sid = OICStrdup(sid1);
1119 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1120 payload->resources = resource;
1122 OCResourcePayloadAddStringLL(&resource->types, "rt.firstitem");
1123 OCResourcePayloadAddStringLL(&resource->types, "rt.seconditem");
1124 OCResourcePayloadAddStringLL(&resource->interfaces, "if.firstitem");
1125 OCResourcePayloadAddStringLL(&resource->interfaces, "if.seconditem");
1126 resource->uri = OICStrdup("/uri/thing");
1132 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1133 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1134 cborData, cborSize));
1136 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1137 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1139 EXPECT_EQ(NULL, parsedResource->next);
1140 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1141 EXPECT_EQ(NULL, parsedResource->types->next->next);
1142 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
1143 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
1144 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
1145 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
1146 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
1149 OCPayloadDestroy(cparsed);
1150 OCDiscoveryPayloadDestroy(payload);
1152 TEST(DiscoveryRTandIF, MultiItemExtraLeadSpaces)
1154 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1155 payload->sid = OICStrdup(sid1);
1156 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1157 payload->resources = resource;
1159 OCResourcePayloadAddStringLL(&resource->types, " rt.firstitem");
1160 OCResourcePayloadAddStringLL(&resource->types, " rt.seconditem");
1161 OCResourcePayloadAddStringLL(&resource->interfaces, " if.firstitem");
1162 OCResourcePayloadAddStringLL(&resource->interfaces, " if.seconditem");
1163 resource->uri = OICStrdup("/uri/thing");
1169 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1170 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1171 cborData, cborSize));
1173 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1174 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1176 EXPECT_EQ(NULL, parsedResource->next);
1177 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1178 EXPECT_EQ(NULL, parsedResource->types->next->next);
1179 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
1180 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
1181 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
1182 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
1183 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
1186 OCPayloadDestroy(cparsed);
1187 OCDiscoveryPayloadDestroy(payload);
1189 TEST(DiscoveryRTandIF, MultiItemExtraTrailSpaces)
1191 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1192 payload->sid = OICStrdup(sid1);
1193 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1194 payload->resources = resource;
1196 OCResourcePayloadAddStringLL(&resource->types, "rt.firstitem ");
1197 OCResourcePayloadAddStringLL(&resource->types, "rt.seconditem ");
1198 OCResourcePayloadAddStringLL(&resource->interfaces, "if.firstitem ");
1199 OCResourcePayloadAddStringLL(&resource->interfaces, "if.seconditem ");
1200 resource->uri = OICStrdup("/uri/thing");
1206 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1207 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1208 cborData, cborSize));
1210 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1211 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1213 EXPECT_EQ(NULL, parsedResource->next);
1214 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1215 EXPECT_EQ(NULL, parsedResource->types->next->next);
1216 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
1217 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
1218 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
1219 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
1220 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
1223 OCPayloadDestroy(cparsed);
1224 OCDiscoveryPayloadDestroy(payload);
1226 TEST(DiscoveryRTandIF, MultiItemBothSpaces)
1228 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1229 payload->sid = OICStrdup(sid1);
1230 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1231 payload->resources = resource;
1233 OCResourcePayloadAddStringLL(&resource->types, " rt.firstitem ");
1234 OCResourcePayloadAddStringLL(&resource->types, " rt.seconditem ");
1235 OCResourcePayloadAddStringLL(&resource->interfaces, " if.firstitem ");
1236 OCResourcePayloadAddStringLL(&resource->interfaces, " if.seconditem ");
1237 resource->uri = OICStrdup("/uri/thing");
1243 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1244 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
1245 cborData, cborSize));
1247 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1248 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1250 EXPECT_EQ(NULL, parsedResource->next);
1251 EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
1252 EXPECT_EQ(NULL, parsedResource->types->next->next);
1253 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
1254 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
1255 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
1256 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
1257 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
1260 OCPayloadDestroy(cparsed);
1261 OCDiscoveryPayloadDestroy(payload);
1263 TEST(RepresentationEncodingRTandIF, SingleItemNormal)
1265 OCRepPayload* payload = OCRepPayloadCreate();
1266 OCRepPayloadAddResourceType(payload, "rt.firstitem");
1267 OCRepPayloadAddInterface(payload, "if.firstitem");
1273 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1274 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1275 cborData, cborSize));
1277 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1279 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1280 EXPECT_EQ(NULL, parsedPayload->types->next);
1281 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1282 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
1285 OCRepPayloadDestroy(payload);
1286 OCPayloadDestroy(cparsed);
1288 TEST(RepresentationEncodingRTandIF, SingleItemFrontTrim)
1290 OCRepPayload* payload = OCRepPayloadCreate();
1291 OCRepPayloadAddResourceType(payload, " rt.firstitem");
1292 OCRepPayloadAddInterface(payload, " if.firstitem");
1298 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1299 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1300 cborData, cborSize));
1302 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1304 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1305 EXPECT_EQ(NULL, parsedPayload->types->next);
1306 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1307 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
1311 OCRepPayloadDestroy(payload);
1312 OCPayloadDestroy(cparsed);
1314 TEST(RepresentationEncodingRTandIF, SingleItemBackTrim)
1316 OCRepPayload* payload = OCRepPayloadCreate();
1317 OCRepPayloadAddResourceType(payload, "rt.firstitem ");
1318 OCRepPayloadAddInterface(payload, "if.firstitem ");
1324 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1325 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1326 cborData, cborSize));
1328 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1330 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1331 EXPECT_EQ(NULL, parsedPayload->types->next);
1332 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1333 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
1337 OCRepPayloadDestroy(payload);
1338 OCPayloadDestroy(cparsed);
1340 TEST(RepresentationEncodingRTandIF, SingleItemBothTrim)
1342 OCRepPayload* payload = OCRepPayloadCreate();
1343 OCRepPayloadAddResourceType(payload, " rt.firstitem ");
1344 OCRepPayloadAddInterface(payload, " if.firstitem ");
1350 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1351 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1352 cborData, cborSize));
1354 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1356 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1357 EXPECT_EQ(NULL, parsedPayload->types->next);
1358 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1359 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
1363 OCRepPayloadDestroy(payload);
1364 OCPayloadDestroy(cparsed);
1366 TEST(RepresentationEncodingRTandIF, MultiItemsNormal)
1368 OCRepPayload* payload = OCRepPayloadCreate();
1369 OCRepPayloadAddResourceType(payload, "rt.firstitem");
1370 OCRepPayloadAddResourceType(payload, "rt.seconditem");
1371 OCRepPayloadAddInterface(payload, "if.firstitem");
1372 OCRepPayloadAddInterface(payload, "if.seconditem");
1378 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1379 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1380 cborData, cborSize));
1382 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1384 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1385 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1386 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1387 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1388 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1389 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1393 OCRepPayloadDestroy(payload);
1394 OCPayloadDestroy(cparsed);
1396 TEST(RepresentationEncodingRTandIF, MultiItemExtraLeadSpaces)
1398 OCRepPayload* payload = OCRepPayloadCreate();
1399 OCRepPayloadAddResourceType(payload, " rt.firstitem");
1400 OCRepPayloadAddResourceType(payload, " rt.seconditem");
1401 OCRepPayloadAddInterface(payload, " if.firstitem");
1402 OCRepPayloadAddInterface(payload, " if.seconditem");
1408 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1409 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1410 cborData, cborSize));
1412 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1414 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1415 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1416 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1417 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1418 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1419 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1423 OCRepPayloadDestroy(payload);
1424 OCPayloadDestroy(cparsed);
1426 TEST(RepresentationEncodingRTandIF, MultiItemExtraTrailSpaces)
1428 OCRepPayload* payload = OCRepPayloadCreate();
1429 OCRepPayloadAddResourceType(payload, "rt.firstitem ");
1430 OCRepPayloadAddResourceType(payload, "rt.seconditem ");
1431 OCRepPayloadAddInterface(payload, "if.firstitem ");
1432 OCRepPayloadAddInterface(payload, "if.seconditem ");
1438 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1439 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1440 cborData, cborSize));
1442 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1444 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1445 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1446 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1447 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1448 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1449 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1453 OCRepPayloadDestroy(payload);
1454 OCPayloadDestroy(cparsed);
1456 TEST(RepresentationEncodingRTandIF, MultiItemExtraMiddleSpaces)
1458 OCRepPayload* payload = OCRepPayloadCreate();
1459 OCRepPayloadAddResourceType(payload, " rt.firstitem ");
1460 OCRepPayloadAddResourceType(payload, " rt.seconditem ");
1461 OCRepPayloadAddInterface(payload, " if.firstitem ");
1462 OCRepPayloadAddInterface(payload, " if.seconditem ");
1468 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1469 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1470 cborData, cborSize));
1472 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1474 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1475 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1476 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1477 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1478 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1479 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1483 OCRepPayloadDestroy(payload);
1484 OCPayloadDestroy(cparsed);
1486 TEST(RepresentationEncodingRTandIF, TestPayloadContents)
1488 OC::OCRepresentation subRep1;
1489 std::vector<std::string> types;
1490 types.push_back("rt.firstitem");
1491 std::vector<std::string> interfaces;
1492 interfaces.push_back("if.firstitem");
1493 subRep1.setResourceTypes(types);
1494 subRep1.setResourceInterfaces(interfaces);
1495 subRep1.setNULL("NullAttr");
1496 subRep1.setValue("IntAttr", 77);
1497 subRep1.setValue("DoubleAttr", 3.333);
1498 subRep1.setValue("BoolAttr", true);
1499 subRep1.setValue("StringAttr", std::string("String attr"));
1501 OC::MessageContainer mc1;
1502 mc1.addRepresentation(subRep1);
1504 OCRepPayload *repPayload = mc1.getPayload();
1505 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, repPayload->base.type);
1507 uint8_t *cborData = NULL;
1508 size_t cborSize = 0;
1509 OCPayload *cparsed = NULL;
1511 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)repPayload, &cborData, &cborSize));
1512 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1513 cborData, cborSize));
1515 OCRepPayload *parsedPayload = (OCRepPayload *)cparsed;
1516 EXPECT_EQ(NULL, parsedPayload->uri);
1517 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1518 EXPECT_EQ(NULL, parsedPayload->types->next);
1519 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1520 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
1522 // To make sure rt and if are not duplicated.
1523 EXPECT_STREQ("BoolAttr", parsedPayload->values->name);
1524 EXPECT_EQ(true, parsedPayload->values->b);
1525 EXPECT_EQ(OCREP_PROP_BOOL, parsedPayload->values->type);
1526 parsedPayload->values = parsedPayload->values->next;
1528 EXPECT_STREQ("DoubleAttr", parsedPayload->values->name);
1529 EXPECT_EQ(OCREP_PROP_DOUBLE, parsedPayload->values->type);
1530 EXPECT_EQ(3.3330000000000002, parsedPayload->values->d);
1531 parsedPayload->values = parsedPayload->values->next;
1533 EXPECT_STREQ("IntAttr", parsedPayload->values->name);
1534 EXPECT_EQ(77, parsedPayload->values->i);
1535 EXPECT_EQ(OCREP_PROP_INT, parsedPayload->values->type);
1536 parsedPayload->values = parsedPayload->values->next;
1538 EXPECT_STREQ("NullAttr", parsedPayload->values->name);
1539 EXPECT_EQ(OCREP_PROP_NULL, parsedPayload->values->type);
1540 parsedPayload->values = parsedPayload->values->next;
1542 EXPECT_STREQ("StringAttr", parsedPayload->values->name);
1543 EXPECT_STREQ("String attr", parsedPayload->values->str);
1544 EXPECT_EQ(OCREP_PROP_STRING, parsedPayload->values->type);
1545 parsedPayload->values = parsedPayload->values->next;
1547 EXPECT_EQ(NULL, parsedPayload->values);
1550 OCRepPayloadDestroy(repPayload);
1551 OCPayloadDestroy(cparsed);