Adding Unit Test for OCDirectPairing.cpp in IoTivity 55/236355/1
authorsamanway <samanway@linux-samanway.sa.corp.samsungelectronics.net>
Wed, 29 Apr 2020 18:46:27 +0000 (00:16 +0530)
committerSudipto <sudipto.bal@samsung.com>
Tue, 16 Jun 2020 10:37:07 +0000 (16:07 +0530)
- 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>
resource/unittests/OCDirectPairingTest.cpp [new file with mode: 0644]
resource/unittests/SConscript

diff --git a/resource/unittests/OCDirectPairingTest.cpp b/resource/unittests/OCDirectPairingTest.cpp
new file mode 100644 (file)
index 0000000..6082c0e
--- /dev/null
@@ -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
index 50c5994..7dbcce5 100644 (file)
@@ -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)):