| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. 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 21 matching lines...) Expand all Loading... |
| 32 #include "wtf/StdLibExtras.h" | 32 #include "wtf/StdLibExtras.h" |
| 33 #include "wtf/text/CString.h" | 33 #include "wtf/text/CString.h" |
| 34 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
| 35 #include <sstream> | 35 #include <sstream> |
| 36 #include <string> | 36 #include <string> |
| 37 | 37 |
| 38 using namespace WTF; | 38 using namespace WTF; |
| 39 | 39 |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 CString toCStringThroughPrinter(const String& string) | 42 CString toCStringThroughPrinter(const String& string) { |
| 43 { | 43 std::ostringstream output; |
| 44 std::ostringstream output; | 44 output << string; |
| 45 output << string; | 45 const std::string& result = output.str(); |
| 46 const std::string& result = output.str(); | 46 return CString(result.data(), result.length()); |
| 47 return CString(result.data(), result.length()); | |
| 48 } | 47 } |
| 49 | 48 |
| 50 TEST(WTFTestHelpersTest, StringPrinter) | 49 TEST(WTFTestHelpersTest, StringPrinter) { |
| 51 { | 50 EXPECT_EQ(CString("\"Hello!\""), toCStringThroughPrinter("Hello!")); |
| 52 EXPECT_EQ(CString("\"Hello!\""), toCStringThroughPrinter("Hello!")); | 51 EXPECT_EQ(CString("\"\\\"\""), toCStringThroughPrinter("\"")); |
| 53 EXPECT_EQ(CString("\"\\\"\""), toCStringThroughPrinter("\"")); | 52 EXPECT_EQ(CString("\"\\\\\""), toCStringThroughPrinter("\\")); |
| 54 EXPECT_EQ(CString("\"\\\\\""), toCStringThroughPrinter("\\")); | 53 EXPECT_EQ( |
| 55 EXPECT_EQ(CString("\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u000
7\""), toCStringThroughPrinter(String("\x00\x01\x02\x03\x04\x05\x06\x07", 8))); | 54 CString("\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\""), |
| 56 EXPECT_EQ(CString("\"\\u0008\\t\\n\\u000B\\u000C\\r\\u000E\\u000F\""), toCSt
ringThroughPrinter(String("\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F", 8))); | 55 toCStringThroughPrinter(String("\x00\x01\x02\x03\x04\x05\x06\x07", 8))); |
| 57 EXPECT_EQ(CString("\"\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u001
7\""), toCStringThroughPrinter(String("\x10\x11\x12\x13\x14\x15\x16\x17", 8))); | 56 EXPECT_EQ( |
| 58 EXPECT_EQ(CString("\"\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001
F\""), toCStringThroughPrinter(String("\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F", 8))); | 57 CString("\"\\u0008\\t\\n\\u000B\\u000C\\r\\u000E\\u000F\""), |
| 59 EXPECT_EQ(CString("\"\\u007F\\u0080\\u0081\""), toCStringThroughPrinter("\x7
F\x80\x81")); | 58 toCStringThroughPrinter(String("\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F", 8))); |
| 60 EXPECT_EQ(CString("\"\""), toCStringThroughPrinter(emptyString())); | 59 EXPECT_EQ( |
| 61 EXPECT_EQ(CString("<null>"), toCStringThroughPrinter(String())); | 60 CString("\"\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\""), |
| 61 toCStringThroughPrinter(String("\x10\x11\x12\x13\x14\x15\x16\x17", 8))); |
| 62 EXPECT_EQ( |
| 63 CString("\"\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F\""), |
| 64 toCStringThroughPrinter(String("\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F", 8))); |
| 65 EXPECT_EQ(CString("\"\\u007F\\u0080\\u0081\""), |
| 66 toCStringThroughPrinter("\x7F\x80\x81")); |
| 67 EXPECT_EQ(CString("\"\""), toCStringThroughPrinter(emptyString())); |
| 68 EXPECT_EQ(CString("<null>"), toCStringThroughPrinter(String())); |
| 62 | 69 |
| 63 static const UChar unicodeSample[] = { 0x30C6, 0x30B9, 0x30C8 }; // "Test" i
n Japanese. | 70 static const UChar unicodeSample[] = {0x30C6, 0x30B9, |
| 64 EXPECT_EQ(CString("\"\\u30C6\\u30B9\\u30C8\""), toCStringThroughPrinter(Stri
ng(unicodeSample, WTF_ARRAY_LENGTH(unicodeSample)))); | 71 0x30C8}; // "Test" in Japanese. |
| 65 | 72 EXPECT_EQ(CString("\"\\u30C6\\u30B9\\u30C8\""), |
| 73 toCStringThroughPrinter( |
| 74 String(unicodeSample, WTF_ARRAY_LENGTH(unicodeSample)))); |
| 66 } | 75 } |
| 67 | |
| 68 } | 76 } |
| OLD | NEW |