1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "gtest/gtest.h"
22 #include "oic_malloc.h"
26 #define STRINGIZE2(x) #x
27 #define STRINGIZE(x) STRINGIZE2(x)
29 // TODO: Remove this, once all cbor related are completed.
30 char* ReadFile(const char* filename)
36 // TODO: Find the location of the executable and concatenate the SVR file name
38 fp = fopen(filename, "r");
41 if (stat(filename, &st) == 0)
43 data = (char*)OICMalloc(st.st_size);
46 if (fread(data, 1, st.st_size, fp) != (size_t)st.st_size)
48 printf("Error in reading file %s", filename);
56 printf("Unable to open %s file", filename);
62 bool ReadCBORFile(const char* filename, uint8_t **data, size_t *size)
67 printf("Passed parameter are INVALID \n");
70 int len = strlen(STRINGIZE(SECURITY_BUILD_UNITTEST_DIR)) + strlen(filename) + 1;
71 char *filepath = (char *)OICCalloc(1, len);
74 printf("filepath memory allocation failed. \n");
77 int ret = snprintf(filepath, len, "%s%s", STRINGIZE(SECURITY_BUILD_UNITTEST_DIR), filename);
78 printf("Root build path: %s \n", filepath);
82 FILE *fp = fopen(filepath, "rb");
86 if (stat(filepath, &st) == 0)
88 *data = (uint8_t *)OICMalloc(st.st_size);
91 if (fread(*data, 1, st.st_size, fp) != (size_t)st.st_size)
93 printf("Error in reading file %s\n", filename);
106 printf("Unable to open %s file\n", filepath);
111 printf("Filepath copy failed.\n");
117 void SetPersistentHandler(OCPersistentStorage *ps, bool set)
129 memset(ps, 0, sizeof(OCPersistentStorage));
131 EXPECT_EQ(OC_STACK_OK,
132 OCRegisterPersistentStorageHandler(ps));