summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamanway <samanway@linux-samanway.sa.corp.samsungelectronics.net>2020-04-30 00:16:27 +0530
committerSudipto <sudipto.bal@samsung.com>2020-06-16 16:07:07 +0530
commita2f913f8c28ab6029d0d9549788a3001c0218243 (patch)
treeef32f5fb216b9d49aafde3b7bc09984dd4d26dc4
parent6f92547c6778edcea814a5d83e789a6337132407 (diff)
downloadiotivity-a2f913f8c28ab6029d0d9549788a3001c0218243.tar.gz
iotivity-a2f913f8c28ab6029d0d9549788a3001c0218243.tar.bz2
iotivity-a2f913f8c28ab6029d0d9549788a3001c0218243.zip
Adding Unit Test for OCDirectPairing.cpp in IoTivity
- Added unit tests for OCDirectPairing.cpp - Enabled building by modifying SConscript https://github.sec.samsung.net/RS7-IOTIVITY/IoTivity/pull/685 (cherry-picked from eb2c92da91a723a7bf7876f09a1784ea514d383b) Change-Id: I6ad094fa4aba180c5846541bc36cf49978241fb1 Signed-off-by: samanway-dey <samanway.dey@samsung.com> Signed-off-by: Sudipto <sudipto.bal@samsung.com>
-rw-r--r--resource/unittests/OCDirectPairingTest.cpp113
-rw-r--r--resource/unittests/SConscript3
2 files changed, 115 insertions, 1 deletions
diff --git a/resource/unittests/OCDirectPairingTest.cpp b/resource/unittests/OCDirectPairingTest.cpp
new file mode 100644
index 000000000..6082c0e11
--- /dev/null
+++ b/resource/unittests/OCDirectPairingTest.cpp
@@ -0,0 +1,113 @@
+//******************************************************************
+//
+// Copyright 2020 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+
+#include "OCDirectPairing.h"
+#include <iomanip>
+#include <OCApi.h>
+#include <gtest/gtest.h>
+#include <string>
+#include <map>
+
+
+using namespace OC;
+
+TEST(getHost, getHost)
+{
+ OCDPDev_t* ptr = (OCDPDev_t*) calloc(1, sizeof(OCDPDev_t));
+ OCDevAddr addrs;
+ strcpy(addrs.addr, "192.168.0.1");
+ ptr->endpoint = addrs;
+ ptr->connType = CT_ADAPTER_IP;
+ ptr->securePort = 0xFF00;
+ OCUUIdentity devId;
+ memcpy(devId.id, "ABCDE1234567890", UUID_IDENTITY_SIZE);
+ ptr->deviceID = devId;
+ OCDirectPairing obj(ptr);
+ std::string str = obj.getHost();
+ EXPECT_EQ("coaps://192.168.0.1:65280", str);
+}
+
+TEST(getDeviceID, getDeviceID)
+{
+ OCDPDev_t* ptr = (OCDPDev_t*) calloc(1, sizeof(OCDPDev_t));
+ OCDevAddr addrs;
+ strcpy(addrs.addr, "192.168.0.1");
+ ptr->endpoint = addrs;
+ ptr->connType = CT_ADAPTER_IP;
+ ptr->securePort = 0xFF00;
+ OCUUIdentity devId;
+ memcpy(devId.id, "ABCDE1234567890", UUID_IDENTITY_SIZE);
+ ptr->deviceID = devId;
+ OCDirectPairing obj(ptr);
+ std::string str = obj.getDeviceID();
+ EXPECT_EQ("41424344-4531-3233-3435-363738393000", str);
+}
+
+TEST(getPairingMethods, getPairingMethods_success)
+{
+ OCDPDev_t* ptr = (OCDPDev_t*) calloc(1, sizeof(OCDPDev_t));
+ ptr->prm = (OCPrm_t *) calloc(3, sizeof(OCPrm_t));
+ ptr->prm[0] = DP_NOT_ALLOWED;
+ ptr->prm[1] = DP_PRE_CONFIGURED;
+ ptr->prm[2] = DP_RANDOM_PIN;
+ ptr->prmLen = 3;
+ std::vector<OCPrm_t> vctr;
+ OCDirectPairing obj(ptr);
+ vctr = obj.getPairingMethods();
+ EXPECT_EQ(ptr->prmLen, vctr.size());
+ for (int i = 0; i < ptr->prmLen; i++)
+ {
+ EXPECT_EQ(ptr->prm[i], vctr[i]);
+ }
+}
+
+TEST(getConnType, getConnType)
+{
+ OCDPDev_t* ptr = (OCDPDev_t*) calloc(1, sizeof(OCDPDev_t));
+ OCDevAddr addrs;
+ strcpy(addrs.addr, "192.168.0.1");
+ ptr->endpoint = addrs;
+ ptr->connType = CT_ADAPTER_IP;
+ ptr->securePort = 0xFF00;
+ OCUUIdentity devId;
+ memcpy(devId.id, "ABCDE1234567890", UUID_IDENTITY_SIZE);
+ ptr->deviceID = devId;
+ OCDirectPairing obj(ptr);
+ OCConnectivityType conn = obj.getConnType();
+ EXPECT_EQ(CT_ADAPTER_IP, conn);
+}
+
+TEST(getDev, getDev)
+{
+ OCDPDev_t* ptr = (OCDPDev_t*) calloc(1, sizeof(OCDPDev_t));
+ OCDevAddr addrs;
+ strcpy(addrs.addr, "192.168.0.1");
+ ptr->endpoint = addrs;
+ ptr->connType = CT_ADAPTER_IP;
+ ptr->securePort = 0xFF00;
+ OCUUIdentity devId;
+ unsigned char st[] = "ABCDE1234567890";
+ memcpy(devId.id, st, UUID_IDENTITY_SIZE);
+ ptr->deviceID = devId;
+ OCDirectPairing obj(ptr);
+ OCDPDev_t* devPtr;
+ devPtr = obj.getDev();
+ EXPECT_EQ(ptr, devPtr);
+} \ No newline at end of file
diff --git a/resource/unittests/SConscript b/resource/unittests/SConscript
index 50c59945b..7dbcce52a 100644
--- a/resource/unittests/SConscript
+++ b/resource/unittests/SConscript
@@ -78,7 +78,8 @@ unittests_src = [
'OCResourceTest.cpp',
'OCExceptionTest.cpp',
'OCResourceResponseTest.cpp',
- 'OCHeaderOptionTest.cpp'
+ 'OCHeaderOptionTest.cpp',
+ 'OCDirectPairingTest.cpp'
]
if (('SUB' in with_mq) or ('PUB' in with_mq) or ('BROKER' in with_mq)):