X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Funittests%2FOCPlatformTest.cpp;h=f2db5df553781d8e6bdd58ba14205712d169cb8b;hb=390866079e285d2c74918432c0d597d5da52f8a0;hp=078aa89f382e17702e08260abf64432a454f5bed;hpb=3e9402ad71cb3e93266a77796f44d17bab9853fd;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/unittests/OCPlatformTest.cpp b/resource/unittests/OCPlatformTest.cpp index 078aa89..f2db5df 100644 --- a/resource/unittests/OCPlatformTest.cpp +++ b/resource/unittests/OCPlatformTest.cpp @@ -20,12 +20,14 @@ #include #include +#include #include namespace OCPlatformTest { using namespace OC; + static const char* SVR_DB_FILE_NAME = "./oic_svr_db_server.dat"; const OCResourceHandle HANDLE_ZERO = 0; const std::string gResourceTypeName = "core.res"; const std::string gResourceInterface = DEFAULT_INTERFACE; @@ -35,9 +37,9 @@ namespace OCPlatformTest //OCPersistent Storage Handlers static FILE* client_open(const char * /*path*/, const char *mode) { - std::cout << "<===Opening SVR DB file = './oic_svr_db_client.json' with mode = '" << mode + std::cout << "<===Opening SVR DB file = './oic_svr_db_client.dat' with mode = '" << mode << "' " << std::endl; - return fopen("./oic_svr_db_client.json", mode); + return fopen(SVR_DB_FILE_NAME, mode); } OCPersistentStorage gps {client_open, fread, fwrite, fclose, unlink }; @@ -61,9 +63,22 @@ namespace OCPlatformTest } //Helper methods + void DeleteStringLL(OCStringLL* ll) + { + if (!ll) + { + return; + } + + DeleteStringLL(ll->next); + delete[] ll->value; + OICFree(ll); + } + void DeleteDeviceInfo(OCDeviceInfo deviceInfo) { delete[] deviceInfo.deviceName; + DeleteStringLL(deviceInfo.types); } @@ -73,6 +88,30 @@ namespace OCPlatformTest strncpy(*targetString, sourceString.c_str(), (sourceString.length() + 1)); } + bool OCResourcePayloadAddStringLL(OCStringLL **stringLL, std::string value) + { + char *dup = NULL; + DuplicateString(&dup, value); + if (!*stringLL) + { + *stringLL = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); + (*stringLL)->value = dup; + return true; + } + else + { + OCStringLL *temp = *stringLL; + while(temp->next) + { + temp = temp->next; + } + temp->next = (OCStringLL *)OICCalloc(1, sizeof(OCStringLL)); + temp->next->value = dup; + return true; + } + return false; + } + OCResourceHandle RegisterResource(std::string uri, std::string type, std::string iface) { PlatformConfig cfg @@ -697,15 +736,17 @@ namespace OCPlatformTest TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithValidParameters) { OCDeviceInfo deviceInfo; - DuplicateString(&deviceInfo.deviceName, "myDeviceName"); + deviceInfo.types = NULL; + OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.wk.d"); + OCResourcePayloadAddStringLL(&deviceInfo.types, "oic.d.tv"); EXPECT_EQ(OC_STACK_OK, OCPlatform::registerDeviceInfo(deviceInfo)); EXPECT_NO_THROW(DeleteDeviceInfo(deviceInfo)); } TEST(RegisterDeviceInfoTest, RegisterDeviceInfoWithEmptyObject) { - OCDeviceInfo di = {0}; + OCDeviceInfo di = {0, 0}; EXPECT_ANY_THROW(OCPlatform::registerDeviceInfo(di)); }