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>
25 #include <ocpayload.h>
26 #include <ocpayloadcbor.h>
27 #include <oic_malloc.h>
28 #include <oic_string.h>
32 bool operator==(const OC::NullType&, const OC::NullType&)
37 bool operator==(const OC::OCRepresentation& lhs, const OC::OCRepresentation& rhs)
39 return lhs.getUri() == rhs.getUri() &&
40 lhs.getChildren() == rhs.getChildren() &&
41 lhs.getResourceInterfaces() == rhs.getResourceInterfaces() &&
42 lhs.getResourceTypes() == rhs.getResourceTypes() &&
43 lhs.m_values == rhs.m_values;
46 // these tests validate the OCRepresentation->OCPayload, OCPayload->CBOR,
47 // CBOR->OCPayload and OCPayload->OCRepresentation conversions
48 namespace OCRepresentationEncodingTest
50 static const uint8_t sid1[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
51 static const char devicename1[] = "device name";
52 static const char specver1[] = "spec version";
53 static const char dmver1[] = "data model version";
55 TEST(DeviceDiscoveryEncoding, Normal)
57 OCDevicePayload* device = OCDevicePayloadCreate(
63 EXPECT_STREQ(devicename1, device->deviceName);
64 EXPECT_STREQ(specver1, device->specVersion);
65 EXPECT_STREQ(dmver1, device->dataModelVersion);
66 EXPECT_EQ(PAYLOAD_TYPE_DEVICE, ((OCPayload*)device)->type);
68 for (uint8_t i = 1; i <= sizeof(sid1); ++i)
70 EXPECT_EQ(i, sid1[i - 1]);
75 OCPayload* parsedDevice;
76 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)device, &cborData, &cborSize));
77 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedDevice, PAYLOAD_TYPE_DEVICE,
81 EXPECT_STREQ(device->deviceName, ((OCDevicePayload*)parsedDevice)->deviceName);
82 EXPECT_STREQ(device->specVersion, ((OCDevicePayload*)parsedDevice)->specVersion);
83 EXPECT_STREQ(device->dataModelVersion, ((OCDevicePayload*)parsedDevice)->dataModelVersion);
84 EXPECT_EQ(device->base.type, ((OCDevicePayload*)parsedDevice)->base.type);
86 OCPayloadDestroy((OCPayload*)device);
88 OC::MessageContainer mc;
89 mc.setPayload(parsedDevice);
90 EXPECT_EQ(1u, mc.representations().size());
91 const OC::OCRepresentation& r = mc.representations()[0];
92 EXPECT_STREQ(devicename1, r.getValue<std::string>(OC_RSRVD_DEVICE_NAME).c_str());
93 EXPECT_STREQ(specver1, r.getValue<std::string>(OC_RSRVD_SPEC_VERSION).c_str());
94 EXPECT_STREQ(dmver1, r.getValue<std::string>(OC_RSRVD_DATA_MODEL_VERSION).c_str());
96 OCPayloadDestroy(parsedDevice);
99 static const char uri1[] = "/testuri";
100 static char pfid1[] = "pfid";
101 static char mfgnm1[] = "mfgnm";
102 static char mfgurl1[] = "mfgurl";
103 static char modelnum1[] = "modelnum";
104 static char dom1[] = "dom";
105 static char pfver1[] = "pfver";
106 static char osver1[] = "osver";
107 static char hwver1[] = "hwver";
108 static char fwver1[] = "fwver";
109 static char url1[] = "url";
110 static char time1[] = "time";
113 TEST(PlatformDiscoveryEncoding, Normal)
115 OCPlatformInfo info {pfid1, mfgnm1, mfgurl1, modelnum1, dom1, pfver1, osver1, hwver1,
116 fwver1, url1, time1};
117 OCPlatformPayload* platform = OCPlatformPayloadCreate(&info);
118 EXPECT_EQ(PAYLOAD_TYPE_PLATFORM, ((OCPayload*)platform)->type);
119 EXPECT_STREQ(pfid1, platform->info.platformID);
120 EXPECT_STREQ(mfgnm1, platform->info.manufacturerName);
121 EXPECT_STREQ(mfgurl1, platform->info.manufacturerUrl);
122 EXPECT_STREQ(modelnum1, platform->info.modelNumber);
123 EXPECT_STREQ(dom1, platform->info.dateOfManufacture);
124 EXPECT_STREQ(pfver1, platform->info.platformVersion);
125 EXPECT_STREQ(osver1, platform->info.operatingSystemVersion);
126 EXPECT_STREQ(hwver1, platform->info.hardwareVersion);
127 EXPECT_STREQ(fwver1, platform->info.firmwareVersion);
128 EXPECT_STREQ(url1, platform->info.supportUrl);
129 EXPECT_STREQ(time1, platform->info.systemTime);
133 OCPayload* parsedPlatform;
134 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)platform, &cborData, &cborSize));
135 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&parsedPlatform, PAYLOAD_TYPE_PLATFORM,
136 cborData, cborSize));
139 EXPECT_EQ(platform->base.type, ((OCPlatformPayload*)parsedPlatform)->base.type);
140 OCPlatformPayload* platform2 = (OCPlatformPayload*)parsedPlatform;
141 EXPECT_STREQ(platform->info.platformID, platform2->info.platformID);
142 EXPECT_STREQ(platform->info.manufacturerName, platform->info.manufacturerName);
143 EXPECT_STREQ(platform->info.manufacturerUrl, platform->info.manufacturerUrl);
144 EXPECT_STREQ(platform->info.modelNumber, platform->info.modelNumber);
145 EXPECT_STREQ(platform->info.dateOfManufacture, platform->info.dateOfManufacture);
146 EXPECT_STREQ(platform->info.platformVersion, platform->info.platformVersion);
147 EXPECT_STREQ(platform->info.operatingSystemVersion, platform->info.operatingSystemVersion);
148 EXPECT_STREQ(platform->info.hardwareVersion, platform->info.hardwareVersion);
149 EXPECT_STREQ(platform->info.firmwareVersion, platform->info.firmwareVersion);
150 EXPECT_STREQ(platform->info.supportUrl, platform->info.supportUrl);
151 EXPECT_STREQ(platform->info.systemTime, platform2->info.systemTime);
153 OCPayloadDestroy((OCPayload*)platform);
155 OC::MessageContainer mc;
156 mc.setPayload(parsedPlatform);
157 EXPECT_EQ(1u, mc.representations().size());
158 const OC::OCRepresentation& r = mc.representations()[0];
159 EXPECT_STREQ(pfid1, r.getValue<std::string>(OC_RSRVD_PLATFORM_ID).c_str());
160 EXPECT_STREQ(mfgnm1, r.getValue<std::string>(OC_RSRVD_MFG_NAME).c_str());
161 EXPECT_STREQ(mfgurl1, r.getValue<std::string>(OC_RSRVD_MFG_URL).c_str());
162 EXPECT_STREQ(modelnum1, r.getValue<std::string>(OC_RSRVD_MODEL_NUM).c_str());
163 EXPECT_STREQ(dom1, r.getValue<std::string>(OC_RSRVD_MFG_DATE).c_str());
164 EXPECT_STREQ(pfver1, r.getValue<std::string>(OC_RSRVD_PLATFORM_VERSION).c_str());
165 EXPECT_STREQ(osver1, r.getValue<std::string>(OC_RSRVD_OS_VERSION).c_str());
166 EXPECT_STREQ(hwver1, r.getValue<std::string>(OC_RSRVD_HARDWARE_VERSION).c_str());
167 EXPECT_STREQ(fwver1, r.getValue<std::string>(OC_RSRVD_FIRMWARE_VERSION).c_str());
168 EXPECT_STREQ(url1, r.getValue<std::string>(OC_RSRVD_SUPPORT_URL).c_str());
169 EXPECT_STREQ(time1, r.getValue<std::string>(OC_RSRVD_SYSTEM_TIME).c_str());
171 OCPayloadDestroy(parsedPlatform);
174 // Representation Payloads
175 TEST(RepresentationEncoding, BaseAttributeTypes)
177 OC::OCRepresentation startRep;
178 startRep.setNULL("NullAttr");
179 startRep.setValue("IntAttr", 77);
180 startRep.setValue("DoubleAttr", 3.333);
181 startRep.setValue("BoolAttr", true);
182 startRep.setValue("StringAttr", std::string("String attr"));
183 OC::MessageContainer mc1;
184 mc1.addRepresentation(startRep);
186 OCRepPayload* cstart = mc1.getPayload();
187 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
192 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
193 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
194 cborData, cborSize));
195 OCPayloadDestroy((OCPayload*)cstart);
198 OC::MessageContainer mc2;
199 mc2.setPayload(cparsed);
200 EXPECT_EQ(1u, mc2.representations().size());
201 const OC::OCRepresentation& r = mc2.representations()[0];
203 EXPECT_TRUE(r.isNULL("NullAttr"));
204 EXPECT_EQ(77, r.getValue<int>("IntAttr"));
205 EXPECT_EQ(3.333, r.getValue<double>("DoubleAttr"));
206 EXPECT_EQ(true, r.getValue<bool>("BoolAttr"));
207 EXPECT_STREQ("String attr", r.getValue<std::string>("StringAttr").c_str());
209 OCPayloadDestroy(cparsed);
212 TEST(RepresentationEncoding, RepAttribute)
214 OC::OCRepresentation startRep;
215 OC::OCRepresentation subRep;
216 subRep.setNULL("NullAttr");
217 subRep.setValue("IntAttr", 77);
218 subRep.setValue("DoubleAttr", 3.333);
219 subRep.setValue("BoolAttr", true);
220 subRep.setValue("StringAttr", std::string("String attr"));
221 startRep.setValue("Sub", subRep);
223 OC::MessageContainer mc1;
224 mc1.addRepresentation(startRep);
226 OCRepPayload* cstart = mc1.getPayload();
227 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
232 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
233 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
234 cborData, cborSize));
235 OCPayloadDestroy((OCPayload*)cstart);
238 OC::MessageContainer mc2;
239 mc2.setPayload(cparsed);
240 EXPECT_EQ(1u, mc2.representations().size());
241 const OC::OCRepresentation& r = mc2.representations()[0];
243 OC::OCRepresentation newSubRep = r["Sub"];
245 EXPECT_TRUE(newSubRep.isNULL("NullAttr"));
246 EXPECT_EQ(77, newSubRep.getValue<int>("IntAttr"));
247 EXPECT_EQ(3.333, newSubRep.getValue<double>("DoubleAttr"));
248 EXPECT_EQ(true, newSubRep.getValue<bool>("BoolAttr"));
249 EXPECT_STREQ("String attr", newSubRep.getValue<std::string>("StringAttr").c_str());
250 OCPayloadDestroy(cparsed);
253 TEST(RepresentationEncoding, OneDVectors)
256 OC::OCRepresentation startRep;
258 OC::OCRepresentation subRep1;
259 OC::OCRepresentation subRep2;
260 OC::OCRepresentation subRep3;
261 subRep1.setNULL("NullAttr");
262 subRep1.setValue("IntAttr", 77);
263 subRep2.setValue("DoubleAttr", 3.333);
264 subRep2.setValue("BoolAttr", true);
265 subRep3.setValue("StringAttr", std::string("String attr"));
267 std::vector<int> iarr {1,2,3,4,5,6,7,8,9};
268 std::vector<double> darr {1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9};
269 std::vector<bool> barr {false, true, false, false, true, true};
270 std::vector<std::string> strarr {"item1", "item2", "item3", "item4"};
271 std::vector<OC::OCRepresentation> objarr {subRep1, subRep2, subRep3};
273 startRep["iarr"] = iarr;
274 startRep["darr"] = darr;
275 startRep["barr"] = barr;
276 startRep["strarr"] = strarr;
277 startRep["objarr"] = objarr;
280 OC::MessageContainer mc1;
281 mc1.addRepresentation(startRep);
283 OCRepPayload* cstart = mc1.getPayload();
284 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
289 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
290 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
291 cborData, cborSize));
292 OCPayloadDestroy((OCPayload*)cstart);
295 OC::MessageContainer mc2;
296 mc2.setPayload(cparsed);
297 EXPECT_EQ(1u, mc2.representations().size());
298 const OC::OCRepresentation& r = mc2.representations()[0];
301 std::vector<int> iarr2 = r["iarr"];
302 std::vector<double> darr2 = r["darr"];
303 std::vector<bool> barr2 = r["barr"];
304 std::vector<std::string> strarr2 = r["strarr"];
305 std::vector<OC::OCRepresentation> objarr2 = r["objarr"];
307 EXPECT_EQ(iarr, iarr2);
308 EXPECT_EQ(darr, darr2);
309 EXPECT_EQ(barr, barr2);
310 EXPECT_EQ(strarr, strarr2);
311 EXPECT_EQ(objarr, objarr2);
312 OCPayloadDestroy(cparsed);
315 TEST(RepresentationEncoding, TwoDVectors)
318 OC::OCRepresentation startRep;
320 OC::OCRepresentation subRep1;
321 OC::OCRepresentation subRep2;
322 OC::OCRepresentation subRep3;
323 subRep1.setNULL("NullAttr");
324 subRep1.setValue("IntAttr", 77);
325 subRep2.setValue("DoubleAttr", 3.333);
326 subRep2.setValue("BoolAttr", true);
327 subRep3.setValue("StringAttr", std::string("String attr"));
329 std::vector<std::vector<int>> iarr {{1,2,3},{4,5,6},{7,8,9}};
330 std::vector<std::vector<double>> darr {{1.1,2.2,3.3},{4.4,5.5,6.6},{7.7,8.8,9.9}};
331 std::vector<std::vector<bool>> barr {{false, true}, {false, false}, {true, true}};
332 std::vector<std::vector<std::string>> strarr {{"item1", "item2"}, {"item3", "item4"}};
333 std::vector<std::vector<OC::OCRepresentation>> objarr
334 {{subRep1, subRep2, subRep3}, {subRep3, subRep2, subRep1}};
336 startRep["iarr"] = iarr;
337 startRep["darr"] = darr;
338 startRep["barr"] = barr;
339 startRep["strarr"] = strarr;
340 startRep["objarr"] = objarr;
343 OC::MessageContainer mc1;
344 mc1.addRepresentation(startRep);
346 OCRepPayload* cstart = mc1.getPayload();
347 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
352 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
353 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
354 cborData, cborSize));
355 OCPayloadDestroy((OCPayload*)cstart);
358 OC::MessageContainer mc2;
359 mc2.setPayload(cparsed);
360 EXPECT_EQ(1u, mc2.representations().size());
361 const OC::OCRepresentation& r = mc2.representations()[0];
364 std::vector<std::vector<int>> iarr2 = r["iarr"];
365 std::vector<std::vector<double>> darr2 = r["darr"];
366 std::vector<std::vector<bool>> barr2 = r["barr"];
367 std::vector<std::vector<std::string>> strarr2 = r["strarr"];
368 std::vector<std::vector<OC::OCRepresentation>> objarr2 = r["objarr"];
370 EXPECT_EQ(iarr, iarr2);
371 EXPECT_EQ(darr, darr2);
372 EXPECT_EQ(barr, barr2);
373 EXPECT_EQ(strarr, strarr2);
374 EXPECT_EQ(objarr, objarr2);
375 OCPayloadDestroy(cparsed);
378 TEST(RepresentationEncoding, TwoDVectorsJagged)
381 OC::OCRepresentation startRep;
383 OC::OCRepresentation subRep1;
384 OC::OCRepresentation subRep2;
385 OC::OCRepresentation subRep3;
386 subRep1.setNULL("NullAttr");
387 subRep1.setValue("IntAttr", 77);
388 subRep2.setValue("DoubleAttr", 3.333);
389 subRep2.setValue("BoolAttr", true);
390 subRep3.setValue("StringAttr", std::string("String attr"));
392 std::vector<std::vector<int>> iarr {{1,2,3},{4,6},{7,8,9}};
393 std::vector<std::vector<double>> darr {{1.1,2.2,3.3},{4.4,5.5,6.6},{8.8,9.9}};
394 std::vector<std::vector<bool>> barr {{false, true}, {false}, {true, true}};
395 std::vector<std::vector<std::string>> strarr {{"item1"}, {"item3", "item4"}};
396 std::vector<std::vector<OC::OCRepresentation>> objarr
397 {{subRep1, subRep3}, {subRep3, subRep2, subRep1}};
399 startRep["iarr"] = iarr;
400 startRep["darr"] = darr;
401 startRep["barr"] = barr;
402 startRep["strarr"] = strarr;
403 startRep["objarr"] = objarr;
406 OC::MessageContainer mc1;
407 mc1.addRepresentation(startRep);
409 OCRepPayload* cstart = mc1.getPayload();
410 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
415 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
416 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
417 cborData, cborSize));
418 OCPayloadDestroy((OCPayload*)cstart);
421 OC::MessageContainer mc2;
422 mc2.setPayload(cparsed);
423 EXPECT_EQ(1u, mc2.representations().size());
424 const OC::OCRepresentation& r = mc2.representations()[0];
427 std::vector<std::vector<int>> iarr2 = r["iarr"];
428 std::vector<std::vector<double>> darr2 = r["darr"];
429 std::vector<std::vector<bool>> barr2 = r["barr"];
430 std::vector<std::vector<std::string>> strarr2 = r["strarr"];
431 std::vector<std::vector<OC::OCRepresentation>> objarr2 = r["objarr"];
433 // Note: due to the way that the CSDK works, all 2d arrays need to be rectangular.
434 // Since std::vector doesn't require this, items received on the other side end up
435 // being backfilled. This section removes the backfilling
439 strarr2[0].pop_back();
440 objarr2[0].pop_back();
442 EXPECT_EQ(iarr, iarr2);
443 EXPECT_EQ(darr, darr2);
444 EXPECT_EQ(barr, barr2);
445 EXPECT_EQ(strarr, strarr2);
446 EXPECT_EQ(objarr, objarr2);
447 OCPayloadDestroy(cparsed);
450 TEST(RepresentationEncoding, ThreeDVectors)
453 OC::OCRepresentation startRep;
455 OC::OCRepresentation subRep1;
456 OC::OCRepresentation subRep2;
457 OC::OCRepresentation subRep3;
458 subRep1.setNULL("NullAttr");
459 subRep1.setValue("IntAttr", 77);
460 subRep2.setValue("DoubleAttr", 3.333);
461 subRep2.setValue("BoolAttr", true);
462 subRep3.setValue("StringAttr", std::string("String attr"));
464 std::vector<std::vector<std::vector<int>>> iarr
465 {{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}},{{13,14,15},{16,17,18}}};
466 std::vector<std::vector<std::vector<double>>> darr
467 {{{1.1,2.2,3.3},{4.4,5.5,6.6}},
468 {{7.7,8.7,9.7},{10.7,11.7,12.7}},
469 {{13.7,14.7,15.7},{16.7,17.7,18.7}}};
470 std::vector<std::vector<std::vector<bool>>> barr
471 {{{false, true},{true, false}},{{false, true},{true, false}}};
472 std::vector<std::vector<std::vector<std::string>>> strarr
474 {{"item1", "item2"},{"item3", "item4"}},
475 {{"item5", "item6"},{"item7", "item8"}},
476 {{"item9", "item10"},{"item11", ""}}
478 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr
480 {{subRep1, subRep2},{subRep3, subRep1}},
481 {{subRep2, subRep3},{subRep2, subRep1}},
482 {{subRep3, subRep2},{subRep1, subRep2}}
485 startRep["iarr"] = iarr;
486 startRep["darr"] = darr;
487 startRep["barr"] = barr;
488 startRep["strarr"] = strarr;
489 startRep["objarr"] = objarr;
492 OC::MessageContainer mc1;
493 mc1.addRepresentation(startRep);
495 OCRepPayload* cstart = mc1.getPayload();
496 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
501 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
502 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
503 cborData, cborSize));
504 OCPayloadDestroy((OCPayload*)cstart);
507 OC::MessageContainer mc2;
508 mc2.setPayload(cparsed);
509 EXPECT_EQ(1u, mc2.representations().size());
510 const OC::OCRepresentation& r = mc2.representations()[0];
513 std::vector<std::vector<std::vector<int>>> iarr2 = r["iarr"];
514 std::vector<std::vector<std::vector<double>>> darr2 = r["darr"];
515 std::vector<std::vector<std::vector<bool>>> barr2 = r["barr"];
516 std::vector<std::vector<std::vector<std::string>>> strarr2 = r["strarr"];
517 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr2 = r["objarr"];
519 EXPECT_EQ(iarr, iarr2);
520 EXPECT_EQ(darr, darr2);
521 EXPECT_EQ(barr, barr2);
522 EXPECT_EQ(strarr, strarr2);
523 EXPECT_EQ(objarr, objarr2);
524 OCPayloadDestroy(cparsed);
527 TEST(RepresentationEncoding, ThreeDVectorsJagged)
530 OC::OCRepresentation startRep;
532 OC::OCRepresentation subRep1;
533 OC::OCRepresentation subRep2;
534 OC::OCRepresentation subRep3;
535 subRep1.setNULL("NullAttr");
536 subRep1.setValue("IntAttr", 77);
537 subRep2.setValue("DoubleAttr", 3.333);
538 subRep2.setValue("BoolAttr", true);
539 subRep3.setValue("StringAttr", std::string("String attr"));
541 std::vector<std::vector<std::vector<int>>> iarr
545 {{13,14,15},{16,17,18}}
547 std::vector<std::vector<std::vector<double>>> darr
549 {{1.1,2.2,3.3},{4.4,5.5,6.6}},
550 {{7.7,8.7,9.7},{10.7,12.7}},
551 {{13.7,14.7,15.7},{16.7,17.7,18.7}}
553 std::vector<std::vector<std::vector<bool>>> barr
555 {{false, true},{true}},
556 {{false, true},{true, false}}
558 std::vector<std::vector<std::vector<std::string>>> strarr
560 {{"item1", "item2"},{"item3", "item4"}},
561 {{"item5", "item6"},{"item8"}},
562 {{"item9", "item10"},{"item11", ""}}
564 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr
566 {{subRep1, subRep2},{subRep3, subRep1}},
567 {{subRep2, subRep3},{subRep2}},
571 startRep["iarr"] = iarr;
572 startRep["darr"] = darr;
573 startRep["barr"] = barr;
574 startRep["strarr"] = strarr;
575 startRep["objarr"] = objarr;
578 OC::MessageContainer mc1;
579 mc1.addRepresentation(startRep);
581 OCRepPayload* cstart = mc1.getPayload();
582 EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
587 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
588 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
589 cborData, cborSize));
590 OCPayloadDestroy((OCPayload*)cstart);
593 OC::MessageContainer mc2;
594 mc2.setPayload(cparsed);
595 EXPECT_EQ(1u, mc2.representations().size());
596 const OC::OCRepresentation& r = mc2.representations()[0];
599 std::vector<std::vector<std::vector<int>>> iarr2 = r["iarr"];
600 std::vector<std::vector<std::vector<double>>> darr2 = r["darr"];
601 std::vector<std::vector<std::vector<bool>>> barr2 = r["barr"];
602 std::vector<std::vector<std::vector<std::string>>> strarr2 = r["strarr"];
603 std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr2 = r["objarr"];
605 // Note: due to the way that the CSDK works, all 3d arrays need to be cuboidal.
606 // Since std::vector doesn't require this, items received on the other side end up
607 // being backfilled. This section removes the backfilling
608 iarr2[1][1].pop_back();
609 darr2[1][1].pop_back();
610 barr2[0][1].pop_back();
611 strarr2[1][1].pop_back();
612 objarr2[1][1].pop_back();
613 objarr2[2].pop_back();
615 EXPECT_EQ(iarr, iarr2);
616 EXPECT_EQ(darr, darr2);
617 EXPECT_EQ(barr, barr2);
618 EXPECT_EQ(strarr, strarr2);
619 EXPECT_EQ(objarr, objarr2);
620 OCPayloadDestroy(cparsed);
623 TEST(DiscoveryRTandIF, SingleItemNormal)
625 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
626 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
627 payload->resources = resource;
629 OCResourcePayloadAddResourceType(resource, "rt.singleitem");
630 OCResourcePayloadAddInterface(resource, "if.singleitem");
631 resource->uri = OICStrdup("/uri/thing");
632 resource->sid = (uint8_t*)OICMalloc(16);
638 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
639 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
640 cborData, cborSize));
642 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
643 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
645 EXPECT_EQ(NULL, parsedResource->next);
647 EXPECT_EQ(NULL, parsedResource->types->next);
648 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
649 EXPECT_EQ(NULL, parsedResource->interfaces->next);
650 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
653 OCPayloadDestroy(cparsed);
654 OCDiscoveryPayloadDestroy(payload);
657 TEST(DiscoveryRTandIF, SingleItemFrontTrim)
659 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
660 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
661 payload->resources = resource;
663 OCResourcePayloadAddResourceType(resource, " rt.singleitem");
664 OCResourcePayloadAddInterface(resource, " if.singleitem");
665 resource->uri = OICStrdup("/uri/thing");
666 resource->sid = (uint8_t*)OICMalloc(16);
672 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
673 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
674 cborData, cborSize));
676 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
677 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
679 EXPECT_EQ(NULL, parsedResource->next);
681 EXPECT_EQ(NULL, parsedResource->types->next);
682 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
683 EXPECT_EQ(NULL, parsedResource->interfaces->next);
684 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
687 OCPayloadDestroy(cparsed);
688 OCDiscoveryPayloadDestroy(payload);
690 TEST(DiscoveryRTandIF, SingleItemBackTrim)
692 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
693 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
694 payload->resources = resource;
696 OCResourcePayloadAddResourceType(resource, "rt.singleitem ");
697 OCResourcePayloadAddInterface(resource, "if.singleitem ");
698 resource->uri = OICStrdup("/uri/thing");
699 resource->sid = (uint8_t*)OICMalloc(16);
705 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
706 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
707 cborData, cborSize));
709 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
710 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
712 EXPECT_EQ(NULL, parsedResource->next);
714 EXPECT_EQ(NULL, parsedResource->types->next);
715 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
716 EXPECT_EQ(NULL, parsedResource->interfaces->next);
717 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
720 OCPayloadDestroy(cparsed);
721 OCDiscoveryPayloadDestroy(payload);
723 TEST(DiscoveryRTandIF, SingleItemBothTrim)
725 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
726 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
727 payload->resources = resource;
729 OCResourcePayloadAddResourceType(resource, " rt.singleitem ");
730 OCResourcePayloadAddInterface(resource, " if.singleitem ");
731 resource->uri = OICStrdup("/uri/thing");
732 resource->sid = (uint8_t*)OICMalloc(16);
738 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
739 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
740 cborData, cborSize));
742 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
743 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
745 EXPECT_EQ(NULL, parsedResource->next);
747 EXPECT_EQ(NULL, parsedResource->types->next);
748 EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
749 EXPECT_EQ(NULL, parsedResource->interfaces->next);
750 EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
753 OCPayloadDestroy(cparsed);
754 OCDiscoveryPayloadDestroy(payload);
756 TEST(DiscoveryRTandIF, MultiItemsNormal)
758 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
759 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
760 payload->resources = resource;
762 OCResourcePayloadAddResourceType(resource, "rt.firstitem");
763 OCResourcePayloadAddResourceType(resource, "rt.seconditem");
764 OCResourcePayloadAddInterface(resource, "if.firstitem");
765 OCResourcePayloadAddInterface(resource, "if.seconditem");
766 resource->uri = OICStrdup("/uri/thing");
767 resource->sid = (uint8_t*)OICMalloc(16);
773 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
774 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
775 cborData, cborSize));
777 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
778 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
780 EXPECT_EQ(NULL, parsedResource->next);
782 EXPECT_EQ(NULL, parsedResource->types->next->next);
783 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
784 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
785 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
786 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
787 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
790 OCPayloadDestroy(cparsed);
791 OCDiscoveryPayloadDestroy(payload);
793 TEST(DiscoveryRTandIF, MultiItemExtraLeadSpaces)
795 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
796 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
797 payload->resources = resource;
799 OCResourcePayloadAddResourceType(resource, " rt.firstitem");
800 OCResourcePayloadAddResourceType(resource, " rt.seconditem");
801 OCResourcePayloadAddInterface(resource, " if.firstitem");
802 OCResourcePayloadAddInterface(resource, " if.seconditem");
803 resource->uri = OICStrdup("/uri/thing");
804 resource->sid = (uint8_t*)OICMalloc(16);
810 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
811 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
812 cborData, cborSize));
814 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
815 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
817 EXPECT_EQ(NULL, parsedResource->next);
819 EXPECT_EQ(NULL, parsedResource->types->next->next);
820 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
821 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
822 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
823 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
824 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
827 OCPayloadDestroy(cparsed);
828 OCDiscoveryPayloadDestroy(payload);
830 TEST(DiscoveryRTandIF, MultiItemExtraTrailSpaces)
832 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
833 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
834 payload->resources = resource;
836 OCResourcePayloadAddResourceType(resource, "rt.firstitem ");
837 OCResourcePayloadAddResourceType(resource, "rt.seconditem ");
838 OCResourcePayloadAddInterface(resource, "if.firstitem ");
839 OCResourcePayloadAddInterface(resource, "if.seconditem ");
840 resource->uri = OICStrdup("/uri/thing");
841 resource->sid = (uint8_t*)OICMalloc(16);
847 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
848 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
849 cborData, cborSize));
851 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
852 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
854 EXPECT_EQ(NULL, parsedResource->next);
856 EXPECT_EQ(NULL, parsedResource->types->next->next);
857 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
858 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
859 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
860 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
861 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
864 OCPayloadDestroy(cparsed);
865 OCDiscoveryPayloadDestroy(payload);
867 TEST(DiscoveryRTandIF, MultiItemBothSpaces)
869 OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
870 OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
871 payload->resources = resource;
873 OCResourcePayloadAddResourceType(resource, " rt.firstitem ");
874 OCResourcePayloadAddResourceType(resource, " rt.seconditem ");
875 OCResourcePayloadAddInterface(resource, " if.firstitem ");
876 OCResourcePayloadAddInterface(resource, " if.seconditem ");
877 resource->uri = OICStrdup("/uri/thing");
878 resource->sid = (uint8_t*)OICMalloc(16);
884 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
885 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
886 cborData, cborSize));
888 EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
889 OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
891 EXPECT_EQ(NULL, parsedResource->next);
893 EXPECT_EQ(NULL, parsedResource->types->next->next);
894 EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
895 EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
896 EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
897 EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
898 EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
901 OCPayloadDestroy(cparsed);
902 OCDiscoveryPayloadDestroy(payload);
904 TEST(RepresentationEncodingRTandIF, SingleItemNormal)
906 OCRepPayload* payload = OCRepPayloadCreate();
907 OCRepPayloadAddResourceType(payload, "rt.firstitem");
908 OCRepPayloadAddInterface(payload, "if.firstitem");
914 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
915 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
916 cborData, cborSize));
918 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
920 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
921 EXPECT_EQ(NULL, parsedPayload->types->next);
922 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
923 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
927 OCRepPayloadDestroy(payload);
928 OCPayloadDestroy(cparsed);
930 TEST(RepresentationEncodingRTandIF, SingleItemFrontTrim)
932 OCRepPayload* payload = OCRepPayloadCreate();
933 OCRepPayloadAddResourceType(payload, " rt.firstitem");
934 OCRepPayloadAddInterface(payload, " if.firstitem");
940 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
941 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
942 cborData, cborSize));
944 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
946 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
947 EXPECT_EQ(NULL, parsedPayload->types->next);
948 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
949 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
953 OCRepPayloadDestroy(payload);
954 OCPayloadDestroy(cparsed);
956 TEST(RepresentationEncodingRTandIF, SingleItemBackTrim)
958 OCRepPayload* payload = OCRepPayloadCreate();
959 OCRepPayloadAddResourceType(payload, "rt.firstitem ");
960 OCRepPayloadAddInterface(payload, "if.firstitem ");
966 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
967 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
968 cborData, cborSize));
970 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
972 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
973 EXPECT_EQ(NULL, parsedPayload->types->next);
974 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
975 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
979 OCRepPayloadDestroy(payload);
980 OCPayloadDestroy(cparsed);
982 TEST(RepresentationEncodingRTandIF, SingleItemBothTrim)
984 OCRepPayload* payload = OCRepPayloadCreate();
985 OCRepPayloadAddResourceType(payload, " rt.firstitem ");
986 OCRepPayloadAddInterface(payload, " if.firstitem ");
992 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
993 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
994 cborData, cborSize));
996 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
998 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
999 EXPECT_EQ(NULL, parsedPayload->types->next);
1000 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1001 EXPECT_EQ(NULL, parsedPayload->interfaces->next);
1005 OCRepPayloadDestroy(payload);
1006 OCPayloadDestroy(cparsed);
1008 TEST(RepresentationEncodingRTandIF, MultiItemsNormal)
1010 OCRepPayload* payload = OCRepPayloadCreate();
1011 OCRepPayloadAddResourceType(payload, "rt.firstitem");
1012 OCRepPayloadAddResourceType(payload, "rt.seconditem");
1013 OCRepPayloadAddInterface(payload, "if.firstitem");
1014 OCRepPayloadAddInterface(payload, "if.seconditem");
1020 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1021 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1022 cborData, cborSize));
1024 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1026 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1027 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1028 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1029 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1030 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1031 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1035 OCRepPayloadDestroy(payload);
1036 OCPayloadDestroy(cparsed);
1038 TEST(RepresentationEncodingRTandIF, MultiItemExtraLeadSpaces)
1040 OCRepPayload* payload = OCRepPayloadCreate();
1041 OCRepPayloadAddResourceType(payload, " rt.firstitem");
1042 OCRepPayloadAddResourceType(payload, " rt.seconditem");
1043 OCRepPayloadAddInterface(payload, " if.firstitem");
1044 OCRepPayloadAddInterface(payload, " if.seconditem");
1050 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1051 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1052 cborData, cborSize));
1054 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1056 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1057 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1058 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1059 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1060 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1061 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1065 OCRepPayloadDestroy(payload);
1066 OCPayloadDestroy(cparsed);
1068 TEST(RepresentationEncodingRTandIF, MultiItemExtraTrailSpaces)
1070 OCRepPayload* payload = OCRepPayloadCreate();
1071 OCRepPayloadAddResourceType(payload, "rt.firstitem ");
1072 OCRepPayloadAddResourceType(payload, "rt.seconditem ");
1073 OCRepPayloadAddInterface(payload, "if.firstitem ");
1074 OCRepPayloadAddInterface(payload, "if.seconditem ");
1080 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1081 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1082 cborData, cborSize));
1084 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1086 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1087 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1088 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1089 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1090 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1091 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1095 OCRepPayloadDestroy(payload);
1096 OCPayloadDestroy(cparsed);
1098 TEST(RepresentationEncodingRTandIF, MultiItemExtraMiddleSpaces)
1100 OCRepPayload* payload = OCRepPayloadCreate();
1101 OCRepPayloadAddResourceType(payload, " rt.firstitem ");
1102 OCRepPayloadAddResourceType(payload, " rt.seconditem ");
1103 OCRepPayloadAddInterface(payload, " if.firstitem ");
1104 OCRepPayloadAddInterface(payload, " if.seconditem ");
1110 EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
1111 EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
1112 cborData, cborSize));
1114 OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1116 EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
1117 EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
1118 EXPECT_EQ(NULL, parsedPayload->types->next->next);
1119 EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
1120 EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
1121 EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
1125 OCRepPayloadDestroy(payload);
1126 OCPayloadDestroy(cparsed);