有三种: EXPECT_*
EXPECT_STR*
EXPECT_STRCASE*
一.EXPECT_*
仅当用户定义了比较操作符(如==,<等)时,该断言可以在用户定义类型上运行 ,
所以可以比较string和wstring类型的字符串
二. (const char*)
只支持C字符串,char*,wchar_t*,不支持string和wstring,
三.EXPECT_STRCASE*
也是只支持C字符串,不支持string和wstring。
与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);