gtest中的字符串比较断言

 

有三种:  EXPECT_*

        EXPECT_STR*

        EXPECT_STRCASE*

一.EXPECT_*

仅当用户定义了比较操作符(如==,<等)时,该断言可以在用户定义类型上运行 ,

所以可以比较stringwstring类型的字符串  

二.  (const char*)

  只支持C字符串,char*,wchar_t*,不支持stringwstring,

三.EXPECT_STRCASE*   

  也是只支持C字符串,不支持stringwstring

  与EXPECT_STR* 不同的是,它不支持wchar_t*类型的

在断言名称中的CASE表示是大小写忽略的

例子:

TEST(StringCmpTest, Demo)

{

    string szJC = "JC";

    wstring szTQ = L"TQ";    //前面加L就是将其简单转换成unicode码的字串,要用对应的wcout才能输出    

    char* cJC = "JC";

    wchar_t* cTQ = L"TQ";

    EXPECT_EQ("JC", szJC);

    EXPECT_EQ(L"TQ", szTQ);

    EXPECT_STREQ("JC", cJC);

    EXPECT_STREQ(L"TQ", cTQ);

    EXPECT_STRCASEEQ("JC", cJC);

}

 

另附一点:关于带中文的unicode字符串的打印

第一种方法:使用setlocale方法 或size_t   wcstombs(char   *s,   const   wchar_t   *pwcs,   size_t   n);或 size_t   mbstowcs(wchar_t   *pwcs,   const   char   *s,   size_t   n);      

wchar_t buffer[256]= L"傻B!";  //用cout,wcout打印不出来

    setlocale(LC_ALL, "chs" );    

wprintf(L"%s",buffer);       //用printf会乱码

 

char *setlocale( int category, const char *locale );

Category:
LC_ALL

All categories, as listed below

LC_COLLATE

The strcoll, _stricoll, wcscoll, _wcsicoll, and strxfrm functions

LC_CTYPE

The character-handling functions (except isdigit, isxdigit, mbstowcs, and mbtowc, which are unaffected)

LC_MONETARY

Monetary-formatting information returned by the localeconv function

LC_NUMERIC

Decimal-point character for the formatted output routines (such as printf), for the data-conversion routines, and for the nonmonetary-formatting information returned by localeconv

LC_TIME

The strftime and wcsftime functions

 

locale :: "lang[_country[.code_page]]"              

       | ".code_page"            

        | ""           

        | NULL

第二种方法:不使用wprintf,而使用_cwprintf或_tcprintf等等

wchar_t buffer[256]= L"傻B!";

    _cwprintf(L"%s",buffer); 


 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值