case OCREP_PROP_STRING:
dest->str = OICStrdup(source->str);
break;
+ case OCREP_PROP_BYTE_STRING:
+ dest->ocByteStr.bytes = (uint8_t*)OICMalloc(source->ocByteStr.len * sizeof(uint8_t));
+ VERIFY_PARAM_NON_NULL(TAG, dest->ocByteStr.bytes, "Failed allocating memory");
+ dest->ocByteStr.len = source->ocByteStr.len;
+ memcpy(dest->ocByteStr.bytes, source->ocByteStr.bytes, dest->ocByteStr.len);
+ break;
case OCREP_PROP_OBJECT:
dest->obj = OCRepPayloadClone(source->obj);
break;
// Nothing to do for the trivially copyable types.
break;
}
+exit:
+ return;
}
static void OCFreeRepPayloadValueContents(OCRepPayloadValue* val)
extern "C"
{
+ #include "ocpayload.h"
#include "ocstack.h"
#include "ocstackinternal.h"
#include "logger.h"
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+
+TEST(StackPayload, CloneByteString)
+{
+ uint8_t bytes[] = { 0, 1, 2, 3 };
+ OCByteString byteString;
+ byteString.bytes = bytes;
+ byteString.len = sizeof(bytes);
+
+ OCRepPayload *original = OCRepPayloadCreate();
+ ASSERT_TRUE(original != NULL);
+ EXPECT_TRUE(OCRepPayloadSetPropByteString(original, "name", byteString));
+
+ OCRepPayload *clone = OCRepPayloadClone(original);
+ ASSERT_TRUE(clone != NULL);
+
+ OCRepPayloadDestroy(original);
+
+ OCByteString cloneByteString;
+ EXPECT_TRUE(OCRepPayloadGetPropByteString(clone, "name", &cloneByteString));
+ ASSERT_TRUE(cloneByteString.bytes != NULL);
+ EXPECT_EQ(sizeof(bytes), cloneByteString.len);
+ EXPECT_TRUE(0 == memcmp(bytes, cloneByteString.bytes, sizeof(bytes)));
+ OICFree(cloneByteString.bytes);
+
+ OCRepPayloadDestroy(clone);
+}