[zeromq-dev] GoogleTest and GoogleMock for ØMQ

Steven McCoy steven.mccoy at miru.hk
Sat Oct 22 23:55:15 CEST 2011


Another large integration project.  Before I continue running through new
tests it is probably a good idea for the code layout and infrastructure to
be updated to all work cleanly.

   1. I'm following my own weak coding style for unit tests which
   is visibly different from the rest of ØMQ.
   2. The test files sit in the tree side-by-side with classes, this is by
   design so to ensure the tests are updated along with the targeted code.
   3. There are two libraries: Google Test and Google Mock, the mock library
   isn't required when there are no dependencies obviously.
   4. You don't actually need a main function, you can link in gtest-main or
   gmock-main and have Google look after it for you.  The attached versions
   are a standard boiler plate for bringing up a WinSock compatible environment
   and can be stripped a lot.
   5. I haven't started on mocks or fakes, they will require header files to
   be placed somewhere.
   6. Google prefers CMake these days but provide Autoconf and some other
   script as the Google Test and Google Mock libraries should be built in-tree,
   e.g. hanging off $ZEROMQ_ROOT/foreign.
   7. The Google Mock download includes Google Test, not obvious by the
   documentation.
   8. Google Test is available in some Linux repo's but Google Mock isn't.
    Generally C++ ABI breakage can cause wonderous failures according to Google
   and so they don't recommend using bundled libraries.
   9. Once built run test --help for oodles of options for randomly running
   tests, integrating with websites and automation systems, etc.
   10. Not yet tested on Windows because one mountain at a time.

Example build.sh:

#!/bin/sh

GMOCK_ROOT=../foreign/gmock/build-staging/gmock-1.6.0
GTEST_ROOT=$GMOCK_ROOT/gtest

g++ -o clock_test clock_test.cpp clock.cpp \
-I$GMOCK_ROOT/include $GMOCK_ROOT/src/.libs/gmock-all.o
$GTEST_ROOT/src/.libs/gtest-all.o -pthread

g++ -o array_test array_test.cpp \
 -I$GMOCK_ROOT/include $GMOCK_ROOT/src/.libs/gmock-all.o
$GTEST_ROOT/src/.libs/gtest-all.o -pthread

g++ -o atomic_counter_test atomic_counter_test.cpp \
 -I$GMOCK_ROOT/include $GTEST_ROOT/src/.libs/gtest-all.o -pthread

g++ -o atomic_ptr_test atomic_ptr_test.cpp \
 -I$GMOCK_ROOT/include $GTEST_ROOT/src/.libs/gtest-all.o -pthread

*last minute update:*  The tests for the atomic counter subtraction are
mistakenly inverted, you can consider it an example of what happens when a
test fails.

:-)

-- 
Steve-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111022/6cf9c591/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Start-implementing-unit-tests-via-GTest.patch
Type: application/octet-stream
Size: 11578 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20111022/6cf9c591/attachment.obj>


More information about the zeromq-dev mailing list