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 "iotivity_config.h"
22 #include "gtest/gtest.h"
29 #ifdef HAVE_LINUX_LIMITS_H
30 #include <linux/limits.h>
33 #include "cainterface.h"
34 #include "secureresourcemanager.h"
35 #include "srmtestcommon.h"
40 void UTRequestHandler(const CAEndpoint_t * /*endPoint*/,
41 const CARequestInfo_t * /*requestInfo*/)
43 EXPECT_TRUE(true) << "UTRequestHandler\n";
46 void UTResponseHandler(const CAEndpoint_t * /*endPoint*/,
47 const CAResponseInfo_t * /*responseInfo*/)
49 EXPECT_TRUE(true) << "UTResponseHandler\n";
52 void UTErrorHandler(const CAEndpoint_t * /*endPoint*/,
53 const CAErrorInfo_t * /*errorInfo*/)
55 EXPECT_TRUE(true) << "UTErrorHandler\n";
58 static OCPersistentStorage gpsi;
60 //RegisterHandler Tests
61 TEST(RegisterHandlerTest, RegisterNullRequestHandler)
63 EXPECT_EQ(OC_STACK_INVALID_PARAM, SRMRegisterHandler(NULL, UTResponseHandler, NULL));
66 TEST(RegisterHandlerTest, RegisterNullResponseHandler)
68 EXPECT_EQ(OC_STACK_INVALID_PARAM, SRMRegisterHandler(UTRequestHandler, NULL, NULL));
71 TEST(RegisterHandlerTest, RegisterNullHandler)
73 EXPECT_EQ(OC_STACK_INVALID_PARAM, SRMRegisterHandler(NULL, NULL, NULL));
76 TEST(RegisterHandlerTest, RegisterValidHandler)
78 EXPECT_EQ(OC_STACK_OK, SRMRegisterHandler(UTRequestHandler, UTResponseHandler, UTErrorHandler));
81 // PersistentStorageHandler Tests
82 TEST(PersistentStorageHandlerTest, RegisterNullHandler)
84 EXPECT_EQ(OC_STACK_INVALID_PARAM,
85 SRMRegisterPersistentStorageHandler(NULL));
88 TEST(PersistentStorageHandlerTest, RegisterValidHandler)
90 SetPersistentHandler(&gpsi, true);
91 OCPersistentStorage *ps = SRMGetPersistentStorageHandler();
92 EXPECT_TRUE(&gpsi == ps);
95 #if !(defined(HAVE_LINUX_LIMITS_H) && defined(HAVE_PWD_H))
96 TEST(PersistentStorageHandlerTest, DISABLED_PersistentStorageValidHandlers)
98 /** @todo: Implement test on non-Linux platform */
101 TEST(PersistentStorageHandlerTest, PersistentStorageValidHandlers)
103 OCPersistentStorage *psi = SRMGetPersistentStorageHandler();
104 EXPECT_TRUE(psi != NULL);
106 unsigned char buf[PATH_MAX];
107 FILE* streamIn = NULL;
108 FILE* streamOut = NULL;
109 struct passwd *pw = getpwuid(getuid());
110 const char *homeDir = pw->pw_dir;
111 char inFilePath [PATH_MAX];
112 char outFilePath [PATH_MAX];
113 snprintf(inFilePath, PATH_MAX, "%s/iotivity/Readme.scons.txt", homeDir );
114 snprintf(outFilePath, PATH_MAX, "%s/Downloads/Readme.scons.out.txt", homeDir );
116 streamIn = psi->open(inFilePath, "r");
117 streamOut = psi->open(outFilePath, "w");
119 if (streamIn && streamOut)
124 value = psi->read(buf, 1, sizeof(buf), streamIn);
125 psi->write(buf, 1, value, streamOut);
131 psi->close(streamIn);
135 psi->close(streamOut);
137 psi->unlink(outFilePath);