Hi Anders,

I'll remove the turtle example. Perhaps we also can add a git pull if the repo is older than some date?

/Thanks HansN


On 04/09/2018 10:09 AM, Anders Widell wrote:
Ack with comments:

1) You must replace the turtle example with something that you have written yourself, to avoid potential license problems.

2) One inline comment below, marked AndersW>

regards,

Anders Widell


On 04/03/2018 01:05 PM, Hans Nordeback wrote:
---
  00-README.unittest                      | 24 ++++++++++++++----------
  src/ais/Makefile.am                     |  5 ++++-
  src/amf/Makefile.am                     |  7 +++++--
  src/base/Makefile.am                    | 21 +++++++++++++++++----
  src/base/tests/mock_turtle.cc           | 20 ++++++++++++++++++++
  src/base/tests/mock_turtle.h            | 18 ++++++++++++++++++
  src/base/tests/turtle.h                 | 17 +++++++++++++++++
  src/dtm/Makefile.am                     |  5 ++++-
  src/experimental/immcpp/api/Makefile.am |  5 ++++-
  src/log/Makefile.am                     |  5 ++++-
  test.sh                                 | 12 +++++++++---
  11 files changed, 116 insertions(+), 23 deletions(-)
  create mode 100644 src/base/tests/mock_turtle.cc
  create mode 100644 src/base/tests/mock_turtle.h
  create mode 100644 src/base/tests/turtle.h

diff --git a/00-README.unittest b/00-README.unittest
index 79e4b4b41..f297bccd0 100644
--- a/00-README.unittest
+++ b/00-README.unittest
@@ -1,22 +1,25 @@
-Support for using google unit test in openSAF. Using unit test during e.g. refactoring +Support for using google unit test and google mock in openSAF. Using unit test and mocking during e.g. refactoring   to identify units and make code unit testable should improve the overall code quality and robustness.
  Regarding google unit test, see:
  https://code.google.com/p/googletest/
    To get and install google test do the following:
  -wget https://googletest.googlecode.com/files/gtest-1.7.0.zip
-unzip gtest-1.7.0.zip
-cd gtest-1.7.0
-./configure
-make
-export GTEST_DIR=`pwd`
+git clone https://github.com/google/googletest.git
+cd googletest
+
+autoreconf -vi
+./configure --with-pthreads
+make -j 4
+
+export GTEST_DIR=`pwd`/googletest
+export GMOCK_DIR=`pwd`/googlemock
    configure openSAF as usual, for example:
  ./bootstrap.ch
  ./configure CFLAGS="-DRUNASROOT -O2" CXXFLAGS="-DRUNASROOT -O2" --enable-tipc
  -make -j
+make -j 4
    To build and run the unit tests
  make check
@@ -40,8 +43,9 @@ services/saf/amf/
  └── config
    The test code to have the following naming convention as below:
-tests will be in file test_xxxx.cc, where xxxx is the name of the unit test case, -e.g test_amfdb.cc. No need to call the RUN_ALL_TESTS() macro, it is included in gtest_main +tests will be in file xxxx_test.cc, where xxxx is the name of the unit test case,
+mocks will be in file mock_xxxx.cc, where xxxx is the name of the mock.
+No need to call the RUN_ALL_TESTS() macro, it is included in gtest_main and gmock_main
  and are automatically linked with the unit test cases.
    diff --git a/src/ais/Makefile.am b/src/ais/Makefile.am
index 1af75a0f4..2ef34b219 100644
--- a/src/ais/Makefile.am
+++ b/src/ais/Makefile.am
@@ -101,7 +101,8 @@ bin_testlib_CXXFLAGS = \
    bin_testlib_CPPFLAGS = \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_testlib_LDFLAGS = \
      $(AM_LDFLAGS)
@@ -112,4 +113,6 @@ bin_testlib_SOURCES = \
  bin_testlib_LDADD = \
      $(GTEST_DIR)/lib/libgtest.la \
      $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la \
      lib/libopensaf_core.la
diff --git a/src/amf/Makefile.am b/src/amf/Makefile.am
index 25261fded..413571a52 100644
--- a/src/amf/Makefile.am
+++ b/src/amf/Makefile.am
@@ -194,7 +194,8 @@ bin_testamfd_CXXFLAGS =$(AM_CXXFLAGS)
  bin_testamfd_CPPFLAGS = \
      -DSA_CLM_B01=1 -DSA_EXTENDED_NAME_SOURCE \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_testamfd_LDFLAGS = \
      $(AM_LDFLAGS) \
@@ -264,7 +265,9 @@ bin_testamfd_LDADD = \
      lib/libSaNtf.la \
      lib/libopensaf_core.la \
      $(GTEST_DIR)/lib/libgtest.la \
-    $(GTEST_DIR)/lib/libgtest_main.la
+    $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la
    bin_amfpm_CPPFLAGS = \
      -DSA_EXTENDED_NAME_SOURCE \
diff --git a/src/base/Makefile.am b/src/base/Makefile.am
index bb13d6c43..a7316ceb7 100644
--- a/src/base/Makefile.am
+++ b/src/base/Makefile.am
@@ -150,6 +150,8 @@ noinst_HEADERS += \
      src/base/tests/mock_osaf_abort.h \
      src/base/tests/mock_osafassert.h \
      src/base/tests/mock_syslog.h \
+    src/base/tests/mock_turtle.h \
+    src/base/tests/turtle.h \
      src/base/time.h \
      src/base/unix_client_socket.h \
      src/base/unix_server_socket.h \
@@ -163,7 +165,8 @@ bin_testleap_CXXFLAGS =$(AM_CXXFLAGS)
  bin_testleap_CPPFLAGS = \
      -DSA_CLM_B01=1 \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_testleap_LDFLAGS = \
      $(AM_LDFLAGS)
@@ -175,6 +178,8 @@ bin_testleap_SOURCES = \
  bin_testleap_LDADD = \
      $(GTEST_DIR)/lib/libgtest.la \
      $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la \
      lib/libosaf_common.la \
      lib/libopensaf_core.la \
      lib/libamf_common.la \
@@ -188,7 +193,8 @@ bin_libbase_test_CXXFLAGS =$(AM_CXXFLAGS)
    bin_libbase_test_CPPFLAGS = \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_libbase_test_LDFLAGS = \
      $(AM_LDFLAGS) \
@@ -208,6 +214,7 @@ bin_libbase_test_SOURCES = \
      src/base/tests/mock_logtrace.cc \
      src/base/tests/mock_osaf_abort.cc \
      src/base/tests/mock_osafassert.cc \
+    src/base/tests/mock_turtle.cc \
      src/base/tests/string_parse_test.cc \
      src/base/tests/time_add_test.cc \
      src/base/tests/time_compare_test.cc \
@@ -218,13 +225,17 @@ bin_libbase_test_SOURCES = \
  bin_libbase_test_LDADD = \
      $(GTEST_DIR)/lib/libgtest.la \
      $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la \
      lib/libopensaf_core.la
    bin_core_common_test_CXXFLAGS =$(AM_CXXFLAGS)
    bin_core_common_test_CPPFLAGS = \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
+
    bin_core_common_test_LDFLAGS = \
      $(AM_LDFLAGS) \
@@ -247,4 +258,6 @@ bin_core_common_test_SOURCES = \
    bin_core_common_test_LDADD = \
      $(GTEST_DIR)/lib/libgtest.la \
-    $(GTEST_DIR)/lib/libgtest_main.la
+    $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la
diff --git a/src/base/tests/mock_turtle.cc b/src/base/tests/mock_turtle.cc
new file mode 100644
index 000000000..000e7f3f1
--- /dev/null
+++ b/src/base/tests/mock_turtle.cc
@@ -0,0 +1,20 @@
+#include "mock_turtle.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+/*
+  This is a dummy implementation to verify that google mock
+  compiles and runs in OpenSAF. Can be removed when real
+  mock classes are implemented
+ */
+
+using ::testing::AtLeast;
+using namespace testing;
+
+TEST(PainterTest, CanDrawSomething) {
+  MockTurtle turtle;
+  EXPECT_CALL(turtle, PenUp())
+      .Times(AtLeast(0));
+
+  //  Painter painter(&turtle);
+}
diff --git a/src/base/tests/mock_turtle.h b/src/base/tests/mock_turtle.h
new file mode 100644
index 000000000..a128d1399
--- /dev/null
+++ b/src/base/tests/mock_turtle.h
@@ -0,0 +1,18 @@
+#ifndef MOCK_TURTLE_
+#define MOCK_TURTLE_
+
+/*
+  This is a dummy implementation to verify that google mock
+  compiles and runs in OpenSAF
+ */
+
+#include "gmock/gmock.h"  // Brings in Google Mock.
+#include "turtle.h"
+
+class MockTurtle : public Turtle {
+ public:
+  MOCK_METHOD0(PenUp, void());
+  MOCK_METHOD0(PenDown, void());
+};
+
+#endif  //  MOCK_TURTLE_
diff --git a/src/base/tests/turtle.h b/src/base/tests/turtle.h
new file mode 100644
index 000000000..5e10c6af8
--- /dev/null
+++ b/src/base/tests/turtle.h
@@ -0,0 +1,17 @@
+#ifndef TURTLE_H_
+#define TURTLE_H_
+
+/*
+  This is a dummy interface to verify that google mock
+  compiles and runs in OpenSAF
+ */
+
+class Turtle {
+ public:
+  Turtle() {}
+  virtual ~Turtle() {}
+  virtual void PenUp() = 0;
+  virtual void PenDown() = 0;
+};
+
+#endif  // TURTLE_H_
diff --git a/src/dtm/Makefile.am b/src/dtm/Makefile.am
index 822249cbe..f925e512e 100644
--- a/src/dtm/Makefile.am
+++ b/src/dtm/Makefile.am
@@ -101,7 +101,8 @@ bin_transport_test_CXXFLAGS =$(AM_CXXFLAGS)
    bin_transport_test_CPPFLAGS = \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_transport_test_LDFLAGS = \
      $(AM_LDFLAGS) \
@@ -118,4 +119,6 @@ bin_transport_test_SOURCES = \
  bin_transport_test_LDADD = \
      $(GTEST_DIR)/lib/libgtest.la \
      $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la \
      lib/libopensaf_core.la
diff --git a/src/experimental/immcpp/api/Makefile.am b/src/experimental/immcpp/api/Makefile.am
index e1dba9d08..f0400b710 100644
--- a/src/experimental/immcpp/api/Makefile.am
+++ b/src/experimental/immcpp/api/Makefile.am
@@ -116,7 +116,8 @@ bin_testimmcpp_CXXFLAGS =$(AM_CXXFLAGS)
  bin_testimmcpp_CPPFLAGS = \
      -DSA_EXTENDED_NAME_SOURCE \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_testimmcpp_LDFLAGS = \
      $(AM_LDFLAGS)
@@ -139,6 +140,8 @@ bin_testimmcpp_SOURCES = \
  bin_testimmcpp_LDADD = \
      $(GTEST_DIR)/lib/libgtest.la \
      $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la \
      lib/libopensaf_core.la \
      lib/libopensaf_immoi.la \
      lib/libopensaf_immom.la
diff --git a/src/log/Makefile.am b/src/log/Makefile.am
index 3d951eb5d..a772c9287 100644
--- a/src/log/Makefile.am
+++ b/src/log/Makefile.am
@@ -244,7 +244,8 @@ bin_testlogd_CXXFLAGS =$(AM_CXXFLAGS)
  bin_testlogd_CPPFLAGS = \
      -DSA_EXTENDED_NAME_SOURCE \
      $(AM_CPPFLAGS) \
-    -I$(GTEST_DIR)/include
+    -I$(GTEST_DIR)/include \
+    -I$(GMOCK_DIR)/include
    bin_testlogd_LDFLAGS = \
      $(AM_LDFLAGS)
@@ -258,6 +259,8 @@ bin_testlogd_LDADD = \
      lib/libopensaf_core.la \
      $(GTEST_DIR)/lib/libgtest.la \
      $(GTEST_DIR)/lib/libgtest_main.la \
+    $(GMOCK_DIR)/lib/libgmock.la \
+    $(GMOCK_DIR)/lib/libgmock_main.la \
      src/log/logd/bin_osaflogd-lgs_unixsock_dest.o \
      src/log/logd/bin_osaflogd-lgs_dest.o \
      src/log/logd/bin_osaflogd-lgs_nildest.o
diff --git a/test.sh b/test.sh
index 6416fdd43..8fdb52fde 100755
--- a/test.sh
+++ b/test.sh
@@ -23,15 +23,21 @@ fi
  test -d "$OSAF_TEST_WORKDIR" || mkdir -p "$OSAF_TEST_WORKDIR"
  test -d "$OSAF_TEST_WORKDIR/good_revisions" || mkdir -p "$OSAF_TEST_WORKDIR/good_revisions"   -if ! test -f "$OSAF_TEST_WORKDIR/googletest/googletest/lib/libgtest.la"; then +if [[ ! -f "$OSAF_TEST_WORKDIR/googletest/googlemock/lib/libgmock.la" || +      ! -f "$OSAF_TEST_WORKDIR/googletest/googletest/lib/libgtest.la" ]]; then
      cd "$OSAF_TEST_WORKDIR"
-    "$GIT" clone https://github.com/google/googletest.git
-    cd "$OSAF_TEST_WORKDIR/googletest/googletest"
+
+    if [ ! -f "$OSAF_TEST_WORKDIR/googletest" ]; then

AndersW>  -f should be -d since googletest is a directory. However, I had a very old clone of googletest that didn't include googlemock, so I suggest checking for configure.ac which was missing in my old clone, like this:

    if [ ! -f "$OSAF_TEST_WORKDIR/googletest/configure.ac" ]; then
    rm -rf "$OSAF_TEST_WORKDIR/googletest"
        "$GIT" clone https://github.com/google/googletest.git
    fi


+      "$GIT" clone https://github.com/google/googletest.git
+    fi
+
+    cd "$OSAF_TEST_WORKDIR/googletest"
      autoreconf -vi
      ./configure --with-pthreads
      make -j "$no_of_processors"
  fi
  export GTEST_DIR="$OSAF_TEST_WORKDIR/googletest/googletest"
+export GMOCK_DIR="$OSAF_TEST_WORKDIR/googletest/googlemock"
    rm -rf "$OSAF_TEST_WORKDIR/repo" "$OSAF_TEST_WORKDIR/srcdir" "$OSAF_TEST_WORKDIR/objdir"   mkdir "$OSAF_TEST_WORKDIR/repo" "$OSAF_TEST_WORKDIR/srcdir" "$OSAF_TEST_WORKDIR/objdir"




------------------------------------------------------------------------------
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