osaf/libs/core/cplusplus/base/tests/Makefile.am         |   7 +-
 osaf/libs/core/cplusplus/base/tests/file_notify_test.cc |  82 +++++++++++++++++
 2 files changed, 87 insertions(+), 2 deletions(-)


diff --git a/osaf/libs/core/cplusplus/base/tests/Makefile.am 
b/osaf/libs/core/cplusplus/base/tests/Makefile.am
--- a/osaf/libs/core/cplusplus/base/tests/Makefile.am
+++ b/osaf/libs/core/cplusplus/base/tests/Makefile.am
@@ -32,13 +32,15 @@ libbase_test_CPPFLAGS = \
 libbase_test_LDFLAGS = \
        -pthread -lrt \
        $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-getenv.o \
-       $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-process.o
+       $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-process.o \
+       $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-file_notify.o
 
 libbase_test_SOURCES = \
        time_add_test.cc \
        time_subtract_test.cc \
        time_compare_test.cc \
        time_convert_test.cc \
+       file_notify_test.cc \
        getenv_test.cc \
        mock_logtrace.cc \
        mock_osafassert.cc \
@@ -46,4 +48,5 @@ libbase_test_SOURCES = \
 
 libbase_test_LDADD = \
        $(GTEST_DIR)/lib/libgtest.la \
-       $(GTEST_DIR)/lib/libgtest_main.la
+       $(GTEST_DIR)/lib/libgtest_main.la \
+       $(top_builddir)/osaf/libs/core/libopensaf_core.la
diff --git a/osaf/libs/core/cplusplus/base/tests/file_notify_test.cc 
b/osaf/libs/core/cplusplus/base/tests/file_notify_test.cc
new file mode 100644
--- /dev/null
+++ b/osaf/libs/core/cplusplus/base/tests/file_notify_test.cc
@@ -0,0 +1,82 @@
+/*      -*- OpenSAF  -*-
+ *
+ * (C) Copyright 2016 The OpenSAF Foundation
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
+ * under the GNU Lesser General Public License Version 2.1, February 1999.
+ * The complete license can be accessed from the following location:
+ * http://opensource.org/licenses/lgpl-license.php
+ * See the Copying file included with the OpenSAF distribution for full
+ * licensing terms.
+ *
+ * Author(s): Ericsson AB
+ *
+ */
+
+#include "base/file_notify.h"
+#include "gtest/gtest.h"
+
+class FileNotifyTest : public ::testing::Test {
+ protected:
+  FileNotifyTest() {
+    // Setup work can be done here for each test.
+  }
+
+  virtual ~FileNotifyTest() {
+    // Cleanup work that doesn't throw exceptions here.
+  }
+
+  // If the constructor and destructor are not enough for setting up
+  // and cleaning up each test, you can define the following methods:
+
+  // cppcheck-suppress unusedFunction
+  virtual void SetUp() {
+    // Code here will be called immediately after the constructor (right
+    // before each test).
+  }
+
+  // cppcheck-suppress unusedFunction
+  virtual void TearDown() {
+    // Code here will be called immediately after each test (right
+    // before the destructor).
+  }
+
+  // Objects declared here can be used by all tests in the test case.
+};
+
+//
+TEST_F(FileNotifyTest, TestNonExistingPathCreation) {
+  base::FileNotify file_notify;
+  std::string non_existing_file = "/a/b/c";
+
+  int rc = file_notify.WaitForFileCreation(non_existing_file, 10);
+  ASSERT_EQ(rc, base::FileNotify::kError);
+}
+
+//
+TEST_F(FileNotifyTest, TestExistingFileCreation) {
+  base::FileNotify file_notify;
+  std::string existing_file = __FILE__;
+
+  int rc = file_notify.WaitForFileCreation(existing_file, 10);
+  ASSERT_EQ(rc, base::FileNotify::kOK);
+}
+
+//
+TEST_F(FileNotifyTest, TestNonExistingPathDeletion) {
+  base::FileNotify file_notify;
+  std::string non_existing_path = "/a/b/c";
+
+  int rc = file_notify.WaitForFileDeletion(non_existing_path, 10);
+  ASSERT_EQ(rc, base::FileNotify::kError);
+}
+
+TEST_F(FileNotifyTest, TestExistingFileDeletion) {
+  base::FileNotify file_notify;
+  std::string existing_file = __FILE__;
+
+  int rc = file_notify.WaitForFileDeletion(existing_file, 10);
+  ASSERT_EQ(rc, base::FileNotify::kTimeOut);
+}

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
Opensaf-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to