The provisioning unittest 69/29569/1
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Wed, 26 Jun 2019 10:38:20 +0000 (13:38 +0300)
committerOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Wed, 26 Jun 2019 10:46:45 +0000 (13:46 +0300)
deviceonboardingstate tests added

Change-Id: Idd2f65bfab3909ac139d5e24855cc0e57ddbfe4c
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
resource/csdk/security/provisioning/unittest/SConscript
resource/csdk/security/provisioning/unittest/deviceonboardingstate.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/otmunittest.cpp
resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp

index 585951b..89759bf 100644 (file)
@@ -232,7 +232,8 @@ if target_os in ['linux']:
         'oxmmanufacturercert.cpp',
         'oxmrandompin.cpp',
         'credentialgenerator.cpp',
-        'otmunittest.cpp'
+        'otmunittest.cpp',
+        'deviceonboardingstate.cpp'
     ]
     if sptest_env.get('WITH_TCP') == True and sptest_env.get('WITH_CLOUD') == True:
         unittest_src.append('cloudresource.cpp')
diff --git a/resource/csdk/security/provisioning/unittest/deviceonboardingstate.cpp b/resource/csdk/security/provisioning/unittest/deviceonboardingstate.cpp
new file mode 100644 (file)
index 0000000..82f0cf1
--- /dev/null
@@ -0,0 +1,78 @@
+/* *****************************************************************
+ *
+ * Copyright 2019 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 <stdio.h>
+#include <stdlib.h>
+#include <gtest/gtest.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "ocprovisioningmanager.h"
+#include "../src/deviceonboardingstate.c"
+#include "tools.h"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#define TAG "DOBT_UNITTEST"
+
+#define SVR_DB_FILE_NAME "oic_dobt.dat"
+#define PM_DB_FILE_NAME "oic_dovt.db"
+
+using namespace std;
+
+class DOBT : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
+TEST_F(DOBT, DoStateChange)
+{
+    EXPECT_EQ(OC_STACK_OK, DoStateChange(DOS_RESET));
+    EXPECT_EQ(OC_STACK_OK, DoStateChange(DOS_RFOTM));
+    EXPECT_EQ(OC_STACK_FORBIDDEN_REQ, DoStateChange(DOS_RFPRO));
+    EXPECT_EQ(OC_STACK_FORBIDDEN_REQ, DoStateChange(DOS_RFNOP));
+    EXPECT_EQ(OC_STACK_FORBIDDEN_REQ, DoStateChange(DOS_SRESET));
+
+    OicUuid_t *owner = createUuid();
+
+    EXPECT_EQ(OC_STACK_OK, SetDoxmSelfOwnership(owner));
+
+    EXPECT_EQ(OC_STACK_OK, DoStateChange(DOS_RESET));
+    EXPECT_EQ(OC_STACK_OK, DoStateChange(DOS_RFOTM));
+    EXPECT_EQ(OC_STACK_FORBIDDEN_REQ, DoStateChange(DOS_RFPRO));
+    EXPECT_EQ(OC_STACK_FORBIDDEN_REQ, DoStateChange(DOS_RFNOP));
+    EXPECT_EQ(OC_STACK_FORBIDDEN_REQ, DoStateChange(DOS_SRESET));
+
+    freeUuid(owner);
+}
+
index 62dbf29..8165548 100644 (file)
@@ -867,7 +867,6 @@ TEST_F(OTM, OCSaveTrustCertChainFull)
     uint8_t *trustCertChain = (uint8_t *)getPemCert();
     uint16_t credId = 0;
     EXPECT_EQ(OC_STACK_OK, OCSaveTrustCertChain(trustCertChain, chainSize, OIC_ENCODING_PEM, &credId));
-    OICFree(trustCertChain);
 }
 
 TEST_F(OTM, OCSaveOwnRoleCertFull)
@@ -875,7 +874,6 @@ TEST_F(OTM, OCSaveOwnRoleCertFull)
     uint16_t credId = 0;
     char *cert = (char *)getPemCert();
     EXPECT_EQ(OC_STACK_OK, OCSaveOwnRoleCert(cert, &credId));
-    OICFree(cert);
 }
 
 static void trustCertChainChangeCB(void *ctx, uint16_t credId, uint8_t *trustCertChain,
@@ -909,9 +907,6 @@ TEST_F(OTM, OCSaveOwnCertChainFull)
     uint16_t credId = 0;
 
     EXPECT_EQ(OC_STACK_OK, OCSaveOwnCertChain(cert, key, &credId));
-
-    OICFree(key);
-    OICFree(cert);
 }
 
 TEST_F(OTM, OCRemoveCredentialFull)
index 82ccd00..bf6f12a 100644 (file)
@@ -55,29 +55,26 @@ const char ID_13[] = "4222222222222222";
 #define F_OK 0
 #endif
 
-TEST(CallPDMAPIbeforeInit, BeforeInit)
-{
-    if (0 == access(PM_DB_FILE_NAME, F_OK))
-    {
-        EXPECT_EQ(0, remove(PM_DB_FILE_NAME));
-    }
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMAddDevice(NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsDuplicateDevice(NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMLinkDevices(NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMUnlinkDevices(NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMDeleteDevice(NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetOwnedDevices(NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetLinkedDevices(NULL, NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMSetLinkStale(NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetToBeUnlinkedDevices(NULL, NULL));
-    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsLinkExists(NULL, NULL, NULL));
-}
-
 class PDB : public ::testing::Test
 {
     public:
         static void SetUpTestCase()
         {
+            if (0 == access(PM_DB_FILE_NAME, F_OK))
+            {
+                EXPECT_EQ(0, remove(PM_DB_FILE_NAME));
+            }
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMAddDevice(NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsDuplicateDevice(NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMLinkDevices(NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMUnlinkDevices(NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMDeleteDevice(NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetOwnedDevices(NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetLinkedDevices(NULL, NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMSetLinkStale(NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMGetToBeUnlinkedDevices(NULL, NULL));
+            EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsLinkExists(NULL, NULL, NULL));
+
             unlink("PDM.db");
             IOT_Init(PM_DB_FILE_NAME);
         }