#include "cainterface.h"
#include "cacommon.h"
+#define CA_TRANSPORT_ADAPTER_SCOPE 1000
class CATests : public testing::Test {
protected:
CAResult_t checkGetNetworkInfo();
CAResult_t checkSelectNetwork();
-void request_handler(const CAEndpoint_t *object, const CARequestInfo_t *requestInfo)
+void request_handler(const CAEndpoint_t * /*object*/,
+ const CARequestInfo_t * /*requestInfo*/)
{
}
-void response_handler(const CAEndpoint_t *object, const CAResponseInfo_t *responseInfo)
+void response_handler(const CAEndpoint_t * /*object*/,
+ const CAResponseInfo_t * /*responseInfo*/)
{
}
return;
}
-static char* uri = NULL;
static char* addr = NULL;
static CAEndpoint_t* tempRep = NULL;
static CARequestInfo_t requestInfo;
static CAResponseInfo_t responseInfo;
static CAToken_t tempToken = NULL;
static uint8_t tokenLength = CA_MAX_TOKEN_LEN;
-static const char URI[] = "coap://10.11.12.13:4545/a/light";
static const char ADDRESS[] = "10.11.12.13";
static const uint16_t PORT = 4545;
-static const char RESOURCE_URI[] = "/a/light";
-static const char SECURE_INFO_DATA[] =
- "{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
- "\"if\":[\"oc.mi.def\"],\"obs\":1,\"sec\":1,\"port\":%d}}]}";
static const char NORMAL_INFO_DATA[] =
"{\"oc\":[{\"href\":\"%s\",\"prop\":{\"rt\":[\"core.led\"],"
"\"if\":[\"oc.mi.def\"],\"obs\":1}}]}";
// check return value
TEST(StartListeningServerTest, DISABLED_TC_03_Positive_01)
{
- CASelectNetwork(CA_IPV4);
+ CASelectNetwork(CA_ADAPTER_IP);
EXPECT_EQ(CA_STATUS_OK, CAStartListeningServer());
}
CADestroyToken(tempToken);
FAIL() << "requestData.payload allocation failed";
}
- snprintf(requestData.payload, length, NORMAL_INFO_DATA, "a/light");
+ snprintf((char*)requestData.payload, length, NORMAL_INFO_DATA, "a/light");
+ requestData.payloadSize = length + 1;
requestData.type = CA_MSG_NONCONFIRM;
memset(&requestInfo, 0, sizeof(CARequestInfo_t));
memset(&responseData, 0, sizeof(CAInfo_t));
responseData.type = CA_MSG_NONCONFIRM;
responseData.messageId = 1;
- responseData.payload = (char *) "response payload";
+ responseData.payload = (CAPayload_t)malloc(sizeof("response payload"));
+
+ EXPECT_TRUE(responseData.payload != NULL);
+ if(!responseData.payload)
+ {
+ CADestroyEndpoint(tempRep);
+ return;
+ }
+
+ memcpy(responseData.payload, "response payload", sizeof("response payload"));
+ responseData.payloadSize = sizeof("response payload");
CAGenerateToken(&tempToken, tokenLength);
requestData.token = tempToken;
CADestroyToken(tempToken);
CADestroyEndpoint(tempRep);
+ free(responseData.payload);
tempRep = NULL;
}
memset(&responseData, 0, sizeof(CAInfo_t));
responseData.type = CA_MSG_NONCONFIRM;
responseData.messageId = 1;
- responseData.payload = (char *) "response payload";
+ responseData.payload = (CAPayload_t)malloc(sizeof("response payload"));
+ EXPECT_TRUE(responseData.payload != NULL);
+
+ if(!responseData.payload)
+ {
+ CADestroyEndpoint(tempRep);
+ return;
+ }
+
+ memcpy(responseData.payload, "response payload", sizeof("response payload"));
+ responseData.payloadSize = sizeof("response payload");
CAGenerateToken(&tempToken, tokenLength);
requestData.token = tempToken;
CADestroyEndpoint(tempRep);
tempRep = NULL;
}
+ free (responseData.payload);
}
// check return value NULL is passed instead of a valid CAResponseInfo_t address
memset(&responseData, 0, sizeof(CAInfo_t));
responseData.type = CA_MSG_NONCONFIRM;
- responseData.payload = (char *) "Temp Notification Data";
+ responseData.payload = (CAPayload_t)malloc(sizeof("Temp Notification Data"));
+
+ EXPECT_TRUE(responseData.payload != NULL);
+ if(!responseData.payload)
+ {
+ CADestroyEndpoint(tempRep);
+ return;
+ }
+
+ memcpy(responseData.payload, "Temp Notification Data", sizeof("Temp Notification Data"));
+ responseData.payloadSize = sizeof("Temp Notification Data");
CAGenerateToken(&tempToken, tokenLength);
requestData.token = tempToken;
CADestroyEndpoint(tempRep);
tempRep = NULL;
}
+ free(responseData.payload);
}
// CASelectNewwork TC
TEST_F(CATests, SelectNetworkTestBad)
{
//Select disable network
- EXPECT_EQ(CA_NOT_SUPPORTED, CASelectNetwork(1000));
+ EXPECT_EQ(CA_NOT_SUPPORTED, CASelectNetwork((CATransportAdapter_t)
+ CA_TRANSPORT_ADAPTER_SCOPE));
}
// check return value when selected network is disable
TEST_F(CATests, UnSelectNetworkTest)
{
//UnSelect disable network
- EXPECT_EQ(CA_STATUS_FAILED, CAUnSelectNetwork(1000));
+ EXPECT_EQ(CA_STATUS_FAILED, CAUnSelectNetwork((CATransportAdapter_t)
+ CA_TRANSPORT_ADAPTER_SCOPE));
}
// CAHandlerRequestResponse TC