gtest 字符串比较


The assertions in this group compare two C strings. If you want to compare two string objects, use EXPECT_EQEXPECT_NE, and etc instead.

Fatal assertion Nonfatal assertion Verifies
ASSERT_STREQ(expected_stractual_str); EXPECT_STREQ(expected_stractual_str); the two C strings have the same content
ASSERT_STRNE(str1str2); EXPECT_STRNE(str1str2); the two C strings have different content
ASSERT_STRCASEEQ(expected_stractual_str); EXPECT_STRCASEEQ(expected_stractual_str); the two C strings have the same content, ignoring case
ASSERT_STRCASENE(str1str2); EXPECT_STRCASENE(str1str2); the two C strings have different content, ignoring case

Note that "CASE" in an assertion name means that case is ignored.

*STREQ* and *STRNE* also accept wide C strings (wchar_t*). If a comparison of two wide strings fails, their values will be printed as UTF-8 narrow strings.

NULL pointer and an empty string are considered different.


http://code.google.com/p/googletest/wiki/Primer#Binary_Comparison


翻译:

本组断言用于比较C字符串。如果你想比较两个字符串对象,你可以使用 EXPECT_EQ, EXPECT_NE等等。

注名断言 不注名断言 检验
ASSERT_STREQ(expected_stractual_str); EXPECT_STREQ(expected_stractual_str); 检查两个字符串内容是否相同
ASSERT_STRNE(str1str2); EXPECT_STRNE(str1str2); 检查两个字符串内容是否不同
ASSERT_STRCASEEQ(expected_stractual_str); EXPECT_STRCASEEQ(expected_stractual_str); 检查两个字符串内容是否相同,忽略大小写
ASSERT_STRCASENE(str1str2); EXPECT_STRCASENE(str1str2); 检查两个字符串内容是否相同,忽略大小写

注意带“CASE"的断言名表示该断言不区分大小写

*STREQ* 和 *STRNE* 也可以用于比较宽字符串 (wchar_t*)。如果两个宽字符串比较失败,它们的值会以UTF-8 窄字符串打印出来。

空指针和0长度的字符串被认为是不同的。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值