[IOT-1513] One more incorrect URI construction
[platform/upstream/iotivity.git] / resource / unittests / OCRepresentationEncodingTest.cpp
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
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
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
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.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #include <gtest/gtest.h>
22 #include <OCApi.h>
23 #include <OCRepresentation.h>
24 #include <octypes.h>
25 #include <ocstack.h>
26 #include <ocpayload.h>
27 #include <ocpayloadcbor.h>
28 #include <oic_malloc.h>
29 #include <oic_string.h>
30 #include "payload_logging.h"
31
32 bool operator==(const OCByteString& lhs, const OCByteString& rhs)
33 {
34     bool result = (lhs.len == rhs.len);
35     if (result)
36     {
37         result = (memcmp(lhs.bytes, rhs.bytes, lhs.len) == 0);
38     }
39     return result;
40 }
41
42 namespace OC
43 {
44     bool operator==(const OC::NullType&, const OC::NullType&)
45     {
46         return true;
47     }
48
49     bool operator==(const OC::OCRepresentation& lhs, const OC::OCRepresentation& rhs)
50     {
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;
56     }
57 }
58 // these tests validate the OCRepresentation->OCPayload, OCPayload->CBOR,
59 // CBOR->OCPayload and OCPayload->OCRepresentation conversions
60 namespace OCRepresentationEncodingTest
61 {
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;
67     // Device Payloads
68     TEST(DeviceDiscoveryEncoding, Normal)
69     {
70         OCResourcePayloadAddStringLL(&types, "oic.wk.d");
71         OCResourcePayloadAddStringLL(&types, "oic.d.tv");
72
73         OCDevicePayload* device = OCDevicePayloadCreate(
74                 sid1,
75                 devicename1,
76                 types,
77                 specver1,
78                 dmver1);
79         EXPECT_TRUE(device);
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);
89
90         uint8_t* cborData;
91         size_t cborSize;
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,
95                     cborData, cborSize));
96         OICFree(cborData);
97
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);
105
106         OCPayloadDestroy((OCPayload*)device);
107
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());
116
117         OCPayloadDestroy(parsedDevice);
118
119         static const char dmver2[] = "res.1.1.0,sh.1.1.0";
120         device = OCDevicePayloadCreate(
121                      sid1,
122                      devicename1,
123                      types,
124                      specver1,
125                      dmver2);
126
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));
134         OICFree(cborData);
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());
146
147         OCPayloadDestroy(parsedDevice);
148     }
149
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";
162
163     // Platform Payloads
164     TEST(PlatformDiscoveryEncoding, Normal)
165     {
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);
184
185         uint8_t* cborData;
186         size_t cborSize;
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));
191         OICFree(cborData);
192
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);
208
209         OCPayloadDestroy((OCPayload*)platform);
210
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());
226
227         OCPayloadDestroy(parsedPlatform);
228     }
229     TEST(PresencePayload, Normal)
230     {
231         uint32_t maxAge = 0;
232         uint32_t sequenceNumber = 0;
233         OCPresenceTrigger trigger = OC_PRESENCE_TRIGGER_CREATE;
234         OCPresencePayload *presence = OCPresencePayloadCreate(sequenceNumber, maxAge, trigger, uri1);
235
236         uint8_t* cborData;
237         size_t cborSize;
238         OCPayload* cparsed;
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);
243         OICFree(cborData);
244
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);
250
251         OCPayloadDestroy(cparsed);
252     }
253     // Representation Payloads
254     TEST(RepresentationEncoding, BaseAttributeTypes)
255     {
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"));
262
263         uint8_t binval[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8,
264                             0x9, 0x0, 0xA, 0xB, 0xC, 0xD, 0xE, 0xF
265                            };
266         OCByteString byteString = {binval, sizeof(binval)};
267         startRep.setValue("ByteStringAttr", byteString);
268
269         OC::MessageContainer mc1;
270         mc1.addRepresentation(startRep);
271
272         OCRepPayload* cstart = mc1.getPayload();
273         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
274
275         uint8_t* cborData;
276         size_t cborSize;
277         OCPayload* cparsed;
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);
282         OICFree(cborData);
283
284         OC::MessageContainer mc2;
285         mc2.setPayload(cparsed);
286         EXPECT_EQ(1u, mc2.representations().size());
287         const OC::OCRepresentation& r = mc2.representations()[0];
288
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());
296
297         OCPayloadDestroy(cparsed);
298     }
299
300     TEST(RepresentationEncoding, RepAttributeEmpty)
301     {
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"));
317
318         OC::MessageContainer mc1;
319         mc1.addRepresentation(startRep);
320         OCRepPayload* cstart = mc1.getPayload();
321         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
322
323         uint8_t *cborData = NULL;
324         size_t cborSize = 0;
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);
330         OICFree(cborData);
331
332         OC::MessageContainer mc2;
333         mc2.setPayload(cparsed);
334         EXPECT_EQ(1u, mc2.representations().size());
335         const OC::OCRepresentation& r = mc2.representations()[0];
336
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);
353     }
354
355     TEST(RepresentationEncoding, RepAttribute)
356     {
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);
367
368         OC::MessageContainer mc1;
369         mc1.addRepresentation(startRep);
370
371         OCRepPayload* cstart = mc1.getPayload();
372         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
373
374         uint8_t* cborData;
375         size_t cborSize;
376         EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)cstart, &cborData, &cborSize));
377         OCPayload* cparsed;
378         EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
379                     cborData, cborSize));
380         OCPayloadDestroy((OCPayload*)cstart);
381         OICFree(cborData);
382
383         OC::MessageContainer mc2;
384         mc2.setPayload(cparsed);
385         EXPECT_EQ(1u, mc2.representations().size());
386         const OC::OCRepresentation& r = mc2.representations()[0];
387
388         OC::OCRepresentation newSubRep = r["Sub"];
389
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());
395         EXPECT_EQ(bin_data,
396                 newSubRep.getValue<std::vector<uint8_t>>("BinaryAttr"));
397         OCPayloadDestroy(cparsed);
398     }
399
400     TEST(RepresentationEncoding, OneDVectors)
401     {
402         // Setup
403         OC::OCRepresentation startRep;
404
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"));
413
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};
419
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 };
430
431         startRep["iarr"] = iarr;
432         startRep["darr"] = darr;
433         startRep["barr"] = barr;
434         startRep["strarr"] = strarr;
435         startRep["objarr"] = objarr;
436         startRep["bytestrarr"] = bytestrarr;
437
438         // Encode/decode
439         OC::MessageContainer mc1;
440         mc1.addRepresentation(startRep);
441
442         OCRepPayload* cstart = mc1.getPayload();
443         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
444
445         uint8_t* cborData;
446         size_t cborSize;
447         OCPayload* cparsed;
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);
452         OICFree(cborData);
453
454         OC::MessageContainer mc2;
455         mc2.setPayload(cparsed);
456         EXPECT_EQ(1u, mc2.representations().size());
457         const OC::OCRepresentation &r = mc2.representations()[0];
458
459         // Test
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"];
466
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);
472
473         EXPECT_EQ(bytestrarrRef, bytestrarr2);
474         OCPayloadDestroy(cparsed);
475     }
476
477     TEST(RepresentationEncoding, TwoDVectors)
478     {
479         // Setup
480         OC::OCRepresentation startRep;
481
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"));
490
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}};
497
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
515         {
516             {byteStringRef1, byteStringRef2}, {byteStringRef3, byteStringRef4}
517         };
518         std::vector<std::vector<OCByteString>> bytestrarr
519         {
520             {byteString1, byteString2}, {byteString3, byteString4}
521         };
522
523         startRep["iarr"] = iarr;
524         startRep["darr"] = darr;
525         startRep["barr"] = barr;
526         startRep["strarr"] = strarr;
527         startRep["objarr"] = objarr;
528         startRep["bytestrarr"] = bytestrarr;
529
530         // Encode/decode
531         OC::MessageContainer mc1;
532         mc1.addRepresentation(startRep);
533
534         OCRepPayload *cstart = mc1.getPayload();
535         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
536
537         uint8_t* cborData;
538         size_t cborSize;
539         OCPayload* cparsed;
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);
544         OICFree(cborData);
545
546         OC::MessageContainer mc2;
547         mc2.setPayload(cparsed);
548         EXPECT_EQ(1u, mc2.representations().size());
549         const OC::OCRepresentation &r = mc2.representations()[0];
550
551         // Test
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"];
558
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);
564
565         EXPECT_EQ(bytestrarrRef, bytestrarr2);
566
567         OCPayloadDestroy(cparsed);
568     }
569
570     TEST(RepresentationEncoding, TwoDVectorsJagged)
571     {
572         // Setup
573         OC::OCRepresentation startRep;
574
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"));
583
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}};
590
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));
603
604         std::vector<std::vector<OCByteString>> bytestrarrRef
605         {
606             {byteStringRef1}, {byteStringRef3, byteStringRef4}
607         };
608
609         std::vector<std::vector<OCByteString>> bytestrarr
610         {
611             {byteString1}, {byteString3, byteString4}
612         };
613
614         startRep["iarr"] = iarr;
615         startRep["darr"] = darr;
616         startRep["barr"] = barr;
617         startRep["strarr"] = strarr;
618         startRep["objarr"] = objarr;
619
620         startRep["bytestrarr"] = bytestrarr;
621
622         EXPECT_STREQ("[[\\x1 ] [\\x2\\x3\\x4 \\x5\\x6\\x7\\x8 ] ]",
623                      startRep.getValueToString("bytestrarr").c_str());
624         // Encode/decode
625         OC::MessageContainer mc1;
626         mc1.addRepresentation(startRep);
627
628         OCRepPayload *cstart = mc1.getPayload();
629         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
630
631         uint8_t *cborData;
632         size_t cborSize;
633         OCPayload *cparsed;
634         OCStackResult result = OCConvertPayload((OCPayload *)cstart, &cborData, &cborSize);
635         EXPECT_EQ(OC_STACK_OK, result);
636         result = OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
637                                 cborData, cborSize);
638         EXPECT_EQ(OC_STACK_OK, result);
639
640         OCPayloadDestroy((OCPayload *)cstart);
641         OICFree(cborData);
642
643         OC::MessageContainer mc2;
644         mc2.setPayload(cparsed);
645         EXPECT_EQ(1u, mc2.representations().size());
646         const OC::OCRepresentation &r = mc2.representations()[0];
647
648         // Test
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"];
654
655         std::vector<std::vector<OCByteString>> bytestrarr2 = r["bytestrarr"];
656
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
660         iarr2[1].pop_back();
661         darr2[2].pop_back();
662         barr2[1].pop_back();
663         strarr2[0].pop_back();
664         objarr2[0].pop_back();
665         bytestrarr2[0].pop_back();
666
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);
674
675         OCPayloadDestroy(cparsed);
676     }
677
678     TEST(RepresentationEncoding, ThreeDVectors)
679     {
680         // Setup
681         OC::OCRepresentation startRep;
682
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"));
691
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
701             {
702                 {{"item1", "item2"},{"item3", "item4"}},
703                 {{"item5", "item6"},{"item7", "item8"}},
704                 {{"item9", "item10"},{"item11", ""}}
705             };
706         std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr
707             {
708                 {{subRep1, subRep2},{subRep3, subRep1}},
709                 {{subRep2, subRep3},{subRep2, subRep1}},
710                 {{subRep3, subRep2},{subRep1, subRep2}}
711             };
712
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));
761
762         std::vector<std::vector<std::vector<OCByteString>>> bytestrarrRef
763         {
764             {{byteStringRef1, byteStringRef2}, {byteStringRef3, byteStringRef4}},
765             {{byteStringRef5, byteStringRef6}, {byteStringRef7, byteStringRef8}},
766             {{byteStringRef9, byteStringRef10}, {byteStringRef11, byteStringRef12}}
767         };
768
769         std::vector<std::vector<std::vector<OCByteString>>> bytestrarr
770         {
771             {{byteString1, byteString2}, {byteString3, byteString4}},
772             {{byteString5, byteString6}, {byteString7, byteString8}},
773             {{byteString9, byteString10}, {byteString11, byteString12}}
774         };
775
776         startRep["iarr"] = iarr;
777         startRep["darr"] = darr;
778         startRep["barr"] = barr;
779         startRep["strarr"] = strarr;
780         startRep["objarr"] = objarr;
781         startRep["bytestrarr"] = bytestrarr;
782
783         // Encode/decode
784         OC::MessageContainer mc1;
785         mc1.addRepresentation(startRep);
786
787         OCRepPayload *cstart = mc1.getPayload();
788         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
789
790         uint8_t *cborData;
791         size_t cborSize;
792         OCPayload *cparsed;
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);
797         OICFree(cborData);
798
799         OC::MessageContainer mc2;
800         mc2.setPayload(cparsed);
801         EXPECT_EQ(1u, mc2.representations().size());
802         const OC::OCRepresentation &r = mc2.representations()[0];
803
804         // Test
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"];
811
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);
819     }
820
821     TEST(RepresentationEncoding, ThreeDVectorsJagged)
822     {
823         // Setup
824         OC::OCRepresentation startRep;
825
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"));
834
835         std::vector<std::vector<std::vector<int>>> iarr
836             {
837                 {{1,2,3},{4,5,6}},
838                 {{7,8,9},{10,12}},
839                 {{13,14,15},{16,17,18}}
840             };
841         std::vector<std::vector<std::vector<double>>> darr
842             {
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}}
846             };
847         std::vector<std::vector<std::vector<bool>>> barr
848             {
849                 {{false, true},{true}},
850                 {{false, true},{true, false}}
851             };
852         std::vector<std::vector<std::vector<std::string>>> strarr
853             {
854                 {{"item1", "item2"},{"item3", "item4"}},
855                 {{"item5", "item6"},{"item8"}},
856                 {{"item9", "item10"},{"item11", ""}}
857             };
858         std::vector<std::vector<std::vector<OC::OCRepresentation>>> objarr
859             {
860                 {{subRep1, subRep2},{subRep3, subRep1}},
861                 {{subRep2, subRep3},{subRep2}},
862                 {{subRep3, subRep2}}
863             };
864
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));
909
910         std::vector<std::vector<std::vector<OCByteString>>> bytestrarrRef
911         {
912             {{byteStringRef1, byteStringRef2}, {byteStringRef3, byteStringRef4}},
913             {{byteStringRef5, byteStringRef6}, {byteStringRef8}},
914             {{byteStringRef9, byteStringRef10}, {byteStringRef11, byteStringRef12}}
915         };
916
917         std::vector<std::vector<std::vector<OCByteString>>> bytestrarr
918         {
919             {{byteString1, byteString2}, {byteString3, byteString4}},
920             {{byteString5, byteString6}, {byteString8}},
921             {{byteString9, byteString10}, {byteString11, byteString12}}
922         };
923
924         startRep["iarr"] = iarr;
925         startRep["darr"] = darr;
926         startRep["barr"] = barr;
927         startRep["strarr"] = strarr;
928         startRep["objarr"] = objarr;
929         startRep["bytestrarr"] = bytestrarr;
930
931         // Encode/decode
932         OC::MessageContainer mc1;
933         mc1.addRepresentation(startRep);
934
935         OCRepPayload *cstart = mc1.getPayload();
936         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, cstart->base.type);
937
938         uint8_t *cborData;
939         size_t cborSize;
940         OCPayload *cparsed;
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);
945         OICFree(cborData);
946
947         OC::MessageContainer mc2;
948         mc2.setPayload(cparsed);
949         EXPECT_EQ(1u, mc2.representations().size());
950         const OC::OCRepresentation &r = mc2.representations()[0];
951
952         // Test
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"];
959
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();
970
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);
978     }
979
980     TEST(DiscoveryRTandIF, SingleItemNormal)
981     {
982         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
983         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
984         payload->sid = OICStrdup(sid1);
985         payload->resources = resource;
986
987         EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem"));
988         EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->interfaces, "if.singleitem"));
989
990         resource->uri = OICStrdup("/uri/thing");
991
992         uint8_t* cborData;
993         size_t cborSize;
994         OCPayload* cparsed;
995
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));
999
1000         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1001         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1002
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);
1009
1010         OICFree(cborData);
1011         OCPayloadDestroy(cparsed);
1012         OCDiscoveryPayloadDestroy(payload);
1013     }
1014
1015     TEST(DiscoveryRTandIF, SingleItemFrontTrim)
1016     {
1017         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1018         payload->sid = OICStrdup(sid1);
1019         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1020         payload->resources = resource;
1021
1022         EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, "    rt.singleitem"));
1023         EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->interfaces, "    if.singleitem"));
1024         resource->uri = OICStrdup("/uri/thing");
1025
1026         uint8_t* cborData;
1027         size_t cborSize;
1028         OCPayload* cparsed;
1029
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));
1033
1034         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1035         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1036
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);
1043
1044         OICFree(cborData);
1045         OCPayloadDestroy(cparsed);
1046         OCDiscoveryPayloadDestroy(payload);
1047     }
1048
1049     TEST(DiscoveryRTandIF, SingleItemBackTrim)
1050     {
1051         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1052         payload->sid = OICStrdup(sid1);
1053         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1054         payload->resources = resource;
1055
1056         OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem    ");
1057         OCResourcePayloadAddStringLL(&resource->interfaces, "if.singleitem    ");
1058         resource->uri = OICStrdup("/uri/thing");
1059
1060         uint8_t* cborData;
1061         size_t cborSize;
1062         OCPayload* cparsed;
1063
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));
1067
1068         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1069         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1070
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);
1077
1078         OICFree(cborData);
1079         OCPayloadDestroy(cparsed);
1080         OCDiscoveryPayloadDestroy(payload);
1081     }
1082     TEST(DiscoveryRTandIF, SingleItemBothTrim)
1083     {
1084         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1085         payload->sid = OICStrdup(sid1);
1086         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1087         payload->resources = resource;
1088
1089         OCResourcePayloadAddStringLL(&resource->types, "    rt.singleitem    ");
1090         OCResourcePayloadAddStringLL(&resource->interfaces, "    if.singleitem     ");
1091         resource->uri = OICStrdup("/uri/thing");
1092
1093         uint8_t* cborData;
1094         size_t cborSize;
1095         OCPayload* cparsed;
1096
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));
1100
1101         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1102         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1103
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);
1110
1111         OICFree(cborData);
1112         OCPayloadDestroy(cparsed);
1113         OCDiscoveryPayloadDestroy(payload);
1114     }
1115     TEST(DiscoveryRTandIF, MultiItemsNormal)
1116     {
1117         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1118         payload->sid = OICStrdup(sid1);
1119         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1120         payload->resources = resource;
1121
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");
1127
1128         uint8_t* cborData;
1129         size_t cborSize;
1130         OCPayload* cparsed;
1131
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));
1135
1136         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1137         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1138
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);
1147
1148         OICFree(cborData);
1149         OCPayloadDestroy(cparsed);
1150         OCDiscoveryPayloadDestroy(payload);
1151     }
1152     TEST(DiscoveryRTandIF, MultiItemExtraLeadSpaces)
1153     {
1154         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1155         payload->sid = OICStrdup(sid1);
1156         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1157         payload->resources = resource;
1158
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");
1164
1165         uint8_t* cborData;
1166         size_t cborSize;
1167         OCPayload* cparsed;
1168
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));
1172
1173         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1174         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1175
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);
1184
1185         OICFree(cborData);
1186         OCPayloadDestroy(cparsed);
1187         OCDiscoveryPayloadDestroy(payload);
1188     }
1189     TEST(DiscoveryRTandIF, MultiItemExtraTrailSpaces)
1190     {
1191         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1192         payload->sid = OICStrdup(sid1);
1193         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1194         payload->resources = resource;
1195
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");
1201
1202         uint8_t* cborData;
1203         size_t cborSize;
1204         OCPayload* cparsed;
1205
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));
1209
1210         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1211         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1212
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);
1221
1222         OICFree(cborData);
1223         OCPayloadDestroy(cparsed);
1224         OCDiscoveryPayloadDestroy(payload);
1225     }
1226     TEST(DiscoveryRTandIF, MultiItemBothSpaces)
1227     {
1228         OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
1229         payload->sid = OICStrdup(sid1);
1230         OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
1231         payload->resources = resource;
1232
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");
1238
1239         uint8_t* cborData;
1240         size_t cborSize;
1241         OCPayload* cparsed;
1242
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));
1246
1247         EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
1248         OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
1249
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);
1258
1259         OICFree(cborData);
1260         OCPayloadDestroy(cparsed);
1261         OCDiscoveryPayloadDestroy(payload);
1262     }
1263     TEST(RepresentationEncodingRTandIF, SingleItemNormal)
1264     {
1265         OCRepPayload* payload = OCRepPayloadCreate();
1266         OCRepPayloadAddResourceType(payload, "rt.firstitem");
1267         OCRepPayloadAddInterface(payload, "if.firstitem");
1268
1269         uint8_t* cborData;
1270         size_t cborSize;
1271         OCPayload* cparsed;
1272
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));
1276
1277         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1278
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);
1283
1284         OICFree(cborData);
1285         OCRepPayloadDestroy(payload);
1286         OCPayloadDestroy(cparsed);
1287     }
1288     TEST(RepresentationEncodingRTandIF, SingleItemFrontTrim)
1289     {
1290         OCRepPayload* payload = OCRepPayloadCreate();
1291         OCRepPayloadAddResourceType(payload, "  rt.firstitem");
1292         OCRepPayloadAddInterface(payload, "  if.firstitem");
1293
1294         uint8_t* cborData;
1295         size_t cborSize;
1296         OCPayload* cparsed;
1297
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));
1301
1302         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1303
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);
1308
1309
1310         OICFree(cborData);
1311         OCRepPayloadDestroy(payload);
1312         OCPayloadDestroy(cparsed);
1313     }
1314     TEST(RepresentationEncodingRTandIF, SingleItemBackTrim)
1315     {
1316         OCRepPayload* payload = OCRepPayloadCreate();
1317         OCRepPayloadAddResourceType(payload, "rt.firstitem  ");
1318         OCRepPayloadAddInterface(payload, "if.firstitem  ");
1319
1320         uint8_t* cborData;
1321         size_t cborSize;
1322         OCPayload* cparsed;
1323
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));
1327
1328         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1329
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);
1334
1335
1336         OICFree(cborData);
1337         OCRepPayloadDestroy(payload);
1338         OCPayloadDestroy(cparsed);
1339     }
1340     TEST(RepresentationEncodingRTandIF, SingleItemBothTrim)
1341     {
1342         OCRepPayload* payload = OCRepPayloadCreate();
1343         OCRepPayloadAddResourceType(payload, "  rt.firstitem  ");
1344         OCRepPayloadAddInterface(payload, "  if.firstitem  ");
1345
1346         uint8_t* cborData;
1347         size_t cborSize;
1348         OCPayload* cparsed;
1349
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));
1353
1354         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1355
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);
1360
1361
1362         OICFree(cborData);
1363         OCRepPayloadDestroy(payload);
1364         OCPayloadDestroy(cparsed);
1365     }
1366     TEST(RepresentationEncodingRTandIF, MultiItemsNormal)
1367     {
1368         OCRepPayload* payload = OCRepPayloadCreate();
1369         OCRepPayloadAddResourceType(payload, "rt.firstitem");
1370         OCRepPayloadAddResourceType(payload, "rt.seconditem");
1371         OCRepPayloadAddInterface(payload, "if.firstitem");
1372         OCRepPayloadAddInterface(payload, "if.seconditem");
1373
1374         uint8_t* cborData;
1375         size_t cborSize;
1376         OCPayload* cparsed;
1377
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));
1381
1382         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1383
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);
1390
1391
1392         OICFree(cborData);
1393         OCRepPayloadDestroy(payload);
1394         OCPayloadDestroy(cparsed);
1395     }
1396     TEST(RepresentationEncodingRTandIF, MultiItemExtraLeadSpaces)
1397     {
1398         OCRepPayload* payload = OCRepPayloadCreate();
1399         OCRepPayloadAddResourceType(payload, "  rt.firstitem");
1400         OCRepPayloadAddResourceType(payload, "  rt.seconditem");
1401         OCRepPayloadAddInterface(payload, "  if.firstitem");
1402         OCRepPayloadAddInterface(payload, "  if.seconditem");
1403
1404         uint8_t* cborData;
1405         size_t cborSize;
1406         OCPayload* cparsed;
1407
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));
1411
1412         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1413
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);
1420
1421
1422         OICFree(cborData);
1423         OCRepPayloadDestroy(payload);
1424         OCPayloadDestroy(cparsed);
1425     }
1426     TEST(RepresentationEncodingRTandIF, MultiItemExtraTrailSpaces)
1427     {
1428         OCRepPayload* payload = OCRepPayloadCreate();
1429         OCRepPayloadAddResourceType(payload, "rt.firstitem  ");
1430         OCRepPayloadAddResourceType(payload, "rt.seconditem  ");
1431         OCRepPayloadAddInterface(payload, "if.firstitem  ");
1432         OCRepPayloadAddInterface(payload, "if.seconditem  ");
1433
1434         uint8_t* cborData;
1435         size_t cborSize;
1436         OCPayload* cparsed;
1437
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));
1441
1442         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1443
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);
1450
1451
1452         OICFree(cborData);
1453         OCRepPayloadDestroy(payload);
1454         OCPayloadDestroy(cparsed);
1455     }
1456     TEST(RepresentationEncodingRTandIF, MultiItemExtraMiddleSpaces)
1457     {
1458         OCRepPayload* payload = OCRepPayloadCreate();
1459         OCRepPayloadAddResourceType(payload, "  rt.firstitem  ");
1460         OCRepPayloadAddResourceType(payload, "  rt.seconditem  ");
1461         OCRepPayloadAddInterface(payload, "  if.firstitem  ");
1462         OCRepPayloadAddInterface(payload, "  if.seconditem  ");
1463
1464         uint8_t* cborData;
1465         size_t cborSize;
1466         OCPayload* cparsed;
1467
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));
1471
1472         OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
1473
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);
1480
1481
1482         OICFree(cborData);
1483         OCRepPayloadDestroy(payload);
1484         OCPayloadDestroy(cparsed);
1485     }
1486     TEST(RepresentationEncodingRTandIF, TestPayloadContents)
1487     {
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"));
1500
1501         OC::MessageContainer mc1;
1502         mc1.addRepresentation(subRep1);
1503
1504         OCRepPayload *repPayload = mc1.getPayload();
1505         EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, repPayload->base.type);
1506
1507         uint8_t *cborData = NULL;
1508         size_t cborSize = 0;
1509         OCPayload *cparsed = NULL;
1510
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));
1514
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);
1521
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;
1527
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;
1532
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;
1537
1538         EXPECT_STREQ("NullAttr", parsedPayload->values->name);
1539         EXPECT_EQ(OCREP_PROP_NULL, parsedPayload->values->type);
1540         parsedPayload->values = parsedPayload->values->next;
1541
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;
1546
1547         EXPECT_EQ(NULL, parsedPayload->values);
1548
1549         OICFree(cborData);
1550         OCRepPayloadDestroy(repPayload);
1551         OCPayloadDestroy(cparsed);
1552     }
1553 }