1 /* *****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * *****************************************************************/
24 #include "gtest/gtest.h"
26 #define STR(...) STR_(__VA_ARGS__)
27 #define STR_(...) # __VA_ARGS__
29 #define DNEF "does_not_exist.dat"
30 #define DEFAULT_FILE "oic_svr_db_prov.dat"
33 #include "../src/psinterface.c"
36 #include "cainterface.h"
37 #include "secureresourcemanager.h"
40 static OCPersistentStorage _ps;
42 char localPath[PATH_MAX] = {0};
44 FILE *fopenCustom(const char *path, const char *mode)
47 FILE *fp = fopen(localPath, mode);
53 _ps.open = fopenCustom;
59 int len = strlen(STR(SECURITY_BUILD_UNITTEST_DIR)) + strlen(DEFAULT_FILE) + 1;
60 snprintf(localPath, len, "%s%s", STR(SECURITY_BUILD_UNITTEST_DIR), DEFAULT_FILE);
62 InitPersistentStorageInterface();
64 EXPECT_EQ(OC_STACK_OK, SRMRegisterPersistentStorageHandler(&_ps));
67 TEST(PersistentStorageInterfaceTest, Null)
69 EXPECT_NE(OC_STACK_OK,GetSecureVirtualDatabaseFromPS(OIC_JSON_CRED_NAME, NULL, NULL));
72 TEST(PersistentStorageInterfaceTest, NullPayload)
75 size_t payloadSize = 0;
77 EXPECT_NE(OC_STACK_OK,GetSecureVirtualDatabaseFromPS(OIC_JSON_CRED_NAME, NULL, &payloadSize));
80 TEST(PersistentStorageInterfaceTest, NullPayloadSize)
83 uint8_t* payload = NULL;
85 EXPECT_NE(OC_STACK_OK,GetSecureVirtualDatabaseFromPS(OIC_JSON_CRED_NAME, &payload, NULL));
88 TEST(PersistentStorageInterfaceTest, DoesNotExistsDbFile)
90 uint8_t* payload = NULL;
91 size_t payloadSize = 0;
93 int len = strlen(STR(SECURITY_BUILD_UNITTEST_DIR)) + strlen(DEFAULT_FILE) + 1;
94 snprintf(localPath, len, "%s%s", STR(SECURITY_BUILD_UNITTEST_DIR), DNEF);
97 InitPersistentStorageInterface();
99 EXPECT_NE(OC_STACK_OK,GetSecureVirtualDatabaseFromPS(OIC_JSON_CRED_NAME, &payload, &payloadSize));
102 TEST(PersistentStorageInterfaceTest, CredRead)
105 uint8_t* payload = NULL;
106 size_t payloadSize = 0;
108 int len = strlen(STR(SECURITY_BUILD_UNITTEST_DIR)) + strlen(DEFAULT_FILE) + 1;
109 snprintf(localPath, len, "%s%s", STR(SECURITY_BUILD_UNITTEST_DIR), DEFAULT_FILE);
110 InitPersistentStorageInterface();
112 EXPECT_EQ(OC_STACK_OK,GetSecureVirtualDatabaseFromPS(OIC_JSON_CRED_NAME, &payload, &payloadSize));
115 TEST(PersistentStorageInterfaceTest, FileSizeCashe)
118 uint8_t* payload = NULL;
119 size_t payloadSize = 0;
121 InitPersistentStorageInterface();
123 EXPECT_EQ(OC_STACK_OK,GetSecureVirtualDatabaseFromPS(OIC_JSON_CRED_NAME, &payload, &payloadSize));