extern "C"
{
#include "ocstack.h"
+ #include "ocstackinternal.h"
#include "logger.h"
- #include "ocmalloc.h"
+ #include "oic_malloc.h"
}
#include "gtest/gtest.h"
#include <iostream>
#include <stdint.h>
+
+#include "gtest_helper.h"
+
using namespace std;
+namespace itst = iotivity::test;
+
#define DEFAULT_CONTEXT_VALUE 0x99
+
//-----------------------------------------------------------------------------
// Private variables
//-----------------------------------------------------------------------------
static const char TAG[] = "TestHarness";
+char gDeviceUUID[] = "myDeviceUUID";
+char gManufacturerName[] = "myName";
+char gTooLongManufacturerName[] = "extremelylongmanufacturername";
+char gManufacturerUrl[] = "www.foooooooooooooooo.baaaaaaaaaaaaar";
+static OCPrm_t pmSel;
+static char pinNumber;
+static OCDPDev_t peer;
+
+std::chrono::seconds const SHORT_TEST_TIMEOUT = std::chrono::seconds(5);
+
//-----------------------------------------------------------------------------
// Callback functions
//-----------------------------------------------------------------------------
-extern "C" OCStackApplicationResult asyncDoResourcesCallback(void* ctx, OCDoHandle handle, OCClientResponse * clientResponse)
+extern "C" OCStackApplicationResult asyncDoResourcesCallback(void* ctx,
+ OCDoHandle /*handle*/, OCClientResponse * clientResponse)
{
- OC_LOG(INFO, TAG, "Entering asyncDoResourcesCallback");
+ OIC_LOG(INFO, TAG, "Entering asyncDoResourcesCallback");
EXPECT_EQ(OC_STACK_OK, clientResponse->result);
if(ctx == (void*)DEFAULT_CONTEXT_VALUE) {
- OC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
+ OIC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
}
- OC_LOG_V(INFO, TAG, "result = %d", clientResponse->result);
+ OIC_LOG_V(INFO, TAG, "result = %d", clientResponse->result);
+
+ return OC_STACK_KEEP_TRANSACTION;
+}
+
+static void resultCallback(OCDPDev_t *UNUSED1, OCStackResult UNUSED2)
+{
+ (void) (UNUSED1);
+ (void) (UNUSED2);
+}
+
+extern "C" OCStackApplicationResult discoveryCallback(void* ctx,
+ OCDoHandle /*handle*/, OCClientResponse * clientResponse)
+{
+ OIC_LOG(INFO, TAG, "Entering asyncDoResourcesCallback");
+
+ EXPECT_EQ(OC_STACK_OK, clientResponse->result);
+
+ if(ctx == (void*)DEFAULT_CONTEXT_VALUE)
+ {
+ OIC_LOG_V(INFO, TAG, "Callback Context recvd successfully");
+ }
+
+ OIC_LOG_V(INFO, TAG, "result = %d", clientResponse->result);
+
+ OCDiscoveryPayload *discoveryPayload = ((OCDiscoveryPayload *) clientResponse->payload);
+ EXPECT_TRUE(discoveryPayload != NULL);
+ OCResourcePayload *res = discoveryPayload->resources;
+ size_t count = 0;
+ for (OCResourcePayload *res1 = discoveryPayload->resources; res1; res1 = res1->next)
+ {
+ count++;
+ }
+ EXPECT_EQ(3, count);
+ EXPECT_EQ("/a/led1", res->uri);
+ res = res->next;
+ EXPECT_EQ("/a/led2", res->uri);
+ res = res->next;
+ EXPECT_EQ("/a/led3", res->uri);
+ res = res->next;
+ EXPECT_TRUE(res == NULL);
return OC_STACK_KEEP_TRANSACTION;
}
//-----------------------------------------------------------------------------
// Entity handler
//-----------------------------------------------------------------------------
-OCEntityHandlerResult entityHandler(OCEntityHandlerFlag flag, OCEntityHandlerRequest * entityHandlerRequest)
+OCEntityHandlerResult entityHandler(OCEntityHandlerFlag /*flag*/,
+ OCEntityHandlerRequest * /*entityHandlerRequest*/,
+ void* /*callbackParam*/)
{
- OC_LOG(INFO, TAG, "Entering entityHandler");
+ OIC_LOG(INFO, TAG, "Entering entityHandler");
return OC_EH_OK;
}
//-----------------------------------------------------------------------------
void InitStack(OCMode mode)
{
- OC_LOG(INFO, TAG, "Entering InitStack");
+ OIC_LOG(INFO, TAG, "Entering InitStack");
EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, mode));
- OC_LOG(INFO, TAG, "Leaving InitStack");
+ OIC_LOG(INFO, TAG, "Leaving InitStack");
}
uint8_t InitNumExpectedResources()
TEST(StackInit, StackInitNullAddr)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit(0, 5683, OC_SERVER));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackInit, StackInitNullPort)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 0, OC_SERVER));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackInit, StackInitNullAddrAndPort)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit(0, 0, OC_SERVER));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackInit, StackInitInvalidMode)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_ERROR, OCInit(0, 0, (OCMode)10));
EXPECT_EQ(OC_STACK_ERROR, OCStop());
}
TEST(StackStart, StackStartSuccessClient)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackStart, StackStartSuccessServer)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackStart, StackStartSuccessClientServer)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT_SERVER));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackStart, StackStartSuccessiveInits)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.2", 5683, OC_SERVER));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
-TEST(StackDiscovery, DoResourceDeviceDiscovery)
+TEST(StackStart, SetPlatformInfoValid)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+
+ OCPlatformInfo info =
+ {
+ gDeviceUUID,
+ gManufacturerName,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ EXPECT_EQ(OC_STACK_OK, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetPlatformInfoWithClientMode)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
+
+ OCPlatformInfo info =
+ {
+ gDeviceUUID,
+ gManufacturerName,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ EXPECT_EQ(OC_STACK_ERROR, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetPlatformInfoWithNoPlatformID)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+
+ OCPlatformInfo info =
+ {
+ 0,
+ gDeviceUUID,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetPlatformInfoWithNoManufacturerName)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+
+ OCPlatformInfo info =
+ {
+ gDeviceUUID,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetPlatformInfoWithZeroLengthManufacturerName)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+
+ OCPlatformInfo info =
+ {
+ gDeviceUUID,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+ info.manufacturerName = (char *) "";
+
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetPlatformInfoWithTooLongManufacName)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+
+ OCPlatformInfo info =
+ {
+ gDeviceUUID,
+ gTooLongManufacturerName,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackStart, SetPlatformInfoWithTooLongManufacURL)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_SERVER));
+ OCPlatformInfo info =
+ {
+ gDeviceUUID,
+ gManufacturerName,
+ gManufacturerUrl,
+ 0, 0, 0, 0, 0, 0, 0, 0
+ };
+
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetPlatformInfo(info));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackDiscovery, DISABLED_DoResourceDeviceDiscovery)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
OCCallbackData cbData;
OCDoHandle handle;
- OC_LOG(INFO, TAG, "Starting DoResourceDeviceDiscovery test ");
+ OIC_LOG(INFO, TAG, "Starting DoResourceDeviceDiscovery test ");
InitStack(OC_CLIENT);
/* Start a discovery query*/
char szQueryUri[64] = { 0 };
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
+ strcpy(szQueryUri, OC_RSRVD_WELL_KNOWN_URI);
cbData.cb = asyncDoResourcesCallback;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
szQueryUri,
0,
0,
- OC_WIFI,
+ CT_ADAPTER_IP,
OC_LOW_QOS,
&cbData,
NULL,
TEST(StackStop, StackStopWithoutInit)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ EXPECT_EQ(OC_STACK_ERROR, OCStop());
+}
+
+TEST(StackStop, StackStopRepeated)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
EXPECT_EQ(OC_STACK_OK, OCInit("127.0.0.1", 5683, OC_CLIENT));
EXPECT_EQ(OC_STACK_OK, OCStop());
EXPECT_EQ(OC_STACK_ERROR, OCStop());
}
-TEST(StackResource, UpdateResourceNullURI)
+TEST(StackResource, DISABLED_UpdateResourceNullURI)
{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
OCCallbackData cbData;
OCDoHandle handle;
- OC_LOG(INFO, TAG, "Starting UpdateResourceNullURI test");
+ OIC_LOG(INFO, TAG, "Starting UpdateResourceNullURI test");
InitStack(OC_CLIENT);
/* Start a discovery query*/
char szQueryUri[64] = { 0 };
- strcpy(szQueryUri, OC_WELL_KNOWN_QUERY);
+ strcpy(szQueryUri, OC_RSRVD_WELL_KNOWN_URI);
cbData.cb = asyncDoResourcesCallback;
cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
cbData.cd = NULL;
szQueryUri,
0,
0,
- OC_WIFI,
+ CT_ADAPTER_IP,
OC_LOW_QOS,
&cbData,
NULL,
TEST(StackResource, CreateResourceBadParams)
{
- OC_LOG(INFO, TAG, "Starting CreateResourceBadParams test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceBadParams test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
// Property bitmask out of range
"core.rw",
"/a/led",
0,
+ NULL,
128));// invalid bitmask for OCResourceProperty
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+TEST(StackResource, CreateResourceBadUri)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceBadUri test");
+ InitStack(OC_SERVER);
+
+ const char *uri65 = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKL";
+
+ OCResourceHandle handle;
+
+ EXPECT_EQ(OC_STACK_INVALID_URI, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ NULL, //"/a/led",
+ 0,
+ 0,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ EXPECT_EQ(OC_STACK_INVALID_URI, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ "", //"/a/led",
+ 0,
+ 0,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ EXPECT_EQ(OC_STACK_INVALID_URI, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ uri65, //"/a/led",
+ 0,
+ 0,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
TEST(StackResource, CreateResourceSuccess)
{
- OC_LOG(INFO, TAG, "Starting CreateResourceSuccess test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceSuccess test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
const char *url = OCGetResourceUri(handle);
EXPECT_STREQ("/a/led", url);
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+TEST(StackResource, CreateResourceSuccessWithResourcePolicyPropNone)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceSuccessWithResourcePolicyPropNone test");
+ InitStack(OC_SERVER);
+
+ OCResourceHandle handle;
+ // the resource is non-discoverable & non-observable by the client.
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ "/a/led",
+ 0,
+ NULL,
+ OC_RES_PROP_NONE));// the resource is non-discoverable &
+ // non-observable by the client.
+ const char* url = OCGetResourceUri(handle);
+ EXPECT_STREQ("/a/led", url);
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackResource, CreateResourceWithClientStackMode)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceSuccess test");
+ InitStack(OC_CLIENT);
+
+ OCResourceHandle handle;
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ "/a/led",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
TEST(StackResource, CreateResourceFailDuplicateUri)
{
- OC_LOG(INFO, TAG, "Starting CreateResourceFailDuplicateUri test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceFailDuplicateUri test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
const char *url = OCGetResourceUri(handle);
EXPECT_STREQ("/a/led", url);
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCStop());
TEST(StackResource, CreateResourceMultipleResources)
{
- OC_LOG(INFO, TAG, "Starting CreateResourceMultipleResources test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceMultipleResources test");
InitStack(OC_SERVER);
OCResourceHandle handle1;
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
OCResourceHandle handle2;
"core.rw",
"/a/led2",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
OCResourceHandle handle3;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
"core.rw",
"/a/led3",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
const char *url = OCGetResourceUri(handle1);
TEST(StackResource, CreateResourceBadResoureType)
{
- OC_LOG(INFO, TAG, "Starting CreateResourceBadResoureType test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceBadResoureType test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ OCResourceHandle handle2;
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCreateResource(&handle2,
+ "",
+ "core.rw",
+ "/a/led",
+ 0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCStop());
TEST(StackResource, CreateResourceGoodResourceType)
{
- OC_LOG(INFO, TAG, "Starting CreateResourceGoodResourceType test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting CreateResourceGoodResourceType test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCStop());
TEST(StackResource, ResourceTypeName)
{
- OC_LOG(INFO, TAG, "Starting ResourceTypeName test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting ResourceTypeName test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceTypes;
TEST(StackResource, ResourceTypeAttrRepresentation)
{
- OC_LOG(INFO, TAG, "Starting ResourceTypeAttrRepresentation test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting ResourceTypeAttrRepresentation test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceTypes;
TEST(StackResource, ResourceTypeInterface)
{
- OC_LOG(INFO, TAG, "Starting ResourceTypeInterface test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting ResourceTypeInterface test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
- const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
+ EXPECT_EQ(2, numResourceInterfaces);
+ const char *resourceInterfaceName1 = OCGetResourceInterfaceName(handle, 0);
+ EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, resourceInterfaceName1);
+ const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
EXPECT_STREQ("core.rw", resourceInterfaceName);
// try getting resource interface names with an invalid index
- resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
+ resourceInterfaceName = OCGetResourceInterfaceName(handle, 2);
EXPECT_STREQ(NULL, resourceInterfaceName);
// try getting resource interface names with an invalid index
resourceInterfaceName = OCGetResourceInterfaceName(handle, 10);
EXPECT_EQ(OC_STACK_OK, OCStop());
}
+TEST(StackResource, ResourceDefaultInterfaceAlwaysFirst)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+ OIC_LOG(INFO, TAG, "Starting ResourceDefaultInterfaceAlwaysFirst test");
+
+ InitStack(OC_SERVER);
+
+ OCResourceHandle handle;
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ "/a/led",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle,
+ OC_RSRVD_INTERFACE_DEFAULT));
+ uint8_t numResourceInterfaces;
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
+ EXPECT_EQ(2, numResourceInterfaces);
+
+ const char *interfaceName_1 = OCGetResourceInterfaceName(handle, 0);
+ EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, interfaceName_1);
+
+ const char*interfaceName_2 = OCGetResourceInterfaceName(handle, 1);
+ EXPECT_STREQ("core.rw", interfaceName_2);
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackResource, ResourceDuplicateDefaultInterfaces)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+ OIC_LOG(INFO, TAG, "Starting ResourceDuplicateDefaultInterfaces test");
+
+ InitStack(OC_SERVER);
+
+ OCResourceHandle handle;
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ "/a/led",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle,
+ OC_RSRVD_INTERFACE_DEFAULT));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle,
+ OC_RSRVD_INTERFACE_DEFAULT));
+
+ uint8_t numResourceInterfaces;
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
+ EXPECT_EQ(2, numResourceInterfaces);
+
+ const char *interfaceName_1 = OCGetResourceInterfaceName(handle, 0);
+ EXPECT_STREQ(OC_RSRVD_INTERFACE_DEFAULT, interfaceName_1);
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
+TEST(StackResource, ResourceDuplicateNonDefaultInterfaces)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+
+ OIC_LOG(INFO, TAG, "Starting ResourceDuplicateInterfaces test");
+
+ InitStack(OC_SERVER);
+
+ OCResourceHandle handle;
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
+ "core.led",
+ "core.rw",
+ "/a/led",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle,
+ "core.rw"));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle,
+ "core.rw"));
+
+ uint8_t numResourceInterfaces;
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
+ EXPECT_EQ(2, numResourceInterfaces);
+
+ EXPECT_EQ(OC_STACK_OK, OCStop());
+}
+
TEST(StackResource, ResourceTypeInterfaceMethods)
{
- OC_LOG(INFO, TAG, "Starting ResourceTypeInterfaceMethods test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting ResourceTypeInterfaceMethods test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
+ EXPECT_EQ(2, numResourceInterfaces);
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackResource, GetResourceProperties)
{
- OC_LOG(INFO, TAG, "Starting GetResourceProperties test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting GetResourceProperties test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_ACTIVE|OC_DISCOVERABLE|OC_OBSERVABLE, OCGetResourceProperties(handle));
TEST(StackResource, StackTestResourceDiscoverOneResourceBad)
{
- OC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverOneResourceBad test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverOneResourceBad test");
InitStack(OC_SERVER);
+ uint8_t numResources = 0;
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
OCResourceHandle handle;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle,
"core.rw",
"/a1/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
const char *url = OCGetResourceUri(handle);
EXPECT_STREQ("/a1/led", url);
//EXPECT_EQ(OC_STACK_INVALID_URI, OCHandleServerRequest(&res, uri, query, req, rsp));
EXPECT_EQ(OC_STACK_OK, OCDeleteResource(handle));
- uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
+ uint8_t numExpectedResources = 0;
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
EXPECT_EQ(numExpectedResources, numResources);
EXPECT_EQ(OC_STACK_OK, OCStop());
TEST(StackResource, StackTestResourceDiscoverOneResource)
{
- OC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverOneResource test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverOneResource test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
const char *url = OCGetResourceUri(handle);
EXPECT_STREQ("/a/led", url);
TEST(StackResource, StackTestResourceDiscoverManyResources)
{
- OC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverManyResources test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting StackTestResourceDiscoverManyResources test");
InitStack(OC_SERVER);
OCResourceHandle handle1;
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE));
const char *url = OCGetResourceUri(handle1);
EXPECT_STREQ("/a/led1", url);
"core.rw",
"/a/led2",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
url = OCGetResourceUri(handle2);
EXPECT_STREQ("/a/led2", url);
"core.rw",
"/a/led3",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
url = OCGetResourceUri(handle3);
EXPECT_STREQ("/a/led3", url);
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.ll"));
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, "oc.mi.b"));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, OC_RSRVD_INTERFACE_LL));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle3, OC_RSRVD_INTERFACE_BATCH));
OCResourceHandle handle4;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle4,
"core.rw",
"/a/led4",
0,
+ NULL,
OC_DISCOVERABLE));
url = OCGetResourceUri(handle4);
EXPECT_STREQ("/a/led4", url);
EXPECT_EQ(OC_STACK_OK, OCBindResourceTypeToResource(handle4, "core.brightled"));
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.ll"));
- EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, "oc.mi.b"));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, OC_RSRVD_INTERFACE_LL));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle4, OC_RSRVD_INTERFACE_BATCH));
//EXPECT_EQ(OC_STACK_OK, OCHandleServerRequest(&res, uri, query, req, rsp));
TEST(StackBind, BindResourceTypeNameBad)
{
- OC_LOG(INFO, TAG, "Starting BindResourceTypeNameBad test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceTypeNameBad test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceTypes;
TEST(StackBind, BindResourceTypeNameGood)
{
- OC_LOG(INFO, TAG, "Starting BindResourceTypeNameGood test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceTypeNameGood test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceTypes;
TEST(StackBind, BindResourceTypeAttribRepGood)
{
- OC_LOG(INFO, TAG, "Starting BindResourceTypeAttribRepGood test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceTypeAttribRepGood test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceTypes;
TEST(StackBind, BindResourceInterfaceNameBad)
{
- OC_LOG(INFO, TAG, "Starting BindResourceInterfaceNameBad test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceInterfaceNameBad test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
- const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
+ EXPECT_EQ(2, numResourceInterfaces);
+ const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
EXPECT_STREQ("core.rw", resourceInterfaceName);
EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceInterfaceToResource(handle, NULL));
TEST(StackBind, BindResourceInterfaceNameGood)
{
- OC_LOG(INFO, TAG, "Starting BindResourceInterfaceNameGood test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceInterfaceNameGood test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
- const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 0);
+ EXPECT_EQ(2, numResourceInterfaces);
+ const char *resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
EXPECT_STREQ("core.rw", resourceInterfaceName);
EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle, "core.r"));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(2, numResourceInterfaces);
- resourceInterfaceName = OCGetResourceInterfaceName(handle, 1);
+ EXPECT_EQ(3, numResourceInterfaces);
+ resourceInterfaceName = OCGetResourceInterfaceName(handle, 2);
EXPECT_STREQ("core.r", resourceInterfaceName);
EXPECT_EQ(OC_STACK_OK, OCStop());
TEST(StackBind, BindResourceInterfaceMethodsBad)
{
- OC_LOG(INFO, TAG, "Starting BindResourceInterfaceMethodsBad test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceInterfaceMethodsBad test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
+ EXPECT_EQ(2, numResourceInterfaces);
EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceInterfaceToResource(handle, 0));
TEST(StackBind, BindResourceInterfaceMethodsGood)
{
- OC_LOG(INFO, TAG, "Starting BindResourceInterfaceMethodsGood test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindResourceInterfaceMethodsGood test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
+ EXPECT_EQ(2, numResourceInterfaces);
EXPECT_EQ(OC_STACK_OK, OCBindResourceInterfaceToResource(handle, "core.r"));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle, &numResourceInterfaces));
- EXPECT_EQ(2, numResourceInterfaces);
+ EXPECT_EQ(3, numResourceInterfaces);
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackBind, BindContainedResourceBad)
{
- OC_LOG(INFO, TAG, "Starting BindContainedResourceBad test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindContainedResourceBad test");
InitStack(OC_SERVER);
OCResourceHandle containerHandle;
"core.rw",
"/a/kitchen",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
OCResourceHandle handle0;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResource(containerHandle, containerHandle));
TEST(StackBind, BindContainedResourceGood)
{
- OC_LOG(INFO, TAG, "Starting BindContainedResourceGood test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindContainedResourceGood test");
InitStack(OC_SERVER);
uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
+ uint8_t numExpectedResources = 0;
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
- EXPECT_EQ(numExpectedResources, numResources);
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
OCResourceHandle containerHandle;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
"core.rw",
"/a/kitchen",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led0",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led2",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led3",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led4",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led5",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle2));
EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle3));
EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle4));
- EXPECT_EQ(OC_STACK_ERROR, OCBindResource(containerHandle, handle5));
+ EXPECT_EQ(OC_STACK_OK, OCBindResource(containerHandle, handle5));
EXPECT_EQ(handle0, OCGetResourceHandleFromCollection(containerHandle, 0));
EXPECT_EQ(handle1, OCGetResourceHandleFromCollection(containerHandle, 1));
EXPECT_EQ(handle2, OCGetResourceHandleFromCollection(containerHandle, 2));
EXPECT_EQ(handle3, OCGetResourceHandleFromCollection(containerHandle, 3));
EXPECT_EQ(handle4, OCGetResourceHandleFromCollection(containerHandle, 4));
-
- EXPECT_EQ(NULL, OCGetResourceHandleFromCollection(containerHandle, 5));
+ EXPECT_EQ(handle5, OCGetResourceHandleFromCollection(containerHandle, 5));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackBind, BindEntityHandlerBad)
{
- OC_LOG(INFO, TAG, "Starting BindEntityHandlerBad test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindEntityHandlerBad test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
- EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceHandler(NULL, NULL));
+ EXPECT_EQ(OC_STACK_INVALID_PARAM, OCBindResourceHandler(NULL, NULL, NULL));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackBind, BindEntityHandlerGood)
{
- OC_LOG(INFO, TAG, "Starting BindEntityHandlerGood test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting BindEntityHandlerGood test");
InitStack(OC_SERVER);
OCResourceHandle handle;
"core.rw",
"/a/led",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
OCEntityHandler myHandler = entityHandler;
- EXPECT_EQ(OC_STACK_OK, OCBindResourceHandler(handle, myHandler));
+ EXPECT_EQ(OC_STACK_OK, OCBindResourceHandler(handle, myHandler, NULL));
EXPECT_EQ(myHandler, OCGetResourceHandler(handle));
TEST(StackResourceAccess, GetResourceByIndex)
{
- OC_LOG(INFO, TAG, "Starting GetResourceByIndex test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting GetResourceByIndex test");
InitStack(OC_SERVER);
uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
- uint8_t resourceIndex = InitResourceIndex();
-
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
- EXPECT_EQ(numExpectedResources, numResources);
-
+ uint8_t numExpectedResources = 0;
+ uint8_t resourceIndex = 0;
+ uint8_t prevResources = 0;
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
+ prevResources = numExpectedResources;
OCResourceHandle containerHandle;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&containerHandle,
"core.led",
"core.rw",
"/a/kitchen",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led0",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led2",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led3",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led4",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led5",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
-
+ resourceIndex += prevResources;
EXPECT_EQ(containerHandle, OCGetResourceHandle(resourceIndex));
EXPECT_EQ(handle0, OCGetResourceHandle(++resourceIndex));
EXPECT_EQ(handle1, OCGetResourceHandle(++resourceIndex));
TEST(StackResourceAccess, DeleteHeadResource)
{
- OC_LOG(INFO, TAG, "Starting DeleteHeadResource test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting DeleteHeadResource test");
InitStack(OC_SERVER);
uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
+ uint8_t numExpectedResources = 0;
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
- EXPECT_EQ(numExpectedResources, numResources);
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
OCResourceHandle handle0;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
"core.rw",
"/a/led0",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
TEST(StackResourceAccess, DeleteHeadResource2)
{
- OC_LOG(INFO, TAG, "Starting DeleteHeadResource2 test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting DeleteHeadResource2 test");
InitStack(OC_SERVER);
uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
- uint8_t resourceIndex = InitResourceIndex();
-
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
- EXPECT_EQ(numExpectedResources, numResources);
+ uint8_t numExpectedResources = 0;
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
OCResourceHandle handle0;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
"core.led",
"core.rw",
"/a/led0",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(--numExpectedResources, numResources);
- EXPECT_EQ(handle1, OCGetResourceHandle(resourceIndex));
+ EXPECT_EQ(handle1, OCGetResourceHandle(numResources - 1));
EXPECT_EQ(OC_STACK_OK, OCStop());
}
TEST(StackResourceAccess, DeleteLastResource)
{
- OC_LOG(INFO, TAG, "Starting DeleteLastResource test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting DeleteLastResource test");
InitStack(OC_SERVER);
uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
- uint8_t resourceIndex = InitResourceIndex();
+ uint8_t numExpectedResources = 0;
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
- EXPECT_EQ(numExpectedResources, numResources);
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
OCResourceHandle handle0;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
"core.rw",
"/a/led0",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(--numExpectedResources, numResources);
- EXPECT_EQ(handle0, OCGetResourceHandle(resourceIndex));
+ EXPECT_EQ(handle0, OCGetResourceHandle(numResources - 1));
OCResourceHandle handle2;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
"core.rw",
"/a/led2",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
TEST(StackResourceAccess, DeleteMiddleResource)
{
- OC_LOG(INFO, TAG, "Starting DeleteMiddleResource test");
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting DeleteMiddleResource test");
InitStack(OC_SERVER);
uint8_t numResources = 0;
- uint8_t numExpectedResources = InitNumExpectedResources();
+ uint8_t numExpectedResources = 0;
uint8_t resourceIndex = InitResourceIndex();
- EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
- EXPECT_EQ(numExpectedResources, numResources);
-
+ EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numExpectedResources));
+ resourceIndex = numExpectedResources;
OCResourceHandle handle0;
EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle0,
"core.led",
"core.rw",
"/a/led0",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led1",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
"core.rw",
"/a/led2",
0,
+ NULL,
OC_DISCOVERABLE|OC_OBSERVABLE));
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResources(&numResources));
EXPECT_EQ(++numExpectedResources, numResources);
// Make sure the resource elements are still correct
uint8_t numResourceInterfaces;
EXPECT_EQ(OC_STACK_OK, OCGetNumberOfResourceInterfaces(handle2, &numResourceInterfaces));
- EXPECT_EQ(1, numResourceInterfaces);
- const char *resourceInterfaceName = OCGetResourceInterfaceName(handle2, 0);
+ EXPECT_EQ(2, numResourceInterfaces);
+ const char *resourceInterfaceName = OCGetResourceInterfaceName(handle2, 1);
EXPECT_STREQ("core.rw", resourceInterfaceName);
EXPECT_EQ(OC_STACK_OK, OCStop());
}
-
-#ifdef __cplusplus
-extern "C" {
-#endif // __cplusplus
- void parsePresencePayload(char* payload, uint32_t* seqNum, uint32_t* maxAge, char** resType);
-#ifdef __cplusplus
+TEST(PODTests, OCHeaderOption)
+{
+ EXPECT_TRUE(std::is_pod<OCHeaderOption>::value);
}
-#endif // __cplusplus
-TEST(StackPresence, ParsePresencePayload)
+TEST(PODTests, OCCallbackData)
{
+ EXPECT_TRUE(std::is_pod<OCHeaderOption>::value);
+}
- OC_LOG(INFO, TAG, "Starting ParsePresencePayload test");
-
- char payload[100];
- uint32_t seqNum = 0, maxAge = 0;
- char * resType = NULL;
-
- //Good Scenario
- strncpy(payload, "{\"oc\":[100:99:presence]}", sizeof(payload));
- parsePresencePayload(payload, &seqNum, &maxAge, &resType);
- EXPECT_TRUE(100 == seqNum);
- EXPECT_TRUE(99 == maxAge);
- EXPECT_STREQ("presence", resType);
- OCFree(resType);
+TEST(OCDoDirectPairingTests, Nullpeer)
+{
+ EXPECT_EQ(OC_STACK_INVALID_PARAM,OCDoDirectPairing(NULL, pmSel, &pinNumber, &resultCallback));
+}
- //Bad Scenario -- should not result in Seg Fault
- parsePresencePayload(payload, NULL, &maxAge, &resType);
+TEST(OCDoDirectPairingTests, NullCallback)
+{
+ EXPECT_EQ(OC_STACK_INVALID_CALLBACK,OCDoDirectPairing(&peer, pmSel, &pinNumber, NULL));
+}
- //Bad Scenario
- seqNum = 0; maxAge = 0; resType = NULL;
- strncpy(payload, "{abracadabra}", sizeof(payload));
- parsePresencePayload(payload, &seqNum, &maxAge, &resType);
- EXPECT_TRUE(0 == seqNum);
- EXPECT_TRUE(0 == maxAge);
- EXPECT_EQ(NULL, resType);
- OCFree(resType);
+TEST(OCDoDirectPairingTests, NullpinNumber)
+{
+ EXPECT_EQ(OC_STACK_INVALID_PARAM,OCDoDirectPairing(&peer, pmSel, NULL, &resultCallback));
+}
- //Bad Scenario
- seqNum = 0; maxAge = 0; resType = NULL;
- strncpy(payload, "{\"oc\":[100]}", sizeof(payload));
- parsePresencePayload(payload, &seqNum, &maxAge, &resType);
- EXPECT_TRUE(100 == seqNum);
- EXPECT_TRUE(0 == maxAge);
- EXPECT_EQ(NULL, resType);
- OCFree(resType);
+TEST(StackResource, MultipleResourcesDiscovery)
+{
+ itst::DeadmanTimer killSwitch(SHORT_TEST_TIMEOUT);
+ OIC_LOG(INFO, TAG, "Starting MultipleResourcesDiscovery test");
+ InitStack(OC_SERVER);
- //Bad Scenario
- seqNum = 0; maxAge = 0; resType = NULL;
- strncpy(payload, "{\"oc\":[]}", sizeof(payload));
- parsePresencePayload(payload, &seqNum, &maxAge, &resType);
- EXPECT_TRUE(0 == seqNum);
- EXPECT_TRUE(0 == maxAge);
- EXPECT_EQ(NULL, resType);
- OCFree(resType);
+ OCResourceHandle handle1;
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle1,
+ "core.led",
+ "core.rw",
+ "/a/led1",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
- //Bad Scenario
- strncpy(payload, "{:]}", sizeof(payload));
- parsePresencePayload(payload, &seqNum, &maxAge, &resType);
- EXPECT_TRUE(0 == seqNum);
- EXPECT_TRUE(0 == maxAge);
- EXPECT_EQ(NULL, resType);
- OCFree(resType);
+ OCResourceHandle handle2;
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle2,
+ "core.led",
+ "core.rw",
+ "/a/led2",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+ OCResourceHandle handle3;
+ EXPECT_EQ(OC_STACK_OK, OCCreateResource(&handle3,
+ "core.led",
+ "core.rw",
+ "/a/led3",
+ 0,
+ NULL,
+ OC_DISCOVERABLE|OC_OBSERVABLE));
+ /* Start a discovery query*/
+ char szQueryUri[256] = "/oic/res?if=oic.if.ll";
+ OCCallbackData cbData;
+ cbData.cb = discoveryCallback;
+ cbData.context = (void*)DEFAULT_CONTEXT_VALUE;
+ cbData.cd = NULL;
- //Bad Scenario
- strncpy(payload, "{:[presence}", sizeof(payload));
- parsePresencePayload(payload, &seqNum, &maxAge, &resType);
- EXPECT_TRUE(0 == seqNum);
- EXPECT_TRUE(0 == maxAge);
- EXPECT_EQ(NULL, resType);
- OCFree(resType);
+ OCDoHandle handle;
+ EXPECT_EQ(OC_STACK_OK, OCDoResource(&handle,
+ OC_REST_DISCOVER,
+ szQueryUri,
+ 0,
+ 0,
+ CT_ADAPTER_IP,
+ OC_LOW_QOS,
+ &cbData,
+ NULL,
+ 0));
+ EXPECT_EQ(OC_STACK_OK, OCStop());
}
-
-