googletest

How to compile Google Test using IAR compiler for ARM

烈酒焚心 提交于 2019-12-05 02:59:33
问题 I am trying to compile Google Test Framework using IAR compiler for ARM, but I face difficulties related to the lack of system libraries such as pthread. Has anybody been able to compile Google Framework using IAR compiler for ARM? 回答1: I have tried for the past few days to get GoogleTest to work so that I can perform unit testing on our ARM microcontroller in IAR using the simulator and I've given up. Like you stated, I was running into issues like threading and libraries that aren't

Specify constructor arguments for a Google test Fixture

烈酒焚心 提交于 2019-12-05 02:03:21
With Google test I want to specify a Test fixture for use in different test cases. The fixture shall allocate and deallocate objects of the class TheClass and its data management class TheClassData , where the data management class requires the name of a datafile. For the different tests, the file name should vary. I defined the following Fixture: class TheClassTest : public ::testing::Test { protected: TheClassTest(std::string filename) : datafile(filename) {} virtual ~TheClassTest() {} virtual void SetUp() { data = new TheClassData(datafile); tc = new TheClass(data); } virtual void TearDown(

Building tests with CMake while not using CTest

眉间皱痕 提交于 2019-12-05 01:11:17
Here is what I want to do: Typing make all will build my library and the docs for it. Typing make test will build my lib (if necessary), gtest and then my tests Typing make check runs make test if needed and then runs the executable Right now I've only managed to get the first to work. The problem I'm having is the conditional include of gtest. Gtest uses CMake which is nice, in theory all I need to do is to include the gtest directory with add_subdirectory but then gtest will always be built. My structure right now is: CMakeLists.txt (Here I add targets for doc and the library) doc (my

Compare Eigen matrices in Google Test or Google Mock

家住魔仙堡 提交于 2019-12-04 21:14:23
问题 I was wondering if there is a good way to test two Eigen matrices for approximate equality using Google Test, or Google Mock. Take the following test-case as a simplified example: I am multiplying two complex valued matrices A , and B , and expect a certain result C_expect . I calculate the numerical result C_actual = A * B , using Eigen. Now, I want to compare C_expect , and C_actual . Right now, the corresponding code looks like this: #include <complex> #include <Eigen/Dense> #include

gtest - testing template class

偶尔善良 提交于 2019-12-04 19:31:38
问题 I want to test a template class with gtest. I read about TYPED_TESTs in Google Test manual and looked at official example they reference, but still can't wrap my head around getting an object of template class instantiated in my test. Suppose the following simple template class: template <typename T> class Foo { public: T data ; }; In testing class we declare typedef ::testing::Types<int, float> MyTypes ; Now how can I instantiate an object of class Foo for Ts listed in MyTypes in a test? E.g

How to mock method with optional parameter in Google Mock?

半城伤御伤魂 提交于 2019-12-04 16:29:40
问题 How to mock a method with optional parameter in Google Mock ? For example: class A { public: void set_enable( bool enabled = true ); }; class MockA : public A { MOCK_METHOD1( set_enable, void( bool ) ); // this is not working }; 回答1: This is an alternative of Marko's answer: If you don't want to change your original code, just implement the helper in the mock class: class A { public: virtual void set_enable( bool enabled = true ); }; class MockA : public A { MOCK_METHOD1( set_enable_impl,

Can Googletest value-parameterized with multiple, different types of parameters match mbUnit flexibility?

☆樱花仙子☆ 提交于 2019-12-04 09:22:01
问题 I'd like to write C++ Google tests which can use value-parameterized tests with multiple parameters of different data types, ideally matching the complexity of the following mbUnit tests written in C++/CLI. Note how compact this is, with the [Test] attribute indicating this is a test method and the [Row(...)] attributes defining the values for an instantiation. [Test] [Row("Empty.mdb", "select count(*) from collar", 0)] [Row("SomeCollars.mdb", "select count(*) from collar", 17)] [Row(

Mocking an entire library

折月煮酒 提交于 2019-12-04 07:51:45
I'm developing code that uses boost::asio . To test it, I need to mock a set of classes from this library. I'm using Google Mock, which allows for mocking virtual methods. The usual (and tedious) process would be to write an interface for each of the classes I need to use. On the other hand, the Google Mock Cookbook describes an alternative when it comes to mocking non-virtual methods: using templates. The problem in my case is that I might need to mock several classes at the same time (so using templates directly wouldn't work). So I thought: why not use two-levels of templates? I came up

Passing a typename and string to parameterized test using google test

南笙酒味 提交于 2019-12-04 07:24:03
Is there a way of passing both a type and a string to a parametrized test using google's test. I would like to do: template <typename T> class RawTypesTest : public ::testing::TestWithParam<const char * type> { protected: virtual void SetUp() { message = type; } }; TEST_P(RawTypesTest, Foo) { ASSERT_STREQ(message, type); ParamType * data = ..; ... } Thanks in advance VladLosev Value parameterized tests won't work for passing type information; you can only do that with typed or type parameterized tests. In both cases you'll have to package your type and string information into special

How to test input and output overloaded operator in C++ Gtest

一笑奈何 提交于 2019-12-04 07:11:05
问题 I am using following example from here Consider I have following class #include <iostream> class Distance { private: int feet; int inches; public: Distance() : feet(), inches() {} Distance(int f, int i) : feet(f), inches(i) {} friend std::ostream &operator<<( std::ostream &output, const Distance &D ) { output << "F : " << D.feet << " I : " << D.inches; return output; } friend std::istream &operator>>( std::istream &input, Distance &D ) { input >> D.feet >> D.inches; return input; } }; I am