summaryrefslogtreecommitdiff
path: root/chromium/base/win/hstring_compare_unittest.cc
blob: 48ffddf4ca5c5b5bc261b8e2123cf71c3ff87766 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright 2019 The Chromium 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 "base/win/hstring_compare.h"

#include "base/win/hstring_reference.h"
#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace win {
namespace {

constexpr wchar_t kTestString12[] = L"12";
constexpr wchar_t kTestString123[] = L"123";
constexpr wchar_t kTestString1234[] = L"1234";

}  // namespace

TEST(HStringCompareTest, WorksOnWindows8AndAbove) {
  INT32 result;
  HRESULT hr = HStringCompare(nullptr, nullptr, &result);
  // HStringCompare requires WinRT core functions, which are not available in
  // older versions.
  if (GetVersion() < Version::WIN8)
    EXPECT_HRESULT_FAILED(hr);
  else
    EXPECT_HRESULT_SUCCEEDED(hr);
}

TEST(HStringCompareTest, FirstStringBeforeSecondString) {
  if (GetVersion() < Version::WIN8)
    return;

  ASSERT_TRUE(HStringReference::ResolveCoreWinRTStringDelayload());

  const HStringReference string12(kTestString12);
  const HStringReference string123(kTestString123);
  INT32 result;
  HRESULT hr = HStringCompare(string12.Get(), string123.Get(), &result);
  EXPECT_HRESULT_SUCCEEDED(hr);
  EXPECT_EQ(-1, result);
}

TEST(HStringCompareTest, StringsEqual) {
  if (GetVersion() < Version::WIN8)
    return;

  ASSERT_TRUE(HStringReference::ResolveCoreWinRTStringDelayload());

  const HStringReference string123(kTestString123);
  INT32 result;
  HRESULT hr = HStringCompare(string123.Get(), string123.Get(), &result);
  EXPECT_HRESULT_SUCCEEDED(hr);
  EXPECT_EQ(0, result);
}

TEST(HStringCompareTest, FirstStringAfterSecondString) {
  if (GetVersion() < Version::WIN8)
    return;

  ASSERT_TRUE(HStringReference::ResolveCoreWinRTStringDelayload());

  const HStringReference string123(kTestString123);
  const HStringReference string1234(kTestString1234);
  INT32 result;
  HRESULT hr = HStringCompare(string1234.Get(), string123.Get(), &result);
  EXPECT_HRESULT_SUCCEEDED(hr);
  EXPECT_EQ(1, result);
}

}  // namespace win
}  // namespace base