OLD | NEW |
1 // Copyright 2007, Google Inc. | 1 // Copyright 2007, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 } | 307 } |
308 | 308 |
309 // Tests printing other simple, built-in types. | 309 // Tests printing other simple, built-in types. |
310 | 310 |
311 // bool. | 311 // bool. |
312 TEST(PrintBuiltInTypeTest, Bool) { | 312 TEST(PrintBuiltInTypeTest, Bool) { |
313 EXPECT_EQ("false", Print(false)); | 313 EXPECT_EQ("false", Print(false)); |
314 EXPECT_EQ("true", Print(true)); | 314 EXPECT_EQ("true", Print(true)); |
315 } | 315 } |
316 | 316 |
| 317 #if GTEST_HAS_WCHAR |
317 // wchar_t. | 318 // wchar_t. |
318 TEST(PrintBuiltInTypeTest, Wchar_t) { | 319 TEST(PrintBuiltInTypeTest, Wchar_t) { |
319 EXPECT_EQ("L'\\0'", Print(L'\0')); | 320 EXPECT_EQ("L'\\0'", Print(L'\0')); |
320 EXPECT_EQ("L'\\'' (39, 0x27)", Print(L'\'')); | 321 EXPECT_EQ("L'\\'' (39, 0x27)", Print(L'\'')); |
321 EXPECT_EQ("L'\"' (34, 0x22)", Print(L'"')); | 322 EXPECT_EQ("L'\"' (34, 0x22)", Print(L'"')); |
322 EXPECT_EQ("L'?' (63, 0x3F)", Print(L'?')); | 323 EXPECT_EQ("L'?' (63, 0x3F)", Print(L'?')); |
323 EXPECT_EQ("L'\\\\' (92, 0x5C)", Print(L'\\')); | 324 EXPECT_EQ("L'\\\\' (92, 0x5C)", Print(L'\\')); |
324 EXPECT_EQ("L'\\a' (7)", Print(L'\a')); | 325 EXPECT_EQ("L'\\a' (7)", Print(L'\a')); |
325 EXPECT_EQ("L'\\b' (8)", Print(L'\b')); | 326 EXPECT_EQ("L'\\b' (8)", Print(L'\b')); |
326 EXPECT_EQ("L'\\f' (12, 0xC)", Print(L'\f')); | 327 EXPECT_EQ("L'\\f' (12, 0xC)", Print(L'\f')); |
327 EXPECT_EQ("L'\\n' (10, 0xA)", Print(L'\n')); | 328 EXPECT_EQ("L'\\n' (10, 0xA)", Print(L'\n')); |
328 EXPECT_EQ("L'\\r' (13, 0xD)", Print(L'\r')); | 329 EXPECT_EQ("L'\\r' (13, 0xD)", Print(L'\r')); |
329 EXPECT_EQ("L'\\t' (9)", Print(L'\t')); | 330 EXPECT_EQ("L'\\t' (9)", Print(L'\t')); |
330 EXPECT_EQ("L'\\v' (11, 0xB)", Print(L'\v')); | 331 EXPECT_EQ("L'\\v' (11, 0xB)", Print(L'\v')); |
331 EXPECT_EQ("L'\\x7F' (127)", Print(L'\x7F')); | 332 EXPECT_EQ("L'\\x7F' (127)", Print(L'\x7F')); |
332 EXPECT_EQ("L'\\xFF' (255)", Print(L'\xFF')); | 333 EXPECT_EQ("L'\\xFF' (255)", Print(L'\xFF')); |
333 EXPECT_EQ("L' ' (32, 0x20)", Print(L' ')); | 334 EXPECT_EQ("L' ' (32, 0x20)", Print(L' ')); |
334 EXPECT_EQ("L'a' (97, 0x61)", Print(L'a')); | 335 EXPECT_EQ("L'a' (97, 0x61)", Print(L'a')); |
335 EXPECT_EQ("L'\\x576' (1398)", Print(static_cast<wchar_t>(0x576))); | 336 EXPECT_EQ("L'\\x576' (1398)", Print(static_cast<wchar_t>(0x576))); |
336 EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D))); | 337 EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D))); |
337 } | 338 } |
338 | 339 |
339 // Test that Int64 provides more storage than wchar_t. | 340 // Test that Int64 provides more storage than wchar_t. |
340 TEST(PrintTypeSizeTest, Wchar_t) { | 341 TEST(PrintTypeSizeTest, Wchar_t) { |
341 EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64)); | 342 EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64)); |
342 } | 343 } |
| 344 #endif |
343 | 345 |
344 // Various integer types. | 346 // Various integer types. |
345 TEST(PrintBuiltInTypeTest, Integer) { | 347 TEST(PrintBuiltInTypeTest, Integer) { |
346 EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255))); // uint8 | 348 EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255))); // uint8 |
347 EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128))); // int8 | 349 EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128))); // int8 |
348 EXPECT_EQ("65535", Print(USHRT_MAX)); // uint16 | 350 EXPECT_EQ("65535", Print(USHRT_MAX)); // uint16 |
349 EXPECT_EQ("-32768", Print(SHRT_MIN)); // int16 | 351 EXPECT_EQ("-32768", Print(SHRT_MIN)); // int16 |
350 EXPECT_EQ("4294967295", Print(UINT_MAX)); // uint32 | 352 EXPECT_EQ("4294967295", Print(UINT_MAX)); // uint32 |
351 EXPECT_EQ("-2147483648", Print(INT_MIN)); // int32 | 353 EXPECT_EQ("-2147483648", Print(INT_MIN)); // int32 |
352 EXPECT_EQ("18446744073709551615", | 354 EXPECT_EQ("18446744073709551615", |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 } | 403 } |
402 | 404 |
403 // Tests that C strings are escaped properly. | 405 // Tests that C strings are escaped properly. |
404 TEST(PrintCStringTest, EscapesProperly) { | 406 TEST(PrintCStringTest, EscapesProperly) { |
405 const char* p = "'\"?\\\a\b\f\n\r\t\v\x7F\xFF a"; | 407 const char* p = "'\"?\\\a\b\f\n\r\t\v\x7F\xFF a"; |
406 EXPECT_EQ(PrintPointer(p) + " pointing to \"'\\\"?\\\\\\a\\b\\f" | 408 EXPECT_EQ(PrintPointer(p) + " pointing to \"'\\\"?\\\\\\a\\b\\f" |
407 "\\n\\r\\t\\v\\x7F\\xFF a\"", | 409 "\\n\\r\\t\\v\\x7F\\xFF a\"", |
408 Print(p)); | 410 Print(p)); |
409 } | 411 } |
410 | 412 |
411 | |
412 | |
413 // MSVC compiler can be configured to define whar_t as a typedef | 413 // MSVC compiler can be configured to define whar_t as a typedef |
414 // of unsigned short. Defining an overload for const wchar_t* in that case | 414 // of unsigned short. Defining an overload for const wchar_t* in that case |
415 // would cause pointers to unsigned shorts be printed as wide strings, | 415 // would cause pointers to unsigned shorts be printed as wide strings, |
416 // possibly accessing more memory than intended and causing invalid | 416 // possibly accessing more memory than intended and causing invalid |
417 // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when | 417 // memory accesses. MSVC defines _NATIVE_WCHAR_T_DEFINED symbol when |
418 // wchar_t is implemented as a native type. | 418 // wchar_t is implemented as a native type. |
419 #if !defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED) | 419 #if GTEST_HAS_WCHAR && (!defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)) |
420 | 420 |
421 // const wchar_t*. | 421 // const wchar_t*. |
422 TEST(PrintWideCStringTest, Const) { | 422 TEST(PrintWideCStringTest, Const) { |
423 const wchar_t* p = L"World"; | 423 const wchar_t* p = L"World"; |
424 EXPECT_EQ(PrintPointer(p) + " pointing to L\"World\"", Print(p)); | 424 EXPECT_EQ(PrintPointer(p) + " pointing to L\"World\"", Print(p)); |
425 } | 425 } |
426 | 426 |
427 // wchar_t*. | 427 // wchar_t*. |
428 TEST(PrintWideCStringTest, NonConst) { | 428 TEST(PrintWideCStringTest, NonConst) { |
429 wchar_t p[] = L"Hi"; | 429 wchar_t p[] = L"Hi"; |
(...skipping 872 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 tuple<const int&, const char*>(n, "a")); | 1302 tuple<const int&, const char*>(n, "a")); |
1303 ASSERT_EQ(2u, result.size()); | 1303 ASSERT_EQ(2u, result.size()); |
1304 EXPECT_EQ("1", result[0]); | 1304 EXPECT_EQ("1", result[0]); |
1305 EXPECT_EQ("\"a\"", result[1]); | 1305 EXPECT_EQ("\"a\"", result[1]); |
1306 } | 1306 } |
1307 | 1307 |
1308 #endif // GTEST_HAS_TR1_TUPLE | 1308 #endif // GTEST_HAS_TR1_TUPLE |
1309 | 1309 |
1310 } // namespace gtest_printers_test | 1310 } // namespace gtest_printers_test |
1311 } // namespace testing | 1311 } // namespace testing |
OLD | NEW |