1 // Copyright 2021 The Dawn Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <gtest/gtest.h>
16
17 #include "common/WindowsUtils.h"
18
TEST(WindowsUtilsTests,WCharToUTF8)19 TEST(WindowsUtilsTests, WCharToUTF8) {
20 // Test the empty string
21 ASSERT_EQ("", WCharToUTF8(L""));
22
23 // Test ASCII characters
24 ASSERT_EQ("abc", WCharToUTF8(L"abc"));
25
26 // Test ASCII characters
27 ASSERT_EQ("abc", WCharToUTF8(L"abc"));
28
29 // Test two-byte utf8 character
30 ASSERT_EQ("\xd1\x90", WCharToUTF8(L"\x450"));
31
32 // Test three-byte utf8 codepoint
33 ASSERT_EQ("\xe1\x81\x90", WCharToUTF8(L"\x1050"));
34 }
35
TEST(WindowsUtilsTests,UTF8ToWStr)36 TEST(WindowsUtilsTests, UTF8ToWStr) {
37 // Test the empty string
38 ASSERT_EQ(L"", UTF8ToWStr(""));
39
40 // Test ASCII characters
41 ASSERT_EQ(L"abc", UTF8ToWStr("abc"));
42
43 // Test ASCII characters
44 ASSERT_EQ(L"abc", UTF8ToWStr("abc"));
45
46 // Test two-byte utf8 character
47 ASSERT_EQ(L"\x450", UTF8ToWStr("\xd1\x90"));
48
49 // Test three-byte utf8 codepoint
50 ASSERT_EQ(L"\x1050", UTF8ToWStr("\xe1\x81\x90"));
51 }