googletest

SEH exception with code 0xc0000005 thrown in the test body

[亡魂溺海] 提交于 2019-11-30 22:27:19
问题 I am writing a test using GoogleTest for the following class and I am getting the above error. class Base { // Other Functions; CSig objSig[50]; } The Class CSig is as follows: class CSig { //... constructor, destructor(empty) and some functions CMod *objMod; CDemod *objDemod; } CSig :: CSig { bIsInitialised = false; for (int i=0; i<MAX_NUM; i++) { PStrokePrev[i] = 0.0; } } However, when I discard CSig objSig[50] , the tests run fine. What can I do to solve this issue? Also, I need to have

GTest installed with Conan: undefined reference

≯℡__Kan透↙ 提交于 2019-11-30 22:13:52
I tried to use gtest installed through conan, but ended up with an undefined reference linker error. This question is a more or less a follow up to this stackoverflow question . But I think the provided example was to simple. I compile under up to date arch linux x64, using gcc 6.3. Could there be some missmatch of C++ versions? Or do you have any other idea of how to fix the Problem? I will provide my source code in the following: Directory tree: tree . ├── CMakeLists.txt ├── conanfile.txt └── main.cpp main.cpp: #include <iostream> #include <gtest/gtest.h> class TestFixture : public ::testing

GTest installed with Conan: undefined reference

偶尔善良 提交于 2019-11-30 18:16:33
问题 I tried to use gtest installed through conan, but ended up with an undefined reference linker error. This question is a more or less a follow up to this stackoverflow question. But I think the provided example was to simple. I compile under up to date arch linux x64, using gcc 6.3. Could there be some missmatch of C++ versions? Or do you have any other idea of how to fix the Problem? I will provide my source code in the following: Directory tree: tree . ├── CMakeLists.txt ├── conanfile.txt └─

Googletest Eclipse C++ : How to have both test and production executable?

无人久伴 提交于 2019-11-30 15:23:59
I have a basic question regarding Googletest in Eclipse. I am using the test-runner plug in to run the Googletests. But I need to specify a binary which runs my unit tests (of course that makes sense.) The problem is that in my project I now have two main functions, one to run the actual program and one int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } to run the google tests. Each time I want to run one I comment the other out, which of course is stupid. But what practice do you use to handle this situation? Googletest C++ is a unit-testing

Time out for test cases in googletest

断了今生、忘了曾经 提交于 2019-11-30 13:28:26
问题 Is there a way in gtest to have a timeout for inline/test cases or even tests. For example I would like to do something like: EXPECT_TIMEOUT(5 seconds, myFunction()); I found this issue googletest issues as 'Type:Enhancement' from Dec 09 2010. https://code.google.com/p/googletest/issues/detail?id=348 Looks like there is no gtest way from this post. I am probably not the first to trying to figure out a way for this. The only way I can think is to make a child thread run the function, and if it

Teach Google-Test how to print Eigen Matrix

与世无争的帅哥 提交于 2019-11-30 12:50:30
问题 Introduction I am writing tests on Eigen matrices using Google's testing framework Google-Mock, as already discussed in another question. With the following code I was able to add a custom Matcher to match Eigen matrices to a given precision. MATCHER_P2(EigenApproxEqual, expect, prec, std::string(negation ? "isn't" : "is") + " approx equal to" + ::testing::PrintToString(expect) + "\nwith precision " + ::testing::PrintToString(prec)) { return arg.isApprox(expect, prec); } What this does is to

Test a specific exception type is thrown AND the exception has the right properties

*爱你&永不变心* 提交于 2019-11-30 11:07:55
问题 I want to test that MyException is thrown in a certain case. EXPECT_THROW is good here. But I also want to check the exception has a specific state e.g e.msg() == "Cucumber overflow" . How is this best implemented in GTest? 回答1: I mostly second Lilshieste's answer but would add that you also should verify that the wrong exception type is not thrown: #include <stdexcept> #include "gtest/gtest.h" struct foo { int bar(int i) { if (i > 100) { throw std::out_of_range("Out of range"); } return i; }

Time out for test cases in googletest

余生长醉 提交于 2019-11-30 09:40:44
Is there a way in gtest to have a timeout for inline/test cases or even tests. For example I would like to do something like: EXPECT_TIMEOUT(5 seconds, myFunction()); I found this issue googletest issues as 'Type:Enhancement' from Dec 09 2010. https://code.google.com/p/googletest/issues/detail?id=348 Looks like there is no gtest way from this post. I am probably not the first to trying to figure out a way for this. The only way I can think is to make a child thread run the function, and if it does not return by the time limit the parent thread will kill it and show timeout error. Is there any

No tests found when using gtest with cmake/ctest

别来无恙 提交于 2019-11-30 08:25:07
问题 I have a project with the following structure: linalg ├── build ├── CMakeLists.txt ├── docs │ └── Doxyfile ├── include │ └── linalg │ └── vector3.hpp ├── src │ ├── CMakeLists.txt │ └── linalg │ └── vector3.cpp └── test ├── CMakeLists.txt └── linalg └── test_vector3.cpp The file test_vector3.cpp is a gtest unit test file which provides two simple tests. The top level CMakeLists.txt simply sets up the includes and adds the src and test subdirectories: cmake_minimum_required(VERSION 2.8) project

Generate Google C++ Unit Test XML Report

a 夏天 提交于 2019-11-30 08:12:46
I am new to using Google test framework for unit testing and am intending to generate an XML report of the tests or the command output as a report (I could just print it obviously). I have read up on Generate XML Report , but haven't been able to understand clearly on how to go about generating the report. Any help would be greatly appreciated. Cheers. v01d For Linux environments: It's simple you just have to set the GTEST_OUTPUT environment variable like this: export GTEST_OUTPUT="xml:/home/user/src". or use the -gtest_output flag set the same way. I have referred to v01d's solution and just