1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
base / win / scoped_hstring_unittest.cc [blame]
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/win/scoped_hstring.h"
#include <winstring.h>
#include <string>
#include <string_view>
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base::win {
namespace {
constexpr wchar_t kTestString1[] = L"123";
constexpr wchar_t kTestString2[] = L"456789";
} // namespace
TEST(ScopedHStringTest, Init) {
ScopedHString hstring = ScopedHString::Create(kTestString1);
std::string buffer = hstring.GetAsUTF8();
EXPECT_EQ(kTestString1, UTF8ToWide(buffer));
std::wstring_view contents = hstring.Get();
EXPECT_EQ(kTestString1, contents);
hstring.reset();
EXPECT_TRUE(hstring == nullptr);
EXPECT_EQ(nullptr, hstring.get());
hstring = ScopedHString::Create(kTestString2);
buffer = hstring.GetAsUTF8();
EXPECT_EQ(kTestString2, UTF8ToWide(buffer));
contents = hstring.Get();
EXPECT_EQ(kTestString2, contents);
}
} // namespace base::win