Enhance handling of assertion from googletest (#2331)

* Enhance handling of assertion from googletest

* Update googletest, and add it to cmake build

* Enhance ASSERT_STR* in googletest.cfg
This commit is contained in:
KenPatrickLehrmann 2019-11-06 21:38:01 +01:00 committed by amai2012
parent 828a3fda1f
commit 1114dc0536
3 changed files with 24 additions and 12 deletions

View File

@ -1,29 +1,29 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<def format="2"> <def format="2">
<!-- see https://github.com/google/googletest/blob/master/googletest/docs/primer.md --> <!-- see https://github.com/google/googletest/blob/master/googletest/docs/primer.md -->
<define name="ASSERT_TRUE(cond)" value="(void)(cond)"/> <define name="ASSERT_TRUE(cond)" value="assert(cond)"/>
<define name="EXPECT_TRUE(cond)" value="(void)(cond)"/> <define name="EXPECT_TRUE(cond)" value="(void)(cond)"/>
<define name="ASSERT_FALSE(cond)" value="(void)(cond)"/> <define name="ASSERT_FALSE(cond)" value="assert(!cond)"/>
<define name="EXPECT_FALSE(cond)" value="(void)(cond)"/> <define name="EXPECT_FALSE(cond)" value="(void)(cond)"/>
<define name="ASSERT_EQ(val1,val2)" value="(void)((val1)==(val2))"/> <define name="ASSERT_EQ(val1,val2)" value="assert((val1)==(val2))"/>
<define name="EXPECT_EQ(val1,val2)" value="(void)((val1)==(val2))"/> <define name="EXPECT_EQ(val1,val2)" value="(void)((val1)==(val2))"/>
<define name="ASSERT_NE(val1,val2)" value="(void)((val1)!=(val2))"/> <define name="ASSERT_NE(val1,val2)" value="assert((val1)!=(val2))"/>
<define name="EXPECT_NE(val1,val2)" value="(void)((val1)!=(val2))"/> <define name="EXPECT_NE(val1,val2)" value="(void)((val1)!=(val2))"/>
<define name="ASSERT_LT(val1,val2)" value="(void)((val1)&lt;(val2))"/> <define name="ASSERT_LT(val1,val2)" value="assert((val1)&lt;(val2))"/>
<define name="EXPECT_LT(val1,val2)" value="(void)((val1)&lt;(val2))"/> <define name="EXPECT_LT(val1,val2)" value="(void)((val1)&lt;(val2))"/>
<define name="ASSERT_LE(val1,val2)" value="(void)((val1)&lt;=(val2))"/> <define name="ASSERT_LE(val1,val2)" value="assert((val1)&lt;=(val2))"/>
<define name="EXPECT_LE(val1,val2)" value="(void)((val1)&lt;=(val2))"/> <define name="EXPECT_LE(val1,val2)" value="(void)((val1)&lt;=(val2))"/>
<define name="ASSERT_GT(val1,val2)" value="(void)((val1)&gt;(val2))"/> <define name="ASSERT_GT(val1,val2)" value="assert((val1)&gt;(val2))"/>
<define name="EXPECT_GT(val1,val2)" value="(void)((val1)&gt;(val2))"/> <define name="EXPECT_GT(val1,val2)" value="(void)((val1)&gt;(val2))"/>
<define name="ASSERT_GE(val1,val2)" value="(void)((val1)&gt;=(val2))"/> <define name="ASSERT_GE(val1,val2)" value="assert((val1)&gt;=(val2))"/>
<define name="EXPECT_GE(val1,val2)" value="(void)((val1)&gt;=(val2))"/> <define name="EXPECT_GE(val1,val2)" value="(void)((val1)&gt;=(val2))"/>
<define name="ASSERT_STREQ(str1,str2)" value="(void)(*(str1)==*(str2))"/> <define name="ASSERT_STREQ(str1,str2)" value="assert(strcmp(str1, str2) == 0)"/>
<define name="EXPECT_STREQ(str1,str2)" value="(void)(*(str1)==*(str2))"/> <define name="EXPECT_STREQ(str1,str2)" value="(void)(*(str1)==*(str2))"/>
<define name="ASSERT_STRNE(str1,str2)" value="(void)(*(str1)!=*(str2))"/> <define name="ASSERT_STRNE(str1,str2)" value="assert(strcmp(str1, str2) != 0)"/>
<define name="EXPECT_STRNE(str1,str2)" value="(void)(*(str1)!=*(str2))"/> <define name="EXPECT_STRNE(str1,str2)" value="(void)(*(str1)!=*(str2))"/>
<define name="ASSERT_STRCASEEQ(str1,str2)" value="(void)(*(str1)==*(str2))"/> <define name="ASSERT_STRCASEEQ(str1,str2)" value="assert(stricmp(str1, str2) == 0)"/>
<define name="EXPECT_STRCASEEQ(str1,str2)" value="(void)(*(str1)==*(str2))"/> <define name="EXPECT_STRCASEEQ(str1,str2)" value="(void)(*(str1)==*(str2))"/>
<define name="ASSERT_STRCASENE(str1,str2)" value="(void)(*(str1)!=*(str2))"/> <define name="ASSERT_STRCASENE(str1,str2)" value="assert(stricmp(str1, str2) != 0)"/>
<define name="EXPECT_STRCASENE(str1,str2)" value="(void)(*(str1)!=*(str2))"/> <define name="EXPECT_STRCASENE(str1,str2)" value="(void)(*(str1)!=*(str2))"/>
<define name="ASSERT_THROW(code, e)" value="try{code}catch(e){}"/> <define name="ASSERT_THROW(code, e)" value="try{code}catch(e){}"/>
<define name="EXPECT_THROW(code, e)" value="try{code}catch(e){}"/> <define name="EXPECT_THROW(code, e)" value="try{code}catch(e){}"/>

View File

@ -103,6 +103,7 @@ if (BUILD_TESTS)
add_cfg(boost.cpp INCONCLUSIVE) add_cfg(boost.cpp INCONCLUSIVE)
add_cfg(bsd.c) add_cfg(bsd.c)
add_cfg(gnu.c LIBRARY posix gnu) add_cfg(gnu.c LIBRARY posix gnu)
add_cfg(googletest.cpp)
add_cfg(gtk.c) add_cfg(gtk.c)
add_cfg(libcurl.c) add_cfg(libcurl.c)
add_cfg(lua.c) add_cfg(lua.c)

View File

@ -8,6 +8,7 @@
// //
#include <gmock/gmock-generated-matchers.h> #include <gmock/gmock-generated-matchers.h>
#include <gtest/gtest.h>
// #9397 syntaxError when MATCHER_P is not known // #9397 syntaxError when MATCHER_P is not known
namespace ExampleNamespace { namespace ExampleNamespace {
@ -18,3 +19,13 @@ namespace ExampleNamespace {
return ((arg <= (expected + TOLERANCE)) && (arg >= (expected - TOLERANCE))); return ((arg <= (expected + TOLERANCE)) && (arg >= (expected - TOLERANCE)));
} }
} }
TEST(ASSERT, ASSERT) {
int *a = (int*)calloc(10,sizeof(int));
ASSERT_TRUE(a != nullptr);
a[0] = 10;
free(a);
}