+ EXPECT_EQ(bytestrarrRef, bytestrarr2);
+ OCPayloadDestroy(cparsed);
+ }
+
+ TEST(DiscoveryRTandIF, SingleItemNormal)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->sid = OICStrdup(sid1);
+ payload->resources = resource;
+
+ EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem"));
+ EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->interfaces, "if.singleitem"));
+
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
+ EXPECT_EQ(NULL, parsedResource->types->next);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next);
+ EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+
+ TEST(DiscoveryRTandIF, SingleItemFrontTrim)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->types, " rt.singleitem"));
+ EXPECT_TRUE(OCResourcePayloadAddStringLL(&resource->interfaces, " if.singleitem"));
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next);
+ EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next);
+ EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+
+ TEST(DiscoveryRTandIF, SingleItemBackTrim)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ OCResourcePayloadAddStringLL(&resource->types, "rt.singleitem ");
+ OCResourcePayloadAddStringLL(&resource->interfaces, "if.singleitem ");
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next);
+ EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next);
+ EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+ TEST(DiscoveryRTandIF, SingleItemBothTrim)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ OCResourcePayloadAddStringLL(&resource->types, " rt.singleitem ");
+ OCResourcePayloadAddStringLL(&resource->interfaces, " if.singleitem ");
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next);
+ EXPECT_STREQ("rt.singleitem", parsedResource->types->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next);
+ EXPECT_STREQ("if.singleitem", parsedResource->interfaces->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+ TEST(DiscoveryRTandIF, MultiItemsNormal)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ OCResourcePayloadAddStringLL(&resource->types, "rt.firstitem");
+ OCResourcePayloadAddStringLL(&resource->types, "rt.seconditem");
+ OCResourcePayloadAddStringLL(&resource->interfaces, "if.firstitem");
+ OCResourcePayloadAddStringLL(&resource->interfaces, "if.seconditem");
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next->next);
+ EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
+ EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+ TEST(DiscoveryRTandIF, MultiItemExtraLeadSpaces)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ OCResourcePayloadAddStringLL(&resource->types, " rt.firstitem");
+ OCResourcePayloadAddStringLL(&resource->types, " rt.seconditem");
+ OCResourcePayloadAddStringLL(&resource->interfaces, " if.firstitem");
+ OCResourcePayloadAddStringLL(&resource->interfaces, " if.seconditem");
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next->next);
+ EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
+ EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+ TEST(DiscoveryRTandIF, MultiItemExtraTrailSpaces)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ OCResourcePayloadAddStringLL(&resource->types, "rt.firstitem ");
+ OCResourcePayloadAddStringLL(&resource->types, "rt.seconditem ");
+ OCResourcePayloadAddStringLL(&resource->interfaces, "if.firstitem ");
+ OCResourcePayloadAddStringLL(&resource->interfaces, "if.seconditem ");
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next->next);
+ EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
+ EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+ TEST(DiscoveryRTandIF, MultiItemBothSpaces)
+ {
+ OCDiscoveryPayload* payload = OCDiscoveryPayloadCreate();
+ payload->sid = OICStrdup(sid1);
+ OCResourcePayload* resource = (OCResourcePayload*)OICCalloc(1, sizeof(OCResourcePayload));
+ payload->resources = resource;
+
+ OCResourcePayloadAddStringLL(&resource->types, " rt.firstitem ");
+ OCResourcePayloadAddStringLL(&resource->types, " rt.seconditem ");
+ OCResourcePayloadAddStringLL(&resource->interfaces, " if.firstitem ");
+ OCResourcePayloadAddStringLL(&resource->interfaces, " if.seconditem ");
+ resource->uri = OICStrdup("/uri/thing");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_DISCOVERY,
+ cborData, cborSize));
+
+ EXPECT_EQ(1u, OCDiscoveryPayloadGetResourceCount((OCDiscoveryPayload*)cparsed));
+ OCResourcePayload* parsedResource = ((OCDiscoveryPayload*)cparsed)->resources;
+
+ EXPECT_EQ(NULL, parsedResource->next);
+ EXPECT_STREQ(sid1, ((OCDiscoveryPayload*)cparsed)->sid);
+ EXPECT_EQ(NULL, parsedResource->types->next->next);
+ EXPECT_STREQ("rt.firstitem", parsedResource->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedResource->types->next->value);
+ EXPECT_EQ(NULL, parsedResource->interfaces->next->next);
+ EXPECT_STREQ("if.firstitem", parsedResource->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedResource->interfaces->next->value);
+
+ OICFree(cborData);
+ OCPayloadDestroy(cparsed);
+ OCDiscoveryPayloadDestroy(payload);
+ }
+ TEST(RepresentationEncodingRTandIF, SingleItemNormal)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, "rt.firstitem");
+ OCRepPayloadAddInterface(payload, "if.firstitem");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next);
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, SingleItemFrontTrim)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, " rt.firstitem");
+ OCRepPayloadAddInterface(payload, " if.firstitem");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, SingleItemBackTrim)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, "rt.firstitem ");
+ OCRepPayloadAddInterface(payload, "if.firstitem ");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, SingleItemBothTrim)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, " rt.firstitem ");
+ OCRepPayloadAddInterface(payload, " if.firstitem ");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, MultiItemsNormal)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, "rt.firstitem");
+ OCRepPayloadAddResourceType(payload, "rt.seconditem");
+ OCRepPayloadAddInterface(payload, "if.firstitem");
+ OCRepPayloadAddInterface(payload, "if.seconditem");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, MultiItemExtraLeadSpaces)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, " rt.firstitem");
+ OCRepPayloadAddResourceType(payload, " rt.seconditem");
+ OCRepPayloadAddInterface(payload, " if.firstitem");
+ OCRepPayloadAddInterface(payload, " if.seconditem");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, MultiItemExtraTrailSpaces)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, "rt.firstitem ");
+ OCRepPayloadAddResourceType(payload, "rt.seconditem ");
+ OCRepPayloadAddInterface(payload, "if.firstitem ");
+ OCRepPayloadAddInterface(payload, "if.seconditem ");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, MultiItemExtraMiddleSpaces)
+ {
+ OCRepPayload* payload = OCRepPayloadCreate();
+ OCRepPayloadAddResourceType(payload, " rt.firstitem ");
+ OCRepPayloadAddResourceType(payload, " rt.seconditem ");
+ OCRepPayloadAddInterface(payload, " if.firstitem ");
+ OCRepPayloadAddInterface(payload, " if.seconditem ");
+
+ uint8_t* cborData;
+ size_t cborSize;
+ OCPayload* cparsed;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)payload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload* parsedPayload = (OCRepPayload*)cparsed;
+
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_STREQ("rt.seconditem", parsedPayload->types->next->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_STREQ("if.seconditem", parsedPayload->interfaces->next->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next->next);
+
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(payload);
+ OCPayloadDestroy(cparsed);
+ }
+ TEST(RepresentationEncodingRTandIF, TestPayloadContents)
+ {
+ OC::OCRepresentation subRep1;
+ std::vector<std::string> types;
+ types.push_back("rt.firstitem");
+ std::vector<std::string> interfaces;
+ interfaces.push_back("if.firstitem");
+ subRep1.setResourceTypes(types);
+ subRep1.setResourceInterfaces(interfaces);
+ subRep1.setNULL("NullAttr");
+ subRep1.setValue("IntAttr", 77);
+ subRep1.setValue("DoubleAttr", 3.333);
+ subRep1.setValue("BoolAttr", true);
+ subRep1.setValue("StringAttr", std::string("String attr"));
+
+ OC::MessageContainer mc1;
+ mc1.addRepresentation(subRep1);
+
+ OCRepPayload *repPayload = mc1.getPayload();
+ EXPECT_EQ(PAYLOAD_TYPE_REPRESENTATION, repPayload->base.type);
+
+ uint8_t *cborData = NULL;
+ size_t cborSize = 0;
+ OCPayload *cparsed = NULL;
+
+ EXPECT_EQ(OC_STACK_OK, OCConvertPayload((OCPayload*)repPayload, &cborData, &cborSize));
+ EXPECT_EQ(OC_STACK_OK, OCParsePayload(&cparsed, PAYLOAD_TYPE_REPRESENTATION,
+ cborData, cborSize));
+
+ OCRepPayload *parsedPayload = (OCRepPayload *)cparsed;
+ EXPECT_EQ(NULL, parsedPayload->uri);
+ EXPECT_STREQ("rt.firstitem", parsedPayload->types->value);
+ EXPECT_EQ(NULL, parsedPayload->types->next);
+ EXPECT_STREQ("if.firstitem", parsedPayload->interfaces->value);
+ EXPECT_EQ(NULL, parsedPayload->interfaces->next);
+
+ // To make sure rt and if are not duplicated.
+ EXPECT_STREQ("BoolAttr", parsedPayload->values->name);
+ EXPECT_EQ(true, parsedPayload->values->b);
+ EXPECT_EQ(OCREP_PROP_BOOL, parsedPayload->values->type);
+ parsedPayload->values = parsedPayload->values->next;
+
+ EXPECT_STREQ("DoubleAttr", parsedPayload->values->name);
+ EXPECT_EQ(OCREP_PROP_DOUBLE, parsedPayload->values->type);
+ EXPECT_EQ(3.3330000000000002, parsedPayload->values->d);
+ parsedPayload->values = parsedPayload->values->next;
+
+ EXPECT_STREQ("IntAttr", parsedPayload->values->name);
+ EXPECT_EQ(77, parsedPayload->values->i);
+ EXPECT_EQ(OCREP_PROP_INT, parsedPayload->values->type);
+ parsedPayload->values = parsedPayload->values->next;
+
+ EXPECT_STREQ("NullAttr", parsedPayload->values->name);
+ EXPECT_EQ(OCREP_PROP_NULL, parsedPayload->values->type);
+ parsedPayload->values = parsedPayload->values->next;
+
+ EXPECT_STREQ("StringAttr", parsedPayload->values->name);
+ EXPECT_STREQ("String attr", parsedPayload->values->str);
+ EXPECT_EQ(OCREP_PROP_STRING, parsedPayload->values->type);
+ parsedPayload->values = parsedPayload->values->next;
+
+ EXPECT_EQ(NULL, parsedPayload->values);
+
+ OICFree(cborData);
+ OCRepPayloadDestroy(repPayload);