the security provisioning unittests 17/27917/49
authorOleksandr Dmytrenko <o.dmytrenko@samsung.com>
Wed, 6 Feb 2019 16:10:10 +0000 (18:10 +0200)
committerAleksey Volkov <a.volkov@samsung.com>
Tue, 25 Jun 2019 07:41:27 +0000 (07:41 +0000)
the security provisioning unittests
coverage up t0 75

Change-Id: Idd98ddf4c61de900842c4c7e9567c1ed527dc59a
Signed-off-by: Oleksandr Dmytrenko <o.dmytrenko@samsung.com>
16 files changed:
resource/csdk/security/provisioning/unittest/SConscript
resource/csdk/security/provisioning/unittest/cloudresource.cpp
resource/csdk/security/provisioning/unittest/credentialgenerator.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/credentialgeneratortest.cpp [deleted file]
resource/csdk/security/provisioning/unittest/ocprovisioningmanager.cpp
resource/csdk/security/provisioning/unittest/otmcontextlist.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/otmunittest.cpp
resource/csdk/security/provisioning/unittest/ownershiptransfermanager.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/oxmjustworks.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/oxmmanufacturercert.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/oxmrandompin.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/pmutilitytest.cpp
resource/csdk/security/provisioning/unittest/provisioningdatabasemanager.cpp
resource/csdk/security/provisioning/unittest/secureresourceprovider.cpp
resource/csdk/security/provisioning/unittest/tools.cpp [new file with mode: 0644]
resource/csdk/security/provisioning/unittest/tools.h [new file with mode: 0644]

index f2a16b1..585951b 100644 (file)
@@ -59,7 +59,6 @@ cfg_client = 'oic_svr_db_client.dat'
 server_bin = 'sample_server' + sptest_env.get('PROGSUFFIX')
 unittest_bin = 'unittest' + sptest_env.get('PROGSUFFIX')
 
-
 ######################################################################
 # Functions
 ######################################################################
@@ -74,10 +73,9 @@ def clean_config():
     safe_remove('oic_svr_db_server1.dat')
     safe_remove('oic_svr_db_server2.dat')
     safe_remove(cfg_client)
-    safe_remove('test.db')
-    safe_remove('PDM.db')
-    safe_remove('secureresourceprovider.dat')
     safe_remove('device_properties.dat')
+    safe_remove('LIB_UNITTEST.dat')
+    safe_remove('secureresourceprovider.dat')
 
 
 def start_srv(num):
@@ -85,7 +83,10 @@ def start_srv(num):
         print("no executable file")
         return
     cfg_srv = 'oic_svr_db_server' + num + '.dat'
-    copyfile(sec_provisioning_src_dir + 'oic_svr_db_server_justworks.dat', cfg_srv)
+    cfg = sec_provisioning_src_dir + 'oic_svr_db_server_justworks.dat'
+    if not path.exists(cfg):
+        raise Exception("cannot copy file: "+cfg)
+    copyfile(cfg, cfg_srv)
     if not sptest_env.get('RELEASE'):
         po = Popen(
             unittest_build_dir + server_bin + ' ' + num + ' ' + cfg_srv,
@@ -133,20 +134,20 @@ def kill_all():
 def run_test(target, source, env):
     kill_all()
     clean_config()
-    copyfile(sec_provisioning_src_dir + 'oic_svr_db_client.dat', cfg_client)
+    cfg = sec_provisioning_src_dir + 'oic_svr_db_client.dat'
+    if not path.exists(cfg):
+        raise Exception("cannot copy file: "+cfg)
+    copyfile(cfg, cfg_client)
     po_srv1 = start_srv(str(1))
     po_srv2 = start_srv(str(2))
     print("Waiting for servers start")
-    sleep(3)
     call([unittest_build_dir + unittest_bin])
     print("Servers are stopping")
-    sleep(3)
     po_srv1.terminate()
     po_srv2.terminate()
     clean_config()
     kill_all()
 
-
 ######################################################################
 # Build flags
 ######################################################################
@@ -178,7 +179,9 @@ sptest_env.PrependUnique(CPPPATH=[
     '#resource/csdk/security/include',
     '#resource/csdk/security/include/experimental',
     '#resource/csdk/security/provisioning/src/cloud',
-    '#resource/csdk/security/provisioning/include/cloud/'
+    '#resource/csdk/security/provisioning/include/cloud/',
+    '#resource/csdk/logger/include/experimental',
+    '#extlibs/sqlite3'
 ])
 
 sptest_env.PrependUnique(LIBS=[
@@ -216,26 +219,29 @@ else:
 # Source files and Targets
 ######################################################################
 
-unittest_src = [
-    'pmutilitytest.cpp',
-    'secureresourceprovider.cpp',
-    'provisioningdatabasemanager.cpp',
-    'ocprovisioningmanager.cpp',
-    'credentialgeneratortest.cpp',
-    'otmunittest.cpp',
-]
-
-if sptest_env.get('WITH_TCP') == True and sptest_env.get('WITH_CLOUD') == True:
-    unittest_src = unittest_src + [
-        'cloudresource.cpp',
+if target_os in ['linux']:
+    unittest_src = [
+        'tools.cpp',
+        'ocprovisioningmanager.cpp',
+        'pmutilitytest.cpp',
+        'secureresourceprovider.cpp',
+        'provisioningdatabasemanager.cpp',
+        'oxmjustworks.cpp',
+        'otmcontextlist.cpp',
+        'ownershiptransfermanager.cpp',
+        'oxmmanufacturercert.cpp',
+        'oxmrandompin.cpp',
+        'credentialgenerator.cpp',
+        'otmunittest.cpp'
     ]
+    if sptest_env.get('WITH_TCP') == True and sptest_env.get('WITH_CLOUD') == True:
+        unittest_src.append('cloudresource.cpp')
 
-tests = sptest_env.Program(unittest_bin, unittest_src)
-server = sptest_env.Program(server_bin, ['sampleserver.cpp'])
+    tests = sptest_env.Program(unittest_bin, unittest_src)
+    server = sptest_env.Program(server_bin, ['sampleserver.cpp'])
 
-Alias('build', [tests, server])
+    Alias('build', [tests, server])
 
-if sptest_env.get('TEST') == '1':
-    if target_os in ['linux', 'windows']:
+    if sptest_env.get('TEST') == '1':
         print("Start tests")
         sptest_env.Command('start', [server_bin, unittest_bin], Action(run_test))
index 6f6cb8c..dc5dc4f 100644 (file)
@@ -37,21 +37,28 @@ extern "C" {
 #endif /* (__WITH_DTLS__) || (__WITH_TLS__) */
 #include "experimental/doxmresource.h"
 #include "pstatresource.h"
-}
+#include "tools.h"
 
+#undef TAG
 #include "../src/cloud/cloudresource.c"
-
-#ifdef TAG
 #undef TAG
-#endif
-
-#include "../src/cloud/config.c"
-
-#ifdef TAG
+#include "../src/cloud/aclgroup.c"
+#undef TAG
+#include "../src/cloud/aclid.c"
+#undef TAG
+#include "../src/cloud/aclinvite.c"
 #undef TAG
-#endif
-
 #include "../src/cloud/auth.c"
+#undef TAG
+#include "../src/cloud/config.c"
+#undef TAG
+#include "../src/cloud/crl.c"
+#undef TAG
+#include "../src/cloud/csr.c"
+#undef TAG
+#include "../src/cloud/utils.c"
+#undef TAG
+}
 
 #ifdef TAG
 #undef TAG
@@ -59,12 +66,29 @@ extern "C" {
 
 #define TAG  "CLOUD_UNITTEST"
 
-#define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
-#define PM_DB_FILE_NAME "test.db"
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
 #define STR_LEN 512
 static const char *sample =
     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#'?!:/";
 
+class CLOUD : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+            EXPECT_EQ(OC_STACK_OK, InitCloudResource());
+        }
+
+        static void TearDownTestCase()
+        {
+            EXPECT_EQ(OC_STACK_OK, DeInitCloudResource());
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
 void sessionInit(session_t *ses)
 {
     ses->expireSin = 1;
@@ -85,7 +109,7 @@ OicCloud_t *getCloud()
     OicCloud_t *cloud = (OicCloud_t *)OICCalloc(1, sizeof(OicCloud_t));
     VERIFY_NOT_NULL_RETURN(TAG, cloud, ERROR, NULL);
 
-
+    cloud->next = NULL;
     cloud->apn = (char *)OICCalloc(STR_LEN, sizeof(char));
     cloud->cis = (char *)OICCalloc(STR_LEN, sizeof(char));
     cloud->at = (char *)OICCalloc(STR_LEN, sizeof(char));
@@ -107,49 +131,12 @@ OicCloud_t *getCloud()
     sessionInit(cloud->session);
 
     cloud->stat = OC_CLOUD_OK;
-
     cloud->pid = 0;
 
     return cloud;
 }
 
-static FILE *fopen_prvnMng(const char *path, const char *mode)
-{
-    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
-    {
-        return fopen(SVR_DB_FILE_NAME, mode);
-    }
-    OIC_LOG_V(DEBUG, TAG, "use db: %s", path);
-    return fopen(path, mode);
-}
-
-TEST(CloudResourceTest, Init)
-{
-    static OCPersistentStorage gPst;
-    OCStackResult result = OC_STACK_ERROR;
-
-#ifdef HAVE_UNISTD_H
-    EXPECT_EQ(0, access(SVR_DB_FILE_NAME, F_OK));
-#endif // HAVE_UNISTD_H
-    gPst.open = fopen_prvnMng;
-    gPst.read = fread;
-    gPst.write = fwrite;
-    gPst.close = fclose;
-    gPst.unlink = unlink;
-
-    result = OCRegisterPersistentStorageHandler(&gPst);
-    EXPECT_EQ(OC_STACK_OK, result);
-
-    result = OCInit(NULL, 0, OC_CLIENT_SERVER);
-    EXPECT_EQ(OC_STACK_OK, result);
-}
-
-TEST(CloudResourceTest, InitCloudResource)
-{
-    EXPECT_EQ(OC_STACK_OK, InitCloudResource());
-}
-
-TEST(CloudResourceTest, CloudToCBORPayloadNULL)
+TEST_F(CLOUD, CloudToCBORPayloadNULL)
 {
     OicCloud_t *cloud =  getCloud();
     size_t size = 10;
@@ -162,7 +149,7 @@ TEST(CloudResourceTest, CloudToCBORPayloadNULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, CloudToCBORPayloadVALID)
+TEST_F(CLOUD, CloudToCBORPayloadVALID)
 {
     OicCloud_t *cloud = getCloud();
 
@@ -175,7 +162,7 @@ TEST(CloudResourceTest, CloudToCBORPayloadVALID)
     OCPayloadDestroy((OCPayload *)payload);
 }
 
-TEST(CloudResourceTest, CloudToCBORPayloadResourceVALID)
+TEST_F(CLOUD, CloudToCBORPayloadResourceVALID)
 {
     OicCloud_t *cloud = getCloud();
 
@@ -188,7 +175,7 @@ TEST(CloudResourceTest, CloudToCBORPayloadResourceVALID)
     OCPayloadDestroy((OCPayload *)payload);
 }
 
-TEST(CloudResourceTest, CBORPayloadToCloudNULL)
+TEST_F(CLOUD, CBORPayloadToCloudNULL)
 {
     OicCloud_t *cloud = NULL;
     uint8_t *cborPayload = (uint8_t *)OICCalloc(1, sizeof(uint8_t));
@@ -207,7 +194,7 @@ TEST(CloudResourceTest, CBORPayloadToCloudNULL)
     OICFree(cborPayload);
 }
 
-TEST(CloudResourceTest, CBORPayloadToCloudFULL)
+TEST_F(CLOUD, CBORPayloadToCloudFULL)
 {
     OicCloud_t *cloud = NULL;
     uint8_t *payload = NULL;
@@ -240,7 +227,7 @@ TEST(CloudResourceTest, CBORPayloadToCloudFULL)
     OCPayloadDestroy((OCPayload *)payload);
 }
 
-TEST(CloudResourceTest, strCopyFULL)
+TEST_F(CLOUD, strCopyFULL)
 {
     EXPECT_FALSE(strCopy(NULL, NULL));
     char *sample1 = (char *)OICCalloc(1, 1024);
@@ -260,7 +247,7 @@ TEST(CloudResourceTest, strCopyFULL)
     OICFree(sample1);
 }
 
-TEST(CloudResourceTest, CBORPayloadToCloudResourceFULL)
+TEST_F(CLOUD, CBORPayloadToCloudResourceFULL)
 {
     OicCloud_t *cloud =  getCloud();
     uint8_t *payload = NULL;
@@ -280,7 +267,7 @@ TEST(CloudResourceTest, CBORPayloadToCloudResourceFULL)
     OCPayloadDestroy((OCPayload *)payload);
 }
 
-TEST(CloudResourceTest, ValidCloudFULL)
+TEST_F(CLOUD, ValidCloudFULL)
 {
     ASSERT_TRUE(false == ValidCloud(NULL));
     OicCloud_t *cloud =  getCloud();
@@ -294,7 +281,7 @@ TEST(CloudResourceTest, ValidCloudFULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, DeleteCloudListFULL)
+TEST_F(CLOUD, DeleteCloudListFULL)
 {
     DeleteCloudList(NULL, true);
     OicCloud_t *cloud =  getCloud();
@@ -303,7 +290,7 @@ TEST(CloudResourceTest, DeleteCloudListFULL)
     DeleteCloudList(cloud, true);
 }
 
-TEST(CloudResourceTest, CreateCloudGetPayloadFULL)
+TEST_F(CLOUD, CreateCloudGetPayloadFULL)
 {
     OCRepPayload *payload = CreateCloudGetPayload(NULL);
     ASSERT_TRUE(NULL != payload);
@@ -324,7 +311,7 @@ TEST(CloudResourceTest, CreateCloudGetPayloadFULL)
     OCPayloadDestroy((OCPayload *)payload);
 }
 
-TEST(CloudResourceTest, StartCloudFULL)
+TEST_F(CLOUD, StartCloudFULL)
 {
     ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RESET));
     StartClouds();
@@ -342,8 +329,9 @@ TEST(CloudResourceTest, StartCloudFULL)
     OICFree(uuid);
 }
 
-TEST(CloudResourceTest, HandleCloudPostRequestFULL)
+TEST_F(CLOUD, HandleCloudPostRequestFULL)
 {
+    #define _MULTIPLE_CNC_
     ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(NULL));
 
     OCEntityHandlerRequest *ehRequest = (OCEntityHandlerRequest *)OICCalloc(1,
@@ -393,15 +381,16 @@ TEST(CloudResourceTest, HandleCloudPostRequestFULL)
     OCRepPayloadSetPropInt(payload, OIC_JSON_CLOUD_CLEC, (int64_t)cloud->stat);
     ASSERT_TRUE(OC_EH_ERROR == HandleCloudPostRequest(ehRequest));
 
+    CloudsSignOut();
+
     OICFree(uuid);
     FreeCloud(cloud);
     ASSERT_TRUE(OC_STACK_OK == SetDosState(DOS_RFNOP));
     OCPayloadDestroy(ehRequest->payload);
     OICFree(ehRequest);
-    exit(0);
 }
 
-TEST(CloudResourceTest, HandleCloudGetRequestFULL)
+TEST_F(CLOUD, HandleCloudGetRequestFULL)
 {
     ASSERT_TRUE(OC_EH_ERROR == HandleCloudGetRequest(NULL));
     OCRepPayload *payload = NULL;
@@ -452,7 +441,7 @@ TEST(CloudResourceTest, HandleCloudGetRequestFULL)
     OICFree(ehRequest);
 }
 
-TEST(CloudResourceTest, HandleCloudDeleteRequestFULL)
+TEST_F(CLOUD, HandleCloudDeleteRequestFULL)
 {
     ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(NULL));
 
@@ -486,6 +475,8 @@ TEST(CloudResourceTest, HandleCloudDeleteRequestFULL)
     ehRequest->payload = (OCPayload *)CreateCloudGetPayload(cloud);
     ASSERT_TRUE(NULL != ehRequest->payload);
     OCRepPayloadSetPropString((OCRepPayload *)ehRequest->payload, OIC_JSON_CLOUD_AT, "3453245234");
+    OCRepPayloadSetPropString((OCRepPayload *)ehRequest->payload, OC_CLOUD_PROVISIONING_CIS,
+                              cloud->cis);
     ASSERT_TRUE(OC_EH_ERROR == HandleCloudDeleteRequest(ehRequest));
 
     OICFree(uuid);
@@ -495,7 +486,7 @@ TEST(CloudResourceTest, HandleCloudDeleteRequestFULL)
     OICFree(ehRequest);
 }
 
-TEST(CloudResourceTest, CloudEntityHandlerFULL)
+TEST_F(CLOUD, CloudEntityHandlerFULL)
 {
     ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler((OCEntityHandlerFlag)0, NULL, NULL));
     ASSERT_TRUE(OC_EH_ERROR == CloudEntityHandler(OC_OBSERVE_FLAG, NULL, NULL));
@@ -522,7 +513,7 @@ OCStackApplicationResult resultHandler(void *context, OCDoHandle handle,
     return OC_STACK_DELETE_TRANSACTION;
 }
 
-TEST(CloudResourceTest, OCProvisionCloudConfigFULL)
+TEST_F(CLOUD, OCProvisionCloudConfigFULL)
 {
     void *ctx = NULL;
     OCProvisionDev_t *pDev = NULL;
@@ -539,14 +530,13 @@ TEST(CloudResourceTest, OCProvisionCloudConfigFULL)
     ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
     resultCallback = resultHandler;
     ASSERT_TRUE(OC_STACK_ERROR == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
-    snprintf(pDev->endpoint.addr, sizeof(pDev->endpoint.addr), "127.0.0.1");
-    pDev->securePort = 1024;
-    pDev->connType = (OCConnectivityType)(CT_ADAPTER_IP | CT_FLAG_SECURE | CT_IP_USE_V4);
+
+    pDev = createProvisionDev();
     ASSERT_TRUE(OC_STACK_OK == OCProvisionCloudConfig(ctx, pDev, cloud, resultCallback));
 
+    freeProvisionDev(pDev);
     FreeCloud(cloud);
     OICFree(ctx);
-    OICFree(pDev);
 }
 
 static OCStackApplicationResult clientResponseHandler(void *context, OCDoHandle handle,
@@ -559,7 +549,7 @@ static OCStackApplicationResult clientResponseHandler(void *context, OCDoHandle
     return ret;
 }
 
-TEST(CloudResourceTest, handleCloudStatusResponseFULL)
+TEST_F(CLOUD, handleCloudStatusResponseFULL)
 {
     void *ctx = NULL;
     OCDoHandle handle = NULL;
@@ -583,7 +573,7 @@ TEST(CloudResourceTest, handleCloudStatusResponseFULL)
     OICFree(response);
 }
 
-TEST(CloudResourceTest, OCRemoveCloudConfigCBFULL)
+TEST_F(CLOUD, OCRemoveCloudConfigCBFULL)
 {
     void *ctx = NULL;
     OCDoHandle handle = NULL;
@@ -628,7 +618,7 @@ TEST(CloudResourceTest, OCRemoveCloudConfigCBFULL)
     OICFree(response);
 }
 
-TEST(CloudResourceTest, OCGetCloudStatusRequestFULL)
+TEST_F(CLOUD, OCGetCloudStatusRequestFULL)
 {
     void *ctx = NULL;
     OCProvisionDev_t *pDev = NULL;
@@ -665,7 +655,7 @@ void resultCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
     return;
 }
 
-TEST(CloudResourceTest, OCRemoveCloudConfigFULL)
+TEST_F(CLOUD, OCRemoveCloudConfigFULL)
 {
     void *ctx = NULL;
     OCProvisionDev_t *pDev = NULL;
@@ -692,7 +682,7 @@ TEST(CloudResourceTest, OCRemoveCloudConfigFULL)
     OICFree(pDev);
 }
 
-TEST(CloudResourceTest, GetCloudStatusFULL)
+TEST_F(CLOUD, GetCloudStatusFULL)
 {
     gCloud = getCloud();
     ASSERT_TRUE(NULL != gCloud);
@@ -708,7 +698,7 @@ TEST(CloudResourceTest, GetCloudStatusFULL)
     gCloud = NULL;
 }
 
-TEST(CloudResourceTest, handleCloudTokenRefreshResponseFULL)
+TEST_F(CLOUD, handleCloudTokenRefreshResponseFULL)
 {
     void *ctx = NULL;
     OCDoHandle handle = NULL;
@@ -738,7 +728,7 @@ TEST(CloudResourceTest, handleCloudTokenRefreshResponseFULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, OCCloudTokenRefreshFULL)
+TEST_F(CLOUD, OCCloudTokenRefreshFULL)
 {
     OicCloud_t *cloud = NULL;
     ASSERT_TRUE(OC_STACK_INVALID_PARAM == OCCloudTokenRefresh(cloud));
@@ -759,7 +749,7 @@ TEST(CloudResourceTest, OCCloudTokenRefreshFULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, handleCloudSignUpResponseFULL)
+TEST_F(CLOUD, handleCloudSignUpResponseFULL)
 {
     void *ctx = NULL;
     OCDoHandle handle = NULL;
@@ -797,7 +787,7 @@ TEST(CloudResourceTest, handleCloudSignUpResponseFULL)
 }
 
 /*
-TEST(CloudResourceTest, CloudTokenRefreshFULL)
+TEST_F(CLOUD, CloudTokenRefreshFULL)
 {
     OicCloud_t *cloud = NULL;
 
@@ -810,7 +800,7 @@ TEST(CloudResourceTest, CloudTokenRefreshFULL)
 }
 */
 
-TEST(CloudResourceTest, handleCloudSignInResponseFULL)
+TEST_F(CLOUD, handleCloudSignInResponseFULL)
 {
     void *ctx = NULL;
     OCDoHandle handle = NULL;
@@ -846,7 +836,7 @@ TEST(CloudResourceTest, handleCloudSignInResponseFULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, CloudSignFULL)
+TEST_F(CLOUD, CloudSignFULL)
 {
     OicCloud_t *cloud = NULL;
 
@@ -860,7 +850,7 @@ TEST(CloudResourceTest, CloudSignFULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, CloudSignUpParsePayloadFULL)
+TEST_F(CLOUD, CloudSignUpParsePayloadFULL)
 {
     OicCloud_t *cloud = NULL;
     OCRepPayload *payload = NULL;
@@ -928,7 +918,7 @@ TEST(CloudResourceTest, CloudSignUpParsePayloadFULL)
     FreeCloud(cloud);
 }
 
-TEST(CloudResourceTest, handleCloudSignOutResponseFULL)
+TEST_F(CLOUD, handleCloudSignOutResponseFULL)
 {
     void *ctx = NULL;
     OCDoHandle handle = NULL;
@@ -948,7 +938,7 @@ TEST(CloudResourceTest, handleCloudSignOutResponseFULL)
     OICFree(response);
 }
 
-TEST(CloudResourceTest, UpdateCloudPersistentStorageFULL)
+TEST_F(CLOUD, UpdateCloudPersistentStorageFULL)
 {
     DeleteCloudList(gCloud, true);
     ASSERT_TRUE(false == UpdateCloudPersistentStorage());
@@ -959,7 +949,797 @@ TEST(CloudResourceTest, UpdateCloudPersistentStorageFULL)
     gCloud = NULL;
 }
 
-TEST(CloudResourceTest, DeInitCloudResource)
+TEST_F(CLOUD, handleAclCreateGroupResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclCreateGroupResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclCreateGroupResponse(NULL, (void **)&data, response));
+
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    EXPECT_TRUE(OC_STACK_MALFORMED_RESPONSE == handleAclCreateGroupResponse(NULL, (void **)&data,
+                response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_GROUP_ID, "val");
+    EXPECT_TRUE(OC_STACK_OK == handleAclCreateGroupResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, handleAclFindMyGroupResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclFindMyGroupResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclFindMyGroupResponse(NULL, (void **)&data, response));
+
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    EXPECT_TRUE(OC_STACK_MALFORMED_RESPONSE == handleAclFindMyGroupResponse(NULL, (void **)&data,
+                response));
+
+    const char **array = (const char **)OICCalloc(2, sizeof(const char *));
+    array[0] = OICStrdup("val0");
+// TODO wait for https://gerrit.iotivity.org/gerrit/#/c/29354
+#if defined(BUG_FIX)
+    array[1] = OICStrdup("val1");
+    size_t dim[MAX_REP_ARRAY_DEPTH] = {5, 5, 0};
+#else
+    size_t dim[MAX_REP_ARRAY_DEPTH] = {5, 0, 0};
+#endif
+    EXPECT_TRUE(OCRepPayloadSetStringArray((OCRepPayload *)response->payload, OC_RSRVD_GROUP_ID_LIST,
+                                           array, dim));
+    EXPECT_TRUE(OC_STACK_OK == handleAclFindMyGroupResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree((void *)array[1]);
+    OICFree((void *)array[0]);
+    OICFree(array);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, OCCloudAclCreateGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclCreateGroup(NULL, NULL, NULL, NULL, NULL));
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclCreateGroup(NULL, "group", "grandmaster",
+                "coaps+tcp://127.0.0.1:7777", NULL));
+}
+
+TEST_F(CLOUD, OCCloudAclFindMyGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclFindMyGroup(NULL, NULL, NULL, NULL));
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclFindMyGroup(NULL, "theId", "coaps+tcp://127.0.0.1:7777",
+                NULL));
+}
+
+TEST_F(CLOUD, OCCloudAclDeleteGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclDeleteGroup(NULL, NULL, NULL, NULL, NULL));
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclDeleteGroup(NULL, "group", "grandmaster",
+                "coaps+tcp://127.0.0.1:7777", NULL));
+}
+
+TEST_F(CLOUD, OCCloudAclJoinToInvitedGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclJoinToInvitedGroup(NULL, NULL, NULL, NULL));
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclJoinToInvitedGroup(NULL, "theId", "coaps+tcp://127.0.0.1:7777",
+                NULL));
+}
+
+TEST_F(CLOUD, OCCloudAclObserveGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclObserveGroup(NULL, NULL, NULL, NULL));
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclObserveGroup(NULL, "theId", "coaps+tcp://127.0.0.1:7777",
+                NULL));
+}
+
+TEST_F(CLOUD, OCCloudAclShareDeviceIntoGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclShareDeviceIntoGroup(NULL, NULL, NULL, NULL, NULL,
+                NULL));
+    stringArray_t *memberIds = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+    stringArray_t *deviceIds = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclShareDeviceIntoGroup(NULL, "theId", memberIds, deviceIds,
+                "coaps+tcp://127.0.0.1:7777", NULL));
+
+    OICFree(memberIds);
+    OICFree(deviceIds);
+}
+
+TEST_F(CLOUD, OCCloudAclDeleteDeviceFromGroup)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclDeleteDeviceFromGroup(NULL, NULL, NULL, NULL, NULL,
+                NULL));
+    stringArray_t *memberIds = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+    stringArray_t *deviceIds = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclDeleteDeviceFromGroup(NULL, "theId", memberIds, deviceIds,
+                "coaps+tcp://127.0.0.1:7777", NULL));
+
+    OICFree(memberIds);
+    OICFree(deviceIds);
+}
+
+TEST_F(CLOUD, OCCloudAclGroupGetInfo)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclGroupGetInfo(NULL, NULL, NULL, NULL, NULL));
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclGroupGetInfo(NULL, "groupId", "memberId",
+                "coaps+tcp://127.0.0.1:7777", NULL));
+}
+
+#define CLOUD_URI "coaps+tcp://cloud_uri.com"
+#define X_UUID "33333333-3333-3333-3333-222222222221"
+
+static void cloudResponseCB(void *ctx, OCClientResponse *response, void *data)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(response);
+    OC_UNUSED(data);
+    OIC_LOG_V(DEBUG, TAG, "%s: data: %s", __func__, (const char *)data);
+}
+
+TEST_F(CLOUD, getAclIdFromResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == getAclIdFromResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == getAclIdFromResponse(NULL, (void **)&data, response));
+
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    EXPECT_TRUE(OC_STACK_MALFORMED_RESPONSE == getAclIdFromResponse(NULL, (void **)&data, response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_ACL_ID, "acl_id");
+    EXPECT_TRUE(OC_STACK_OK == getAclIdFromResponse(NULL, (void **)&data, response));
+    EXPECT_TRUE(OC_STACK_OK == handleGetAclIdByDeviceResponse(NULL, (void **)&data, response));
+    EXPECT_TRUE(OC_STACK_OK == handleAclIdCreateResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, OCCloudGetAclIdByDevice)
+{
+    const char *deviceId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudGetAclIdByDevice(NULL, NULL, NULL, NULL));
+
+    deviceId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)deviceId, MAX_URI_LENGTH, X_UUID);
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudGetAclIdByDevice(NULL, deviceId, cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudGetAclIdByDevice(NULL, deviceId, cloudUri, cloudResponseCB));
+
+    OICFree((void *)deviceId);
+    OICFree((void *)cloudUri);
+}
+
+TEST_F(CLOUD, OCCloudAclIdCreate)
+{
+    const char *ownerId = NULL;
+    const char *deviceId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclIdCreate(NULL, NULL, NULL, NULL, NULL));
+
+    ownerId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)ownerId, MAX_URI_LENGTH, X_UUID);
+    deviceId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)deviceId, MAX_URI_LENGTH, "33333333-3333-3333-3333-222222222222");
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclIdCreate(NULL, ownerId, deviceId, cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclIdCreate(NULL, ownerId, deviceId, cloudUri, cloudResponseCB));
+
+    OICFree((void *)deviceId);
+    OICFree((void *)cloudUri);
+    OICFree((void *)ownerId);
+}
+
+TEST_F(CLOUD, OCCloudAclIdDelete)
+{
+    const char *aclId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclIdDelete(NULL, NULL, NULL, NULL));
+
+    aclId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)aclId, MAX_URI_LENGTH, X_UUID);
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclIdDelete(NULL, aclId, cloudUri, cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclIdDelete(NULL, aclId, cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+    OICFree((void *)aclId);
+}
+
+TEST_F(CLOUD, handleAclGetInfoResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclGetInfoResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclGetInfoResponse(NULL, (void **)&data, response));
+
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    EXPECT_TRUE(OC_STACK_OK == handleAclGetInfoResponse(NULL, (void **)&data, response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_ACL_ID, "acl_id");
+    EXPECT_TRUE(OC_STACK_OK == handleAclGetInfoResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, OCCloudAclIndividualGetInfo)
+{
+    const char *aclId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclIndividualGetInfo(NULL, NULL, NULL, NULL));
+
+    aclId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)aclId, MAX_URI_LENGTH, X_UUID);
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclIndividualGetInfo(NULL, aclId, cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclIndividualGetInfo(NULL, aclId, cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+    OICFree((void *)aclId);
+}
+
+TEST_F(CLOUD, OCCloudAclIndividualAclUpdate)
+{
+    const char *aclId = NULL;
+    const char *cloudUri = NULL;
+    cloudAce_t *ace = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclIndividualAclUpdate(NULL, NULL, NULL, NULL, NULL));
+
+    aclId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)aclId, MAX_URI_LENGTH, X_UUID);
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCloudAclIndividualAclUpdate(NULL, aclId, ace, cloudUri,
+              cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+
+    ace = (cloudAce_t *)OICCalloc(1, sizeof(cloudAce_t));
+    ace->aceId = OICStrdup("ace_id");
+    EXPECT_TRUE(OC_STACK_OK == ConvertStrToUuid(X_UUID, &ace->subjectuuid));
+    ace->stype = 1;
+    ace->permission = 1;
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCloudAclIndividualAclUpdate(NULL, aclId, ace, cloudUri,
+              cloudResponseCB));
+
+    ace->resources = (OicSecRsrc_t *)OICCalloc(1, sizeof(OicSecRsrc_t));
+    ace->resources->href = OICStrdup(OC_RSRVD_ACL_ID_URL);
+
+    EXPECT_EQ(OC_STACK_OK, OCCloudAclIndividualAclUpdate(NULL, aclId, ace, cloudUri, cloudResponseCB));
+
+    OICFree((void *)ace->resources->href);
+    OICFree((void *)ace->resources);
+    OICFree((void *)ace->aceId);
+    OICFree((void *)ace);
+    OICFree((void *)cloudUri);
+    OICFree((void *)aclId);
+}
+
+TEST_F(CLOUD, OCCloudAclIndividualAceUpdate)
+{
+    const char *aclId = NULL;
+    const char *aceId = NULL;
+    const char *cloudUri = NULL;
+    cloudAce_t *ace = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclIndividualAceUpdate(NULL, NULL, NULL, NULL, NULL,
+                NULL));
+
+    aclId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)aclId, MAX_URI_LENGTH, X_UUID);
+    aceId = OICStrdup("ace_id");
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCloudAclIndividualAceUpdate(NULL, aclId, aceId, ace, cloudUri,
+              cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+
+    ace = (cloudAce_t *)OICCalloc(1, sizeof(cloudAce_t));
+    ace->aceId = OICStrdup("ace_id");
+    EXPECT_TRUE(OC_STACK_OK == ConvertStrToUuid(X_UUID, &ace->subjectuuid));
+    ace->stype = 1;
+    ace->permission = 1;
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCCloudAclIndividualAceUpdate(NULL, aclId, aceId, ace, cloudUri,
+              cloudResponseCB));
+
+    ace->resources = (OicSecRsrc_t *)OICCalloc(1, sizeof(OicSecRsrc_t));
+    ace->resources->href = OICStrdup(OC_RSRVD_ACL_ID_URL);
+
+    EXPECT_EQ(OC_STACK_OK, OCCloudAclIndividualAceUpdate(NULL, aclId, aceId, ace, cloudUri,
+              cloudResponseCB));
+
+    OICFree((void *)ace->resources->href);
+    OICFree((void *)ace->resources);
+    OICFree((void *)ace->aceId);
+    OICFree((void *)ace);
+    OICFree((void *)cloudUri);
+    OICFree((void *)aceId);
+    OICFree((void *)aclId);
+}
+
+TEST_F(CLOUD, OCCloudAclAcesDelete)
+{
+    const char *aclId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclAcesDelete(NULL, NULL, NULL, NULL));
+
+    aclId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)aclId, MAX_URI_LENGTH, X_UUID);
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_EQ(OC_STACK_INVALID_URI, OCCloudAclAcesDelete(NULL, aclId, cloudUri, cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+
+    EXPECT_EQ(OC_STACK_OK, OCCloudAclAcesDelete(NULL, aclId, cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+    OICFree((void *)aclId);
+}
+
+TEST_F(CLOUD, OCCloudAclIndividualAceDelete)
 {
-    EXPECT_EQ(OC_STACK_OK, DeInitCloudResource());
+    const char *aclId = NULL;
+    const char *aceId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclIndividualAceDelete(NULL, NULL, NULL, NULL, NULL));
+
+    aclId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)aclId, MAX_URI_LENGTH, X_UUID);
+    aceId = OICStrdup("ace_id");
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_EQ(OC_STACK_INVALID_URI, OCCloudAclIndividualAceDelete(NULL, aclId, aceId, cloudUri,
+              cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+
+    EXPECT_EQ(OC_STACK_OK, OCCloudAclIndividualAceDelete(NULL, aclId, aceId, cloudUri,
+              cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+    OICFree((void *)aceId);
+    OICFree((void *)aclId);
+}
+
+//-------------------aclinvite-----------------
+TEST_F(CLOUD, parseInvitePayload)
+{
+    OCRepPayload *payload = (OCRepPayload *)OCRepPayloadCreate();
+    stringArrayPair_t *out = (stringArrayPair_t *)OICCalloc(1, sizeof(stringArrayPair_t));
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
+
+    EXPECT_EQ(OC_STACK_MALFORMED_RESPONSE, parseInvitePayload(NULL, NULL, NULL));
+
+    EXPECT_EQ(OC_STACK_MALFORMED_RESPONSE, parseInvitePayload(payload, OC_RSRVD_RESOURCES, out));
+
+    OCRepPayload **helperPayload = (OCRepPayload **)OICCalloc(1, sizeof(OCRepPayload *));
+    *helperPayload = OCRepPayloadCreate();
+    OCRepPayloadSetPropString(*helperPayload, OC_RSRVD_GROUP_ID, "12");
+    OCRepPayloadSetPropString(*helperPayload, OC_RSRVD_MEMBER_ID, "2");
+    dimensions[0] = 1;
+    EXPECT_TRUE(OCRepPayloadSetPropObjectArray(payload, "arrId",
+                (const OCRepPayload **)helperPayload, dimensions));
+
+    EXPECT_EQ(OC_STACK_OK, parseInvitePayload(payload, "arrId", out));
+    OICFree(out);
+}
+
+TEST_F(CLOUD, handleAclGetInvitationResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+    size_t dimensions[MAX_REP_ARRAY_DEPTH] = {0, 0, 0};
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclGetInvitationResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclGetInvitationResponse(NULL, (void **)&data,
+                response));
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    EXPECT_TRUE(OC_STACK_MALFORMED_RESPONSE == handleAclGetInvitationResponse(NULL, (void **)&data,
+                response));
+
+    OCRepPayload **helperPayload = (OCRepPayload **)OICCalloc(1, sizeof(OCRepPayload *));
+    *helperPayload = OCRepPayloadCreate();
+    OCRepPayloadSetPropString(*helperPayload, OC_RSRVD_GROUP_ID, "12");
+    OCRepPayloadSetPropString(*helperPayload, OC_RSRVD_MEMBER_ID, "2");
+    dimensions[0] = 1;
+    EXPECT_TRUE(OCRepPayloadSetPropObjectArray((OCRepPayload *)response->payload, OC_RSRVD_INVITE,
+                (const OCRepPayload **)helperPayload, dimensions));
+
+    OCRepPayload **helperPayload1 = (OCRepPayload **)OICCalloc(1, sizeof(OCRepPayload *));
+    *helperPayload1 = OCRepPayloadCreate();
+    OCRepPayloadSetPropString(*helperPayload1, OC_RSRVD_GROUP_ID, "11");
+    OCRepPayloadSetPropString(*helperPayload1, OC_RSRVD_MEMBER_ID, "1");
+    dimensions[0] = 1;
+    EXPECT_TRUE(OCRepPayloadSetPropObjectArray((OCRepPayload *)response->payload, OC_RSRVD_INVITED,
+                (const OCRepPayload **)helperPayload1, dimensions));
+
+    EXPECT_EQ(OC_STACK_OK, handleAclGetInvitationResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, handleAclPolicyCheckResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclPolicyCheckResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleAclPolicyCheckResponse(NULL, (void **)&data, response));
+
+    response->payload = (OCPayload *)OCRepPayloadCreate();
+    EXPECT_TRUE(OC_STACK_MALFORMED_RESPONSE == handleAclPolicyCheckResponse(NULL, (void **)&data,
+                response));
+
+    OCRepPayloadSetPropString((OCRepPayload *)response->payload, OC_RSRVD_GROUP_PERMISSION, "0644");
+    EXPECT_EQ(OC_STACK_OK, handleAclPolicyCheckResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, OCCloudAclInviteUser)
+{
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclInviteUser(NULL, NULL, NULL, NULL, NULL, NULL));
+
+    stringArray_t *memberIds = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+    stringArray_t *groupIds = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+    groupIds->length = 1;
+    groupIds->array = (char **)OICCalloc(groupIds->length, sizeof(char *));
+    groupIds->array[groupIds->length - 1] = OICStrdup("root");
+
+    memberIds->length = 1;
+    memberIds->array = (char **)OICCalloc(memberIds ->length, sizeof(char *));
+    memberIds->array[memberIds ->length - 1] = OICStrdup("root");
+
+    EXPECT_EQ(OC_STACK_OK, OCCloudAclInviteUser(NULL, "007", groupIds, memberIds, CLOUD_URI,
+              cloudResponseCB));
+}
+
+TEST_F(CLOUD, OCCloudAclGetInvitation)
+{
+    const char *userId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclGetInvitation(NULL, NULL, NULL, NULL));
+
+    userId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)userId, MAX_URI_LENGTH, X_UUID);
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclGetInvitation(NULL, userId, cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclGetInvitation(NULL, userId, cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+    OICFree((void *)userId);
+
+}
+
+TEST_F(CLOUD, OCCloudAclDeleteInvitation)
+{
+    const char *ownerId = NULL;
+    const char *deviceId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclDeleteInvitation(NULL, NULL, NULL, NULL, NULL));
+
+    ownerId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)ownerId, MAX_URI_LENGTH, X_UUID);
+    deviceId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)deviceId, MAX_URI_LENGTH, "33333333-3333-3333-3333-222222222222");
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclDeleteInvitation(NULL, ownerId, deviceId, cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclDeleteInvitation(NULL, ownerId, deviceId, cloudUri,
+                cloudResponseCB));
+
+    OICFree((void *)deviceId);
+    OICFree((void *)cloudUri);
+    OICFree((void *)ownerId);
+}
+
+TEST_F(CLOUD, OCCloudAclCancelInvitation)
+{
+    const char *userId = NULL;
+    const char *groupId = NULL;
+    const char *memberId = NULL;
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclCancelInvitation(NULL, NULL, NULL, NULL, NULL,
+                NULL));
+
+    userId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)userId, MAX_URI_LENGTH, X_UUID);
+    groupId = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    snprintf((char *)groupId, MAX_URI_LENGTH, "33333333-3333-3333-3333-222222222222");
+    memberId = OICStrdup("root");
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclCancelInvitation(NULL, userId, groupId, memberId,
+                cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudAclCancelInvitation(NULL, userId, groupId, memberId, cloudUri,
+                cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+    OICFree((void *)memberId);
+    OICFree((void *)groupId);
+    OICFree((void *)userId);
+}
+
+TEST_F(CLOUD, OCCloudAclPolicyCheck)
+{
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudAclPolicyCheck(NULL, NULL, NULL, NULL, NULL, NULL,
+                NULL));
+
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudAclPolicyCheck(NULL, X_UUID, X_UUID, "GET", "uuri",
+                cloudUri, cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_EQ(OC_STACK_OK, OCCloudAclPolicyCheck(NULL, X_UUID, X_UUID, "GET", "uuri", cloudUri,
+              cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+}
+//---------------------auth--------------------
+TEST_F(CLOUD, CloudTokenRefresh)
+{
+    OicCloud_t *cloud = (OicCloud_t *)OICCalloc(1, sizeof(OicCloud_t));
+    cloud->stat = OC_CLOUD_TOKEN_REFRESH0;
+    cloud->session = (session_t *)OICCalloc(1, sizeof(session_t));
+    cloud->session->expireSin = 3;
+    CloudTokenRefresh((void *)cloud);
+}
+//---------------------auth--------------------
+TEST_F(CLOUD, CloudsSignOut)
+{
+    CloudsSignOut();
+
+    DeleteCloudAccount();
+}
+//--------------------crl------------------
+TEST_F(CLOUD, handleCrlGetResponse)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleCrlGetResponse(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == handleCrlGetResponse(NULL, (void **)&data, response));
+
+    OicSecCrl_t *crl = (OicSecCrl_t *)OICCalloc(1, sizeof(OicSecCrl_t));
+    crl->CrlId = 3;
+    crl->ThisUpdate.data = certData();
+    crl->ThisUpdate.len = certDataLen();
+    crl->CrlData.data = keyData();
+    crl->CrlData.len = keyDataLen();
+
+    OCSecurityPayload *payload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
+    payload->base.type = PAYLOAD_TYPE_SECURITY;
+    response->payload = (OCPayload *)payload;
+
+    EXPECT_TRUE(OC_STACK_OK == CrlToCBORPayload(crl, (uint8_t **)&payload->securityData,
+                &payload->payloadSize, NULL));
+    response->payload->type = PAYLOAD_TYPE_SECURITY;
+
+    EXPECT_TRUE(OC_STACK_OK == handleCrlGetResponse(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, OCCloudGetCRL)
+{
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudGetCRL(NULL, NULL, NULL));
+
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudGetCRL(NULL, cloudUri, cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_EQ(OC_STACK_OK, OCCloudGetCRL(NULL, cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+}
+
+TEST_F(CLOUD, OCCloudPostCRL)
+{
+    const char *thisUpdate = OICStrdup("this");
+    const char *nextUpdate = OICStrdup("next");
+    OCByteString *crl = (OCByteString *)OICCalloc(1, sizeof(OCByteString ));
+    stringArray_t *serialNumbers = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudPostCRL(NULL, NULL, NULL, NULL, NULL, NULL, NULL));
+
+    crl->bytes = keyData();
+    crl->len = keyDataLen();
+
+    serialNumbers->length = 1;
+    serialNumbers->array = (char **)OICCalloc(serialNumbers->length, sizeof(char *));
+    serialNumbers->array[serialNumbers->length - 1] = OICStrdup("root");
+
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudPostCRL(NULL, thisUpdate, nextUpdate, crl, serialNumbers,
+                cloudUri, cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudPostCRL(NULL, thisUpdate, nextUpdate, crl, serialNumbers,
+                cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+}
+//--------------------csr------------------
+TEST_F(CLOUD, CSRMakeSubject)
+{
+    char *subject = (char *)OICCalloc(1, 2048);
+    CSRMakeSubject(subject, "UA", "Samsung", "Sec", NULL);
+    CSRMakeSubject(subject, "UA", "Samsung", "Sec", X_UUID);
+    OICFree(subject);
+}
+
+TEST_F(CLOUD, ecdsaGenKeypair)
+{
+    mbedtls_pk_context pkCtx;
+    EXPECT_EQ(0, ecdsaGenKeypair(&pkCtx));
+    mbedtls_pk_free(&pkCtx);
+
+    char *subject = NULL;
+    OCByteString csr = {.bytes = NULL, .len = 0};
+
+    EXPECT_EQ(-1, GenerateCSR(subject, &csr));
+    subject = (char *)X_UUID;
+    EXPECT_EQ(0, GenerateCSR(subject, &csr));
+}
+
+TEST_F(CLOUD, HandleCertificateIssueRequest)
+{
+    OCClientResponse *response = NULL;
+    char *data = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == HandleCertificateIssueRequest(NULL, NULL, NULL));
+
+    response = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    OCRepPayload *payload = OCRepPayloadCreate();
+    response->payload = (OCPayload *)payload;
+
+    EXPECT_EQ(OC_STACK_ERROR, HandleCertificateIssueRequest(NULL, (void **)&data, response));
+
+    response->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_ERROR, HandleCertificateIssueRequest(NULL, (void **)&data, response));
+
+    OCRepPayloadSetPropString(payload, OC_RSRVD_DEVICE_ID, X_UUID);
+
+    EXPECT_EQ(OC_STACK_ERROR, HandleCertificateIssueRequest(NULL, (void **)&data, response));
+
+    OicSecKey_t *key = (OicSecKey_t *)OICCalloc(1, sizeof(OicSecKey_t));
+    key->data = keyData();
+    key->len = keyDataLen();
+    key->encoding = OIC_ENCODING_DER;
+    OCRepPayloadSetPropPubDataType(payload, OC_RSRVD_CERT, key);
+
+    EXPECT_EQ(OC_STACK_ERROR, HandleCertificateIssueRequest(NULL, (void **)&data, response));
+
+    OicSecKey_t *caCert = (OicSecKey_t *)OICCalloc(1, sizeof(OicSecKey_t));
+    caCert->data = keyData();
+    caCert->len = keyDataLen();
+    caCert->encoding = OIC_ENCODING_DER;
+    OCRepPayloadSetPropPubDataType(payload, OC_RSRVD_CACERT, caCert);
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, HandleCertificateIssueRequest(NULL, (void **)&data, response));
+
+    OCPayloadDestroy((OCPayload *)response->payload);
+    OICFree(response);
+}
+
+TEST_F(CLOUD, OCCloudCertificateIssueRequest)
+{
+    const char *cloudUri = NULL;
+
+    EXPECT_TRUE(OC_STACK_INVALID_PARAM == OCCloudCertificateIssueRequest(NULL, NULL, NULL));
+
+    cloudUri = (const char *)OICCalloc(1, MAX_URI_LENGTH);
+    size_t ret = snprintf((char *)cloudUri, MAX_URI_LENGTH, CLOUD_URI);
+    memset((void *)(cloudUri + ret), 117, MAX_URI_LENGTH - ret);
+
+    EXPECT_TRUE(OC_STACK_INVALID_URI == OCCloudCertificateIssueRequest(NULL, cloudUri,
+                cloudResponseCB));
+    memset((void *)(cloudUri + ret), 0, MAX_URI_LENGTH - ret);
+    EXPECT_TRUE(OC_STACK_OK == OCCloudCertificateIssueRequest(NULL, cloudUri, cloudResponseCB));
+
+    OICFree((void *)cloudUri);
+}
+//--------------------util-----------------
+TEST_F(CLOUD, utill)
+{
+    setCoapPrefix(false);
+    setCoapPrefix(true);
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, handleResponse(NULL, NULL, NULL));
+
+    stringArray_t *serialNumbers = (stringArray_t *)OICCalloc(1, sizeof(stringArray_t));
+
+    clearStringArray(serialNumbers);
+
+    serialNumbers->length = 1;
+    serialNumbers->array = (char **)OICCalloc(serialNumbers->length, sizeof(char *));
+    serialNumbers->array[serialNumbers->length - 1] = OICStrdup("root");
+    clearStringArray(serialNumbers);
 }
diff --git a/resource/csdk/security/provisioning/unittest/credentialgenerator.cpp b/resource/csdk/security/provisioning/unittest/credentialgenerator.cpp
new file mode 100644 (file)
index 0000000..b05156f
--- /dev/null
@@ -0,0 +1,145 @@
+/* *****************************************************************
+ *
+ * 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/credentialgenerator.c"
+#include "tools.h"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#undef TAG
+#define TAG "CG_UNITTEST"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+using namespace std;
+
+class CG : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+
+};
+
+TEST_F(CG, PMGeneratePairWiseCredentialsInvalidFirstDevID)
+{
+    OicUuid_t *SecondDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    if (SecondDevID)
+    {
+        SecondDevID->id[0] = 2;
+    }
+    OicSecCred_t *cred1 = NULL;
+    OicSecCred_t *cred2 = NULL;
+    size_t keySize = OWNER_PSK_LENGTH_128;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE,
+              keySize, NULL, SecondDevID, NULL, NULL, &cred1, &cred2));
+    OICFree(SecondDevID);
+}
+
+TEST_F(CG, PMGeneratePairWiseCredentialsInvalidSecondDevID)
+{
+    OicUuid_t *firstDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    if (firstDevID)
+    {
+        firstDevID->id[0] = 1;
+    }
+    OicUuid_t *provisioningDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    if (provisioningDevID)
+    {
+        provisioningDevID->id[0] = 2;
+    }
+    OicSecCred_t *cred1 = NULL;
+    OicSecCred_t *cred2 = NULL;
+    size_t keySize = OWNER_PSK_LENGTH_128;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE, keySize,
+              firstDevID, NULL, NULL, NULL, &cred1, &cred2));
+    OICFree(firstDevID);
+    OICFree(provisioningDevID);
+}
+
+TEST_F(CG, PMGeneratePairWiseCredentialsInvalidCred)
+{
+    OicUuid_t *firstDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    if (firstDevID)
+    {
+        firstDevID->id[0] = 1;
+    }
+    OicUuid_t *SecondDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    if (SecondDevID)
+    {
+        SecondDevID->id[0] = 2;
+    }
+    OicUuid_t *provisioningDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    if (provisioningDevID)
+    {
+        provisioningDevID->id[0] = 3;
+    }
+    size_t keySize = OWNER_PSK_LENGTH_128;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE, keySize,
+              firstDevID, SecondDevID, NULL, NULL, NULL, NULL));
+    OICFree(firstDevID);
+    OICFree(SecondDevID);
+    OICFree(provisioningDevID);
+}
+
+TEST_F(CG, PMGeneratePairWiseCredentialsFull)
+{
+    OicUuid_t *firstDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    EXPECT_TRUE(NULL != firstDevID);
+    ConvertStrToUuid("11111111-1234-1234-1234-123456789011", firstDevID);
+    OicUuid_t *secondDevID = (OicUuid_t *)OICMalloc(sizeof(OicUuid_t));
+    EXPECT_TRUE(NULL != secondDevID);
+    ConvertStrToUuid("11111111-1234-1234-1234-123456789012", secondDevID);
+    OicSecRole_t *firstRole = (OicSecRole_t *)OICMalloc(sizeof(OicSecRole_t));
+    OicSecRole_t *secondRole = (OicSecRole_t *)OICMalloc(sizeof(OicSecRole_t));
+    OicSecCred_t *firstCred = NULL;
+    OicSecCred_t *secondCred = NULL;
+
+    EXPECT_EQ(OC_STACK_OK, PMGeneratePairWiseCredentials(SYMMETRIC_PAIR_WISE_KEY, OWNER_PSK_LENGTH_256,
+              firstDevID, secondDevID, firstRole, secondRole, &firstCred, &secondCred));
+
+    OICFree(firstCred->privateData.data);
+    OICFree(secondCred->privateData.data);
+    OICFree(secondCred);
+    OICFree(firstCred);
+    OICFree(secondRole);
+    OICFree(firstRole);
+    OICFree(firstDevID);
+    OICFree(secondDevID);
+}
diff --git a/resource/csdk/security/provisioning/unittest/credentialgeneratortest.cpp b/resource/csdk/security/provisioning/unittest/credentialgeneratortest.cpp
deleted file mode 100644 (file)
index 07f7f7c..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/* *****************************************************************
- *
- * Copyright 2015 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 <gtest/gtest.h>
-#include "credentialgenerator.h"
-#include "oic_malloc.h"
-
-
-TEST(PMGeneratePairWiseCredentialsTest, InvalidFirstDevID)
-{
-    OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
-    if(SecondDevID)
-    {
-        SecondDevID->id[0] = 2;
-    }
-    OicSecCred_t *cred1 = NULL;
-    OicSecCred_t *cred2 = NULL;
-    size_t keySize = OWNER_PSK_LENGTH_128;
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE,
-              keySize, NULL, SecondDevID, NULL, NULL, &cred1, &cred2));
-    OICFree(SecondDevID);
-}
-
-TEST(PMGeneratePairWiseCredentialsTest, InvalidSecondDevID)
-{
-    OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
-    if(firstDevID)
-    {
-        firstDevID->id[0] = 1;
-    }
-    OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
-    if(provisioningDevID)
-    {
-        provisioningDevID->id[0] = 2;
-    }
-    OicSecCred_t *cred1 = NULL;
-    OicSecCred_t *cred2 = NULL;
-    size_t keySize = OWNER_PSK_LENGTH_128;
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE, keySize,
-              firstDevID, NULL, NULL, NULL, &cred1, &cred2));
-    OICFree(firstDevID);
-    OICFree(provisioningDevID);
-}
-
-TEST(PMGeneratePairWiseCredentialsTest, InvalidCred)
-{
-    OicUuid_t *firstDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
-    if(firstDevID)
-    {
-        firstDevID->id[0] = 1;
-    }
-    OicUuid_t *SecondDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
-    if(SecondDevID)
-    {
-        SecondDevID->id[0] = 2;
-    }
-    OicUuid_t *provisioningDevID = (OicUuid_t*)OICMalloc(sizeof(OicUuid_t));
-    if(provisioningDevID)
-    {
-        provisioningDevID->id[0] = 3;
-    }
-    size_t keySize = OWNER_PSK_LENGTH_128;
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMGeneratePairWiseCredentials(NO_SECURITY_MODE, keySize,
-              firstDevID, SecondDevID, NULL, NULL, NULL, NULL));
-    OICFree(firstDevID);
-    OICFree(SecondDevID);
-    OICFree(provisioningDevID);
-}
index 3f2e4d5..48de7bf 100644 (file)
  * *****************************************************************/
 #include <gtest/gtest.h>
 #include "ocprovisioningmanager.h"
+#include "experimental/logger.h"
 
-static OicSecAcl_t acl1;
-static OicSecAcl_t acl2;
-static OCProvisionDev_t pDev1;
-static OCProvisionDev_t pDev2;
-static OicSecCredType_t credType = SYMMETRIC_PAIR_WISE_KEY;
-static OicSecOxm_t oicSecDoxmJustWorks = OIC_JUST_WORKS;
-static OicSecOxm_t oicSecDoxmRandomPin = OIC_RANDOM_DEVICE_PIN;
-static OicSecDoxm_t defaultDoxm1 =
-{
-    &oicSecDoxmJustWorks,  /* uint16_t *oxm */
-    1,                      /* size_t oxmLen */
-    OIC_JUST_WORKS,         /* uint16_t oxmSel */
-    SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
-    false,                  /* bool owned */
-    {{0}},                  /* OicUuid_t deviceID */
-    false,                  /* bool dpc */
-    {{0}},                  /* OicUuid_t owner */
-#ifdef MULTIPLE_OWNER
-    NULL,                   /* OicSecSubOwner_t* subOwners */
-    NULL,                   /* OicSecMom_t *mom */
-#endif //MULTIPLE_OWNER
-    {{0}}                   /* rownerID */
-};
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "../src/ocprovisioningmanager.c"
+#include "tools.h"
+
+#ifdef __cplusplus
+}
+#endif
 
-static OicSecDoxm_t defaultDoxm2 =
-{
-    &oicSecDoxmRandomPin,   /* uint16_t *oxm */
-    1,                      /* size_t oxmLen */
-    OIC_RANDOM_DEVICE_PIN,  /* uint16_t oxmSel */
-    SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
-    false,                  /* bool owned */
-    {{0}},                  /* OicUuid_t deviceID */
-    false,                  /* bool dpc */
-    {{0}},                  /* OicUuid_t owner */
-#ifdef MULTIPLE_OWNER
-    NULL,                   /* OicSecSubOwner_t* subOwners */
-    NULL,                   /* OicSecMom_t *mom */
-#endif //MULTIPLE_OWNER
-    {{0}}                   /* rownerID */
+#undef TAG
+#define TAG "OTM_OCPROVISIONINGMANAGER"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+static OCProvisionDev_t *pDev1 = NULL;
+static OCProvisionDev_t *pDev2 = NULL;
+
+class PM : public ::testing::Test
+{
+    public:
+
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+
+            pDev1 = createProvisionDev();
+            pDev2 = createProvisionDev();
+            pDev2->endpoint.port = 9998;
+            ConvertStrToUuid("33333355-3333-3333-3333-111111111111", &pDev2->doxm->deviceID);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+
+        OicSecAcl_t acl1;
+        OicSecAcl_t acl2;
 };
 
-static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4)
+static void provisioningCB (void *UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3,
+                            bool UNUSED4)
 {
     //dummy callback
     (void) UNUSED1;
@@ -70,88 +74,112 @@ static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *
     (void) UNUSED4;
 }
 
-static OCStackResult OTMLoadSecretCallback(OTMContext_totmCtx)
+static OCStackResult OTMLoadSecretCallback(OTMContext_t *otmCtx)
 {
     //dummy callback
     (void) otmCtx;
     return OC_STACK_OK;
 }
 
-TEST(OCInitPMTest, NullPath)
+TEST_F(PM, OCProvisionPairwiseDevicesTestNullDevice1)
 {
-    EXPECT_EQ(OC_STACK_OK, OCInitPM(NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, NULL, &acl1,
+              pDev2, &acl2, &provisioningCB));
 }
 
-TEST(OCProvisionPairwiseDevicesTest, NullDevice1)
+TEST_F(PM, OCProvisionPairwiseDevicesTestNullDevice2)
 {
-    pDev1.doxm = &defaultDoxm1;
-    uint8_t deviceId1[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64};
-    memcpy(pDev1.doxm->deviceID.id, deviceId1, sizeof(deviceId1));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, pDev1, &acl1,
+              NULL, &acl2, &provisioningCB));
+}
 
-    pDev2.doxm = &defaultDoxm2;
-    uint8_t deviceId2[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x63};
-    memcpy(pDev2.doxm->deviceID.id, deviceId2, sizeof(deviceId2));
+TEST_F(PM, OCProvisionPairwiseDevicesTestSamelDeviceId)
+{
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, pDev1, &acl1,
+              pDev1, &acl2, &provisioningCB));
+}
 
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
-                                                              OWNER_PSK_LENGTH_128, NULL, &acl1,
-                                                              &pDev2, &acl2, &provisioningCB));
+TEST_F(PM, OCProvisionPairwiseDevicesTestNullCallback)
+{
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, pDev1, &acl1,
+              pDev2, &acl2, NULL));
 }
 
-TEST(OCProvisionPairwiseDevicesTest, NullDevice2)
+TEST_F(PM, OCProvisionPairwiseDevicesTestInvalidKeySize)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
-                                                              OWNER_PSK_LENGTH_128, &pDev1, &acl1,
-                                                              NULL, &acl2, &provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              0, pDev1, &acl1,
+              pDev2, &acl2, &provisioningCB));
 }
 
-TEST(OCProvisionPairwiseDevicesTest, SamelDeviceId)
+TEST_F(PM, OCProvisionPairwiseDevices)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
-                                                              OWNER_PSK_LENGTH_128, &pDev1, &acl1,
-                                                              &pDev1, &acl2, &provisioningCB));
+    PDMDeleteDevice(&pDev1->doxm->deviceID);
+    PDMDeleteDevice(&pDev2->doxm->deviceID);
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev1->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev2->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev1->doxm->deviceID, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev2->doxm->deviceID, PDM_DEVICE_ACTIVE));
+
+    EXPECT_EQ(OC_STACK_OK, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_256, pDev1, &acl1,
+              pDev2, &acl2, &provisioningCB));
+    EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_256, pDev1, &acl1,
+              pDev2, &acl2, &provisioningCB));
 }
 
-TEST(OCProvisionPairwiseDevicesTest, NullCallback)
+TEST_F(PM, OCGetDevInfoFromNetwork)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCProvisionPairwiseDevices(NULL, credType,
-                                                              OWNER_PSK_LENGTH_128, &pDev1, &acl1,
-                                                              &pDev2, &acl2, NULL));
+    OCProvisionDev_t *pOwnedDevList = NULL;
+    OCProvisionDev_t *pUnownedDevList = NULL;
+    EXPECT_EQ(OC_STACK_OK, OCGetDevInfoFromNetwork(4, &pOwnedDevList, &pUnownedDevList));
 }
 
-TEST(OCProvisionPairwiseDevicesTest, InvalidKeySize)
+TEST_F(PM, OCUnlinkDevicesTestNullDevice1)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionPairwiseDevices(NULL, credType,
-                                                              0, &pDev1, &acl1,
-                                                              &pDev2, &acl2 ,&provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, NULL, pDev2, provisioningCB));
 }
 
-TEST(OCUnlinkDevicesTest, NullDevice1)
+TEST_F(PM, OCUnlinkDevicesTestNullDevice2)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, NULL, &pDev2, provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, pDev1, NULL, provisioningCB));
 }
 
-TEST(OCUnlinkDevicesTest, NullDevice2)
+TEST_F(PM, OCUnlinkDevicesTestNullCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, &pDev1, NULL, provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCUnlinkDevices(NULL, pDev1, pDev2, NULL));
 }
 
-TEST(OCUnlinkDevicesTest, NullCallback)
+TEST_F(PM, OCUnlinkDevicesTestSamelDeviceId)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCUnlinkDevices(NULL, &pDev1, &pDev2, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL, pDev1, pDev1, provisioningCB));
 }
 
-TEST(OCUnlinkDevicesTest, SamelDeviceId)
+TEST_F(PM, OCUnlinkDevicesTest)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCUnlinkDevices(NULL,&pDev1, &pDev1, &provisioningCB));
+    PDMDeleteDevice(&pDev1->doxm->deviceID);
+    PDMDeleteDevice(&pDev2->doxm->deviceID);
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev1->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev2->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev1->doxm->deviceID, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev2->doxm->deviceID, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, OCUnlinkDevices(NULL, pDev1, pDev2, provisioningCB));
 }
 
-TEST(OCRemoveDeviceTest, NullTargetDevice)
+TEST_F(PM, OCRemoveDeviceTestNullTargetDevice)
 {
     unsigned short waitTime = 10 ;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, NULL, provisioningCB));
 }
 
-TEST(OCRemoveDeviceWithUuidTest, NullTargetDevice)
+TEST_F(PM, OCRemoveDeviceWithUuidTestNullTargetDevice)
 {
     unsigned short waitTime = 10 ;
     OicUuid_t uuid;
@@ -160,33 +188,33 @@ TEST(OCRemoveDeviceWithUuidTest, NullTargetDevice)
     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDeviceWithUuid(NULL, waitTime, &uuid, NULL));
 }
 
-TEST(OCRemoveDeviceTest, NullResultCallback)
+TEST_F(PM, OCRemoveDeviceTestNullResultCallback)
 {
     unsigned short waitTime = 10;
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDevice(NULL, waitTime, &pDev1, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCRemoveDevice(NULL, waitTime, pDev1, NULL));
 }
 
-TEST(OCRemoveDeviceTest, ZeroWaitTime)
+TEST_F(PM, OCRemoveDeviceTestZeroWaitTime)
 {
     unsigned short waitTime = 0;
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, &pDev1, provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCRemoveDevice(NULL, waitTime, pDev1, provisioningCB));
 }
 
-TEST(OCGetDevInfoFromNetworkTest, NullUnOwnedDeviceInfo)
+TEST_F(PM, OCGetDevInfoFromNetworkTestNullUnOwnedDeviceInfo)
 {
     unsigned short waitTime = 10;
     OCProvisionDev_t *ownedList = NULL;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, NULL));
 }
 
-TEST(OCGetDevInfoFromNetworkTest, NullOwnedDeviceInfo)
+TEST_F(PM, OCGetDevInfoFromNetworkTestNullOwnedDeviceInfo)
 {
     unsigned short waitTime = 10;
     OCProvisionDev_t *unownedList = NULL;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, NULL, &unownedList));
 }
 
-TEST(OCGetDevInfoFromNetworkTest, ZeroWaitTime)
+TEST_F(PM, OCGetDevInfoFromNetworkTestZeroWaitTime)
 {
     unsigned short waitTime = 0;
     OCProvisionDev_t *ownedList = NULL;
@@ -194,61 +222,205 @@ TEST(OCGetDevInfoFromNetworkTest, ZeroWaitTime)
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetDevInfoFromNetwork(waitTime, &ownedList, &unownedList));
 }
 
-TEST(OCGetLinkedStatusTest, NULLDeviceID)
+TEST_F(PM, OCGetLinkedStatusTestNULLDeviceID)
 {
     OCUuidList_t *list = NULL;
     size_t noOfDevices = 0;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCGetLinkedStatus(NULL, &list, &noOfDevices));
 }
 
-TEST(OCDeleteUuidListTest, NullUuidList)
+TEST_F(PM, OCDeleteUuidListTestNullUuidList)
 {
     OCDeleteUuidList(NULL);
     EXPECT_EQ(1, 1);
 }
 
-TEST(OCDeleteACLListTest, NullACLList)
+TEST_F(PM, OCDeleteACLListTestNullACLList)
 {
     OCDeleteACLList(NULL);
     EXPECT_EQ(1, 1);
 }
 
-TEST(OCDeleteDiscoveredDevicesTest, NullProvisionDevList)
+TEST_F(PM, OCDeleteDiscoveredDevicesTestNullProvisionDevList)
 {
     OCDeleteDiscoveredDevices(NULL);
     EXPECT_EQ(1, 1);
 }
 
-TEST(OCSetOwnerTransferCallbackDataTest, NULLCallback)
+TEST_F(PM, OCSetOwnerTransferCallbackDataTestNULLCallback)
 {
     OicSecOxm_t ownershipTransferMethod = OIC_JUST_WORKS;
     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
-    NULL));
+              NULL));
 }
 
-TEST(OCSetOwnerTransferCallbackDataTest, InvalidOXMType)
+TEST_F(PM, OCSetOwnerTransferCallbackDataTestInvalidOXMType)
 {
     OicSecOxm_t ownershipTransferMethod = OIC_OXM_COUNT;
     OTMCallbackData_t stOTMCallbackData = { &OTMLoadSecretCallback, NULL, NULL, NULL};
     EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetOwnerTransferCallbackData(ownershipTransferMethod,
-    &stOTMCallbackData));
+              &stOTMCallbackData));
 }
 
-TEST(OCResetDeviceTest, NULLCallback)
+TEST_F(PM, UpdateLinkResults)
 {
-    unsigned short waitTime = 10;
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCResetDevice(NULL, waitTime, &pDev1, NULL));
+    Linkdata_t *link = (Linkdata_t *)OICMalloc(sizeof(Linkdata_t));
+    link->pDev1 = NULL;
+    link->pDev1Acl = (OicSecAcl_t *)OICCalloc(1, sizeof(OicSecAcl_t));
+    link->pDev2 = NULL;
+    link->pDev2Acl = (OicSecAcl_t *)OICCalloc(1, sizeof(OicSecAcl_t));
+//    link->ctx = ctx;
+    link->numOfResults = 2;
+//    link->resultCallback = resultCallback;
+    link->currentCountResults = 0;
+    link->resArr = (OCProvisionResult_t *)OICCalloc(link->numOfResults, sizeof(OCProvisionResult_t));
+
+    UpdateLinkResults(NULL, 1, OC_STACK_OK);
+    UpdateLinkResults(link, 1, OC_STACK_OK);
+    link->pDev1 = createProvisionDev();
+    UpdateLinkResults(link, 1, OC_STACK_OK);
+    link->pDev2 = createProvisionDev();
+    UpdateLinkResults(link, 2, OC_STACK_OK);
+
+    freeProvisionDev((OCProvisionDev_t *)link->pDev1);
+    freeProvisionDev((OCProvisionDev_t *)link->pDev2);
+    OICFree(link->pDev2Acl);
+    OICFree(link->pDev1Acl);
+    OICFree(link->resArr);
+    OICFree(link);
 }
 
-TEST(OCResetDeviceTest, NullTargetDevice)
+static void prcb(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
 {
-    unsigned short waitTime = 10;
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCResetDevice(NULL, waitTime, NULL, provisioningCB));
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+    OC_UNUSED(ctx);
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
 }
 
-TEST(OCResetDeviceTest, ZeroWaitTime)
+Linkdata_t *createLinkData()
 {
-    unsigned short waitTime = 0;
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCResetDevice(NULL, waitTime, &pDev1, provisioningCB));
+    Linkdata_t *link = (Linkdata_t *)OICMalloc(sizeof(Linkdata_t));
+    link->pDev1 = createProvisionDev();
+    link->pDev1Acl = (OicSecAcl_t *)OICCalloc(1, sizeof(OicSecAcl_t));
+    link->pDev2 = createProvisionDev();
+    link->pDev2Acl = (OicSecAcl_t *)OICCalloc(1, sizeof(OicSecAcl_t));
+    link->numOfResults = 2;
+    link->currentCountResults = 0;
+    link->resArr = (OCProvisionResult_t *) OICMalloc(sizeof(OCProvisionResult_t) * link->numOfResults);
+    link->resultCallback = prcb;
+    return link;
+}
+
+void freeLinkData(Linkdata_t *link)
+{
+    freeProvisionDev((OCProvisionDev_t *)link->pDev2);
+    freeProvisionDev((OCProvisionDev_t *)link->pDev1);
+    OICFree(link->resArr);
+    OICFree(link->pDev2Acl);
+    OICFree(link->pDev1Acl);
+    OICFree(link);
+}
+
+TEST_F(PM, AclProv2CB)
+{
+    OCProvisionResult_t *arr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+
+    AclProv2CB(NULL, 1, arr, false);
+
+    Linkdata_t *link = createLinkData();
+    AclProv2CB((void *)link, 1, arr, false);
+
+    Linkdata_t *link1 = createLinkData();
+    AclProv2CB((void *)link1, 1, arr, true);
+
+    OICFree(arr);
+}
+
+TEST_F(PM, ProvisionCredsCB)
+{
+    Linkdata_t *link = createLinkData();
+    OCProvisionResult_t *arr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+
+    ProvisionCredsCB(NULL, 1, arr, false);
+    ProvisionCredsCB((void *)link, 1, arr, false);
+
+    Linkdata_t *link1 = createLinkData();
+    ProvisionCredsCB((void *)link1, 1, arr, true);
+
+    OICFree(arr);
+}
+
+TEST_F(PM, AclProv1CB)
+{
+    Linkdata_t *link = createLinkData();
+    OCProvisionResult_t *arr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+
+    AclProv1CB(NULL, 1, arr, false);
+    AclProv1CB((void *)link, 1, arr, true);
+
+    Linkdata_t *link1 = createLinkData();
+    AclProv1CB((void *)link1, 1, arr, false);
+
+    OICFree(arr);
+}
+
+TEST_F(PM, RemoveDeviceInfoFromLocal)
+{
+    OCProvisionDev_t *pDev = createProvisionDev();
+    PDMAddDevice(&pDev->doxm->deviceID);
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev->doxm->deviceID, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, RemoveDeviceInfoFromLocal(pDev));
+    freeProvisionDev(pDev);
+}
+
+static void provisionResultCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+    OIC_LOG_V(DEBUG, TAG, "%s: has error: %d", __func__, hasError);
+}
+TEST_F(PM, OCRemoveDevice)
+{
+    void *ctx = NULL;
+    OCProvisionDev_t *pDev = createProvisionDev();
+//    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev->doxm->deviceID, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, OCRemoveDevice(ctx, 1, pDev, provisionResultCB));
+    freeProvisionDev(pDev);
+}
+
+TEST_F(PM, OCRemoveDeviceWithUuid)
+{
+    void *ctx = NULL;
+
+    OicUuid_t *uuid1 = createUuidWith("33333333-3333-3333-3333-000000000000");
+    OicUuid_t *uuid2 = createUuidWith("33333333-3333-3333-3333-000000000001");
+
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(uuid1));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(uuid1, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(uuid2));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(uuid2, PDM_DEVICE_ACTIVE));
+
+    EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(uuid1, uuid2));
+
+    EXPECT_EQ(OC_STACK_OK, OCRemoveDeviceWithUuid(ctx, 1, uuid1, provisionResultCB));
+    freeUuid(uuid1);
+    freeUuid(uuid2);
+}
+
+TEST_F(PM, OCResetDevice)
+{
+    void *ctx = NULL;
+    OCProvisionDev_t *pDev = createProvisionDev();
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev->doxm->deviceID, PDM_DEVICE_ACTIVE));
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCResetDevice(ctx, 0, pDev, provisionResultCB));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, OCResetDevice(ctx, 1, pDev, NULL));
+    EXPECT_EQ(OC_STACK_OK, OCResetDevice(ctx, 1, pDev, provisionResultCB));
+    freeProvisionDev(pDev);
 }
 
diff --git a/resource/csdk/security/provisioning/unittest/otmcontextlist.cpp b/resource/csdk/security/provisioning/unittest/otmcontextlist.cpp
new file mode 100644 (file)
index 0000000..fce7c5d
--- /dev/null
@@ -0,0 +1,58 @@
+/* *****************************************************************
+ *
+ * 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/otmcontextlist.c"
+#include "tools.h"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#undef TAG
+#define TAG "OCL_UNITTEST"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+using namespace std;
+
+class OCL : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
index e09a883..62dbf29 100644 (file)
 #include "pmutility.h"
 #include "experimental/ocrandom.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+//#include "../src/ocprovisioningmanager.c"
+#include "../../../stack/src/ocpayloadparse.c"
+#include "tools.h"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#define TAG "OTM_UNITTEST"
+
 #define OTM_TIMEOUT 60
 #define DISCOVERY_TIMEOUT 10
 
 #define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
-#define PM_DB_FILE_NAME "test.db"
+#define PM_DB_FILE_NAME TAG".db"
 
-static OCPersistentStorage gPst;
 static bool g_doneCB;
 static bool g_callbackResult;
 static const char *g_otmCtx = "Test User Context";
@@ -56,9 +70,107 @@ static size_t gNumOfOwnDevice = 0;
 
 using namespace std;
 
-#define TAG "OTM_UNITTEST"
+#define UUID_TEMPLATE "11111111-1234-1234-1234-12345678901"
+#define UUID_TEMPLATE_LEN 35
+
+class OTM : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+
+            OTMCallbackData_t otmcb;
+            otmcb.loadSecretCB = LoadSecretJustWorksCallback;
+            otmcb.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
+            otmcb.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
+            otmcb.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
+
+            EXPECT_EQ(OC_STACK_OK, OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb));
+
+            g_doneCB = false;
+            g_callbackResult = false;
+
+            gNumOfUnownDevice = 0;
+            gNumOfOwnDevice = 0;
+        }
+
+        static void TearDownTestCase()
+        {
+            PMDeleteDeviceList(g_unownedDevices);
+            PMDeleteDeviceList(g_ownedDevices);
+
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
+TEST_F(OTM, OCParsPayloadFull)
+{
+    OCPayload *outPayload = NULL;
+    uint8_t payload[] =
+        "\277brt\202hoic.wk.dhoic.d.tvbif\202ooic.if.baselinehoic.if.rbdix$80d642ae-9263-4a37-be4d-6ae7165bbda5cdmvrres.1.1.0,sh.1.1.0cicvjcore.1.1.0anl[TV] Samsung\377";
+    size_t payloadSize = 147;
+    EXPECT_EQ(OC_STACK_OK, OCParsePayload(&outPayload, OC_FORMAT_CBOR, PAYLOAD_TYPE_REPRESENTATION,
+                                          payload, payloadSize));
+}
+
+TEST_F(OTM, OCDiscoverUnownedDevices)
+{
+    PMDeleteDeviceList(g_unownedDevices);
+    g_unownedDevices = NULL;
+    EXPECT_EQ(OC_STACK_OK, OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unownedDevices));
+
+    OCProvisionDev_t *tempDev1 = NULL;
+    OCProvisionDev_t *tempDev2 = NULL;
+    gNumOfUnownDevice = 0;
+    LL_FOREACH_SAFE(g_unownedDevices, tempDev1, tempDev2)
+    {
+        PMPrintOCProvisionDev(tempDev1);
+        char *uuidString = NULL;
+        EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t *) &tempDev1->doxm->deviceID,
+                                                &uuidString));
+
+        OIC_LOG_V(DEBUG, TAG, "%s: id:%s ip:%s:%d", __func__,
+                  uuidString ? uuidString : "unknow id",
+                  tempDev1->endpoint.addr, tempDev1->endpoint.port);
+
+        if (0 != strncmp(UUID_TEMPLATE, uuidString, UUID_TEMPLATE_LEN))
+        {
+            LL_DELETE(g_unownedDevices, tempDev1);
+        }
+        else
+        {
+            OIC_LOG_V(DEBUG, TAG, "%s: append in list", __func__);
+            gNumOfUnownDevice++;
+        }
+        OICFree(uuidString);
+    }
+
+    EXPECT_TRUE(gNumOfUnownDevice > 0);
+}
+
+TEST_F(OTM, CreatePinBasedSelectOxmPayloadFull)
+{
+    OicSecDoxm_t *doxm = createDoxm();
+    doxm->oxm[0] = OIC_RANDOM_DEVICE_PIN;
+    doxm->oxmSel = OIC_RANDOM_DEVICE_PIN;
+    doxm->sct    = SYMMETRIC_PAIR_WISE_KEY | SIGNED_ASYMMETRIC_KEY;
+
+    OTMContext_t *otmCtx = (OTMContext_t *)OICCalloc(1, sizeof(OTMContext_t));
+    otmCtx->selectedDeviceInfo = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    otmCtx->selectedDeviceInfo->doxm = doxm;
+    uint8_t *payload = NULL;
+    size_t size = 0;
+
+    EXPECT_EQ(OC_STACK_OK, CreatePinBasedSelectOxmPayload(otmCtx, &payload, &size));
 
-TEST(JustWorksOxMTest, NullParam)
+    freeDoxm(doxm);
+    OICFree(payload);
+    OICFree(otmCtx->selectedDeviceInfo);
+    OICFree(otmCtx);
+}
+
+TEST_F(OTM, JustWorksOxMTestNullParam)
 {
     OTMContext_t *otmCtx = NULL;
     OCStackResult res = OC_STACK_ERROR;
@@ -95,7 +207,7 @@ TEST(JustWorksOxMTest, NullParam)
     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
 }
 
-TEST(RandomPinOxMTest, NullParam)
+TEST_F(OTM, RandomPinOxMTestNullParam)
 {
     OTMContext_t *otmCtx = NULL;
     OCStackResult res = OC_STACK_ERROR;
@@ -132,7 +244,7 @@ TEST(RandomPinOxMTest, NullParam)
     EXPECT_TRUE(OC_STACK_INVALID_PARAM == res);
 }
 
-TEST(ManufacturerCertOxMTest, NullParam)
+TEST_F(OTM, ManufacturerCertOxMTestNullParam)
 {
     OTMContext_t *otmCtx = NULL;
     OCStackResult res = OC_STACK_ERROR;
@@ -170,16 +282,6 @@ TEST(ManufacturerCertOxMTest, NullParam)
 /****************************************
  * Test the OTM modules with sample server
  ****************************************/
-static FILE *fopen_prvnMng(const char *path, const char *mode)
-{
-    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
-    {
-        return fopen(SVR_DB_FILE_NAME, mode);
-    }
-    OIC_LOG_V(DEBUG, TAG, "use db: %s", path);
-    return fopen(path, mode);
-}
-
 // callback function(s) for provisioning client using C-level provisioning API
 static void ownershipTransferCB(void *ctx, size_t UNUSED1, OCProvisionResult_t *UNUSED2,
                                 bool hasError)
@@ -236,118 +338,53 @@ static int waitCallbackRet(void)
     return 0;
 }
 
-#define UUID_TEMPLATE "11111111-1234-1234-1234-12345678901"
-#define UUID_TEMPLATE_LEN 35
-
-TEST(InitForOTM, NullParam)
-{
-    OCStackResult result = OC_STACK_ERROR;
-
-    OTMCallbackData_t otmcb;
-    otmcb.loadSecretCB = LoadSecretJustWorksCallback;
-    otmcb.createSecureSessionCB = CreateSecureSessionJustWorksCallback;
-    otmcb.createSelectOxmPayloadCB = CreateJustWorksSelectOxmPayload;
-    otmcb.createOwnerTransferPayloadCB = CreateJustWorksOwnerTransferPayload;
-#ifdef HAVE_UNISTD_H
-    EXPECT_EQ(0, access(SVR_DB_FILE_NAME, F_OK));
-#endif // HAVE_UNISTD_H
-    gPst.open = fopen_prvnMng;
-    gPst.read = fread;
-    gPst.write = fwrite;
-    gPst.close = fclose;
-    gPst.unlink = unlink;
-
-    // register the persistent storage handler for SVR
-    result = OCRegisterPersistentStorageHandler(&gPst);
-    EXPECT_EQ(OC_STACK_OK, result);
-
-    // initialize OC stack and provisioning manager
-    result = OCInit(NULL, 0, OC_CLIENT_SERVER);
-    EXPECT_EQ(OC_STACK_OK, result);
-
-    //initialize Provisioning DB Manager
-    result = OCInitPM(PM_DB_FILE_NAME);
-    EXPECT_EQ(OC_STACK_OK, result);
-
-    // register callback function(s) for Justworks OxM
-    result = OCSetOwnerTransferCallbackData(OIC_JUST_WORKS, &otmcb);
-    EXPECT_EQ(OC_STACK_OK, result);
-
-    g_doneCB = false;
-    g_callbackResult = false;
-
-    gNumOfUnownDevice = 0;
-    gNumOfOwnDevice = 0;
-    // close Provisioning DB
-    EXPECT_EQ(OC_STACK_OK, OCClosePM());
-}
-/*
-TEST(OCDiscoverSingleDeviceInUnicast, Simple)
+TEST_F(OTM, OCDiscoverSingleDevice)
 {
-    OCProvisionDev_tfoundDevice = NULL;
+    OCProvisionDev_t *foundDevice = NULL;
 
     OicUuid_t uuid = {0};
     ConvertStrToUuid("11111111-1234-1234-1234-123456789011", &uuid);
 
-    EXPECT_EQ(OC_STACK_OK, OCDiscoverSingleDeviceInUnicast(DISCOVERY_TIMEOUT, &uuid, "::1", CT_ADAPTER_IP, &foundDevice));
+    EXPECT_EQ(OC_STACK_OK, OCDiscoverSingleDevice(DISCOVERY_TIMEOUT, &uuid, &foundDevice));
 
     int NumOfFoundDevice = 0;
-    OCProvisionDev_ttempDev = foundDevice;
-    while(tempDev)
+    OCProvisionDev_t *tempDev = foundDevice;
+    while (tempDev)
     {
         NumOfFoundDevice++;
         tempDev = tempDev->next;
     }
 
-    PMDeleteDeviceList(foundDevice);
     OIC_LOG_V(DEBUG, TAG, "Discoveed: %d devices", NumOfFoundDevice);
-    //TODO fix after:
-    //54:22.622 INFO: OIC_SRM: Received error from remote device with result, 7 for request uri, /oic/sec/doxm
-    //EXPECT_EQ(true, NumOfFoundDevice > 0);
+    EXPECT_EQ(1, NumOfFoundDevice);
+    PMPrintOCProvisionDev(foundDevice);
+    PMDeleteDeviceList(foundDevice);
 }
-*/
-TEST(OCDiscoverUnownedDevices, Simple)
-{
-    //initialize Provisioning DB Manager
-    EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
-    EXPECT_EQ(OC_STACK_OK, OCDiscoverUnownedDevices(DISCOVERY_TIMEOUT, &g_unownedDevices));
 
-    OCProvisionDev_t *tempDev1 = NULL;
-    OCProvisionDev_t *tempDev2 = NULL;
-    gNumOfUnownDevice = 0;
-    LL_FOREACH_SAFE(g_unownedDevices, tempDev1, tempDev2)
+TEST_F(OTM, OCDiscoverSingleDeviceInUnicast)
+{
+    OicUuid_t uuid = {0};
+    ConvertStrToUuid("11111111-1234-1234-1234-123456789011", &uuid);
+    OCProvisionDev_t *foundDevice = NULL;
+    ASSERT_EQ(OC_STACK_OK, OCDiscoverSingleDeviceInUnicast(DISCOVERY_TIMEOUT, &uuid, "", CT_ADAPTER_IP,
+              &foundDevice));
+    int NumOfFoundDevice = 0;
+    OCProvisionDev_t *tempDev = foundDevice;
+    while (tempDev)
     {
-        char *uuidString = NULL;
-        EXPECT_EQ(OC_STACK_OK, ConvertUuidToStr((const OicUuid_t *) &tempDev1->doxm->deviceID,
-                                                &uuidString));
-
-        OIC_LOG_V(DEBUG, TAG, "%s: id:%s ip:%s:%d", __func__,
-                      uuidString ? uuidString : "unknow id",
-                      tempDev1->endpoint.addr, tempDev1->endpoint.port);
-
-        if (0 != strncmp(UUID_TEMPLATE, uuidString, UUID_TEMPLATE_LEN))
-        {
-            LL_DELETE(g_unownedDevices,tempDev1);
-        }
-        else
-        {
-            OIC_LOG_V(DEBUG, TAG, "%s: append in list", __func__);
-            gNumOfUnownDevice++;
-        }
-        OICFree(uuidString);
+        NumOfFoundDevice++;
+        tempDev = tempDev->next;
     }
 
-    EXPECT_EQ(true, gNumOfUnownDevice > 0);
-
-    // close Provisioning DB
-    EXPECT_EQ(OC_STACK_OK, OCClosePM());
+    PMDeleteDeviceList(foundDevice);
+    OIC_LOG_V(DEBUG, TAG, "Discoveed: %d devices", NumOfFoundDevice);
+    EXPECT_GT(NumOfFoundDevice, 0);
 }
 
-TEST(OCDoOwnershipTransfer, Simple)
+TEST_F(OTM, OCDoOwnershipTransfer)
 {
-    //initialize Provisioning DB Manager
-    EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
-    ASSERT_EQ(true, gNumOfUnownDevice > 0);
+    ASSERT_TRUE(gNumOfUnownDevice > 0);
+    ASSERT_NE(nullptr, g_unownedDevices);
 
     g_doneCB = false;
     EXPECT_EQ(OC_STACK_OK, OCDoOwnershipTransfer((void *)g_otmCtx, g_unownedDevices,
@@ -361,15 +398,10 @@ TEST(OCDoOwnershipTransfer, Simple)
 
     EXPECT_EQ(true, g_callbackResult);
     EXPECT_EQ(true, g_doneCB);
-    // close Provisioning DB
-    EXPECT_EQ(OC_STACK_OK, OCClosePM());
 }
 
-TEST(OCDiscoverOwnedDevices, Simple)
+TEST_F(OTM, OCDiscoverOwnedDevices)
 {
-    //initialize Provisioning DB Manager
-    EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
-
     EXPECT_EQ(OC_STACK_OK, OCDiscoverOwnedDevices(DISCOVERY_TIMEOUT, &g_ownedDevices));
 
     gNumOfOwnDevice = 0;
@@ -381,12 +413,157 @@ TEST(OCDiscoverOwnedDevices, Simple)
         tempDev = tempDev->next;
     }
 
-    EXPECT_EQ(true, gNumOfOwnDevice > 0);
-    // close Provisioning DB
-    EXPECT_EQ(OC_STACK_OK, OCClosePM());
+    EXPECT_TRUE(gNumOfOwnDevice > 0);
 }
 
-TEST(PerformLinkDevices, NullParam)
+static void resultCallBack(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+}
+
+static void roleResultCallBack(void *ctx, size_t nOfRes, OCPMGetRolesResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+}
+
+static void SpResultCallBack(void *ctx, size_t nOfRes, OCPMGetSpResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+}
+
+void CSRResultCallBack(void *ctx, size_t nOfRes, OCPMGetCsrResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+}
+
+TEST_F(OTM, ACLFull)
+{
+    if (g_ownedDevices == 0)
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: donn't found owned device", __func__);
+        return;
+    }
+
+    bool ctx = false;
+    OCProvisionDev_t *selectedDeviceInfo = g_ownedDevices;
+    OicSecAcl_t *acl = (OicSecAcl_t *)OICCalloc(1, sizeof(OicSecAcl_t));
+
+    OicSecRsrc_t *rsrc = (OicSecRsrc_t *)OICCalloc(1, sizeof(OicSecRsrc_t));
+    rsrc->href = (char *)OICCalloc(16, sizeof(char));
+    sprintf(rsrc->href, "/oic/sec/pstat");
+    rsrc->wildcard = NO_WILDCARD;
+
+    OicSecAce_t *ace = (OicSecAce_t *)OICCalloc(1, sizeof(OicSecAce_t));
+    OicSecAce_t *acem = NULL;
+    LL_FOREACH(acl->aces, acem)
+    {
+        ace->aceid |= acem->aceid;
+    }
+
+    ace->subjectType = OicSecAceRoleSubject;
+    ace->subjectConn = ANON_CLEAR;
+    ace->permission = PERMISSION_READ | PERMISSION_WRITE;
+    LL_APPEND(ace->resources, rsrc);
+    LL_APPEND(acl->aces, ace);
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionACL((void *)&ctx, selectedDeviceInfo, NULL,
+              resultCallBack));
+
+    EXPECT_EQ(OC_STACK_OK, OCProvisionACL((void *)&ctx, selectedDeviceInfo, acl, resultCallBack));
+
+    ace->subjectType = OicSecAceConntypeSubject;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionACL((void *)&ctx, selectedDeviceInfo, acl,
+              resultCallBack));
+    EXPECT_EQ(OC_STACK_OK, OCProvisionACL2((void *)&ctx, selectedDeviceInfo, acl, resultCallBack));
+    EXPECT_EQ(OC_STACK_OK, OCSaveACL(acl));
+
+    EXPECT_EQ(OC_STACK_OK, OCGetCredResource((void *)&ctx, selectedDeviceInfo, resultCallBack));
+
+    EXPECT_EQ(OC_STACK_OK, OCGetACLResource((void *)&ctx, selectedDeviceInfo, resultCallBack));
+    EXPECT_EQ(OC_STACK_OK, OCGetACL2Resource((void *)&ctx, selectedDeviceInfo, resultCallBack));
+
+    EXPECT_EQ(OC_STACK_OK, OCGetCSRResource((void *)&ctx, selectedDeviceInfo, CSRResultCallBack));
+
+    EXPECT_EQ(OC_STACK_OK, OCGetSpResource((void *)&ctx, selectedDeviceInfo, SpResultCallBack));
+
+    EXPECT_EQ(OC_STACK_OK, OCGetRolesResource((void *)&ctx, selectedDeviceInfo, roleResultCallBack));
+
+    uint8_t *trustCertChain = NULL;
+    size_t chainSize = 0;
+    EXPECT_EQ(OC_STACK_ERROR, OCReadTrustCertChain(0, &trustCertChain, &chainSize));
+
+    EXPECT_EQ(OC_STACK_OK, OCDeleteRoleCertificateByCredId((void *)&ctx, selectedDeviceInfo,
+              resultCallBack, 0));
+
+    OICFree(rsrc->href);
+    OICFree(rsrc);
+    OICFree(ace);
+    OICFree(acl);
+}
+
+static void provisionResultCallBack(void *ctx, size_t nOfRes, OCProvisionResult_t *arr,
+                                    bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
+}
+
+TEST_F(OTM, CredFull)
+{
+    if (g_ownedDevices == 0)
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: donn't found owned device", __func__);
+        return;
+    }
+
+    void *ctx = NULL;
+    OicSecCredType_t type = SYMMETRIC_PAIR_WISE_KEY;
+    size_t keySize = 256;
+    OCProvisionDev_t *pDev1 = g_ownedDevices;
+    OCProvisionDev_t *pDev2 = g_ownedDevices ? g_ownedDevices->next : NULL;
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionCredentials(ctx, type, keySize, pDev1, pDev2,
+              provisionResultCallBack));
+    OicSecRole_t *role1 = (OicSecRole_t *)OICCalloc(1, sizeof(OicSecRole_t));
+    OicSecRole_t *role2 = (OicSecRole_t *)OICCalloc(1, sizeof(OicSecRole_t));
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionSymmetricRoleCredentials(ctx, type, keySize, pDev1,
+              pDev2, role1, role2, provisionResultCallBack));
+    char *pem = (char *)OICCalloc(512, sizeof(char));
+    snprintf(pem, 512, "begin cert\nend cert\n");
+    EXPECT_EQ(OC_STACK_OK, OCProvisionCertificate(ctx, pDev1, pem, provisionResultCallBack));
+
+    OICFree(pem);
+    OICFree(role2);
+    OICFree(role1);
+    OICFree(ctx);
+}
+
+TEST_F(OTM, PerformLinkDevicesNullParam)
 {
     if (gNumOfOwnDevice < 2)
     {
@@ -431,7 +608,7 @@ TEST(PerformLinkDevices, NullParam)
 }
 
 
-TEST(PerformUnlinkDevices, NullParam)
+TEST_F(OTM, PerformUnlinkDevicesNullParam)
 {
     OCStackResult result = OC_STACK_OK;
 
@@ -482,7 +659,7 @@ static void provisionPreconfiguredPinCB(void *ctx, size_t nOfRes, OCProvisionRes
     g_doneCB = true;
 }
 
-TEST(EnableMOT, NullParam)
+TEST_F(OTM, EnableMOTNullParam)
 {
     OCStackResult result = OC_STACK_OK;
 
@@ -508,7 +685,7 @@ TEST(EnableMOT, NullParam)
     EXPECT_TRUE(g_callbackResult);
 }
 
-TEST(DiscoverMOTEnabledDevices, NullParam)
+TEST_F(OTM, DiscoverMOTEnabledDevicesNullParam)
 {
     if (g_motEnabledDevices)
     {
@@ -523,13 +700,13 @@ TEST(DiscoverMOTEnabledDevices, NullParam)
     EXPECT_EQ(true, g_motEnabledDevices != NULL);
 }
 
-TEST(RegisterPreconfiguredPIN, NullParam)
+TEST_F(OTM, RegisterPreconfiguredPINNullParam)
 {
     OCStackResult result = SetPreconfigPin("12341234", strlen("12341234"));
     EXPECT_EQ(OC_STACK_OK, result);
 }
 
-TEST(ProvisonPreconfiguredPIN, NullParam)
+TEST_F(OTM, ProvisonPreconfiguredPINNullParam)
 {
     ASSERT_EQ(true, g_motEnabledDevices != NULL);
     OCStackResult result = OC_STACK_OK;
@@ -547,7 +724,7 @@ TEST(ProvisonPreconfiguredPIN, NullParam)
     EXPECT_EQ(true, g_callbackResult);
 }
 
-TEST(SelectMOTMethod, NullParam)
+TEST_F(OTM, SelectMOTMethodNullParam)
 {
     ASSERT_EQ(true, g_motEnabledDevices != NULL);
     OCStackResult result = OC_STACK_OK;
@@ -565,7 +742,7 @@ TEST(SelectMOTMethod, NullParam)
 }
 
 // TODO: Need to new server to perform MOT
-TEST(PerformMOT, NullParam)
+TEST_F(OTM, PerformMOTNullParam)
 {
     ASSERT_EQ(true, g_motEnabledDevices != NULL);
     OCStackResult result = OC_STACK_OK;
@@ -581,7 +758,7 @@ TEST(PerformMOT, NullParam)
     EXPECT_EQ(true, g_callbackResult);
 }
 
-TEST(DiscoverMultipleOwnedDevices, NullParam)
+TEST_F(OTM, DiscoverMultipleOwnedDevicesNullParam)
 {
     OCStackResult result = OC_STACK_OK;
 
@@ -598,11 +775,10 @@ TEST(DiscoverMultipleOwnedDevices, NullParam)
 }
 #endif //MULTIPLE_OWNER
 
-TEST(OCRemoveDevice, Simple)
+TEST_F(OTM, OCRemoveDevice)
 {
-    //initialize Provisioning DB Manager
-    EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
-    ASSERT_EQ(true, gNumOfUnownDevice > 0);
+    ASSERT_TRUE(gNumOfOwnDevice > 0);
+    ASSERT_NE(nullptr, g_ownedDevices);
 
     OicUuid_t myUuid;
     OCStackResult result = OC_STACK_ERROR;
@@ -619,26 +795,166 @@ TEST(OCRemoveDevice, Simple)
         }
         removeDev = removeDev->next;
     }
-    EXPECT_TRUE(NULL != removeDev);
+    EXPECT_NE(nullptr, removeDev);
 
     g_doneCB = false;
     g_callbackResult = false;
 
-    result = OCRemoveDevice((void *)g_otmCtx, DISCOVERY_TIMEOUT, removeDev, removeDeviceCB);
-    EXPECT_EQ(OC_STACK_OK, result);
-    EXPECT_EQ(true, g_callbackResult);
-    EXPECT_EQ(true, g_doneCB);
-    // close Provisioning DB
-    EXPECT_EQ(OC_STACK_OK, OCClosePM());
+    EXPECT_EQ(OC_STACK_OK, OCResetDevice((void *)g_otmCtx, DISCOVERY_TIMEOUT, removeDev,
+                                         removeDeviceCB));
+
+    EXPECT_TRUE(g_callbackResult);
+    EXPECT_TRUE(g_doneCB);
 }
 
-TEST(FinalizeOTMTest, NullParam)
+TEST_F(OTM, OCSetOxmAllowStatusFull)
 {
-    OCStackResult result = OCStop();
-    EXPECT_EQ(OC_STACK_OK, result);
+    EXPECT_EQ(OC_STACK_OK, OCSetOxmAllowStatus(OIC_JUST_WORKS, true));
+    EXPECT_EQ(OC_STACK_OK, OCSetOxmAllowStatus(OIC_RANDOM_DEVICE_PIN, true));
+    EXPECT_EQ(OC_STACK_OK, OCSetOxmAllowStatus(OIC_MANUFACTURER_CERTIFICATE, true));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCSetOxmAllowStatus(OIC_OXM_COUNT, true));
+#ifdef MULTIPLE_OWNER
+    EXPECT_EQ(OC_STACK_ERROR, OCSetOxmAllowStatus(OIC_PRECONFIG_PIN, true));
+#endif //MULTIPLE_OWNER
+    EXPECT_EQ(OC_STACK_OK, OCSetOxmAllowStatus(OIC_MV_JUST_WORKS, true));
+    EXPECT_EQ(OC_STACK_OK, OCSetOxmAllowStatus(OIC_CON_MFG_CERT, true));
+}
 
-    PMDeleteDeviceList(g_unownedDevices);
-    PMDeleteDeviceList(g_ownedDevices);
-    result = PDMClose();
-    EXPECT_EQ(OC_STACK_OK, result);
+TEST_F(OTM, OCPDMCleanupForTimeoutFull)
+{
+    EXPECT_EQ(OC_STACK_OK, OCPDMCleanupForTimeout());
+}
+
+TEST_F(OTM, OCSelectOwnershipTransferMethodFull)
+{
+    OicSecOxm_t *supportedMethods = (OicSecOxm_t *)OICCalloc(1, sizeof(OicSecOxm_t));
+    OicSecOxm_t *selectedMethod = (OicSecOxm_t *)OICCalloc(1, sizeof(OicSecOxm_t));
+    *supportedMethods = OIC_JUST_WORKS;
+    EXPECT_EQ(OC_STACK_OK, OCSelectOwnershipTransferMethod(supportedMethods, 1, selectedMethod,
+              SUPER_OWNER));
+    OICFree(selectedMethod);
+    OICFree(supportedMethods );
+}
+
+TEST_F(OTM, OCProvisionTrustCertChainFull)
+{
+    if (gNumOfOwnDevice == 0)
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: donn't found owned device", __func__);
+        return;
+    }
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCProvisionTrustCertChain(NULL, SYMMETRIC_PAIR_WISE_KEY, 0,
+              g_ownedDevices, resultCallBack));
+}
+
+TEST_F(OTM, OCProvisionSecurityProfileInfoFull)
+{
+    if (gNumOfOwnDevice == 0)
+    {
+        OIC_LOG_V(WARNING, TAG, "%s: donn't found owned device", __func__);
+        return;
+    }
+
+    OicSecSp_t *sp = (OicSecSp_t *)OICCalloc(1, sizeof(OicSecSp_t));
+    EXPECT_EQ(OC_STACK_OK, OCProvisionSecurityProfileInfo(NULL, sp, g_ownedDevices, resultCallBack));
+    OICFree(sp);
+}
+
+TEST_F(OTM, OCSaveTrustCertChainFull)
+{
+    size_t chainSize = 2048;
+    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)
+{
+    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,
+                                   size_t chainSize)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(credId);
+    OC_UNUSED(trustCertChain);
+    OC_UNUSED(chainSize);
 }
+
+static CAResult_t peerCNVerifyCallback(const unsigned char *cn, size_t cnLen)
+{
+    OC_UNUSED(cn);
+    OC_UNUSED(cnLen);
+    return CA_STATUS_OK;
+}
+
+TEST_F(OTM, OCRegisterTrustCertChainNotifierFull)
+{
+    OCRemoveTrustCertChainNotifier();
+    EXPECT_EQ(OC_STACK_OK, OCRegisterTrustCertChainNotifier(NULL, trustCertChainChangeCB));
+    OCRemoveTrustCertChainNotifier();
+    OCSetPeerCNVerifyCallback(peerCNVerifyCallback);
+}
+
+TEST_F(OTM, OCSaveOwnCertChainFull)
+{
+    char *cert = (char *)getPemCert();
+    char *key = (char *)getPemKey();
+    uint16_t credId = 0;
+
+    EXPECT_EQ(OC_STACK_OK, OCSaveOwnCertChain(cert, key, &credId));
+
+    OICFree(key);
+    OICFree(cert);
+}
+
+TEST_F(OTM, OCRemoveCredentialFull)
+{
+    OicUuid_t uuid = {0};
+    ConvertStrToUuid("11111111-1234-1234-1234-123456789011", &uuid);
+
+    EXPECT_EQ(OC_STACK_RESOURCE_DELETED, OCRemoveCredential(&uuid));
+}
+
+TEST_F(OTM, OCDiscoverSingleDeviceFull)
+{
+    OicUuid_t *deviceID = createUuid();
+    OCProvisionDev_t *ppFoundDevice = NULL;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCDiscoverSingleDevice(0, deviceID, &ppFoundDevice));
+    EXPECT_EQ(OC_STACK_OK, OCDiscoverSingleDevice(3, deviceID, &ppFoundDevice));
+    freeUuid(deviceID);
+}
+
+TEST_F(OTM, OCDiscoverSingleDeviceInUnicastFull)
+{
+    OicUuid_t *deviceID = createUuid();
+    OCProvisionDev_t *ppFoundDevice = NULL;
+    const char hostAddress[] = "127.0.0.1";
+    OCConnectivityType connType = CT_ADAPTER_IP;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCDiscoverSingleDeviceInUnicast(0, deviceID, hostAddress,
+              connType, &ppFoundDevice));
+    EXPECT_EQ(OC_STACK_OK, OCDiscoverSingleDeviceInUnicast(3, deviceID, hostAddress, connType,
+              &ppFoundDevice));
+    freeUuid(deviceID);
+}
+
+TEST_F(OTM, OCDiscoverUnownedDevicesFull)
+{
+    OCProvisionDev_t *ppFoundDevice = NULL;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCDiscoverUnownedDevices(0, &ppFoundDevice));
+    EXPECT_EQ(OC_STACK_OK, OCDiscoverUnownedDevices(3, &ppFoundDevice));
+}
+
+TEST_F(OTM, OCDiscoverOwnedDevicesFull)
+{
+    OCProvisionDev_t *ppFoundDevice = NULL;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OCDiscoverOwnedDevices(0, &ppFoundDevice));
+}
+
+
diff --git a/resource/csdk/security/provisioning/unittest/ownershiptransfermanager.cpp b/resource/csdk/security/provisioning/unittest/ownershiptransfermanager.cpp
new file mode 100644 (file)
index 0000000..3fd9dbe
--- /dev/null
@@ -0,0 +1,376 @@
+/* *****************************************************************
+ *
+ * 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 "tools.h"
+#include "ocprovisioningmanager.h"
+#include "../src/ownershiptransfermanager.c"
+#undef UUID_LENGTH
+#include "../../../connectivity/src/adapter_util/ca_adapter_net_ssl.c"
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#undef TAG
+#define TAG "OWSHT_UNITTEST"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+using namespace std;
+
+class OWSHT : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
+
+TEST_F(OWSHT, PostOwnershipInformation)
+{
+    OTMContext_t *ctx = createOTMContext();
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PostOwnershipInformation(NULL));
+    EXPECT_EQ(OC_STACK_OK, PostOwnershipInformation(ctx));
+    freeOTMContext(ctx);
+}
+
+TEST_F(OWSHT, OTMSetOTCallback)
+{
+    OTMCallbackData_t *callbacks = (OTMCallbackData_t *)OICCalloc(1, sizeof(OTMCallbackData_t));
+    EXPECT_EQ(OC_STACK_OK, OTMSetOTCallback(OIC_JUST_WORKS, callbacks));
+    EXPECT_EQ(OC_STACK_OK, OTMSetOTCallback(OIC_RANDOM_DEVICE_PIN, callbacks));
+    EXPECT_EQ(OC_STACK_OK, OTMSetOTCallback(OIC_RANDOM_DEVICE_PIN, callbacks));
+    EXPECT_EQ(OC_STACK_OK, OTMSetOTCallback(OIC_MANUFACTURER_CERTIFICATE, callbacks));
+    EXPECT_EQ(OC_STACK_INVALID_METHOD, OTMSetOTCallback(OIC_DECENTRALIZED_PUBLIC_KEY, callbacks));
+    EXPECT_EQ(OC_STACK_OK, OTMSetOTCallback(OIC_MV_JUST_WORKS, callbacks));
+    EXPECT_EQ(OC_STACK_OK, OTMSetOTCallback(OIC_CON_MFG_CERT, callbacks));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OTMSetOTCallback(0xFFCC, callbacks));
+    OICFree(callbacks);
+}
+
+TEST_F(OWSHT, OTMSelectOwnershipTransferMethod)
+{
+    OwnerType_t ownerType = SUB_OWNER;
+    EXPECT_EQ(OC_STACK_ERROR, OTMSelectOwnershipTransferMethod(NULL, 0, NULL, ownerType));
+    size_t numberOfMethods = 3;
+    OicSecOxm_t *supportedMethods = (OicSecOxm_t *)OICCalloc(numberOfMethods, sizeof(OicSecOxm_t));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, OTMSelectOwnershipTransferMethod(supportedMethods,
+              numberOfMethods, NULL, ownerType));
+    OICFree(supportedMethods);
+}
+
+TEST_F(OWSHT, GetOxmAllowTableIdx)
+{
+    EXPECT_EQ(OXM_IDX_DECENTRALIZED_PUBLIC_KEY, GetOxmAllowTableIdx(OIC_DECENTRALIZED_PUBLIC_KEY));
+    EXPECT_TRUE(OXM_IDX_UNKNOWN == GetOxmAllowTableIdx((OicSecOxm_t)-1));
+}
+
+TEST_F(OWSHT, getSecurePort)
+{
+    EXPECT_EQ(0, getSecurePort(NULL));
+}
+
+TEST_F(OWSHT, SetResult)
+{
+    OTMContext_t *ctx = createOTMContext();
+    ctx->ctxResultArray = (OCProvisionResult_t *)OICCalloc(3, sizeof(OCProvisionResult_t));
+    SetResult(ctx, OC_STACK_OK);
+    ctx = createOTMContext();
+    ctx->selectedDeviceInfo->doxm->oxmSel = OIC_RANDOM_DEVICE_PIN;
+    SetResult(ctx, OC_STACK_OK);
+    ctx = createOTMContext();
+    ctx->selectedDeviceInfo->doxm->oxmSel = OIC_MANUFACTURER_CERTIFICATE;
+    ctx->ocDoHandle = (OCDoHandle)OICMalloc(1);
+    SetResult(ctx, OC_STACK_OK);
+    ctx = createOTMContext();
+    ctx->ctxHasError = true;
+    SetResult(ctx, OC_STACK_OK);
+}
+
+TEST_F(OWSHT, OwnershipTransferSessionEstablished)
+{
+    OicSecDoxm_t *newDevDoxm = createDoxm();
+    OTMContext_t *otmCtx = createOTMContext();
+    CAEndpoint_t *endpoint = createEndpoint();
+    newDevDoxm->oxmSel = OIC_MV_JUST_WORKS;
+    EXPECT_EQ(CA_HANDLE_ERROR_OTHER_MODULE, OwnershipTransferSessionEstablished(endpoint, newDevDoxm,
+              otmCtx));
+    newDevDoxm->oxmSel = OIC_CON_MFG_CERT;
+    EXPECT_EQ(CA_HANDLE_ERROR_OTHER_MODULE, OwnershipTransferSessionEstablished(endpoint, newDevDoxm,
+              otmCtx));
+    freeEndpoint(endpoint);
+    freeDoxm(newDevDoxm);
+    freeOTMContext(otmCtx);
+}
+
+TEST_F(OWSHT, OwnerUuidUpdateHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+    otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_MV_JUST_WORKS;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnerUuidUpdateHandler((void *)otmCtx, NULL,
+              clientResponse));
+    otmCtx = createOTMContext();
+    clientResponse->result = OC_STACK_OK;
+    otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_MV_JUST_WORKS;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnerUuidUpdateHandler((void *)otmCtx, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(OWSHT, OwnershipTransferSessionFailed)
+{
+    OicSecDoxm_t *newDevDoxm = createDoxm();
+    OTMContext_t *otmCtx = createOTMContext();
+    CAEndpoint_t *endpoint = createEndpoint();
+    CAErrorInfo_t *info = (CAErrorInfo_t *)OICCalloc(1, sizeof(CAErrorInfo_t));
+    info->result = CA_DTLS_AUTHENTICATION_FAILURE;
+    newDevDoxm->oxmSel = OIC_RANDOM_DEVICE_PIN;
+    EXPECT_EQ(CA_HANDLE_ERROR_OTHER_MODULE, OwnershipTransferSessionFailed(endpoint, info, newDevDoxm,
+              otmCtx, false));
+    EXPECT_EQ(CA_HANDLE_ERROR_OTHER_MODULE, OwnershipTransferSessionFailed(endpoint, info, newDevDoxm,
+              otmCtx, true));
+
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&otmCtx->selectedDeviceInfo->doxm->deviceID));
+    EXPECT_EQ(CA_CONTINUE_OPERATION, OwnershipTransferSessionFailed(endpoint, info, newDevDoxm, otmCtx,
+              true));
+    OICFree(info);
+    freeEndpoint(endpoint);
+    freeDoxm(newDevDoxm);
+    freeOTMContext(otmCtx);
+}
+
+TEST_F(OWSHT, OperationModeUpdateHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OperationModeUpdateHandler((void *)otmCtx, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(OWSHT, OwnerCredentialHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+    otmCtx->selectedDeviceInfo->doxm->oxmSel = OIC_RANDOM_DEVICE_PIN;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnerCredentialHandler((void *)otmCtx, NULL,
+              clientResponse));
+    freeProvisionDev(otmCtx->selectedDeviceInfo);
+    otmCtx->selectedDeviceInfo = NULL;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnerCredentialHandler((void *)otmCtx, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+    freeOTMContext(otmCtx);
+}
+
+TEST_F(OWSHT, OwnershipInformationHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnershipInformationHandler((void *)otmCtx, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(OWSHT, ProvisioningStatusHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisioningStatusHandler((void *)otmCtx, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(OWSHT, ReadyForNomalStatusHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ReadyForNomalStatusHandler((void *)otmCtx, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(OWSHT, RownerUuidHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, RownerUuidHandler((void *)otmCtx, NULL, clientResponse));
+    OICFree(clientResponse);
+    freeOTMContext(otmCtx);
+}
+
+TEST_F(OWSHT, PostRownerUuid)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    otmCtx->selectedDeviceInfo->pstat->dos.state = DOS_RESET;
+    EXPECT_EQ(OC_STACK_OK, PostRownerUuid(otmCtx));
+    freeOTMContext(otmCtx);
+}
+
+TEST_F(OWSHT, CloseSslConnection)
+{
+    OCProvisionDev_t *selectedDeviceInfo = createProvisionDev();
+    EXPECT_TRUE(CloseSslConnection(selectedDeviceInfo));
+}
+
+TEST_F(OWSHT, DTLSHandshakeCB)
+{
+    EXPECT_EQ(CA_STATUS_OK, DTLSHandshakeCB(NULL, NULL));
+
+    OTMContext_t *otmCtx = createOTMContext();
+    CAErrorInfo_t *info = (CAErrorInfo_t *)OICCalloc(1, sizeof(CAErrorInfo_t));
+    EXPECT_EQ(OC_STACK_OK, AddOTMContext(otmCtx, otmCtx->selectedDeviceInfo->endpoint.addr,
+                                         otmCtx->selectedDeviceInfo->endpoint.port));
+    OicSecDoxm_t *doxm = otmCtx->selectedDeviceInfo->doxm;
+    otmCtx->selectedDeviceInfo->doxm = NULL;
+    EXPECT_EQ(CA_STATUS_OK, DTLSHandshakeCB((const CAEndpoint_t *)&otmCtx->selectedDeviceInfo->endpoint,
+                                            info));
+    otmCtx->selectedDeviceInfo->doxm = doxm;
+    CAEndpoint_t *endpoint = createEndpoint();
+    endpoint->port = otmCtx->selectedDeviceInfo->endpoint.port;
+    otmCtx->selectedDeviceInfo->securePort = endpoint->port + 1;
+    EXPECT_EQ(CA_STATUS_OK, DTLSHandshakeCB(endpoint, info));
+    OICFree(info);
+    freeOTMContext(otmCtx);
+}
+
+TEST_F(OWSHT, SaveOwnerPSK)
+{
+    OCProvisionDev_t *selectedDeviceInfo = createProvisionDev();
+    CAEndpoint_t endpoint;
+    CopyDevAddrToEndpoint(&selectedDeviceInfo->endpoint, &endpoint);
+    endpoint.port = getSecurePort(selectedDeviceInfo);
+
+    OicUuid_t ownerDeviceID = OC_ZERO_UUID;
+    EXPECT_EQ(OC_STACK_OK, GetDoxmDeviceID(&ownerDeviceID));
+
+    OicSecKey_t ownerKey;
+    memset(&ownerKey, 0, sizeof(ownerKey));
+
+    uint8_t ownerPSK[OWNER_PSK_LENGTH_128] = { 0 };
+    ownerKey.data = ownerPSK;
+    ownerKey.len = OWNER_PSK_LENGTH_128;
+    ownerKey.encoding = OIC_ENCODING_RAW;
+
+    g_caSslContext->selectedCipher = MBEDTLS_TLS_RSA_WITH_AES_128_GCM_SHA256;
+    OicSecCred_t *cred = GenerateCredential(&selectedDeviceInfo->doxm->deviceID,
+                                            SYMMETRIC_PAIR_WISE_KEY, NULL,
+                                            &ownerKey, NULL);
+
+    EXPECT_NE(nullptr, cred);
+    EXPECT_EQ(OC_STACK_OK, AddCredential(cred));
+    EXPECT_EQ(OC_STACK_OK, SaveOwnerPSK(selectedDeviceInfo));
+
+    EXPECT_EQ(OC_STACK_OK, DeInitDoxmResource());
+    EXPECT_EQ(OC_STACK_ERROR, SaveOwnerPSK(selectedDeviceInfo));
+    EXPECT_EQ(OC_STACK_OK, InitDoxmResource());
+
+    freeProvisionDev(selectedDeviceInfo );
+}
+
+TEST_F(OWSHT, OwnerTransferModeHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnerTransferModeHandler((void *)otmCtx, NULL,
+              clientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+    OTMContext_t *otmCtx1 = createOTMContext();
+    otmCtx1->selectedDeviceInfo->endpoint.addr[0] = 0;
+    otmCtx1->selectedDeviceInfo->securePort = 0;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, OwnerTransferModeHandler((void *)otmCtx1, NULL,
+              clientResponse));
+    OICFree(clientResponse);
+}
+
+OCStackResult loadSecret(OTMContext_t *otmCtx)
+{
+    OC_UNUSED(otmCtx);
+    return OC_STACK_ERROR;
+}
+
+TEST_F(OWSHT, ListMethodsHandler)
+{
+    OTMContext_t *otmCtx = createOTMContext();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_CONTINUE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ListMethodsHandler((void *)otmCtx, NULL, clientResponse));
+    OTMContext_t *otmCtx1 = createOTMContext();
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ListMethodsHandler((void *)otmCtx1, NULL, clientResponse));
+    OTMContext_t *otmCtx2 = createOTMContext();
+    OCSecurityPayload *payload = (OCSecurityPayload *)OICCalloc(1, sizeof(OCSecurityPayload));
+    payload->payloadSize = 0;
+    clientResponse->payload = (OCPayload *)payload;
+    clientResponse->payload->type = PAYLOAD_TYPE_REPRESENTATION;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ListMethodsHandler((void *)otmCtx2, NULL, clientResponse));
+    OTMContext_t *otmCtx3 = createOTMContext();
+    clientResponse->payload->type = PAYLOAD_TYPE_SECURITY;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ListMethodsHandler((void *)otmCtx3, NULL, clientResponse));
+    OTMContext_t *otmCtx4 = createOTMContext();
+    otmCtx4->otmCallback.loadSecretCB = loadSecret;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ListMethodsHandler((void *)otmCtx4, NULL, clientResponse));
+    OTMContext_t *otmCtx5 = createOTMContext();
+    OicSecPstat_t *pstat = createPstat();
+    EXPECT_EQ(OC_STACK_OK, PstatToCBORPayload(pstat, &payload->securityData, &payload->payloadSize));
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ListMethodsHandler((void *)otmCtx5, NULL, clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(OWSHT, SetupPDM)
+{
+    OCProvisionDev_t *selectedDevice = createProvisionDev();
+    EXPECT_EQ(OC_STACK_OK, OCClosePM());
+    EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, SetupPDM(selectedDevice));
+    EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
+    selectedDevice->doxm->owned = false;
+    PDMAddDevice(&selectedDevice->doxm->deviceID);
+    PDMSetDeviceState(&selectedDevice->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    EXPECT_EQ(OC_STACK_OK, SetupPDM(selectedDevice));
+}
+
+TEST_F(OWSHT, ConfigSelfOwnership)
+{
+    EXPECT_EQ(OC_STACK_OK, ConfigSelfOwnership());
+}
diff --git a/resource/csdk/security/provisioning/unittest/oxmjustworks.cpp b/resource/csdk/security/provisioning/unittest/oxmjustworks.cpp
new file mode 100644 (file)
index 0000000..66f6e9d
--- /dev/null
@@ -0,0 +1,80 @@
+/* *****************************************************************
+ *
+ * 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/oxmjustworks.c"
+#include "tools.h"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#define TAG "OXMJW_UNITTEST"
+
+#define SVR_DB_FILE_NAME "oic_oxmjustworks.dat"
+#define PM_DB_FILE_NAME "oic_oxmjustworks.db"
+
+using namespace std;
+
+class OXMJW : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+
+        OCProvisionDev_t *g_ownedDevices = NULL;
+};
+
+TEST_F(OXMJW, CreateMVJustWorksSelectOxmPayload)
+{
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    bool propertiesToInclude[DOXM_PROPERTY_COUNT];
+    memset(propertiesToInclude, 0, sizeof(propertiesToInclude));
+    propertiesToInclude[DOXM_OXMS] = true;
+    propertiesToInclude[DOXM_OXMSEL] = true;
+    propertiesToInclude[DOXM_SCT] = true;
+    propertiesToInclude[DOXM_OWNED] = true;
+    propertiesToInclude[DOXM_DEVICEUUID] = true;
+    propertiesToInclude[DOXM_DEVOWNERUUID] = true;
+
+    OTMContext_t *otmCtx = createOTMContext();
+
+    EXPECT_EQ(OC_STACK_OK, CreateMVJustWorksSelectOxmPayload(otmCtx, &payload, &size));
+    EXPECT_TRUE(payload != NULL);
+
+    freeOTMContext(otmCtx);
+}
+
diff --git a/resource/csdk/security/provisioning/unittest/oxmmanufacturercert.cpp b/resource/csdk/security/provisioning/unittest/oxmmanufacturercert.cpp
new file mode 100644 (file)
index 0000000..c100107
--- /dev/null
@@ -0,0 +1,100 @@
+/* *****************************************************************
+ *
+ * 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/oxmmanufacturercert.c"
+#include "tools.h"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#define TAG "OXMMCERT_UNITTEST"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+using namespace std;
+
+class OXMMCERT : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
+TEST_F(OXMMCERT, CreateMCertificateBasedSelectOxmPayload)
+{
+    OTMContext_t *ctx = createOTMContext();
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    EXPECT_EQ(OC_STACK_OK, CreateMCertificateBasedSelectOxmPayload(ctx, &payload, &size));
+    freeOTMContext(ctx);
+}
+
+TEST_F(OXMMCERT, CreateConMCertificateBasedSelectOxmPayload)
+{
+    OTMContext_t *ctx = createOTMContext();
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CreateConMCertificateBasedSelectOxmPayload(NULL, &payload,
+              &size));
+    EXPECT_EQ(OC_STACK_OK, CreateConMCertificateBasedSelectOxmPayload(ctx, &payload, &size));
+    freeOTMContext(ctx);
+}
+
+TEST_F(OXMMCERT, CreateMCertificateBasedOwnerTransferPayload)
+{
+    OTMContext_t *ctx = createOTMContext();
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    EXPECT_EQ(OC_STACK_OK, CreateMCertificateBasedOwnerTransferPayload(ctx, &payload, &size));
+    freeOTMContext(ctx);
+}
+
+TEST_F(OXMMCERT, PrepareMCertificateCallback)
+{
+    OTMContext_t *ctx = createOTMContext();
+    EXPECT_EQ(OC_STACK_OK, PrepareMCertificateCallback(ctx));
+    freeOTMContext(ctx);
+}
+
+TEST_F(OXMMCERT, CreateSecureSessionMCertificateCallback)
+{
+    OTMContext_t *ctx = createOTMContext();
+    EXPECT_EQ(OC_STACK_OK, CreateSecureSessionMCertificateCallback(ctx));
+    freeOTMContext(ctx);
+}
+
diff --git a/resource/csdk/security/provisioning/unittest/oxmrandompin.cpp b/resource/csdk/security/provisioning/unittest/oxmrandompin.cpp
new file mode 100644 (file)
index 0000000..3add014
--- /dev/null
@@ -0,0 +1,83 @@
+/* *****************************************************************
+ *
+ * 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 "tools.h"
+#include "ocprovisioningmanager.h"
+#include "../src/oxmrandompin.c"
+
+#undef TAG
+#ifdef __cplusplus
+}
+#endif
+
+#undef TAG
+#define TAG "ORP_UNITTEST"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+using namespace std;
+
+class ORP : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+};
+
+TEST_F(ORP, CreatePinBasedOwnerTransferPayload)
+{
+    OTMContext_t *ctx = createOTMContext();
+    uint8_t *payload = NULL;
+    size_t size = 0;
+    EXPECT_EQ(OC_STACK_OK, CreatePinBasedOwnerTransferPayload(ctx, &payload, &size));
+    ctx->selectedDeviceInfo->doxm->owned = false;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, CreatePinBasedOwnerTransferPayload(ctx, &payload, &size));
+    freeOTMContext(ctx);
+}
+
+TEST_F(ORP, InputPinCodeCallback)
+{
+    OTMContext_t *ctx = createOTMContext();
+    EXPECT_EQ(OC_STACK_ERROR, InputPinCodeCallback(ctx));
+    freeOTMContext(ctx);
+}
+#if !defined(_WIN32)
+TEST_F(ORP, CreateSecureSessionRandomPinCallback)
+{
+    OTMContext_t *ctx = createOTMContext();
+    EXPECT_EQ(OC_STACK_OK, CreateSecureSessionRandomPinCallback(ctx));
+    freeOTMContext(ctx);
+}
+#endif
index 7ae159a..480a6c9 100644 (file)
 #include "ocstack.h"
 #include "oic_malloc.h"
 #include "utlist.h"
+#include "octypes.h"
 
-using namespace std;
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-extern OCStackResult AddDevice(OCProvisionDev_t **ppDevicesList, const char* addr,
-                               const uint16_t port, OCTransportAdapter adapter,
-                               OCConnectivityType connType, OicSecDoxm_t *doxm);
+#undef _DEFAULT_SOURCE
+#include "../src/pmutility.c"
+#include "tools.h"
+
 #ifdef __cplusplus
 }
 #endif
 
-OCProvisionDev_t* gList = NULL;
+#undef TAG
+#define TAG "PM_UTIL"
+
+#define SVR_DB_FILE_NAME TAG".dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+static OCProvisionDev_t *gList = NULL;
+
+using namespace std;
 
-static bool UuidsIdentical(const OicUuid_t* first, const OicUuid_t* second)
+static bool UuidsIdentical(const OicUuid_t *first, const OicUuid_t *second)
 {
     return (0 == memcmp(first, second, sizeof(OicUuid_t)));
 }
@@ -48,20 +57,20 @@ static bool UuidsIdentical(const OicUuid_t* first, const OicUuid_t* second)
 #ifdef MULTIPLE_OWNER
 class CloneOicSecMomTest : public testing::Test
 {
-public:
-    CloneOicSecMomTest() :
-        m_originalStruct({OIC_MULTIPLE_OWNER_DISABLE}),
-        m_clonedStruct(NULL)
-    {}
+    public:
+        CloneOicSecMomTest() :
+            m_originalStruct({OIC_MULTIPLE_OWNER_DISABLE}),
+                         m_clonedStruct(NULL)
+        {}
 
-    void TearDown()
-    {
-        OICFree(m_clonedStruct);
-    }
-protected:
+        void TearDown()
+        {
+            OICFree(m_clonedStruct);
+        }
+    protected:
 
-    OicSecMom_t m_originalStruct;
-    OicSecMom_t* m_clonedStruct;
+        OicSecMom_t m_originalStruct;
+        OicSecMom_t *m_clonedStruct;
 };
 
 TEST(CloneOicSecMomSimpleTest, shouldReturnNullForNullInput)
@@ -87,11 +96,11 @@ TEST_F(CloneOicSecMomTest, shouldReturnDifferentAddressThanOriginalForValidInput
     EXPECT_NE(&m_originalStruct, m_clonedStruct);
 }
 
-static OicSecSubOwner_tBuildSampleOicSecSubOwner(MotStatus_t status,
-                                                   const OicUuid_t* uuid)
+static OicSecSubOwner_t *BuildSampleOicSecSubOwner(MotStatus_t status,
+        const OicUuid_t *uuid)
 {
-    OicSecSubOwner_tresult =
-        (OicSecSubOwner_t*)OICCalloc(1, sizeof(OicSecSubOwner_t));
+    OicSecSubOwner_t *result =
+        (OicSecSubOwner_t *)OICCalloc(1, sizeof(OicSecSubOwner_t));
     if (NULL == result)
     {
         return NULL;
@@ -104,10 +113,10 @@ static OicSecSubOwner_t* BuildSampleOicSecSubOwner(MotStatus_t status,
     return result;
 }
 
-static void FreeOicSecSubOwner(OicSecSubOwner_tinput)
+static void FreeOicSecSubOwner(OicSecSubOwner_t *input)
 {
-    OicSecSubOwner_tcurrent = input;
-    OicSecSubOwner_ttemp = input;
+    OicSecSubOwner_t *current = input;
+    OicSecSubOwner_t *temp = input;
     while (NULL != current)
     {
         temp = current;
@@ -118,45 +127,51 @@ static void FreeOicSecSubOwner(OicSecSubOwner_t* input)
 
 class CloneOicSecSubOwnerTest : public testing::Test
 {
-public:
-    CloneOicSecSubOwnerTest() :
-        m_originalStruct(NULL),
-        m_clonedStruct(NULL)
-    {}
+    public:
+        CloneOicSecSubOwnerTest() :
+            m_originalStruct(NULL),
+            m_clonedStruct(NULL)
+        {}
 
-    void SetUp()
-    {
-        m_originalStruct =
-            BuildSampleOicSecSubOwner(MOT_STATUS_READY, &s_sampleUuid);
-        ASSERT_FALSE(NULL == m_originalStruct);
+        void SetUp()
+        {
+            m_originalStruct =
+                BuildSampleOicSecSubOwner(MOT_STATUS_READY, &s_sampleUuid);
+            ASSERT_FALSE(NULL == m_originalStruct);
 
-        m_originalStruct->next =
-            BuildSampleOicSecSubOwner(MOT_STATUS_IN_PROGRESS, &s_sampleNextUuid);
-        ASSERT_FALSE(NULL == m_originalStruct->next);
-    }
+            m_originalStruct->next =
+                BuildSampleOicSecSubOwner(MOT_STATUS_IN_PROGRESS, &s_sampleNextUuid);
+            ASSERT_FALSE(NULL == m_originalStruct->next);
+        }
 
-    void TearDown()
-    {
-        FreeOicSecSubOwner(m_originalStruct);
-        FreeOicSecSubOwner(m_clonedStruct);
-    }
-protected:
+        void TearDown()
+        {
+            FreeOicSecSubOwner(m_originalStruct);
+            FreeOicSecSubOwner(m_clonedStruct);
+        }
+    protected:
 
-    static const OicUuid_t s_sampleUuid;
-    static const OicUuid_t s_sampleNextUuid;
+        static const OicUuid_t s_sampleUuid;
+        static const OicUuid_t s_sampleNextUuid;
 
-    OicSecSubOwner_t* m_originalStruct;
-    OicSecSubOwner_t* m_clonedStruct;
+        OicSecSubOwner_t *m_originalStruct;
+        OicSecSubOwner_t *m_clonedStruct;
 };
 
-const OicUuid_t CloneOicSecSubOwnerTest::s_sampleUuid = {
-    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+const OicUuid_t CloneOicSecSubOwnerTest::s_sampleUuid =
+{
+    {
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+    }
 };
 
-const OicUuid_t CloneOicSecSubOwnerTest::s_sampleNextUuid = {
-    { 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }
+const OicUuid_t CloneOicSecSubOwnerTest::s_sampleNextUuid =
+{
+    {
+        0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
+    }
 };
 
 TEST(CloneOicSecSubOwnerSimpleTest, shouldReturnNullForNullInput)
@@ -222,98 +237,112 @@ TEST_F(CloneOicSecSubOwnerTest, copyShouldHaveNullLastNext)
 
 class CloneOicSecDoxmTest : public testing::Test
 {
-public:
-    CloneOicSecDoxmTest() :
-        m_originalStruct(NULL),
-        m_clonedStruct(NULL)
-    {}
+    public:
+        CloneOicSecDoxmTest() :
+            m_originalStruct(NULL),
+            m_clonedStruct(NULL)
+        {}
 
-    void SetUp()
-    {
-        m_originalStruct = BuildSampleOicSecDoxm();
-        ASSERT_FALSE(NULL == m_originalStruct);
-    }
+        void SetUp()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+            m_originalStruct = BuildSampleOicSecDoxm();
+            ASSERT_FALSE(NULL == m_originalStruct);
+        }
 
-    void TearDown()
-    {
-        DeleteDoxmBinData(m_originalStruct);
-        DeleteDoxmBinData(m_clonedStruct);
-    }
+        void TearDown()
+        {
+            DeleteDoxmBinData(m_originalStruct);
+            DeleteDoxmBinData(m_clonedStruct);
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
 
-protected:
+    protected:
 
-    static const OicUuid_t s_sampleDeviceId;
-    static const OicUuid_t s_sampleOwner;
-    static const OicUuid_t s_sampleOwnerId;
-    static const OicUuid_t s_sampleSubOwner;
+        static const OicUuid_t s_sampleDeviceId;
+        static const OicUuid_t s_sampleOwner;
+        static const OicUuid_t s_sampleOwnerId;
+        static const OicUuid_t s_sampleSubOwner;
 
-    OicSecDoxm_t* m_originalStruct;
-    OicSecDoxm_t* m_clonedStruct;
+        OicSecDoxm_t *m_originalStruct;
+        OicSecDoxm_t *m_clonedStruct;
 
-private:
+    private:
 
-    OicSecDoxm_t* BuildSampleOicSecDoxm()
-    {
-        OicSecDoxm_t* result =
-            (OicSecDoxm_t*)OICCalloc(1, sizeof(OicSecDoxm_t));
-        if (NULL == result)
+        OicSecDoxm_t *BuildSampleOicSecDoxm()
         {
-            return NULL;
-        }
+            OicSecDoxm_t *result =
+                (OicSecDoxm_t *)OICCalloc(1, sizeof(OicSecDoxm_t));
+            if (NULL == result)
+            {
+                return NULL;
+            }
 
-        memcpy(&result->deviceID, &s_sampleDeviceId, sizeof(result->deviceID));
-        result->dpc = true;
+            memcpy(&result->deviceID, &s_sampleDeviceId, sizeof(result->deviceID));
+            result->dpc = true;
 
 #ifdef MULTIPLE_OWNER
-        result->mom = (OicSecMom_t*)OICCalloc(1, sizeof(OicSecMom_t));
-        if (NULL == result->mom)
-        {
-            return NULL;
-        }
-        result->mom->mode = OIC_MULTIPLE_OWNER_DISABLE;
-        result->subOwners =
-            BuildSampleOicSecSubOwner(MOT_STATUS_IN_PROGRESS, &s_sampleSubOwner);
-        if (NULL == result->subOwners)
-        {
-            return NULL;
-        }
+            result->mom = (OicSecMom_t *)OICCalloc(1, sizeof(OicSecMom_t));
+            if (NULL == result->mom)
+            {
+                return NULL;
+            }
+            result->mom->mode = OIC_MULTIPLE_OWNER_DISABLE;
+            result->subOwners =
+                BuildSampleOicSecSubOwner(MOT_STATUS_IN_PROGRESS, &s_sampleSubOwner);
+            if (NULL == result->subOwners)
+            {
+                return NULL;
+            }
 #endif
 
-        result->owned = true;
-        memcpy(&result->owner, &s_sampleOwner, sizeof(result->owner));
-        result->oxm = (OicSecOxm_t*)OICCalloc(1, sizeof(OicSecOxm_t));
-        if (NULL == result->oxm)
-        {
-            return NULL;
+            result->owned = true;
+            memcpy(&result->owner, &s_sampleOwner, sizeof(result->owner));
+            result->oxm = (OicSecOxm_t *)OICCalloc(1, sizeof(OicSecOxm_t));
+            if (NULL == result->oxm)
+            {
+                return NULL;
+            }
+            result->oxm[0] = OIC_JUST_WORKS;
+            result->oxmLen = 1U;
+            result->oxmSel = OIC_JUST_WORKS;
+            memcpy(&result->rownerID, &s_sampleOwnerId, sizeof(result->rownerID));
+            result->sct = NO_SECURITY_MODE;
+
+            return result;
         }
-        result->oxm[0] = OIC_JUST_WORKS;
-        result->oxmLen = 1U;
-        result->oxmSel = OIC_JUST_WORKS;
-        memcpy(&result->rownerID, &s_sampleOwnerId, sizeof(result->rownerID));
-        result->sct = NO_SECURITY_MODE;
-
-        return result;
-    }
 };
 
-const OicUuid_t CloneOicSecDoxmTest::s_sampleDeviceId = {
-    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+const OicUuid_t CloneOicSecDoxmTest::s_sampleDeviceId =
+{
+    {
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+    }
 };
 
-const OicUuid_t CloneOicSecDoxmTest::s_sampleOwner = {
-    { 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA }
+const OicUuid_t CloneOicSecDoxmTest::s_sampleOwner =
+{
+    {
+        0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA
+    }
 };
 
-const OicUuid_t CloneOicSecDoxmTest::s_sampleOwnerId = {
-    { 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF }
+const OicUuid_t CloneOicSecDoxmTest::s_sampleOwnerId =
+{
+    {
+        0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF
+    }
 };
 
-const OicUuid_t CloneOicSecDoxmTest::s_sampleSubOwner = {
-    { 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCC }
+const OicUuid_t CloneOicSecDoxmTest::s_sampleSubOwner =
+{
+    {
+        0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCC
+    }
 };
 
 TEST(CloneOicSecDoxmSimpleTest, shouldReturnNullForNullInput)
@@ -446,37 +475,37 @@ TEST_F(CloneOicSecDoxmTest, copyShouldHaveTheSameDpcAsOriginal)
 
 class CloneOCProvisionDevListTest : public ::testing::Test
 {
-public:
-    CloneOCProvisionDevListTest() :
-        m_originalStruct(NULL),
-        m_clonedStruct(NULL)
-    {}
+    public:
+        CloneOCProvisionDevListTest() :
+            m_originalStruct(NULL),
+            m_clonedStruct(NULL)
+        {}
 
-    void SetUp()
-    {
-        m_originalStruct = BuildSampleOCProvisionDev();
-        ASSERT_FALSE(NULL == m_originalStruct);
+        void SetUp()
+        {
+            m_originalStruct = BuildSampleOCProvisionDev();
+            ASSERT_FALSE(NULL == m_originalStruct);
 
-        m_originalStruct->next = BuildSampleOCProvisionDev();
-        ASSERT_FALSE(NULL == m_originalStruct->next);
-    }
+            m_originalStruct->next = BuildSampleOCProvisionDev();
+            ASSERT_FALSE(NULL == m_originalStruct->next);
+        }
 
-    void TearDown()
-    {
-        PMDeleteDeviceList(m_originalStruct);
-        PMDeleteDeviceList(m_clonedStruct);
-    }
-protected:
+        void TearDown()
+        {
+            PMDeleteDeviceList(m_originalStruct);
+            PMDeleteDeviceList(m_clonedStruct);
+        }
+    protected:
 
-    OCProvisionDev_t* m_originalStruct;
-    OCProvisionDev_t* m_clonedStruct;
+        OCProvisionDev_t *m_originalStruct;
+        OCProvisionDev_t *m_clonedStruct;
 
-private:
+    private:
 
-    OCProvisionDev_t* BuildSampleOCProvisionDev()
-    {
-        return (OCProvisionDev_t*)OICCalloc(1, sizeof(OCProvisionDev_t));
-    }
+        OCProvisionDev_t *BuildSampleOCProvisionDev()
+        {
+            return (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+        }
 };
 
 TEST(CloneOCProvisionDevListSimpleTest, shouldReturnNullForNullInput)
@@ -512,52 +541,156 @@ TEST_F(CloneOCProvisionDevListTest, copyShouldHaveDifferentAddressForNext)
     EXPECT_NE(m_originalStruct->next, m_clonedStruct->next);
 }
 
-
 // List add Tests
 TEST(ProvisionListTest, Addition)
 {
-    OCProvisionDev_t* el = NULL;
-    OCStackResult res = OC_STACK_ERROR;
-    OicSecDoxm_t* pDoxm = NULL;
-    int cnt =0;
+    OCProvisionDev_t *el = NULL;
+    OicSecDoxm_t *pDoxm = NULL;
+    int cnt = 0;
 
     // The first addition
-    res = AddDevice(&gList, "10.20.30.40", 5684, OC_DEFAULT_ADAPTER, CT_IP_USE_V4, pDoxm);
-    EXPECT_TRUE(OC_STACK_OK == res);
+    OCDevAddr *addr1 = setAddr("10.20.30.40", 5684, OC_DEFAULT_ADAPTER);
+    EXPECT_EQ(OC_STACK_OK, AddDevice(&gList, addr1, CT_IP_USE_V4, pDoxm));
     EXPECT_TRUE(NULL != gList);
+    OICFree(addr1);
 
-    LL_FOREACH(gList,el){ ++cnt; };
+    LL_FOREACH(gList, el) { ++cnt; };
     EXPECT_TRUE(1 == cnt);
 
     // Same node must not be inserted
-    res = AddDevice(&gList, "10.20.30.40", 5684, OC_ADAPTER_IP, CT_IP_USE_V4, pDoxm);
-    EXPECT_TRUE(OC_STACK_OK == res);
+    OCDevAddr *addr2 = setAddr("10.20.30.40", 5684, OC_ADAPTER_IP);
+    EXPECT_EQ(OC_STACK_OK, AddDevice(&gList, addr2, CT_IP_USE_V4, pDoxm));
     EXPECT_TRUE(NULL != gList);
+    OICFree(addr2);
 
     cnt = 0;
-    LL_FOREACH(gList,el){ ++cnt; };
+    LL_FOREACH(gList, el) { ++cnt; };
     EXPECT_TRUE(1 == cnt);
 
     // Differnet node must be inserted
-    res = AddDevice(&gList, "110.120.130.140", 6789, OC_DEFAULT_ADAPTER, CT_IP_USE_V4, pDoxm);
-    EXPECT_TRUE(OC_STACK_OK == res);
+    OCDevAddr *addr3 = setAddr("110.120.130.140", 6798, OC_DEFAULT_ADAPTER);
+    EXPECT_EQ(OC_STACK_OK, AddDevice(&gList, addr3, CT_IP_USE_V4, pDoxm));
     EXPECT_TRUE(NULL != gList);
+    OICFree(addr3);
 
     cnt = 0;
-    LL_FOREACH(gList,el){ ++cnt; };
+    LL_FOREACH(gList, el) { ++cnt; };
     EXPECT_TRUE(2 == cnt);
+#ifdef __WITH_TLS__
+    EXPECT_EQ(OC_STACK_ERROR, UpdateSecurePortOfDevice(&gList, "110.120.130.14", 6798, 3333, 6799, 3334));
+#else
+    EXPECT_EQ(OC_STACK_ERROR, UpdateSecurePortOfDevice(&gList, "110.120.130.14", 6798, 3333));
+#endif
+    const char *specVer = "1111";
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, UpdateSpecVersionOfDevice(&gList, "110.120.130.14", 6798, NULL));
+    EXPECT_EQ(OC_STACK_ERROR, UpdateSpecVersionOfDevice(&gList, "110.120.130.14", 6798, specVer));
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, MoveDeviceList(&gList, NULL, NULL));
+    OCDevAddr *endpoint = (OCDevAddr *)OICCalloc(1, sizeof(OCDevAddr));
+    strcpy(endpoint->addr, "192.168.1.1");
+    endpoint->port = 888;
+    EXPECT_EQ(OC_STACK_ERROR, MoveDeviceList(&gList, &gList, endpoint));
+    OICFree(endpoint);
+
+    EXPECT_EQ(NULL, PMCloneOCProvisionDev(NULL));
+    gList->pstat = (OicSecPstat_t *)OICCalloc(1, sizeof(OicSecPstat_t));
+    gList->doxm = (OicSecDoxm_t *)OICCalloc(1, sizeof(OicSecDoxm_t));
+    strcpy(gList->specVer, DEFAULT_SPEC_VERSION);
+    OCProvisionDev_t *dev = PMCloneOCProvisionDev(gList);
+    EXPECT_TRUE(NULL != dev);
+    DeleteDoxmBinData(dev->doxm);
+    DeletePstatBinData(dev->pstat);
+    OICFree(dev);
+
+    EXPECT_FALSE(PMGenerateQuery(false, NULL, 0, CT_ADAPTER_IP, NULL, 0, NULL));
+    size_t len = 1024;
+    char *buf = (char *)OICCalloc(1014, sizeof(char));
+    OCConnectivityType connType = (OCConnectivityType)(CT_ADAPTER_TCP | CT_IP_USE_V6);
+    EXPECT_FALSE(PMGenerateQuery(true, "ff.168.1.1%", 2000, connType, buf, len, "/sec/doxm"));
+    EXPECT_TRUE(PMGenerateQuery(true, "192.168.1.1", 2000, CT_ADAPTER_GATT_BTLE, buf, len,
+                                "/sec/doxm"));
+    EXPECT_FALSE(PMGenerateQuery(true, "192.168.1.1", 2000, CT_ADAPTER_RFCOMM_BTEDR, buf, len,
+                                 "/sec/doxm"));
+
+    cnt = 0;
+    LL_FOREACH(gList, el) { ++cnt; };
+    EXPECT_EQ(2, cnt);
+    OICFree(buf);
 }
 
 // List Delete Tests
 TEST(ProvisionListTest, Deletion)
 {
-    OCProvisionDev_tel = NULL;
-    int cnt =0;
+    OCProvisionDev_t *el = NULL;
+    int cnt = 0;
 
     // Delete whole
     PMDeleteDeviceList(gList);
     gList = NULL;
 
-    LL_FOREACH(gList,el){ ++cnt; };
+    LL_FOREACH(gList, el) { ++cnt; };
     EXPECT_TRUE(0 == cnt);
 }
+
+TEST(PMDeleteFromUUIDList, Full)
+{
+    OCUuidList_t *pUuidList = (OCUuidList_t *)OICMalloc(sizeof(OCUuidList_t));
+    pUuidList->next = NULL;
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", &pUuidList->dev);
+    OicUuid_t *targetId = createUuid();
+    EXPECT_FALSE(PMDeleteFromUUIDList(NULL, targetId));
+    EXPECT_TRUE(PMDeleteFromUUIDList(&pUuidList, targetId));
+    pUuidList = (OCUuidList_t *)OICMalloc(sizeof(OCUuidList_t));
+    pUuidList->next = NULL;
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222221", &pUuidList->dev);
+    EXPECT_FALSE(PMDeleteFromUUIDList(&pUuidList, targetId));
+}
+
+TEST(PMPrintOCProvisionDev, NullParam)
+{
+    PMPrintOCProvisionDev(NULL);
+}
+
+TEST(SpecVersionDiscovery, Full)
+{
+    DiscoveryInfo *discoveryInfo = (DiscoveryInfo *)OICCalloc(1, sizeof(DiscoveryInfo));
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SpecVersionDiscovery(NULL, clientResponse));
+    EXPECT_EQ(OC_STACK_ERROR, SpecVersionDiscovery(discoveryInfo, clientResponse));
+}
+
+TEST(SecurePortDiscovery, Full)
+{
+    DiscoveryInfo *discoveryInfo = (DiscoveryInfo *)OICCalloc(1, sizeof(DiscoveryInfo));
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SecurePortDiscovery(NULL, clientResponse));
+    EXPECT_EQ(OC_STACK_ERROR, SecurePortDiscovery(discoveryInfo, clientResponse));
+}
+
+TEST(PMSingleDeviceDiscoveryInUnicast, Full)
+{
+    OCProvisionDev_t *ppFoundDevice = (OCProvisionDev_t *)OICMalloc(sizeof(OCProvisionDev_t));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMSingleDeviceDiscoveryInUnicast(3, NULL, NULL, CT_ADAPTER_IP,
+              &ppFoundDevice));
+    OICFree(ppFoundDevice);
+    ppFoundDevice = NULL;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMSingleDeviceDiscoveryInUnicast(3, NULL, NULL, CT_ADAPTER_IP,
+              &ppFoundDevice));
+}
+
+TEST(PMDeviceDiscovery, Full)
+{
+    OCProvisionDev_t *ppFoundDevice = (OCProvisionDev_t *)OICMalloc(sizeof(OCProvisionDev_t));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMDeviceDiscovery(3, false, &ppFoundDevice));
+    OICFree(ppFoundDevice);
+}
+
+TEST(PMSingleDeviceDiscovery, Full)
+{
+    OCProvisionDev_t *ppFoundDevice = (OCProvisionDev_t *)OICMalloc(sizeof(OCProvisionDev_t));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMSingleDeviceDiscovery(4, NULL, &ppFoundDevice));
+    OICFree(ppFoundDevice);
+    ppFoundDevice = NULL;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PMSingleDeviceDiscovery(4, NULL, &ppFoundDevice));
+}
+
index 33c8349..82ccd00 100644 (file)
  * *****************************************************************/
 #include "iotivity_config.h"
 #include <gtest/gtest.h>
-#include "provisioningdatabasemanager.h"
+#include "ocprovisioningmanager.h"
 
-#ifdef _MSC_VER
-#include <io.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
 
-#define F_OK 0
-#define access _access_s
+#include "tools.h"
+#include "../src/provisioningdatabasemanager.c"
+
+#ifdef __cplusplus
+}
 #endif
 
-#define DB_FILE "PDM.db"
+#undef TAG
+#define TAG "PDB"
+#define PM_DB_FILE_NAME TAG".db"
+#define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
+
 const char ID_1 [] = "1111111111111111";
 const char ID_2 [] = "2111111111111111";
 const char ID_3 [] = "3111111111111111";
@@ -43,15 +51,18 @@ const char ID_11[] = "2222222222222222";
 const char ID_12[] = "3222222222222222";
 const char ID_13[] = "4222222222222222";
 
+#ifndef F_OK
+#define F_OK 0
+#endif
 
 TEST(CallPDMAPIbeforeInit, BeforeInit)
 {
-    if (0 == access(DB_FILE, F_OK))
+    if (0 == access(PM_DB_FILE_NAME, F_OK))
     {
-        EXPECT_EQ(0, remove(DB_FILE));
+        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, 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));
@@ -62,30 +73,43 @@ TEST(CallPDMAPIbeforeInit, BeforeInit)
     EXPECT_EQ(OC_STACK_PDM_IS_NOT_INITIALIZED, PDMIsLinkExists(NULL, NULL, NULL));
 }
 
-TEST(PDMInitTest, PDMInitWithNULL)
+class PDB : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            unlink("PDM.db");
+            IOT_Init(PM_DB_FILE_NAME);
+        }
+
+        static void TearDownTestCase()
+        {
+            IOT_DeInit(PM_DB_FILE_NAME);
+            unlink("PDM.db");
+        }
+};
+
+TEST_F(PDB, PDMInitWithNULL)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     EXPECT_EQ(OC_STACK_OK, PDMClose());
+    EXPECT_EQ(OC_STACK_OK, OCInitPM(NULL));
+    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    EXPECT_EQ(OC_STACK_OK, OCInitPM(PM_DB_FILE_NAME));
 }
 
-TEST(PDMAddDeviceTest, NullUUID)
+TEST_F(PDB, PDMAddDeviceNullUUID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMAddDevice(NULL));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMIsDuplicateDeviceTest, NullUUID)
+TEST_F(PDB, PDMIsDuplicateDeviceNullUUID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMIsDuplicateDevice(NULL,NULL));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMIsDuplicateDevice(NULL, NULL));
 }
 
 
-TEST(PDMIsDuplicateDeviceTest, ValidUUID)
+TEST_F(PDB, PDMIsDuplicateDeviceValidUUID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_1, sizeof(uid1.id));
     EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid1));
@@ -97,17 +121,15 @@ TEST(PDMIsDuplicateDeviceTest, ValidUUID)
     OicUuid_t uid3 = {{0,}};
     memcpy(&uid3.id, ID_3, sizeof(uid3.id));
     bool isDuplicate = true;
-    EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid1,&isDuplicate));
+    EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid1, &isDuplicate));
     EXPECT_TRUE(isDuplicate);
 
     EXPECT_EQ(OC_STACK_OK, PDMIsDuplicateDevice(&uid3, &isDuplicate));
     EXPECT_FALSE(isDuplicate);
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMAddDeviceTest, ValidUUID)
+TEST_F(PDB, PDMAddDeviceValidUUID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
 
     uint8_t id[UUID_LENGTH] = {0,};
@@ -122,30 +144,24 @@ TEST(PDMAddDeviceTest, ValidUUID)
 
     EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid));
     EXPECT_EQ(OC_STACK_OK, PDMDeleteDevice(&uid));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMLinkDevicesTest, NULLDevice1)
+TEST_F(PDB, PDMLinkDevicesNULLDevice1)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_2, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMLinkDevices(NULL, &uid));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMLinkDevicesTest, NULLDevice2)
+TEST_F(PDB, PDMLinkDevicesNULLDevice2)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_3, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMLinkDevices(&uid, NULL));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMLinkDevicesTest, ValidCase)
+TEST_F(PDB, PDMLinkDevicesValidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_4, sizeof(uid1.id));
     EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid1));
@@ -157,49 +173,39 @@ TEST(PDMLinkDevicesTest, ValidCase)
     EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&uid2, PDM_DEVICE_ACTIVE));
 
     EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&uid1, &uid2));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMUnlinkDevicesTest, NULLDevice1)
+TEST_F(PDB, PDMUnlinkDevicesNULLDevice1)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_3, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMUnlinkDevices(NULL, &uid));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMUnlinkDevicesTest, NULLDevice2)
+TEST_F(PDB, PDMUnlinkDevicesNULLDevice2)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_3, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMUnlinkDevices(&uid, NULL));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMUnlinkDevices, ValidCase)
+TEST_F(PDB, PDMUnlinkDevicesValidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_4, sizeof(uid1.id));
     OicUuid_t uid2 = {{0,}};
     memcpy(&uid2.id, ID_5, sizeof(uid2.id));
     EXPECT_EQ(OC_STACK_OK, PDMUnlinkDevices(&uid1, &uid2));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
 
-TEST (PDMDeleteDevice, NULLDeviceID)
+TEST_F(PDB, PDMDeleteDeviceNULLDeviceID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMDeleteDevice(NULL));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST (PDMDeleteDevice, ValidButNonExistDeviceID)
+TEST_F(PDB, PDMDeleteDeviceValidButNonExistDeviceID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     uint8_t id[UUID_LENGTH] = {0,};
     for (size_t i = 0 ; i < sizeof(id) ; i++)
@@ -211,70 +217,60 @@ TEST (PDMDeleteDevice, ValidButNonExistDeviceID)
 
     memcpy(&uid.id, &id, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMDeleteDevice(&uid));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMGetOwnedDevices, ValidCase)
+TEST_F(PDB, PDMGetOwnedDevicesValidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OCUuidList_t *list = NULL;
     size_t noOfDevcies = 0;
     EXPECT_EQ(OC_STACK_OK, PDMGetOwnedDevices(&list, &noOfDevcies));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    PDMFreeLinkedDevices(list);
 }
 
-TEST(PDMGetLinkedDevices, NULLDeviceID)
+TEST_F(PDB, PDMGetLinkedDevicesNULLDeviceID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OCUuidList_t *list = NULL;
     size_t noOfDevices = 0;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMGetLinkedDevices(NULL, &list, &noOfDevices));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    PDMFreeLinkedDevices(list);
 }
 
-TEST(PDMGetLinkedDevices, ValidCase)
+TEST_F(PDB, PDMGetLinkedDevicesValidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_1, sizeof(uid.id));
     OCUuidList_t *list = NULL;
     size_t noOfDevices = 0;
     EXPECT_EQ(OC_STACK_OK, PDMGetLinkedDevices(&uid, &list, &noOfDevices));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    PDMFreeLinkedDevices(list);
 }
 
-TEST(PDMGetLinkedDevices, InvalidCase)
+TEST_F(PDB, PDMGetLinkedDevicesInvalidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_6, sizeof(uid.id));
     OCUuidList_t *list = NULL;
     size_t noOfDevices = 0;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMGetLinkedDevices(&uid, &list, &noOfDevices));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    PDMFreeLinkedDevices(list);
 }
 
-TEST(PDMSetLinkStale, NULLDeviceID1)
+TEST_F(PDB, PDMSetLinkStaleNULLDeviceID1)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_1, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMSetLinkStale(NULL, &uid));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMSetLinkStale, NULLDeviceID2)
+TEST_F(PDB, PDMSetLinkStaleNULLDeviceID2)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid = {{0,}};
     memcpy(&uid.id, ID_1, sizeof(uid.id));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMSetLinkStale(&uid, NULL));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMSetLinkStale, ValidCase)
+TEST_F(PDB, PDMSetLinkStaleValidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_6, sizeof(uid1.id));
     OicUuid_t uid2 = {{0,}};
@@ -289,37 +285,35 @@ TEST(PDMSetLinkStale, ValidCase)
     EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&uid1, &uid2));
 
     EXPECT_EQ(OC_STACK_OK, PDMSetLinkStale(&uid1, &uid2));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMGetToBeUnlinkedDevices, ValidCase)
+TEST_F(PDB, PDMGetToBeUnlinkedDevicesValidCase)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OCPairList_t *list = NULL;
     size_t noOfDevices = 0;
     EXPECT_EQ(OC_STACK_OK, PDMGetToBeUnlinkedDevices(&list, &noOfDevices));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
-}
 
-TEST(PDMClose, ValidCase)
-{
-   EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
-   EXPECT_EQ(OC_STACK_OK, PDMClose());
+    OCPairList_t *p1 = NULL;
+    OCPairList_t *p2 = NULL;
+    LL_FOREACH_SAFE(list, p1, p2)
+    {
+        LL_DELETE(list, p1);
+        OICFree(p1);
+    }
 }
 
-TEST(PDMDestoryOicUuidLinkList, NULLParam)
+TEST_F(PDB, PDMDestoryOicUuidLinkListNULLParam)
 {
     PDMDestoryOicUuidLinkList(NULL);
 }
 
-TEST(PDMDestoryStaleLinkList, NULLParam)
+TEST_F(PDB, PDMDestoryStaleLinkListNULLParam)
 {
     PDMDestoryStaleLinkList(NULL);
 }
 
-TEST(PDMIsLinkExistsTest, DuplicateID)
+TEST_F(PDB, PDMIsLinkExistsDuplicateID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_7, sizeof(uid1.id));
     EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid1));
@@ -334,29 +328,23 @@ TEST(PDMIsLinkExistsTest, DuplicateID)
     OCStackResult res = PDMIsLinkExists(&uid1, &uid2, &linkExisits);
     EXPECT_EQ(OC_STACK_OK, res);
     EXPECT_FALSE(linkExisits);
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMSetDeviceStaleTest, NULLUUID)
+TEST_F(PDB, PDMSetDeviceStaleNULLUUID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     EXPECT_EQ(OC_STACK_INVALID_PARAM, PDMSetDeviceState(NULL, PDM_DEVICE_STALE));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
 
-TEST(PDMSetDeviceStaleTest, VALIDUUID)
+TEST_F(PDB, PDMSetDeviceStaleVALIDUUID)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_9, sizeof(uid1.id));
     EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid1));
-    EXPECT_EQ(OC_STACK_OK,PDMSetDeviceState(&uid1, PDM_DEVICE_STALE));
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&uid1, PDM_DEVICE_STALE));
 }
 
-TEST(PDMSetDeviceStaleTest, StaleDeviceNotinDeviceList)
+TEST_F(PDB, PDMSetDeviceStaleStaleDeviceNotinDeviceList)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_10, sizeof(uid1.id));
     EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&uid1));
@@ -368,15 +356,14 @@ TEST(PDMSetDeviceStaleTest, StaleDeviceNotinDeviceList)
 
     while (list)
     {
-        EXPECT_FALSE(0 == memcmp(list->dev.id, uid1.id,sizeof(uid1.id)));
+        EXPECT_FALSE(0 == memcmp(list->dev.id, uid1.id, sizeof(uid1.id)));
         list = list->next;
     }
-    EXPECT_EQ(OC_STACK_OK, PDMClose());
+    PDMFreeLinkedDevices(list);
 }
 
-TEST(PDMSetDeviceStaleTest, StaleDeviceNotinLinkedDevice)
+TEST_F(PDB, PDMSetDeviceStaleStaleDeviceNotinLinkedDevice)
 {
-    EXPECT_EQ(OC_STACK_OK, PDMInit(NULL));
     OicUuid_t uid1 = {{0,}};
     memcpy(&uid1.id, ID_11, sizeof(uid1.id));
 
@@ -397,7 +384,7 @@ TEST(PDMSetDeviceStaleTest, StaleDeviceNotinLinkedDevice)
     EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&uid2, &uid3));
     EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&uid1, &uid3));
 
-    EXPECT_EQ(OC_STACK_OK,PDMSetDeviceState(&uid1, PDM_DEVICE_STALE));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&uid1, PDM_DEVICE_STALE));
 
     OCUuidList_t *list1 = NULL;
     size_t noOfDevices1 = 0;
@@ -407,15 +394,15 @@ TEST(PDMSetDeviceStaleTest, StaleDeviceNotinLinkedDevice)
     size_t noOfDevices2 = 0;
     EXPECT_EQ(OC_STACK_OK, PDMGetLinkedDevices(&uid2, &list2, &noOfDevices2));
     OCUuidList_t *ptr = list2;
-    while(ptr)
+    while (ptr)
     {
-        EXPECT_FALSE(0 == memcmp(ptr->dev.id, uid1.id,sizeof(uid1.id)));
+        EXPECT_FALSE(0 == memcmp(ptr->dev.id, uid1.id, sizeof(uid1.id)));
         ptr = ptr->next;
     }
     ptr = list2;
-    while(ptr)
+    while (ptr)
     {
-        EXPECT_TRUE(0 == memcmp(ptr->dev.id, uid3.id,sizeof(uid3.id)));
+        EXPECT_TRUE(0 == memcmp(ptr->dev.id, uid3.id, sizeof(uid3.id)));
         ptr = ptr->next;
     }
 
@@ -423,17 +410,27 @@ TEST(PDMSetDeviceStaleTest, StaleDeviceNotinLinkedDevice)
     size_t noOfDevices3 = 0;
     EXPECT_EQ(OC_STACK_OK, PDMGetLinkedDevices(&uid3, &list3, &noOfDevices3));
     ptr = list3;
-    while(ptr)
+    while (ptr)
     {
-        EXPECT_FALSE(0 == memcmp(ptr->dev.id, uid1.id,sizeof(uid1.id)));
+        EXPECT_FALSE(0 == memcmp(ptr->dev.id, uid1.id, sizeof(uid1.id)));
         ptr = ptr->next;
     }
 
     ptr = list3;
-    while(ptr)
+    while (ptr)
     {
-        EXPECT_TRUE(0 == memcmp(ptr->dev.id, uid2.id,sizeof(uid2.id)));
+        EXPECT_TRUE(0 == memcmp(ptr->dev.id, uid2.id, sizeof(uid2.id)));
         ptr = ptr->next;
     }
+    PDMFreeLinkedDevices(list3);
+    PDMFreeLinkedDevices(list2);
+    PDMFreeLinkedDevices(list1);
+}
+
+/*
+TEST_F(PDB, PDMCloseValidCase)
+{
     EXPECT_EQ(OC_STACK_OK, PDMClose());
 }
+*/
+
index 90a6d6a..67ee083 100644 (file)
  *
  * *****************************************************************/
 #include <gtest/gtest.h>
-#include "secureresourceprovider.h"
-
-static OicSecAcl_t acl;
-static OCProvisionDev_t pDev1;
-static OCProvisionDev_t pDev2;
-static OicSecCredType_t credType = SYMMETRIC_PAIR_WISE_KEY;
-static OicSecOxm_t oicSecDoxmJustWorks = OIC_JUST_WORKS;
-static OicSecOxm_t oicSecDoxmRandomPin = OIC_RANDOM_DEVICE_PIN;
-static unsigned short timeout = 60;
-static OicSecDoxm_t defaultDoxm1 =
-{
-    &oicSecDoxmJustWorks,   /* uint16_t *oxm */
-    1,                      /* size_t oxmLen */
-    OIC_JUST_WORKS,         /* uint16_t oxmSel */
-    SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
-    false,                  /* bool owned */
-    {{0}},                  /* OicUuid_t deviceID */
-    false,                  /* bool dpc */
-    {{0}},                  /* OicUuid_t owner */
-#ifdef MULTIPLE_OWNER
-    NULL,                   /* OicSecSubOwner_t* subOwners */
-    NULL,                   /* OicSecMom_t *mom */
-#endif //MULTIPLE_OWNER
-    {{0}}                   /* rownerID */
-};
 
-static OicSecDoxm_t defaultDoxm2 =
-{
-    &oicSecDoxmRandomPin,   /* uint16_t *oxm */
-    1,                      /* size_t oxmLen */
-    OIC_RANDOM_DEVICE_PIN,  /* uint16_t oxmSel */
-    SYMMETRIC_PAIR_WISE_KEY,/* OicSecCredType_t sct */
-    false,                  /* bool owned */
-    {{0}},                  /* OicUuid_t deviceID */
-    false,                  /* bool dpc */
-    {{0}},                  /* OicUuid_t owner */
-#ifdef MULTIPLE_OWNER
-    NULL,                   /* OicSecSubOwner_t* subOwners */
-    NULL,                   /* OicSecMom_t *mom */
-#endif //MULTIPLE_OWNER
-    {{0}}                   /* rownerID */
+#ifdef __cplusplus
+extern "C" {
+#endif
+//#include "../../../connectivity/src/cablockwisetransfer.c"
+#include "../src/secureresourceprovider.c"
+#undef TAG
+#include "../../src/csrresource.c"
+#undef TAG
+#include "../../src/credresource.c"
+#undef TAG
+#include "tools.h"
+#undef TAG
+
+#ifdef __cplusplus
+}
+#endif
+
+#define TAG "SRP"
+
+#define SVR_DB_FILE_NAME "oic_svr_db_client.dat"
+#define PM_DB_FILE_NAME TAG".db"
+
+static OCProvisionDev_t *pDev1 = NULL;
+static OCProvisionDev_t *pDev2 = NULL;
+static unsigned short timeout = 0;
+
+class SRP : public ::testing::Test
+{
+    public:
+        static void SetUpTestCase()
+        {
+            IOT_Init(PM_DB_FILE_NAME);
+
+            pDev1 = createProvisionDev();
+            pDev2 = createProvisionDev();
+            pDev2->endpoint.port = 9998;
+            ConvertStrToUuid("33333355-3333-3333-3333-111111111111", &pDev2->doxm->deviceID);
+
+            timeout = 60;
+        }
+
+        static void TearDownTestCase()
+        {
+            ClientCB *out = NULL;
+            ClientCB *tmp = NULL;
+            LL_FOREACH_SAFE(g_cbList, out, tmp)
+            {
+                LL_DELETE(g_cbList, out);
+            }
+
+            OicSecCred_t *cred = NULL;
+            OicSecCred_t *r = NULL;
+            LL_FOREACH_SAFE(gCred, cred, r)
+            {
+                LL_DELETE(gCred, cred);
+            }
+            /*
+                        size_t len = u_arraylist_length(g_context.dataList);
+                        for (size_t i = len; i > 0; i--)
+                        {
+                            CABlockData_t *removedData = (CABlockData_t *)u_arraylist_remove(g_context.dataList, i - 1);
+                        }*/
+            IOT_DeInit(PM_DB_FILE_NAME);
+        }
+
+        static const ByteArray g_caPublicKey;
+
+        static const ByteArray g_derCode ;
+
+        static ByteArray g_serNum;
+        //static OCProvisionDev_t *gList = NULL;
+        OicSecAcl_t acl;
 };
 
-static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3, bool UNUSED4)
+static void provisionResultCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+    OIC_LOG_V(DEBUG, TAG, "%s: %d", __func__, hasError);
+}
+
+static CredentialData_t *createCredentialData()
+{
+    CredentialData_t *credData = (CredentialData_t *)OICCalloc(1, sizeof(CredentialData_t));
+    memset(credData, 0, sizeof(CredentialData_t));
+    credData->resultCallback = provisionResultCB;
+    credData->numOfResults = 0;
+    credData->resArr = (OCProvisionResult_t *)OICCalloc(2, sizeof(OCProvisionResult_t));
+    credData->deviceInfo[0] = createProvisionDev();
+    credData->deviceInfo[1] = createProvisionDev();
+
+    return credData;
+}
+
+static void freeCredentialData(CredentialData_t *credData)
+{
+    freeProvisionDev((OCProvisionDev_t *)credData->deviceInfo[0]);
+    freeProvisionDev((OCProvisionDev_t *)credData->deviceInfo[1]);
+    OICFree(credData->resArr);
+    OICFree(credData);
+}
+
+static void provisioningCB (void *UNUSED1, size_t UNUSED2, OCProvisionResult_t *UNUSED3,
+                            bool UNUSED4)
 {
     //dummy callback
     (void) UNUSED1;
@@ -70,266 +133,220 @@ static void provisioningCB (void* UNUSED1, size_t UNUSED2, OCProvisionResult_t *
     (void) UNUSED4;
 }
 
-TEST(SRPProvisionACLTest, NullDeviceInfo)
+TEST_F(SRP, SRPProvisionACLNullDeviceInfo)
 {
-    pDev1.doxm = &defaultDoxm1;
-    uint8_t deviceId1[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x64};
-    memcpy(pDev1.doxm->deviceID.id, deviceId1, sizeof(deviceId1));
-
-    pDev2.doxm = &defaultDoxm2;
-    uint8_t deviceId2[] = {0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x49, 0x63};
-    memcpy(pDev2.doxm->deviceID.id, deviceId2, sizeof(deviceId2));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionACL(NULL, NULL, &acl, OIC_SEC_ACL_V2,
+              &provisioningCB));
+}
 
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionACL(NULL, NULL, &acl, OIC_SEC_ACL_V2, &provisioningCB));
+TEST_F(SRP, SRPProvisionACLNullCallback)
+{
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPProvisionACL(NULL, pDev1, &acl, OIC_SEC_ACL_V2, NULL));
 }
 
-TEST(SRPProvisionACLTest, NullCallback)
+TEST_F(SRP, SRPProvisionACLNullACL)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPProvisionACL(NULL, &pDev1, &acl, OIC_SEC_ACL_V2, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionACL(NULL, pDev1, NULL, OIC_SEC_ACL_V2,
+              &provisioningCB));
 }
 
-TEST(SRPProvisionACLTest, NullACL)
+TEST_F(SRP, SRPProvisionACLInvalidVersion)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionACL(NULL, &pDev1, NULL, OIC_SEC_ACL_V2, &provisioningCB));
+    EXPECT_EQ(OC_STACK_OK, SRPProvisionACL(NULL, pDev1, &acl, OIC_SEC_ACL_UNKNOWN,
+                                           &provisioningCB));
 }
 
-TEST(SRPProvisionACLTest, InvalidVersion)
+TEST_F(SRP, SRPProvisionCredentialsNullDevice1)
 {
-    EXPECT_EQ(OC_STACK_ERROR, SRPProvisionACL(NULL, &pDev1, &acl, OIC_SEC_ACL_UNKNOWN, &provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionCredentials(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, NULL,
+              pDev2, NULL, NULL, NULL, &provisioningCB));
 }
 
-TEST(SRPProvisionCredentialsTest, NullDevice1)
+TEST_F(SRP, SRPProvisionCredentialsSamelDeviceId)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionCredentials(NULL, credType,
-                                                              OWNER_PSK_LENGTH_128, NULL,
-                                                              &pDev2, NULL, NULL, NULL, &provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionCredentials(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, pDev1,
+              pDev1, NULL, NULL, NULL, &provisioningCB));
 }
 
-TEST(SRPProvisionCredentialsTest, SamelDeviceId)
+TEST_F(SRP, SRPProvisionCredentialsNullCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionCredentials(NULL, credType,
-                                                              OWNER_PSK_LENGTH_128, &pDev1,
-                                                              &pDev1, NULL, NULL, NULL, &provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPProvisionCredentials(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128,
+              pDev1, pDev2, NULL, NULL, NULL, NULL));
 }
 
-TEST(SRPProvisionCredentialsTest, NullCallback)
+TEST_F(SRP, SRPProvisionCredentialsInvalidKeySize)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPProvisionCredentials(NULL, credType,
-                                                                 OWNER_PSK_LENGTH_128,
-                                                                 &pDev1, &pDev2, NULL, NULL, NULL, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionCredentials(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              0, pDev1, pDev2, NULL, NULL, NULL,
+              &provisioningCB));
 }
 
-TEST(SRPProvisionCredentialsTest, InvalidKeySize)
+TEST_F(SRP, SRPProvisionCredentialsFull)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPProvisionCredentials(NULL, credType,
-                                                                0, &pDev1, &pDev2, NULL, NULL, NULL, 
-                                                                &provisioningCB));
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev1->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev1->doxm->deviceID, PDM_DEVICE_ACTIVE));
+    EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev2->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev2->doxm->deviceID, PDM_DEVICE_ACTIVE));
+//    EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID));
+    EXPECT_EQ(OC_STACK_OK, SRPProvisionCredentials(NULL, SYMMETRIC_PAIR_WISE_KEY,
+              OWNER_PSK_LENGTH_128, pDev1, pDev2, getPemKey(), NULL, NULL,
+              &provisioningCB));
+    EXPECT_EQ(OC_STACK_OK, SRPProvisionCredentials(NULL, SIGNED_ASYMMETRIC_KEY,
+              OWNER_PSK_LENGTH_128, pDev1, pDev2, getPemKey(), NULL, NULL,
+              &provisioningCB));
 }
 
-TEST(SRPUnlinkDevicesTest, NullDevice1)
+
+TEST_F(SRP, SRPUnlinkDevicesTestNullDevice1)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPUnlinkDevices(NULL, NULL, &pDev2, provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPUnlinkDevices(NULL, NULL, pDev2, provisioningCB));
 }
 
-TEST(SRPUnlinkDevicesTest, SamelDeviceId)
+TEST_F(SRP, SRPUnlinkDevicesTestSamelDeviceId)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPUnlinkDevices(NULL, &pDev1, &pDev1, provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPUnlinkDevices(NULL, pDev1, pDev1, provisioningCB));
 }
 
-TEST(SRPUnlinkDevicesTest, NullCallback)
+TEST_F(SRP, SRPUnlinkDevicesTestNullCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPUnlinkDevices(NULL, &pDev1, &pDev2, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPUnlinkDevices(NULL, pDev1, pDev2, NULL));
 }
 
-TEST(SRPRemoveDeviceTest, NullTargetDevice)
+TEST_F(SRP, SRPRemoveDeviceTestNullTargetDevice)
 {
     unsigned short waitTime = 10 ;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPRemoveDevice(NULL, waitTime, NULL, provisioningCB));
 }
 
-TEST(SRPRemoveDeviceTest, NullResultCallback)
+TEST_F(SRP, SRPRemoveDeviceTestNullResultCallback)
 {
     unsigned short waitTime = 10;
     OCProvisionDev_t dev1;
     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPRemoveDevice(NULL, waitTime, &dev1, NULL));
 }
 
-TEST(SRPRemoveDeviceTest, ZeroWaitTime)
+TEST_F(SRP, SRPRemoveDeviceTestZeroWaitTime)
 {
     OCProvisionDev_t dev1;
     EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPRemoveDevice(NULL, 0, &dev1, NULL));
 }
-
-const char *SECURE_RESOURCE_PROVIDER_TEST_FILE_NAME = "secureresourceprovider.dat";
-OCPersistentStorage ps = { NULL, NULL, NULL, NULL, NULL};
-
-static FILE* TestFopen(const char *path, const char *mode)
+/*
+TEST_F(SRP, SRPRemoveDeviceFull)
 {
-    if (0 == strcmp(path, OC_SECURITY_DB_DAT_FILE_NAME))
-    {
-        return fopen(SECURE_RESOURCE_PROVIDER_TEST_FILE_NAME, mode);
-    }
-    else
-    {
-        return fopen(path, mode);
-    }
+    PDMSetDeviceState(&pDev1->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMSetDeviceState(&pDev2->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMLinkDevices(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID);
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPRemoveDevice(NULL, 4, pDev1, provisioningCB));
 }
-
-void SetPersistentHandler(OCPersistentStorage *persistentStorage)
+*/
+void trustCertChainChangeCB(void *ctx, uint16_t credId, uint8_t *trustCertChain, size_t chainSize)
 {
-    if(persistentStorage)
-    {
-        persistentStorage->open = TestFopen;
-        persistentStorage->read = fread;
-        persistentStorage->write = fwrite;
-        persistentStorage->close = fclose;
-        persistentStorage->unlink = remove;
-    }
+    OC_UNUSED(ctx);
+    OC_UNUSED(credId);
+    OC_UNUSED(trustCertChain);
+    OC_UNUSED(chainSize);
+    OIC_LOG_V(DEBUG, TAG, "%s", __func__);
 }
 
-class SRPTest : public ::testing::Test
+TEST_F(SRP, SRPSaveTrustCertChainDER)
 {
-public:
-    static void SetUpTestCase()
-    {
-        SetPersistentHandler(&ps);
-        OCStackResult res = OCRegisterPersistentStorageHandler(&ps);
-        ASSERT_TRUE(res == OC_STACK_OK);
-        res = OCInit(NULL, 0, OC_SERVER);
-        ASSERT_TRUE(res == OC_STACK_OK);
-    }
-
-    static void TearDownTestCase()
-    {
-        OCStackResult res = OCStop();
-        ASSERT_TRUE(res == OC_STACK_OK);
-    }
-
-    static const ByteArray g_caPublicKey;
-
-    static const ByteArray g_derCode ;
+    uint16_t credId;
 
-    static ByteArray g_serNum;
-};
+    SRPRegisterTrustCertChainNotifier(NULL, trustCertChainChangeCB);
+    EXPECT_EQ(OC_STACK_OK, SRPSaveTrustCertChain(certData(), certDataLen(), OIC_ENCODING_DER, &credId));
+}
 
-static uint8_t certData[] = {
-        0x30, 0x82, 0x02, 0x39, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a,
-        0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
-        0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
-        0x09, 0x53, 0x6f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,
-        0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30,
-        0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
-        0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61,
-        0x72, 0x74, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31,
-        0x14, 0x30, 0x12, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05,
-        0x6f, 0x62, 0x40, 0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x35, 0x31,
-        0x33, 0x31, 0x31, 0x31, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x32, 0x31, 0x33,
-        0x31, 0x31, 0x31, 0x37, 0x5a, 0x30, 0x81, 0xd4, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
-        0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x03,
-        0x41, 0x73, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x06, 0x47, 0x6f,
-        0x74, 0x68, 0x61, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x5a,
-        0x5a, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x42, 0x65, 0x61, 0x6d,
-        0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
-        0x01, 0x09, 0x01, 0x16, 0x0d, 0x72, 0x61, 0x69, 0x6c, 0x40, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
-        0x6f, 0x6d, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x29, 0x75, 0x75, 0x69,
-        0x64, 0x3a, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d,
-        0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32,
-        0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, 0x34, 0x30, 0x32, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x0c,
-        0x2b, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x3a, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37,
-        0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d,
-        0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x30, 0x59, 0x30, 0x13,
-        0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
-        0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10, 0xe5, 0x09,
-        0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a, 0xb6, 0x61,
-        0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0, 0xe5, 0xac,
-        0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76, 0x3f, 0xe0,
-        0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
-        0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
-        0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
-        0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21, 0x00, 0xe5, 0x8f, 0x7f,
-        0xf1, 0xa6, 0x82, 0x03, 0x6a, 0x18, 0x7a, 0x54, 0xe7, 0x0e, 0x25, 0x77, 0xd8, 0x46, 0xfa, 0x96,
-        0x8a, 0x7e, 0x14, 0xc4, 0xcb, 0x21, 0x32, 0x3e, 0x89, 0xd9, 0xba, 0x8c, 0x3f
-    };
-
-static uint8_t keyData[] = {
-           0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
-        0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
-        0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
-        0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21
-    };
-
-TEST_F(SRPTest, SRPSaveTrustCertChainDER)
+TEST_F(SRP, SRPSaveTrustCertChainPEM)
 {
-    int result;
     uint16_t credId;
 
-    result = SRPSaveTrustCertChain(certData, sizeof(certData), OIC_ENCODING_DER, &credId);
-    EXPECT_EQ(OC_STACK_OK, result);
+    EXPECT_EQ(OC_STACK_OK, SRPSaveTrustCertChain((const uint8_t *)getPemCert(), certDataLen(),
+              OIC_ENCODING_PEM, &credId));
 }
 
-TEST_F(SRPTest, SRPSaveTrustCertChainPEM)
+TEST_F(SRP, SRPSaveTrustCertChainNullCertData)
 {
-    int result;
     uint16_t credId;
 
-    result = SRPSaveTrustCertChain(certData, sizeof(certData), OIC_ENCODING_PEM, &credId);
-    EXPECT_EQ(OC_STACK_OK, result);
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPSaveTrustCertChain(NULL, certDataLen(), OIC_ENCODING_DER,
+              &credId));
 }
 
-TEST_F(SRPTest, SRPSaveTrustCertChainNullCertData)
+TEST_F(SRP, SRPSaveTrustCertChainNullCredId)
 {
     int result;
-    uint16_t credId;
 
-    result = SRPSaveTrustCertChain(NULL, sizeof(certData), OIC_ENCODING_DER, &credId);
+    result = SRPSaveTrustCertChain(certData(), certDataLen(), OIC_ENCODING_DER, NULL);
 
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPSaveTrustCertChainNullCredId)
+TEST_F(SRP, SRPSaveTrustCertChainDoxm)
 {
-    int result;
+    uint16_t credId;
 
-    result = SRPSaveTrustCertChain(certData, sizeof(certData), OIC_ENCODING_DER, NULL);
+    DeInitDoxmResource();
+    EXPECT_EQ(OC_STACK_ERROR, SRPSaveTrustCertChain(certData(), certDataLen(), OIC_ENCODING_DER,
+              &credId));
+    InitDoxmResource();
+}
 
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+TEST_F(SRP, SRPSaveTrustCertChainPstat)
+{
+    uint16_t credId;
+
+    DeInitPstatResource();
+    EXPECT_EQ(OC_STACK_OK, SRPSaveTrustCertChain(certData(), certDataLen(), OIC_ENCODING_DER, &credId));
+    InitPstatResource();
 }
 
-TEST_F(SRPTest, SRPSaveOwnCertChainTest)
+TEST_F(SRP, SRPSaveTrustCertChainUnknowEnc)
+{
+    uint16_t credId;
+
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPSaveTrustCertChain(certData(), certDataLen(),
+              OIC_ENCODING_UNKNOW, &credId));
+}
+
+
+TEST_F(SRP, SRPSaveOwnCertChainTest)
 {
-    int result;
     uint16_t credId;
     OicSecKey_t cert;
     OicSecKey_t key;
 
-    cert.data = certData;
-    cert.len = sizeof(certData);
+    cert.data = certData();
+    cert.len = certDataLen();
     cert.encoding = OIC_ENCODING_DER;
 
-    key.data = keyData;
-    key.len = sizeof(keyData);
+    key.data = keyData();
+    key.len = keyDataLen();
     key.encoding = OIC_ENCODING_DER;
 
-    result = SRPSaveOwnCertChain(&cert, &key, &credId);
-
-    EXPECT_EQ(OC_STACK_OK, result);
+    EXPECT_EQ(OC_STACK_OK, SRPSaveOwnCertChain(&cert, &key, &credId));
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPSaveOwnCertChainTestNullCert)
+TEST_F(SRP, SRPSaveOwnCertChainTestNullCert)
 {
     int result;
     uint16_t credId;
     OicSecKey_t key;
 
-    key.data = keyData;
-    key.len = sizeof(keyData);
+    key.data = keyData();
+    key.len = keyDataLen();
 
     result = SRPSaveOwnCertChain(NULL, &key, &credId);
 
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPSaveOwnCertChainTestNullCertData)
+TEST_F(SRP, SRPSaveOwnCertChainTestNullCertData)
 {
     int result;
     uint16_t credId;
@@ -337,64 +354,100 @@ TEST_F(SRPTest, SRPSaveOwnCertChainTestNullCertData)
     OicSecKey_t key;
 
     cert.data = NULL;
-    cert.len = sizeof(certData);
-    key.data = keyData;
-    key.len = sizeof(keyData);
+    cert.len = certDataLen();
+    key.data = keyData();
+    key.len = keyDataLen();
 
     result = SRPSaveOwnCertChain(&cert, &key, &credId);
 
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPSaveOwnCertChainTestNullKey)
+TEST_F(SRP, SRPSaveOwnCertChainTestNullKey)
 {
     int result;
     uint16_t credId;
     OicSecKey_t cert;
 
-    cert.data = certData;
-    cert.len = sizeof(certData);
+    cert.data = certData();
+    cert.len = certDataLen();
 
     result = SRPSaveOwnCertChain(&cert, NULL, &credId);
 
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPSaveOwnCertChainTestNullKeyData)
+TEST_F(SRP, SRPSaveOwnCertChainTestNullKeyData)
 {
     int result;
     uint16_t credId;
     OicSecKey_t cert;
     OicSecKey_t key;
 
-    cert.data = certData;
-    cert.len = sizeof(certData);
+    cert.data = certData();
+    cert.len = certDataLen();
     key.data = NULL;
-    key.len = sizeof(keyData);
+    key.len = keyDataLen();
 
     result = SRPSaveOwnCertChain(&cert, &key, &credId);
 
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPSaveOwnCertChainTestNullCredId)
+
+OicSecKey_t *getCert()
+{
+    OicSecKey_t *cert = (OicSecKey_t *)OICCalloc(1, sizeof(OicSecKey_t));
+    cert->data = certData();
+    cert->len = certDataLen();
+    return cert;
+}
+
+OicSecKey_t *getKey()
+{
+    OicSecKey_t *key = (OicSecKey_t *)OICCalloc(1, sizeof(OicSecKey_t));
+    key->data = keyData();
+    key->len = keyDataLen();
+    return key;
+}
+
+TEST_F(SRP, SRPSaveOwnCertChainTestDoxm)
+{
+    uint16_t credId;
+    OicSecKey_t *cert = getCert();
+    OicSecKey_t *key = getKey();
+
+    DeInitDoxmResource();
+    EXPECT_EQ(OC_STACK_ERROR, saveCertChain(cert, key, &credId, "core.der"));
+    InitDoxmResource();
+    RemoveAllCredentials();
+    OICFree(cert);
+    OICFree(key);
+}
+
+
+TEST_F(SRP, SRPSaveOwnCertChainTestNullCredId)
 {
     int result;
     OicSecKey_t cert;
     OicSecKey_t key;
 
-    cert.data = certData;
-    cert.len = sizeof(certData);
-    key.data = keyData;
-    key.len = sizeof(keyData);
+    cert.data = certData();
+    cert.len = certDataLen();
+    key.data = keyData();
+    key.len = keyDataLen();
 
     result = SRPSaveOwnCertChain(&cert, &key, NULL);
 
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
 
-TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainNullSelectedDeviceInfo)
+TEST_F(SRP, SRPProvisionTrustCertChainNullSelectedDeviceInfo)
 {
     int result;
     int ctx;
@@ -403,9 +456,10 @@ TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainNullSelectedDevic
 
     result = SRPProvisionTrustCertChain(&ctx, type, credId, NULL, provisioningCB);
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainNullResultCallback)
+TEST_F(SRP, SRPProvisionTrustCertChainNullResultCallback)
 {
     int result;
     int ctx;
@@ -415,9 +469,10 @@ TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainNullResultCallbac
 
     result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, NULL);
     EXPECT_EQ(OC_STACK_INVALID_CALLBACK, result);
+    RemoveAllCredentials();
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainInvalidOicSecCredType)
+TEST_F(SRP, SRPProvisionTrustCertChainInvalidOicSecCredType)
 {
     int result;
     int ctx;
@@ -427,9 +482,21 @@ TEST(SRPProvisionTrustCertChainTest, SRPProvisionTrustCertChainInvalidOicSecCred
 
     result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, provisioningCB);
     EXPECT_EQ(OC_STACK_INVALID_PARAM, result);
+    RemoveAllCredentials();
+}
+
+
+static void provisioningCB1 (void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+    OIC_LOG_V(DEBUG, TAG, "%s has error: %d", __func__, hasError);
+    RemoveAllCredentials();
 }
 
-TEST_F(SRPTest, SRPProvisionTrustCertChainNoResource)
+TEST_F(SRP, SRPProvisionTrustCertChainNoResource)
 {
     int result;
     int ctx;
@@ -437,70 +504,815 @@ TEST_F(SRPTest, SRPProvisionTrustCertChainNoResource)
     uint16_t credId = 0;
     OCProvisionDev_t deviceInfo;
 
-    result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, provisioningCB);
+    memset(&deviceInfo, 0, sizeof(OCProvisionDev_t));
+
+    result = SRPProvisionTrustCertChain(&ctx, type, credId, &deviceInfo, provisioningCB1);
     EXPECT_EQ(OC_STACK_ERROR, result);
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPGetACLResourceNoCallback)
+TEST_F(SRP, SRPGetACLResourceNoCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPGetACLResource(NULL, &pDev1, OIC_SEC_ACL_V2, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPGetACLResource(NULL, pDev1, OIC_SEC_ACL_V2, NULL));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPGetACLResourceNoDevice)
+TEST_F(SRP, SRPGetACLResourceNoDevice)
 {
     EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPGetACLResource(NULL, NULL, OIC_SEC_ACL_V2, provisioningCB));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPGetCredResourceNoCallback)
+TEST_F(SRP, SRPGetCredResourceNoCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPGetCredResource(NULL, &pDev1, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPGetCredResource(NULL, pDev1, NULL));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPGetCredResourceNoDevice)
+TEST_F(SRP, SRPGetCredResourceNoDevice)
 {
     EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPGetCredResource(NULL, NULL, provisioningCB));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPResetDeviceNoCallback)
+TEST_F(SRP, SRPResetDeviceNoCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPResetDevice(&pDev1, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPResetDevice(pDev1, NULL));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPResetDeviceNoDevice)
+TEST_F(SRP, SRPResetDeviceNoDevice)
 {
     EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPResetDevice(NULL, provisioningCB));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPSyncDeviceNoCallback)
+TEST_F(SRP, SRPSyncDeviceNoCallback)
 {
-    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPSyncDevice(NULL, timeout, &pDev1, NULL));
+    EXPECT_EQ(OC_STACK_INVALID_CALLBACK, SRPSyncDevice(NULL, timeout, pDev1, NULL));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPSyncDeviceNoDevice)
+TEST_F(SRP, SRPSyncDeviceNoDevice)
 {
     EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPSyncDevice(NULL, timeout, NULL, provisioningCB));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPSyncDeviceZeroWaitTime)
+TEST_F(SRP, SRPSyncDeviceZeroWaitTime)
 {
-    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPSyncDevice(NULL, 0, &pDev1, provisioningCB));
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPSyncDevice(NULL, 0, pDev1, provisioningCB));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPRemoveDeviceWithoutDiscoveryNoCallback)
+TEST_F(SRP, SRPProvisionTrustCertChainFull)
+{
+    OCProvisionDev_t *pDev = createProvisionDev();
+    /*
+        OicUuid_t *uuid = createUuid();
+        EXPECT_EQ(OC_STACK_OK, PDMAddDevice(&pDev->doxm->deviceID));
+        EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(&pDev->doxm->deviceID, PDM_DEVICE_ACTIVE));
+        EXPECT_EQ(OC_STACK_OK, PDMAddDevice(uuid));
+        EXPECT_EQ(OC_STACK_OK, PDMSetDeviceState(uuid, PDM_DEVICE_ACTIVE));
+        EXPECT_EQ(OC_STACK_OK, PDMLinkDevices(&pDev->doxm->deviceID, uuid));
+    */
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SRPSyncDevice(NULL, 0, pDev, provisioningCB));
+}
+
+TEST_F(SRP, SRPRemoveDeviceWithoutDiscoveryNoCallback)
 {
     EXPECT_EQ(OC_STACK_INVALID_CALLBACK,
-              SRPRemoveDeviceWithoutDiscovery(NULL, &pDev1, &pDev2, NULL));
+              SRPRemoveDeviceWithoutDiscovery(NULL, pDev1, pDev2, NULL));
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPRemoveDeviceWithoutDiscoveryNoDevice)
+TEST_F(SRP, SRPRemoveDeviceWithoutDiscoveryNoDevice)
 {
     EXPECT_EQ(OC_STACK_INVALID_PARAM,
-              SRPRemoveDeviceWithoutDiscovery(NULL, &pDev1, NULL, provisioningCB));
+              SRPRemoveDeviceWithoutDiscovery(NULL, pDev1, NULL, provisioningCB));
+}
+
+TEST_F(SRP, SRPRemoveDeviceWithoutDiscoveryNoDeviceList)
+{
+    EXPECT_EQ(OC_STACK_CONTINUE,
+              SRPRemoveDeviceWithoutDiscovery(NULL, NULL, pDev2, provisioningCB));
+}
+
+TEST_F(SRP, SRPRemoveDeviceWithoutDiscoveryFull)
+{
+    PDMSetDeviceState(&pDev1->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMSetDeviceState(&pDev2->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMLinkDevices(&pDev1->doxm->deviceID, &pDev2->doxm->deviceID);
+    OCProvisionDev_t *pOwnedDevList = NULL;
+    LL_PREPEND(pOwnedDevList, pDev1);
+    LL_PREPEND(pOwnedDevList, pDev2);
+    EXPECT_EQ(OC_STACK_OK, SRPRemoveDeviceWithoutDiscovery(NULL, pDev1, pOwnedDevList, provisioningCB));
+}
+
+
+TEST_F(SRP, registerResultForCredProvisioningFull)
+{
+    OCStackResult stackresult = OC_STACK_OK;
+    CredProvisioningResultCause_t cause = DEVICE_LOCAL_FINISHED;
+    CredentialData_t *credData = (CredentialData_t *)OICCalloc(1, sizeof(CredentialData_t));
+    credData->resArr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+    registerResultForCredProvisioning(credData, stackresult, cause);
+    OICFree(credData->resArr);
+    OICFree(credData);
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, provisionCredentialCB2Full)
+{
+    CredentialData_t *credData = createCredentialData();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    PDMSetDeviceState(&credData->deviceInfo[0]->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMSetDeviceState(&credData->deviceInfo[1]->doxm->deviceID, PDM_DEVICE_ACTIVE);
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, provisionCredentialCB2((void *)credData, NULL,
+              clientResponse));
+    clientResponse->result = OC_STACK_OK;
+    CredentialData_t *credData1 = createCredentialData();
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, provisionCredentialCB2((void *)credData1, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, provisionCredentialCB1Full)
+{
+    CredentialData_t *credData = createCredentialData();
+    OCDoHandle UNUSED = NULL;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, provisionCredentialCB1((void *)credData, UNUSED,
+              NULL));
+
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+    CredentialData_t *credData1 = createCredentialData();
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, provisionCredentialCB1((void *)credData1, UNUSED,
+              clientResponse));
+
+    clientResponse->result = OC_STACK_OK;
+    CredentialData_t *credData2 = createCredentialData();
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, provisionCredentialCB1((void *)credData2, UNUSED,
+              clientResponse));
+
+//    OICFree(clientResponse);
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, ProvisionCredentialDosCB2T1)
+{
+    CredentialData_t *credData = createCredentialData();
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222211", &credData->deviceInfo[0]->doxm->deviceID);
+    ConvertStrToUuid("33333333-3333-3333-1111-222222222211", &credData->deviceInfo[1]->doxm->deviceID);
+    PDMAddDevice(&credData->deviceInfo[0]->doxm->deviceID);
+    PDMAddDevice(&credData->deviceInfo[1]->doxm->deviceID);
+    PDMSetDeviceState(&credData->deviceInfo[0]->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMSetDeviceState(&credData->deviceInfo[1]->doxm->deviceID, PDM_DEVICE_ACTIVE);
+
+
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = credData;
+    ctx->type = PSK_TYPE;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionCredentialDosCB2((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, ProvisionCredentialDosCB2T2)
+{
+    CredentialData_t *credData = createCredentialData();
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222211", &credData->deviceInfo[0]->doxm->deviceID);
+    ConvertStrToUuid("33333333-3333-3333-1111-222222222211", &credData->deviceInfo[1]->doxm->deviceID);
+    PDMAddDevice(&credData->deviceInfo[0]->doxm->deviceID);
+    PDMAddDevice(&credData->deviceInfo[1]->doxm->deviceID);
+    PDMSetDeviceState(&credData->deviceInfo[0]->doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMSetDeviceState(&credData->deviceInfo[1]->doxm->deviceID, PDM_DEVICE_ACTIVE);
+
+
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = credData;
+    ctx->type = PSK_TYPE;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionCredentialDosCB2((void *)ctx, NULL, NULL));
+
+    OICFree(clientResponse);
+    RemoveAllCredentials();
+}
+
+
+TEST_F(SRP, ProvisionCredentialDosCB1Full)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = createCredentialData();
+    ctx->type = PSK_TYPE;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionCredentialDosCB1((void *)ctx, NULL,
+              clientResponse));
+//    OICFree(clientResponse);
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, ProvisionCredentialDosCB1ClientNull)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = createCredentialData();
+    ctx->type = PSK_TYPE;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionCredentialDosCB1((void *)ctx, NULL, NULL));
+//    OICFree(clientResponse);
+    RemoveAllCredentials();
+}
+
+
+static OCStackApplicationResult clientResponseHandler(void *context, OCDoHandle handle,
+        OCClientResponse *clientResponse)
+{
+    OC_UNUSED(context);
+    OC_UNUSED(handle);
+    OC_UNUSED(clientResponse);
+    return OC_STACK_DELETE_TRANSACTION;
+}
+
+TEST_F(SRP, provisionCredentialsFull)
+{
+    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t ));
+    CredentialData_t *credData4 = createCredentialData();
+
+    EXPECT_EQ(OC_STACK_OK, provisionCredentials(cred, pDev1, credData4, clientResponseHandler));
+
+    freeCredentialData(credData4);
+
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, provisionCredentialsdeviceInfo)
+{
+    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t ));
+    CredentialData_t *credData4 = createCredentialData();
+
+    EXPECT_EQ(OC_STACK_OK, provisionCredentials(cred, NULL, credData4, clientResponseHandler));
+
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, ProvisionCredentialsDosFull)
+{
+    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t ));
+
+    EXPECT_EQ(OC_STACK_OK, ProvisionCredentialsDos(NULL, cred, pDev1, clientResponseHandler));
+
+    RemoveAllCredentials();
 }
 
-TEST(SRPProvisionTrustCertChainTest, SRPRemoveDeviceWithoutDiscoveryNoDeviceList)
+TEST_F(SRP, ProvisionCredentialsDosdeviceInfo)
 {
+    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t ));
+
+    EXPECT_EQ(OC_STACK_ERROR, ProvisionCredentialsDos(NULL, cred, NULL, clientResponseHandler));
+
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, ProvisionLocalCredentialFull)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = createCredentialData();
+    ctx->type = PSK_TYPE;
+    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t ));
+
+    EXPECT_EQ(OC_STACK_OK, ProvisionLocalCredential((void *)ctx, cred));
+
+    FreeData(ctx);
+    RemoveAllCredentials();
+}
+
+TEST_F(SRP, SetReadyForNormalOperationCBChainType)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = CHAIN_TYPE;
+    TrustChainData_t *chainData = (TrustChainData_t *)OICCalloc(1, sizeof(TrustChainData_t));
+    ctx->ctx = (TrustChainData_t *)chainData;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SetReadyForNormalOperationCB((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+    OICFree(chainData);
+    OICFree(ctx);
+}
+
+TEST_F(SRP, SetReadyForNormalOperationCBSpType)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = SP_TYPE;
+    SpData_t *pData = (SpData_t *)OICCalloc(1, sizeof(SpData_t));
+    ctx->ctx = (SpData_t *)pData;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SetReadyForNormalOperationCB((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+    OICFree(pData);
+    OICFree(ctx);
+}
+
+TEST_F(SRP, SetReadyForNormalOperationCBAclType)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = ACL_TYPE;
+    ACLData_t *pData = (ACLData_t *)OICCalloc(1, sizeof(ACLData_t));
+    ctx->ctx = (ACLData_t *)pData;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SetReadyForNormalOperationCB((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+    OICFree(pData);
+    OICFree(ctx);
+}
+
+TEST_F(SRP, SetReadyForNormalOperationCBCredType)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = PSK_TYPE;
+    CredentialData_t *pData = createCredentialData();
+    ctx->ctx = (CredentialData_t *)pData;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SetReadyForNormalOperationCB((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, SetReadyForNormalOperationCBCertType)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = CERT_TYPE;
+    CertData_t *pData = (CertData_t *)OICCalloc(1, sizeof(CertData_t));
+    ctx->ctx = (CertData_t *)pData;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SetReadyForNormalOperationCB((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, SetReadyForNormalOperationCBDefault)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = (DataType_t)55;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SetReadyForNormalOperationCB((void *)ctx, NULL,
+              clientResponse));
+
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, ProvisionCBFull)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = CHAIN_TYPE;
+    TrustChainData_t *chainData = (TrustChainData_t *)OICCalloc(1, sizeof(TrustChainData_t));
+    chainData->targetDev = pDev1;
+    ctx->ctx = (TrustChainData_t *)chainData;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionCB((void *)ctx, NULL, clientResponse));
+
+    OICFree(clientResponse);
+    OICFree(chainData);
+    OICFree(ctx);
+}
+
+TEST_F(SRP, ProvisionPskCBFull)
+{
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = createCredentialData();
+    ctx->type = PSK_TYPE;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionPskCB((void *)ctx, NULL, clientResponse));
+
+    Data_t *ctx1 = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx1->ctx = createCredentialData();
+    ctx1->type = PSK_TYPE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionPskCB((void *)ctx1, NULL, NULL));
+
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, provisionCertificateCBFull)
+{
+    CredentialData_t *credData = createCredentialData();
+    OCDoHandle UNUSED = NULL;
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, provisionCertificateCB((void *)credData, UNUSED,
+              clientResponse));
+
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, ProvisionTrustChainCBFull)
+{
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionTrustChainCB(NULL, NULL, clientResponse));
+
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->type = ACL_TYPE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionTrustChainCB((void *)ctx, NULL, clientResponse));
+
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionTrustChainCB((void *)ctx, NULL, clientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    ctx->type = CHAIN_TYPE;
+    TrustChainData_t *chainData = (TrustChainData_t *)OICCalloc(1, sizeof(TrustChainData_t));
+    chainData->targetDev = pDev1;
+    ctx->ctx = (TrustChainData_t *)chainData;
+    /*
+        if (NULL != gCred)
+        {
+            OicSecCred_t *cred = NULL;
+            OicSecCred_t *r = NULL;
+            LL_FOREACH_SAFE(gCred, cred, r)
+            {
+                LL_DELETE(gCred, cred);
+            }
+        }
+    */
+    //RemoveAllCredentials();
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionTrustChainCB((void *)ctx, NULL, clientResponse));
+
+    OicSecCred_t *credA = createCred();
+    EXPECT_EQ(OC_STACK_OK, AddCredential(credA));
+    chainData->credId = credA->credId;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionTrustChainCB((void *)ctx, NULL, clientResponse));
+
+    OICFree(clientResponse);
+    OICFree(chainData);
+    OICFree(ctx);
+}
+
+TEST_F(SRP, DeleteUnlinkData_tFull)
+{
+    UnlinkData_t *u = (UnlinkData_t *)OICCalloc(1, sizeof(UnlinkData_t));
+    u->unlinkDev = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    u->unlinkRes = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+    DeleteUnlinkData_t(u);
+}
+
+TEST_F(SRP, SRPGetCredResourceCBFull)
+{
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    GetSecData_t *getSecData = (GetSecData_t *)OICCalloc(1, sizeof(GetSecData_t));
+    getSecData->deviceInfo = createProvisionDev();
+    getSecData->resArr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPGetCredResourceCB(getSecData, NULL, clientResponse));
+}
+
+TEST_F(SRP, registerResultForGetCSRResourceCBFull)
+{
+    GetCsrData_t *getCsrData = (GetCsrData_t *)OICCalloc(1, sizeof(GetCsrData_t));
+    getCsrData->deviceInfo = createProvisionDev();
+    getCsrData->numOfResults = 0;
+    getCsrData->resArr = (OCPMGetCsrResult_t *)OICCalloc(1, sizeof(OCPMGetCsrResult_t));
+    getCsrData->resArr->csr = certData();
+    getCsrData->resArr->csrLen = certDataLen();
+    getCsrData->resArr->encoding = OIC_ENCODING_DER;
+
+    uint8_t *payload = NULL;
+    size_t payloadSize = 0;
+    OCStackResult stackresult = OC_STACK_OK;
+
+    EXPECT_EQ(OC_STACK_OK, CSRToCBORPayload(getCsrData->resArr->csr,
+                                            getCsrData->resArr->csrLen, getCsrData->resArr->encoding, &payload, &payloadSize));
+    registerResultForGetCSRResourceCB(getCsrData, stackresult, payload, payloadSize);
+}
+
+TEST_F(SRP, registerResultForGetCSRResourceCBNull)
+{
+    GetCsrData_t *getCsrData = (GetCsrData_t *)OICCalloc(1, sizeof(GetCsrData_t));
+    getCsrData->deviceInfo = createProvisionDev();
+    getCsrData->numOfResults = 0;
+    getCsrData->resArr = (OCPMGetCsrResult_t *)OICCalloc(1, sizeof(OCPMGetCsrResult_t));
+    getCsrData->resArr->csr = certData();
+    getCsrData->resArr->csrLen = certDataLen();
+    getCsrData->resArr->encoding = OIC_ENCODING_DER;
+
+    uint8_t *payload = NULL;
+    OCStackResult stackresult = OC_STACK_OK;
+
+    registerResultForGetCSRResourceCB(getCsrData, stackresult, payload, 0);
+}
+
+
+TEST_F(SRP, RegisterProvResultFull)
+{
+    OCProvisionDev_t *targetDev = createProvisionDev();
+    int numOfResults = 0;
+    OCProvisionResult_t *resArr = (OCProvisionResult_t *)OICCalloc(1 + numOfResults,
+                                  sizeof(OCProvisionResult_t));
+    EXPECT_EQ(OC_STACK_OK, RegisterProvResult(targetDev, resArr, &numOfResults, OC_STACK_OK));
+    OICFree(resArr);
+}
+
+static UnlinkData_t *createUlinkData()
+{
+    UnlinkData_t *u = (UnlinkData_t *)OICCalloc(1, sizeof(UnlinkData_t));
+    if (NULL == u)
+    {
+        return NULL;
+    }
+    u->unlinkDev = (OCProvisionDev_t *)OICCalloc(2, sizeof(OCProvisionDev_t));
+    u->unlinkRes = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+    u->numOfResults = 0;
+    u->resultCallback = provisionResultCB;
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", &u->unlinkRes[(u->numOfResults)].deviceId);
+    u->unlinkDev[0].doxm = createDoxm();
+    u->unlinkDev[1].doxm = createDoxm();
+
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222211", &u->unlinkDev[0].doxm->deviceID);
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222233", &u->unlinkDev[1].doxm->deviceID);
+    PDMAddDevice(&u->unlinkDev[0].doxm->deviceID);
+    PDMSetDeviceState(&u->unlinkDev[0].doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMAddDevice(&u->unlinkDev[1].doxm->deviceID);
+    PDMSetDeviceState(&u->unlinkDev[1].doxm->deviceID, PDM_DEVICE_ACTIVE);
+    PDMLinkDevices(&u->unlinkDev[0].doxm->deviceID, &u->unlinkDev[1].doxm->deviceID);
+    return u;
+}
+/*
+static void freeUlinkData(UnlinkData_t *u)
+{
+    PDMUnlinkDevices(&u->unlinkDev[0].doxm->deviceID, &u->unlinkDev[1].doxm->deviceID);
+    PDMDeleteDevice(&u->unlinkDev[0].doxm->deviceID);
+    PDMDeleteDevice(&u->unlinkDev[1].doxm->deviceID);
+    OICFree(u->unlinkDev);
+    OICFree(u->unlinkRes);
+    OICFree(u);
+}
+*/
+TEST_F(SRP, registerResultForUnlinkDevices)
+{
+    UnlinkData_t *u = createUlinkData();
+    registerResultForUnlinkDevices(u, OC_STACK_OK, IDX_DB_UPDATE_RES);
+    PDMUnlinkDevices(&u->unlinkDev[0].doxm->deviceID, &u->unlinkDev[1].doxm->deviceID);
+    PDMDeleteDevice(&u->unlinkDev[0].doxm->deviceID);
+    OICFree(u->unlinkDev);
+    OICFree(u->unlinkRes);
+    OICFree(u);
+}
+
+TEST_F(SRP, SendDeleteACLRequest)
+{
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SendDeleteACLRequest(NULL, clientResponseHandler, pDev1, pDev2));
+    EXPECT_EQ(OC_STACK_OK, SendDeleteACLRequest((void *)clientResponseHandler, clientResponseHandler,
+              pDev1, pDev2));
+}
+
+TEST_F(SRP, SRPUnlinkDevice2CBNull)
+{
+    UnlinkData_t *u = createUlinkData();
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPUnlinkDevice2CB(u, NULL, NULL));
+}
+
+TEST_F(SRP, SRPUnlinkDevice2CBFull)
+{
+    UnlinkData_t *u = createUlinkData();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_CONTINUE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPUnlinkDevice2CB(u, NULL, clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, SRPUnlinkDevice1CBNull)
+{
+    UnlinkData_t *u = createUlinkData();
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPUnlinkDevice1CB(u, NULL, NULL));
+}
+
+TEST_F(SRP, SRPUnlinkDevice1CBResult)
+{
+    UnlinkData_t *u = createUlinkData();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_CONTINUE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPUnlinkDevice1CB(u, NULL, clientResponse));
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, SRPUnlinkDevice1CB)
+{
+    UnlinkData_t *u = createUlinkData();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_DELETED;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPUnlinkDevice1CB(u, NULL, clientResponse));
+    OICFree(clientResponse);
+}
+
+static RemoveData_t *createRemoveData()
+{
+    RemoveData_t *pRemoveData = (RemoveData_t *)OICMalloc(sizeof(RemoveData_t));
+    pRemoveData->revokeTargetDev = createProvisionDev();
+    pRemoveData->linkedDevList = createProvisionDev();
+    pRemoveData->removeRes = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+    pRemoveData->numOfResults = 0;
+    return pRemoveData;
+}
+
+static void freeRemoveData(RemoveData_t *pRemoveData)
+{
+    freeProvisionDev(pRemoveData->revokeTargetDev);
+    freeProvisionDev(pRemoveData->linkedDevList);
+    OICFree(pRemoveData->removeRes);
+    pRemoveData->numOfResults = 0;
+    OICFree(pRemoveData);
+}
+
+TEST_F(SRP, DeleteRemoveData_t)
+{
+    RemoveData_t *pRemoveData = createRemoveData();
+    DeleteRemoveData_t(pRemoveData);
+}
+
+TEST_F(SRP, registerResultForRemoveDevice)
+{
+    RemoveData_t *removeData = createRemoveData();
+    OicUuid_t *pLinkedDevId = createUuid();
+
+    registerResultForRemoveDevice(removeData, pLinkedDevId, OC_STACK_OK, false);
+    freeUuid(pLinkedDevId);
+    freeRemoveData(removeData);
+}
+
+TEST_F(SRP, registerResultForResetDevice)
+{
+    RemoveData_t *removeData = createRemoveData();
+    OicUuid_t *pLinkedDevId = createUuid();
+
+    registerResultForResetDevice(removeData, pLinkedDevId, OC_STACK_OK, false);
+    freeUuid(pLinkedDevId);
+    freeRemoveData(removeData);
+}
+
+static void linkDevs(OicUuid_t *uuid1, OicUuid_t *uuid2)
+{
+    PDMAddDevice(uuid1);
+    PDMSetDeviceState(uuid1, PDM_DEVICE_ACTIVE);
+    PDMAddDevice(uuid2);
+    PDMSetDeviceState(uuid2, PDM_DEVICE_ACTIVE);
+    PDMLinkDevices(uuid1, uuid2);
+}
+
+TEST_F(SRP, SRPRemoveDeviceCB)
+{
+    RemoveData_t *pRemoveData = createRemoveData();
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_DELETED;
+    clientResponse->identity.id_length = UUID_LENGTH;
+
+    OicUuid_t *uuid = createUuid();
+    ConvertStrToUuid("33333333-3333-3333-3333-112222222222", uuid);
+    memcpy(clientResponse->identity.id, uuid->id, sizeof(OicUuid_t));
+    ConvertStrToUuid("33333333-3333-3333-3333-662222222222",
+                     &pRemoveData->revokeTargetDev->doxm->deviceID);
+    linkDevs(uuid, &pRemoveData->revokeTargetDev->doxm->deviceID);
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPRemoveDeviceCB(pRemoveData, NULL, clientResponse));
+    freeUuid(uuid);
+    OICFree(clientResponse );
+    freeRemoveData(pRemoveData);
+}
+
+TEST_F(SRP, SRPSyncDeviceCredCB)
+{
+    RemoveData_t *pRemoveData = createRemoveData();
+    pRemoveData->resultCallback = provisionResultCB;
+
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_DELETED;
+    clientResponse->identity.id_length = UUID_LENGTH;
+
+    OicUuid_t *uuid = createUuid();
+    ConvertStrToUuid("33333333-3333-3333-3333-112222222222", uuid);
+    memcpy(clientResponse->identity.id, uuid->id, sizeof(OicUuid_t));
+    ConvertStrToUuid("33333333-3333-3333-3333-662222222222",
+                     &pRemoveData->revokeTargetDev->doxm->deviceID);
+    linkDevs(uuid, &pRemoveData->revokeTargetDev->doxm->deviceID);
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, SRPSyncDeviceCredCB(pRemoveData, NULL, clientResponse));
+    freeUuid(uuid);
+    OICFree(clientResponse );
+    freeRemoveData(pRemoveData);
+}
+
+TEST_F(SRP, GetListofDevToReqDeleteCred)
+{
+    OCProvisionDev_t *pRevokeTargetDev = createProvisionDev();
+    OCProvisionDev_t *pOwnedDevList = createProvisionDev();
+    OCUuidList_t *pLinkedUuidList = (OCUuidList_t *)OICMalloc(sizeof(OCUuidList_t));
+    pLinkedUuidList->next = NULL;
+    ConvertStrToUuid("33333333-3333-3333-3333-111111111111", &pLinkedUuidList->dev);
+    OCProvisionDev_t *ppLinkedDevList = NULL;
+    size_t numOfLinkedDev;
+
+    PDMAddDevice(&pLinkedUuidList->dev);
+    PDMAddDevice(&pRevokeTargetDev->doxm->deviceID);
+
+    EXPECT_EQ(OC_STACK_OK, GetListofDevToReqDeleteCred(pRevokeTargetDev, pOwnedDevList, pLinkedUuidList,
+              &ppLinkedDevList, &numOfLinkedDev));
+    OICFree(pLinkedUuidList);
+    freeProvisionDev(pRevokeTargetDev);
+    freeProvisionDev(pOwnedDevList);
+}
+
+TEST_F(SRP, SRPRemoveDevice)
+{
+    OCProvisionDev_t *pTargetDev = createProvisionDev();
+    OicUuid_t *uuid = createUuid();
+    ConvertStrToUuid("33333333-3333-3333-3333-112222222222", uuid);
+    linkDevs(uuid, &pTargetDev->doxm->deviceID);
+
+    EXPECT_EQ(OC_STACK_CONTINUE, SRPRemoveDevice((void *)provisionResultCB, 3, pTargetDev,
+              provisionResultCB));
+    freeUuid(uuid);
+    freeProvisionDev(pTargetDev);
+}
+
+
+TEST_F(SRP, SRPRemoveDeviceWithoutDiscovery)
+{
+    OCProvisionDev_t *pTargetDev = createProvisionDev();
+
+    OicUuid_t *uuid = createUuid();
+    ConvertStrToUuid(UUID_SRV1, uuid);
+    linkDevs(uuid, &pTargetDev->doxm->deviceID);
+
     EXPECT_EQ(OC_STACK_CONTINUE,
-              SRPRemoveDeviceWithoutDiscovery(NULL, NULL, &pDev2, provisioningCB));
+              SRPRemoveDeviceWithoutDiscovery((void *)provisionResultCB, pTargetDev, pDev2, provisioningCB));
+    freeUuid(uuid);
+    freeProvisionDev(pTargetDev);
 }
 
+
+TEST_F(SRP, ProvisionSecurityProfileInfoCB)
+{
+    SpData_t *pData = (SpData_t *)OICCalloc(1, sizeof(SpData_t));
+    pData->sp = getSpDefault();
+    pData->targetDev = createProvisionDev();
+    pData->resArr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+
+    Data_t *ctx = (Data_t *)OICCalloc(1, sizeof(Data_t));
+    ctx->ctx = (SpData_t *)pData;
+    ctx->type = SP_TYPE;
+
+    OCClientResponse *clientResponse = (OCClientResponse *)OICCalloc(1, sizeof(OCClientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionSecurityProfileInfoCB(NULL, NULL, clientResponse));
+    clientResponse->result = OC_STACK_OK;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionSecurityProfileInfoCB(ctx, NULL, clientResponse));
+    clientResponse->result = OC_STACK_RESOURCE_CHANGED;
+    ctx->type = ACL_TYPE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionSecurityProfileInfoCB(ctx, NULL, clientResponse));
+    ctx->type = SP_TYPE;
+    EXPECT_EQ(OC_STACK_DELETE_TRANSACTION, ProvisionSecurityProfileInfoCB(ctx, NULL, clientResponse));
+
+    FreeData(ctx);
+    OICFree(clientResponse);
+}
+
+TEST_F(SRP, SetDOS)
+{
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SetDOS(NULL, DOS_RFNOP, NULL));
+
+    Data_t *data = (Data_t *)OICCalloc(1, sizeof(Data_t));
+
+    data->ctx = NULL;
+    data->type = (DataType_t)25;
+    EXPECT_EQ(OC_STACK_INVALID_PARAM, SetDOS(data, DOS_RFNOP, clientResponseHandler));
+
+    SpData_t *pData = (SpData_t *)OICCalloc(1, sizeof(SpData_t));
+    pData->sp = getSpDefault();
+    pData->targetDev = createProvisionDev();
+    pData->resArr = (OCProvisionResult_t *)OICCalloc(1, sizeof(OCProvisionResult_t));
+    data->ctx = pData;
+    data->type = SP_TYPE;
+    EXPECT_EQ(OC_STACK_OK, SetDOS(data, DOS_RFNOP, clientResponseHandler));
+
+    OICFree(data);
+}
diff --git a/resource/csdk/security/provisioning/unittest/tools.cpp b/resource/csdk/security/provisioning/unittest/tools.cpp
new file mode 100644 (file)
index 0000000..bfbc4d2
--- /dev/null
@@ -0,0 +1,459 @@
+/* *****************************************************************
+ *
+ * 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 "octhread.h"
+#include "srmutility.h"
+#include "tools.h"
+#include "oic_malloc.h"
+#include "srmresourcestrings.h"
+#include "logger.h"
+#include "oic_string.h"
+#include "ocprovisioningmanager.h"
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef TAG
+#define TAG "LIB_UNITTEST"
+#endif
+
+OicSecDoxm_t *createDoxm()
+{
+    OicSecDoxm_t *doxm = (OicSecDoxm_t *)OICMalloc(sizeof(OicSecDoxm_t));
+    if (NULL == doxm)
+    {
+        return NULL;
+    }
+    doxm->oxmLen     = 1;
+    doxm->oxm        = (OicSecOxm_t *)OICCalloc(doxm->oxmLen, sizeof(OicSecOxm_t));
+    doxm->oxm[0]     = OIC_JUST_WORKS;
+    doxm->oxmSel     = OIC_JUST_WORKS;
+    doxm->sct        = SYMMETRIC_PAIR_WISE_KEY;
+    doxm->owned      = true;
+    ConvertStrToUuid("33333333-3333-3333-3333-111111111111", &doxm->deviceID);
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", &doxm->owner);
+    return doxm;
+}
+
+void freeDoxm(OicSecDoxm_t *doxm)
+{
+    if (NULL == doxm)
+    {
+        return;
+    }
+    OICFree(doxm->oxm);
+    OICFree(doxm);
+}
+
+OCDevAddr *setAddr(const char *ip, uint16_t port, OCTransportAdapter adapter)
+{
+    OCDevAddr *a = (OCDevAddr *)OICCalloc(1, sizeof(OCDevAddr));
+    strcpy(a->addr, ip);
+    a->port = port;
+    a->adapter = adapter;
+    return a;
+}
+
+OCProvisionDev_t *createProvisionDev()
+{
+    OCProvisionDev_t *pd  = (OCProvisionDev_t *)OICCalloc(1, sizeof(OCProvisionDev_t));
+    strcpy(pd->endpoint.addr, "127.0.0.1");
+    pd->endpoint.port = 9999;
+    pd->endpoint.adapter = OC_ADAPTER_IP;
+    pd->pstat = (OicSecPstat_t *)OICCalloc(1, sizeof(OicSecPstat_t));
+    pd->doxm = createDoxm();
+    pd->connType = (OCConnectivityType)(CT_ADAPTER_IP | CT_FLAG_SECURE | CT_IP_USE_V4);
+    pd->securePort = 1023;
+#ifdef WITH_TCP
+    pd->tcpPort = 0;
+    pd->tcpSecurePort = 0;
+#endif
+    OICStrcpy(pd->specVer, SPEC_MAX_VER_LEN, "res.2.0.0");
+    pd->devStatus = DEV_STATUS_ON;
+    pd->handle = NULL;
+    pd->ownerAclUnauthorizedRequest = false;
+    pd->next = NULL;
+    return pd;
+}
+
+void freeProvisionDev(OCProvisionDev_t *pd)
+{
+    if (NULL == pd)
+    {
+        return;
+    }
+    OICFree(pd->pstat);
+    freeDoxm(pd->doxm);
+    OICFree(pd);
+}
+
+static void provisionResultCB(void *ctx, size_t nOfRes, OCProvisionResult_t *arr, bool hasError)
+{
+    OC_UNUSED(ctx);
+    OC_UNUSED(nOfRes);
+    OC_UNUSED(arr);
+    OC_UNUSED(hasError);
+    OIC_LOG_V(DEBUG, TAG, "%s: %d", __func__, hasError);
+}
+
+OTMContext_t *createOTMContext()
+{
+    OTMContext_t *otmCtx = (OTMContext_t *)OICCalloc(1, sizeof(OTMContext_t));
+    otmCtx->selectedDeviceInfo = createProvisionDev();
+    otmCtx->ctxResultCallback = provisionResultCB;
+    return otmCtx;
+}
+
+void freeOTMContext(OTMContext_t *otmCtx)
+{
+    if (NULL == otmCtx)
+    {
+        return;
+    }
+    freeProvisionDev(otmCtx->selectedDeviceInfo);
+    OICFree(otmCtx);
+}
+
+CAEndpoint_t *createEndpoint()
+{
+    CAEndpoint_t *e = (CAEndpoint_t *)OICCalloc(1, sizeof(CAEndpoint_t));
+    e->adapter = CA_ADAPTER_IP;
+    e->flags = (CATransportFlags_t)(CA_SECURE | CA_IPV4);
+    e->port = 1024;
+    strcpy(e->addr, "127.0.0.1");
+    e->ifindex = 0;
+//    e->remoteId[CA_MAX_IDENTITY_SIZE];
+#if defined (ROUTING_GATEWAY) || defined (ROUTING_EP)
+//    char                    routeData[MAX_ADDR_STR_SIZE_CA];
+#endif
+    return e;
+}
+
+void freeEndpoint(CAEndpoint_t *endpoint)
+{
+    OICFree(endpoint);
+}
+
+OicUuid_t *createUuid()
+{
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", uuid);
+    return uuid;
+}
+
+OicUuid_t *createUuidWith(const char *uuidStr)
+{
+    OicUuid_t *uuid = (OicUuid_t *)OICCalloc(1, sizeof(OicUuid_t));
+    ConvertStrToUuid(uuidStr, uuid);
+    return uuid;
+}
+
+
+void freeUuid(OicUuid_t *uuid)
+{
+    OICFree(uuid);
+}
+
+const char *getPemKey()
+{
+    static const char key [] ="-----BEGIN PRIVATE KEY-----\
+MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCmg+2hGPWQUDey\
+NfXNJQnXVVM+tPl+Neu85BjYH1A6q1oJV0+qGhNiT6u3MX8iIn8EvezkGkqgoz2G\
+sUAaeHcsjJYMQFmYsCNtadiE3rDy/g2qfCy8bMUKiIuagf1FnXv4+b+Z5pIDxnBd\
+xDiNvQjeeA6bn1si1oQenM8vf/TnyCh9sXlh/+E1TANaVpr7r/pXOmDLgvBkSs5j\
+65x1ZAlUpRBgEiFaB2yPWfxM76KuyPEXy9ZJ0/o67TAVPMiV5zID8nh2UO+w37eF\
+jmqRR4UO1gRflJuiODJ6aupRhQiU8VUBXy6KKEA+1+p1ztpoDONyaMRen+nCxNKB\
+bARlNlGFAgMBAAECggEBAIfeUDBJ8F0Px1JniygX177XhXQ+MPGVx8O6DreSXWFx\
+3aaPkpZGbpiiT4fMIGNW6HOTEU9SUKBgclyMFrVCpGM6V1ipzTG0T0QAwMYx+wpa\
+2AXLCqm4ytJ8dgTdmi6KgNS33GoUZAImkhtAd7DXlPwJ1EmRLsjvZqCf7MJiUxAn\
+xkhd5DdD04fNGflt/QHEPqlMe8jGrTpKJn2ZX3lR3a7xTjTOCNyuEB2BSq27BKUg\
+ki/2NXBBPnOonvrNx1RvgmoXp5zSApL9WAuL4iI4xeReqMJUZDTqooGO9v+sCD7C\
+6I8wnBOQl5JyAwQFzdsE5QGofbZifF0iMVZkP0TVZeUCgYEAz+6y0+Ebf1KkrkvG\
+fQIC6EMyNHuGRTCT3x2XFjPJUP3fX/kqmRSOax4QqgGRDbGPMr0yCzinFWrxV9Tp\
+BOgaI96wMSKsfSDtlDmXLBDGSZaCID101n6tK+wpH/ZZqtQ0aaVlN+PrUwHyXNeC\
+0/LcXx/a8izV6OKpUP69rPFpZssCgYEAzQIx8IAVNrEFViBvHvyQ/bwGzu4x50D8\
+6BrFdf2UiigtegcIeuC/o2EWzh9Hr/lxTGn8NVLL0s2aqOme/vMBucWFwIO5Dgxp\
+LGv8//+qQ3lDbBoOivjMVOr14qm0Y2Suu61uZgUYRkziKCRihqq3o0nsx6TXRmS1\
+L14R4p5Izu8CgYATrjkY2taab30MzjlEPbt+tlV7KDHmPJnSZV+Wh2JHmy/YSqIg\
+iRSNyPO0058iF6tBFy00aLFP0qZzNMC1aS6INJyimfCPi11RST4oupG6B1fbq1Vy\
+s9y6Kokd8Fg+VgV79l6lMppkaevBo9hLLVJ0YnR7tYitmT6DXwke5F6gjwKBgQCO\
+Wh7ZM+cHEgZ1lpHyf0gimCRWHfnS7UJv3N8OHiW9hUaGvEl8IYGQbgNK31eE7v1o\
+JRP25uYXG6Nv9MDtoUmqeGh2lEC0a5PAP7/u9tWAgrx5XOKKR1aDBJ/2YwaaGbhn\
+I3dMKe+AKTTE0PcFMZfQL63VtzWwcI+LM5PRuz0tSwKBgBXtbXKFqYmIsPrCi1t8\
+spliEwNPJqCyUdE0ZM/pLXl4AVtL3yTdGkTysqlxxLTQZtgZBq316uFIQhM2aSI+\
+FT658IakILe/pcAMZEtz7j2+C9B7hOxPiQYi5WgVx2EB8ishJWO59Rjy3npyHLou\
+arVShNdQS03YzFPzRpRcb03C\
+-----END PRIVATE KEY-----";
+    return key;
+}
+
+const char *getPemCert()
+{
+    static const char cert[] =  "-----BEGIN CERTIFICATE-----\
+MIID9TCCAt2gAwIBAgIJAK9okU/M3zDXMA0GCSqGSIb3DQEBCwUAMIGQMQswCQYD\
+VQQGEwJVQTENMAsGA1UECAwES3lpdjENMAsGA1UEBwwES3lpdjEUMBIGA1UECgwL\
+c2Ftc3VuZy5jb20xDzANBgNVBAsMBkFkU0VDTDEUMBIGA1UEAwwLc2Ftc3VuZy5j\
+b20xJjAkBgkqhkiG9w0BCQEWF28uZG15dHJlbmtvQHNhbXN1bmcuY29tMB4XDTE5\
+MDExODA3NTQxNFoXDTIwMDExODA3NTQxNFowgZAxCzAJBgNVBAYTAlVBMQ0wCwYD\
+VQQIDARLeWl2MQ0wCwYDVQQHDARLeWl2MRQwEgYDVQQKDAtzYW1zdW5nLmNvbTEP\
+MA0GA1UECwwGQWRTRUNMMRQwEgYDVQQDDAtzYW1zdW5nLmNvbTEmMCQGCSqGSIb3\
+DQEJARYXby5kbXl0cmVua29Ac2Ftc3VuZy5jb20wggEiMA0GCSqGSIb3DQEBAQUA\
+A4IBDwAwggEKAoIBAQCmg+2hGPWQUDeyNfXNJQnXVVM+tPl+Neu85BjYH1A6q1oJ\
+V0+qGhNiT6u3MX8iIn8EvezkGkqgoz2GsUAaeHcsjJYMQFmYsCNtadiE3rDy/g2q\
+fCy8bMUKiIuagf1FnXv4+b+Z5pIDxnBdxDiNvQjeeA6bn1si1oQenM8vf/TnyCh9\
+sXlh/+E1TANaVpr7r/pXOmDLgvBkSs5j65x1ZAlUpRBgEiFaB2yPWfxM76KuyPEX\
+y9ZJ0/o67TAVPMiV5zID8nh2UO+w37eFjmqRR4UO1gRflJuiODJ6aupRhQiU8VUB\
+Xy6KKEA+1+p1ztpoDONyaMRen+nCxNKBbARlNlGFAgMBAAGjUDBOMB0GA1UdDgQW\
+BBQkTeNZnWU5Dj608WEwAePuiEPBbjAfBgNVHSMEGDAWgBQkTeNZnWU5Dj608WEw\
+AePuiEPBbjAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAQfBlbA+gi\
+Yu/awzVDY8fJKZy9eC+cckrVdt3lrfzJuj7ckIvMm5JZryTLjlIAnkMSgjvTmmPe\
+cH5RDYvgOUY+SxPWXE+fuYRrLONPtEBbRPgjMHlgln9U/teU/BBYkjUm0VGnBXdr\
+N3SKb16ixlrtQwNk7MoSkKTk4oQU4QeNKW2SZF7vOHeu2zK6W31sqXgzc3cvBySN\
+6NLZvTYy3ohuFdK2krj1YExxFCBLvSc5fmOiv/7cZl5wsOnHqiYSkoQwm6rnVCGV\
+X/MH0JzgkxxnY5qbBLTFqxdr+6yarTbDvWBpv2OrbarmuqyKBjs/7NHCa5zpnAWw\
+sR1iytctB/HY\
+-----END CERTIFICATE-----";
+    return cert;
+}
+
+
+static uint8_t _certData[] =
+{
+    0x30, 0x82, 0x02, 0x39, 0x30, 0x82, 0x01, 0xdf, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a,
+    0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x7c, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
+    0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c,
+    0x09, 0x53, 0x6f, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03,
+    0x55, 0x04, 0x07, 0x0c, 0x08, 0x53, 0x6f, 0x6d, 0x65, 0x63, 0x69, 0x74, 0x79, 0x31, 0x0b, 0x30,
+    0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x42, 0x42, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03,
+    0x55, 0x04, 0x0b, 0x0c, 0x0d, 0x53, 0x65, 0x71, 0x75, 0x72, 0x69, 0x74, 0x79, 0x20, 0x50, 0x61,
+    0x72, 0x74, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x02, 0x6f, 0x62, 0x31,
+    0x14, 0x30, 0x12, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x05,
+    0x6f, 0x62, 0x40, 0x62, 0x62, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x38, 0x31, 0x35, 0x31,
+    0x33, 0x31, 0x31, 0x31, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x39, 0x30, 0x35, 0x31, 0x32, 0x31, 0x33,
+    0x31, 0x31, 0x31, 0x37, 0x5a, 0x30, 0x81, 0xd4, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04,
+    0x06, 0x13, 0x02, 0x55, 0x41, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x03,
+    0x41, 0x73, 0x64, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x06, 0x47, 0x6f,
+    0x74, 0x68, 0x61, 0x6d, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x02, 0x5a,
+    0x5a, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, 0x08, 0x42, 0x65, 0x61, 0x6d,
+    0x54, 0x65, 0x61, 0x6d, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
+    0x01, 0x09, 0x01, 0x16, 0x0d, 0x72, 0x61, 0x69, 0x6c, 0x40, 0x6d, 0x61, 0x69, 0x6c, 0x2e, 0x63,
+    0x6f, 0x6d, 0x31, 0x32, 0x30, 0x30, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x29, 0x75, 0x75, 0x69,
+    0x64, 0x3a, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d,
+    0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x2d, 0x33, 0x32, 0x33, 0x32, 0x33, 0x32,
+    0x33, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, 0x34, 0x30, 0x32, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x0c,
+    0x2b, 0x75, 0x73, 0x65, 0x72, 0x69, 0x64, 0x3a, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37,
+    0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d, 0x36, 0x37, 0x36, 0x37, 0x2d,
+    0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x36, 0x37, 0x30, 0x59, 0x30, 0x13,
+    0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
+    0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xf7, 0x13, 0x5c, 0x73, 0x72, 0xce, 0x10, 0xe5, 0x09,
+    0x97, 0x9a, 0xf8, 0xf2, 0x70, 0xa6, 0x3d, 0x89, 0xf5, 0xc5, 0xe4, 0x44, 0xe2, 0x4a, 0xb6, 0x61,
+    0xa8, 0x12, 0x8d, 0xb4, 0xdc, 0x2b, 0x47, 0x84, 0x60, 0x0c, 0x25, 0x66, 0xe9, 0xe0, 0xe5, 0xac,
+    0x22, 0xbf, 0x15, 0xdc, 0x71, 0xb1, 0x88, 0x4f, 0x16, 0xbf, 0xc2, 0x77, 0x37, 0x76, 0x3f, 0xe0,
+    0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
+    0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
+    0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
+    0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21, 0x00, 0xe5, 0x8f, 0x7f,
+    0xf1, 0xa6, 0x82, 0x03, 0x6a, 0x18, 0x7a, 0x54, 0xe7, 0x0e, 0x25, 0x77, 0xd8, 0x46, 0xfa, 0x96,
+    0x8a, 0x7e, 0x14, 0xc4, 0xcb, 0x21, 0x32, 0x3e, 0x89, 0xd9, 0xba, 0x8c, 0x3f
+};
+
+uint8_t *certData()
+{
+    uint8_t *buf = (uint8_t *)OICCalloc(1, sizeof(_certData));
+    memcpy(buf, _certData, sizeof(_certData));
+    return buf;
+}
+
+static uint8_t _keyData[] =
+{
+    0x67, 0xc6, 0x1d, 0x23, 0xfe, 0x7c, 0x8b, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
+    0x04, 0x03, 0x02, 0x03, 0x48, 0x00, 0x30, 0x45, 0x02, 0x20, 0x47, 0xcc, 0x41, 0x8a, 0x27, 0xc7,
+    0xd0, 0xaa, 0xb4, 0xab, 0x85, 0xbf, 0x09, 0x4d, 0x06, 0xd7, 0x7e, 0x0d, 0x39, 0xf9, 0x36, 0xa1,
+    0x3d, 0x96, 0x23, 0xe2, 0x24, 0x64, 0x98, 0x63, 0x21, 0xba, 0x02, 0x21
+};
+
+uint8_t *keyData()
+{
+    uint8_t *buf = (uint8_t *)OICCalloc(1, sizeof(_keyData));
+    memcpy(buf, _keyData, sizeof(_keyData));
+    return buf;
+}
+
+size_t keyDataLen()
+{
+    return sizeof(_keyData);
+}
+
+size_t certDataLen()
+{
+    return sizeof(_certData);
+}
+
+OicSecCred_t *createCred()
+{
+    OicSecCred_t *cred = (OicSecCred_t *)OICCalloc(1, sizeof(OicSecCred_t ));
+    cred->credId = 33;
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", &cred->subject);
+    // If roleId.id is all zeroes, this property is not set.
+    memset(cred->roleId.id, 0, ROLEID_LENGTH);         // 2:R:M:N:oic.sec.roletype
+    memset(cred->roleId.authority, 0, ROLEAUTHORITY_LENGTH);         // 2:R:M:N:oic.sec.roletype
+    cred->credType = SYMMETRIC_PAIR_WISE_KEY;       // 3:R:S:Y:oic.sec.credtype
+#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
+    cred->publicData.len = sizeof(_certData);
+    cred->publicData.data = (uint8_t *)OICMalloc(cred->publicData.len);
+    cred->publicData.encoding = OIC_ENCODING_DER;
+    memcpy(cred->publicData.data, _certData, cred->publicData.len);
+    cred->credUsage = NULL;            // 4:R:S:N:String
+    cred->optionalData.data = NULL;   // CA's cerificate chain
+    cred->optionalData.len = 0;   // CA's cerificate chain
+    cred->optionalData.encoding = OIC_ENCODING_UNKNOW;
+#endif /* __WITH_DTLS__  or __WITH_TLS__*/
+    cred->privateData.len = sizeof(_keyData);
+    cred->privateData.data = (uint8_t *)OICMalloc(cred->privateData.len);
+    cred->privateData.encoding = OIC_ENCODING_DER;
+    memcpy(cred->privateData.data, _keyData, cred->privateData.len);
+    cred->period = NULL;
+#ifdef MULTIPLE_OWNER
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", cred->eownerID);
+#endif //MULTIPLE_OWNER
+    cred->next = NULL;
+
+    return cred;
+}
+
+#define DEFAULTPROFILE  "1.3.6.1.4.1.51414.0.0.1.0"
+
+OicSecSp_t *getSpDefault()
+{
+    OicSecSp_t *sp = (OicSecSp_t *)OICCalloc(1, sizeof(OicSecSp_t));
+    sp->supportedLen = 1;
+    sp->supportedProfiles = (char **)OICCalloc(1, sizeof(char *));
+    sp->supportedProfiles[0] = OICStrdup(DEFAULTPROFILE);
+    sp->currentProfile = OICStrdup(DEFAULTPROFILE);
+    return sp;
+};
+/*
+char * gSupportedProfilesAll[] = { "1.3.6.1.4.1.51414.0.0.2.0", "1.3.6.1.4.1.51414.0.0.3.0", "1.3.6.1.4.1.51414.0.0.4.0", "1.3.6.1.4.1.51414.0.0.1.0",  };
+OicSecSp_t gSpAll =
+{
+    4,                      // supportedLen
+    gSupportedProfilesAll,  // supportedProfiles[0]
+    "1.3.6.1.4.1.51414.0.0.2.0",     // activeProfile
+};
+char * gSupportedProfilesInvalid[] = { "1.3.6.1.4.1.51414.0.0.2.0", "1.3.6.1.4.1.51414.0.0.3.0", "1.3.6.1.4.1.51414.0.0.4.0", "1.3.6.1.4.1.51414.0.0.1.0",  };
+OicSecSp_t gSpInvalid =
+{
+    4,                         // supportedLen
+    gSupportedProfilesInvalid, // supportedProfiles
+    "oic.sec.sp.invalid",      // activeProfile
+};
+*/
+OicSecPstat_t *createPstat()
+{
+    OicSecPstat_t *pstat = (OicSecPstat_t *)OICCalloc(1, sizeof(OicSecPstat_t));
+    pstat->dos.state = DOS_RFNOP;
+    pstat->dos.pending = false;
+    pstat->isOp = false;
+    pstat->cm = NORMAL;
+    pstat->tm = NORMAL;
+    pstat->om = NORMAL;
+    pstat->smLen = 1;
+    pstat->sm = (OicSecDpom_t *)OICCalloc(pstat->smLen, sizeof(OicSecDpom_t ));
+    pstat->sm[0] = NORMAL;
+    pstat->commitHash = 0;
+    ConvertStrToUuid("33333333-3333-3333-3333-222222222222", &pstat->rownerID);
+    return pstat;
+}
+
+bool pInternalWorking;
+oc_thread pInternalThread;
+
+void *IOT_process(void *p)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN",__func__);
+    OC_UNUSED(p);
+    struct timespec timeout = {0, 100000000L};
+    while (pInternalWorking)
+    {
+        if (OCProcess() != OC_STACK_OK)
+        {
+            OIC_LOG(FATAL, TAG, "OCStack process error");
+            return NULL;
+        }
+        nanosleep(&timeout, NULL);
+    }
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT",__func__);
+    return NULL;
+}
+
+FILE *fopenDb(const char *path, const char *mode)
+{
+    OC_UNUSED(path);
+    return fopen("oic_svr_db_client.dat", mode);
+}
+
+void IOT_Init(const char *pDbName)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN",__func__);
+#ifdef HAVE_UNISTD_H
+    if (-1 != access(pDbName, F_OK))
+    {
+        unlink(pDbName);
+    }
+#endif // HAVE_UNISTD_H
+#   if (__STDC_VERSION__ >= 199901L)
+    static OCPersistentStorage gPst = {.open = fopenDb, .read = fread, .write = fwrite, .close = fclose, .unlink = unlink};
+#   else
+    static OCPersistentStorage gPst = {fopenDb, fread, fwrite, fclose, unlink};
+#   endif
+
+    EXPECT_EQ(OC_STACK_OK, OCRegisterPersistentStorageHandler(&gPst));
+    EXPECT_EQ(OC_STACK_OK, OCInit(NULL, 0, OC_CLIENT_SERVER));
+    EXPECT_EQ(OC_STACK_OK, OCInitPM(pDbName));
+
+    pInternalWorking = true;
+    oc_thread_new(&pInternalThread, IOT_process, NULL);
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT",__func__);
+}
+
+void IOT_DeInit(const char *pDbName)
+{
+    OIC_LOG_V(DEBUG, TAG, "%s: IN",__func__);
+    pInternalWorking = false;
+
+    EXPECT_EQ(OC_STACK_OK, OCClosePM());
+    EXPECT_EQ(OC_STACK_OK, OCStop());
+
+    unlink(pDbName);
+
+    oc_thread_wait(pInternalThread);
+    oc_thread_free(pInternalThread);
+    OIC_LOG_V(DEBUG, TAG, "%s: OUT",__func__);
+}
+
diff --git a/resource/csdk/security/provisioning/unittest/tools.h b/resource/csdk/security/provisioning/unittest/tools.h
new file mode 100644 (file)
index 0000000..bfa17b1
--- /dev/null
@@ -0,0 +1,85 @@
+/* *****************************************************************
+ *
+ * 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.
+ *
+ * *****************************************************************/
+#ifndef __UNITTEST_TOOLS__
+#define __UNITTEST_TOOLS__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#include "securevirtualresourcetypes.h"
+#include "octypes.h"
+#include "pmtypes.h"
+#include "ownershiptransfermanager.h"
+#include "cacommon.h"
+#ifdef __cplusplus
+}
+#endif
+
+#define UUID_SRV1 "11111111-1234-1234-1234-123456789011"
+#define UUID_SRV2 "11111111-1234-1234-1234-123456789012"
+
+FILE *fopen_config(const char *path, const char *mode);
+
+OicSecDoxm_t *createDoxm();
+
+void freeDoxm(OicSecDoxm_t *doxm);
+
+OCDevAddr *setAddr(const char *ip, uint16_t port, OCTransportAdapter adapter);
+
+OCProvisionDev_t *createProvisionDev();
+
+void freeProvisionDev(OCProvisionDev_t *pd);
+
+OTMContext_t *createOTMContext();
+
+void freeOTMContext(OTMContext_t *otmCtx);
+
+CAEndpoint_t *createEndpoint();
+
+void freeEndpoint(CAEndpoint_t *endpoint);
+
+OicUuid_t *createUuid();
+
+OicUuid_t *createUuidWith(const char *uuidStr);
+
+void freeUuid(OicUuid_t *uuid);
+
+uint8_t *certData();
+
+uint8_t *keyData();
+
+const char *getPemKey();
+
+const char *getPemCert();
+size_t keyDataLen();
+
+size_t certDataLen();
+
+OicSecCred_t *createCred();
+
+OicSecSp_t *getSpDefault();
+
+OicSecPstat_t *createPstat();
+
+void IOT_Init(const char *pDbName);
+
+void IOT_DeInit(const char *pDbName);
+
+#endif //__UNITTEST_TOOLS__