#include <OCPlatform.h>
#include <OCApi.h>
+#include <oic_malloc.h>
#include <gtest/gtest.h>
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;
//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 };
}
//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);
}
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
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));
}