flutter_flutter/engine/src/flutter/fml/string_conversion_unittests.cc
Chris Bracken 3e6137c8ec Migrate string encoding conversions to FML (flutter/engine#31334)
We've implemented UTF-8/UTF-16 string encoding conversions in multiple
places, from FML to //flutter/shell/platform/common, to the individual
embedders. This migrates these conversions to FML and adds tests.

Windows APIs use wchar_t-based strings and as a result, we continue to
keep Windows-specific functions in fml/platform/win/wstring_conversion.h.

We break out string_conversions into its own source set since FML brings
with it some Dart dependencies (e.g. dart_timestamp_provider.cc) that
are unused by some targets such as uwptool.exe in the Windows UWP
embedding.

Issue: https://github.com/flutter/flutter/issues/98061
2022-02-09 22:59:48 -08:00

38 lines
867 B
C++

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/string_conversion.h"
#include "gtest/gtest.h"
namespace fml {
namespace testing {
TEST(StringConversion, Utf16ToUtf16Empty) {
EXPECT_EQ(Utf8ToUtf16(""), u"");
}
TEST(StringConversion, Utf8ToUtf16Ascii) {
EXPECT_EQ(Utf8ToUtf16("abc123"), u"abc123");
}
TEST(StringConversion, Utf8ToUtf16Unicode) {
EXPECT_EQ(Utf8ToUtf16("\xe2\x98\x83"), u"\x2603");
}
TEST(StringConversion, Utf16ToUtf8Empty) {
EXPECT_EQ(Utf16ToUtf8(u""), "");
}
TEST(StringConversion, Utf16ToUtf8Ascii) {
EXPECT_EQ(Utf16ToUtf8(u"abc123"), "abc123");
}
TEST(StringConversion, Utf16ToUtf8Unicode) {
EXPECT_EQ(Utf16ToUtf8(u"\x2603"), "\xe2\x98\x83");
}
} // namespace testing
} // namespace fml