osaf/libs/core/cplusplus/base/tests/Makefile.am         |   3 +
 osaf/libs/core/cplusplus/base/tests/unix_socket_test.cc |  74 +++++++++++++++++
 2 files changed, 77 insertions(+), 0 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
@@ -31,12 +31,15 @@ libbase_test_CPPFLAGS = \
 
 libbase_test_LDFLAGS = \
        -pthread -lrt \
+       $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-unix_socket.o \
+       
$(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-unix_server_socket.o \
        $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-getenv.o \
        $(top_builddir)/osaf/libs/core/cplusplus/base/libbase_la-log_message.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 = \
+       unix_socket_test.cc \
        getenv_test.cc \
        log_message_test.cc \
        mock_logtrace.cc \
diff --git a/osaf/libs/core/cplusplus/base/tests/unix_socket_test.cc 
b/osaf/libs/core/cplusplus/base/tests/unix_socket_test.cc
new file mode 100644
--- /dev/null
+++ b/osaf/libs/core/cplusplus/base/tests/unix_socket_test.cc
@@ -0,0 +1,74 @@
+/*      -*- 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 <sys/stat.h>
+#include <unistd.h>
+#include <cstdlib>
+#include <string>
+#include "base/unix_server_socket.h"
+#include "gtest/gtest.h"
+
+class UnixSocketTest : public ::testing::Test {
+ public:
+
+ protected:
+
+  UnixSocketTest() {
+  }
+
+  virtual ~UnixSocketTest() {
+  }
+
+  std::string SocketName() {
+    return tmpdir_ + "/sock";
+  }
+
+  bool SocketExists() {
+    struct stat buf;
+    int result = stat(SocketName().c_str(), &buf);
+    return result == 0 && S_ISSOCK(buf.st_mode);
+  }
+
+  // cppcheck-suppress unusedFunction
+  virtual void SetUp() {
+    char dir_tmpl[] = "/tmp/unix_socket_testXXXXXX";
+    char* dir_name = mkdtemp(dir_tmpl);
+    ASSERT_NE(dir_name, nullptr);
+    tmpdir_ = std::string{dir_name};
+  }
+
+  // cppcheck-suppress unusedFunction
+  virtual void TearDown() {
+    if (!tmpdir_.empty()) {
+      unlink(SocketName().c_str());
+      rmdir(tmpdir_.c_str());
+    }
+  }
+
+  std::string tmpdir_;
+};
+
+TEST_F(UnixSocketTest, CheckThatServerUnlinksSocket) {
+  EXPECT_FALSE(SocketExists());
+  base::UnixServerSocket* sock = new base::UnixServerSocket(SocketName());
+  EXPECT_FALSE(SocketExists());
+  char buf[32];
+  sock->Recv(buf, sizeof(buf));
+  EXPECT_TRUE(SocketExists());
+  delete sock;
+  EXPECT_FALSE(SocketExists());
+}

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to