dawn-cmake/src/tests/unittests/WindowsUtilsTests.cpp
陈俊嘉 672105aa0a Add string to wstring conversion helper and related unittest
Bug: dawn:766
Change-Id: I318c630df01fcdb302d36873a783fdf1a39c608c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/48200
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: 陈俊嘉 <cjj19970505@live.cn>
2021-04-21 11:05:50 +00:00

51 lines
1.5 KiB
C++

// Copyright 2021 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <gtest/gtest.h>
#include "common/WindowsUtils.h"
TEST(WindowsUtilsTests, WCharToUTF8) {
// Test the empty string
ASSERT_EQ("", WCharToUTF8(L""));
// Test ASCII characters
ASSERT_EQ("abc", WCharToUTF8(L"abc"));
// Test ASCII characters
ASSERT_EQ("abc", WCharToUTF8(L"abc"));
// Test two-byte utf8 character
ASSERT_EQ("\xd1\x90", WCharToUTF8(L"\x450"));
// Test three-byte utf8 codepoint
ASSERT_EQ("\xe1\x81\x90", WCharToUTF8(L"\x1050"));
}
TEST(WindowsUtilsTests, UTF8ToWStr) {
// Test the empty string
ASSERT_EQ(L"", UTF8ToWStr(""));
// Test ASCII characters
ASSERT_EQ(L"abc", UTF8ToWStr("abc"));
// Test ASCII characters
ASSERT_EQ(L"abc", UTF8ToWStr("abc"));
// Test two-byte utf8 character
ASSERT_EQ(L"\x450", UTF8ToWStr("\xd1\x90"));
// Test three-byte utf8 codepoint
ASSERT_EQ(L"\x1050", UTF8ToWStr("\xe1\x81\x90"));
}