the Compartmented Robust Posix C++ Unit Test system

Chapter 4. Google-mock

4.1. I like google-mock. Does crpcut work with it?
4.2. What versions of google-mock are supported.
4.3. How do I send command line parameters to google-mock?
4.4. Why do I get a lot of link errors with undefined references from libgmock.so?
4.5. Why do I get a lot of link errors with undefined references from libgmock.so?
4.6. Will a mocking framework, similar to google-mock be written in the vein of crpcut?

4.1.

I like google-mock. Does crpcut work with it?

Yes it does, and transparently too. There are only two differences compared to running under google-test.

  • Under crpcut a test is terminated immediately when a violation is detected.

  • You must #include <gmock/gmock.h> before #include <crpcut.hpp>

4.2.

What versions of google-mock are supported.

crpcut requires version 1.4.0. or later.

4.3.

How do I send command line parameters to google-mock?

Call ::testing::InitGoogleMock(&argc, argv) before the call to crpcut::run(argc, argv). For example like:


    #include <gmock/gmock.h>
    #include <crpcut.hpp>

    int main(int argc, char *argv[])
    {
      ::testing::InitGoogleMock(&argc, argv);
      return crpcut::run(argc, argv);
    }

4.4.

Why do I get a lot of link errors with undefined references from libgmock.so?

Does it look something like the below?


    /usr/lib/libgmock.so: undefined reference to `testing::AssertionSuccess()'
    /usr/lib/libgmock.so: undefined reference to `testing::InitGoogleTest(int*, char**)'
    /usr/lib/libgmock.so: undefined reference to `testing::internal::FormatForFailureMessage(char)'
    /usr/lib/libgmock.so: undefined reference to `testing::internal::String::Compare(testing::internal::String const&) const'

If so, you've forgotten to link with -lgtest. google-mock relies heavily on google-test, so even if you run the tests under crpcut you need to link with -lgtest to resolve all dependencies.

4.5.

Why do I get a lot of link errors with undefined references from libgmock.so?

Does it look something like the below?


/tmp/usr/lib/libgmock.so: undefined reference to `pthread_key_create'
/tmp/usr/lib/libgmock.so: undefined reference to `pthread_getspecific'
/tmp/usr/lib/libgmock.so: undefined reference to `pthread_key_delete'
/tmp/usr/lib/libgmock.so: undefined reference to `pthread_setspecific'
collect2: ld returned 1 exit status

It seems like google-mock version 1.5.0 requires pthreads. Add -lpthread to your link command and it will be all right.

4.6.

Will a mocking framework, similar to google-mock be written in the vein of crpcut?

Time permitting, maybe, but it is not planned, and it's a major undertaking, so don't hold your breath waiting for it.