From a2f913f8c28ab6029d0d9549788a3001c0218243 Mon Sep 17 00:00:00 2001 From: samanway Date: Thu, 30 Apr 2020 00:16:27 +0530 Subject: [PATCH] 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 Signed-off-by: Sudipto --- resource/unittests/OCDirectPairingTest.cpp | 113 +++++++++++++++++++++++++++++ resource/unittests/SConscript | 3 +- 2 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 resource/unittests/OCDirectPairingTest.cpp diff --git a/resource/unittests/OCDirectPairingTest.cpp b/resource/unittests/OCDirectPairingTest.cpp new file mode 100644 index 0000000..6082c0e --- /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 +#include +#include +#include +#include + + +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 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 50c5994..7dbcce5 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)): -- 2.7.4