• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The Chromium Authors
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 "base/win/scoped_hstring.h"
6 
7 #include <winstring.h>
8 
9 #include <string>
10 
11 #include "base/strings/utf_string_conversions.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 
14 namespace base::win {
15 
16 namespace {
17 
18 constexpr wchar_t kTestString1[] = L"123";
19 constexpr wchar_t kTestString2[] = L"456789";
20 
21 }  // namespace
22 
TEST(ScopedHStringTest,Init)23 TEST(ScopedHStringTest, Init) {
24   ScopedHString hstring = ScopedHString::Create(kTestString1);
25   std::string buffer = hstring.GetAsUTF8();
26   EXPECT_EQ(kTestString1, UTF8ToWide(buffer));
27   WStringPiece contents = hstring.Get();
28   EXPECT_EQ(kTestString1, contents);
29 
30   hstring.reset();
31   EXPECT_TRUE(hstring == nullptr);
32   EXPECT_EQ(nullptr, hstring.get());
33 
34   hstring = ScopedHString::Create(kTestString2);
35 
36   buffer = hstring.GetAsUTF8();
37   EXPECT_EQ(kTestString2, UTF8ToWide(buffer));
38   contents = hstring.Get();
39   EXPECT_EQ(kTestString2, contents);
40 }
41 
42 }  // namespace base::win
43