OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "public/platform/FilePathConversion.h" |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "public/platform/WebString.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "wtf/text/WTFString.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 TEST(FilePathConversionTest, convert) |
| 15 { |
| 16 String test8bitString("path"); |
| 17 String test8bitLatin1("a\xC4"); |
| 18 |
| 19 static const UChar test[5] = { 0x0070, 0x0061, 0x0074, 0x0068, 0 }; // path |
| 20 static const UChar testLatin1[3] = { 0x0061, 0x00C4, 0 }; // a\xC4 |
| 21 static const UChar testUTF16[3] = { 0x6587, 0x5B57, 0 }; // \u6587 \u5B57 |
| 22 String test16bitString(test); |
| 23 String test16bitLatin1(testLatin1); |
| 24 String test16bitUTF16(testUTF16); |
| 25 |
| 26 // Latin1 a\xC4 == UTF8 a\xC3\x84 |
| 27 base::FilePath pathLatin1 = base::FilePath::FromUTF8Unsafe("a\xC3\x84"); |
| 28 // UTF16 \u6587\u5B57 == \xE6\x96\x87\xE5\xAD\x97 |
| 29 base::FilePath pathUTF16 = base::FilePath::FromUTF8Unsafe("\xE6\x96\x87\xE5\
xAD\x97"); |
| 30 |
| 31 EXPECT_TRUE(test8bitString.is8Bit()); |
| 32 EXPECT_TRUE(test8bitLatin1.is8Bit()); |
| 33 EXPECT_FALSE(test16bitString.is8Bit()); |
| 34 EXPECT_FALSE(test16bitLatin1.is8Bit()); |
| 35 |
| 36 EXPECT_EQ(FILE_PATH_LITERAL("path"), WebStringToFilePath(test8bitString).val
ue()); |
| 37 EXPECT_EQ(pathLatin1.value(), WebStringToFilePath(test8bitLatin1).value()); |
| 38 EXPECT_EQ(FILE_PATH_LITERAL("path"), WebStringToFilePath(test16bitString).va
lue()); |
| 39 EXPECT_EQ(pathLatin1.value(), WebStringToFilePath(test16bitLatin1).value()); |
| 40 EXPECT_EQ(pathUTF16.value(), WebStringToFilePath(test16bitUTF16).value()); |
| 41 } |
| 42 |
| 43 } // namespace blink |
OLD | NEW |