replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / unittest / securityresourcemanager.cpp
index 1a3f0d2..efc9ff7 100644 (file)
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "iotivity_config.h"
 #include "gtest/gtest.h"
+#ifdef HAVE_PWD_H
 #include <pwd.h>
+#endif
+#ifdef HAVE_GRP_H
 #include <grp.h>
+#endif
+#ifdef HAVE_LINUX_LIMITS_H
 #include <linux/limits.h>
+#endif
 #include "ocstack.h"
 #include "cainterface.h"
 #include "secureresourcemanager.h"
+#include "srmtestcommon.h"
 
 using namespace std;
 
 // Helper Methods
-void UTRequestHandler(const CAEndpoint_t *endPoint, const CARequestInfo_t *requestInfo)
+void UTRequestHandler(const CAEndpoint_t * /*endPoint*/,
+                      const CARequestInfo_t * /*requestInfo*/)
 {
     EXPECT_TRUE(true) << "UTRequestHandler\n";
 }
 
-void UTResponseHandler(const CAEndpoint_t *endPoint, const CAResponseInfo_t *responseInfo)
+void UTResponseHandler(const CAEndpoint_t * /*endPoint*/,
+                       const CAResponseInfo_t * /*responseInfo*/)
 {
      EXPECT_TRUE(true) << "UTResponseHandler\n";
 }
 
-void UTErrorHandler(const CAEndpoint_t *endPoint, const CAErrorInfo_t *errorInfo)
+void UTErrorHandler(const CAEndpoint_t * /*endPoint*/,
+                    const CAErrorInfo_t * /*errorInfo*/)
 {
      EXPECT_TRUE(true) << "UTErrorHandler\n";
 }
 
-FILE *utopen(const char *path, const char *mode)
-{
-    EXPECT_TRUE((path != NULL)) << "utopen\n";
-    FILE *stream = fopen(path, mode);
-    return stream;
-
-}
-
-size_t utread(void *ptr, size_t size, size_t nmemb, FILE *stream)
-{
-    return fread(ptr, size, nmemb, stream);
-}
-
-size_t utwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
-{
-    return fwrite(ptr, size, nmemb, stream);
-}
-
-int utclose(FILE *fp)
-{
-    EXPECT_TRUE((fp != NULL)) << "utclose\n";
-    return fclose(fp);
-}
-int utunlink(const char *path)
-{
-    EXPECT_TRUE((path != NULL)) << "utunlink\n";
-    return unlink(path);
-}
 static OCPersistentStorage gpsi;
 
 //RegisterHandler Tests
@@ -104,18 +87,17 @@ TEST(PersistentStorageHandlerTest, RegisterNullHandler)
 
 TEST(PersistentStorageHandlerTest, RegisterValidHandler)
 {
-    gpsi.open = utopen;
-    gpsi.read = utread;
-    gpsi.write = utwrite;
-    gpsi.close = utclose;
-    gpsi.unlink = utunlink;
-
-    EXPECT_EQ(OC_STACK_OK,
-            SRMRegisterPersistentStorageHandler(&gpsi));
+    SetPersistentHandler(&gpsi, true);
     OCPersistentStorage *ps = SRMGetPersistentStorageHandler();
     EXPECT_TRUE(&gpsi == ps);
 }
 
+#if !(defined(HAVE_LINUX_LIMITS_H) && defined(HAVE_PWD_H))
+TEST(PersistentStorageHandlerTest, DISABLED_PersistentStorageValidHandlers)
+{
+    /** @todo: Implement test on non-Linux platform */
+}
+#else
 TEST(PersistentStorageHandlerTest, PersistentStorageValidHandlers)
 {
     OCPersistentStorage *psi = SRMGetPersistentStorageHandler();
@@ -154,3 +136,5 @@ TEST(PersistentStorageHandlerTest, PersistentStorageValidHandlers)
     }
     psi->unlink(outFilePath);
 }
+#endif
+