Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(429)

Side by Side Diff: ui/gfx/win/text_analysis_source_unittest.cc

Issue 2054273002: Font fallback for UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix clang build error due to signed-unsigned comparison Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
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 "ui/gfx/win/text_analysis_source.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8
9 namespace mswr = Microsoft::WRL;
10
11 namespace gfx {
12 namespace win {
13
14 namespace {
15
16 DWRITE_READING_DIRECTION kReadingDirection =
17 DWRITE_READING_DIRECTION_TOP_TO_BOTTOM;
18 const wchar_t* kLocale = L"hi-in";
19 const wchar_t kText[] = L"sample text";
20 const size_t kTextLength = _countof(kText) - 1;
21 }
msw 2016/06/27 20:45:37 nit: blank line above and add a comment: "} // na
Ilya Kulshin 2016/06/28 18:08:01 Done.
22
23 class TextAnalysisSourceTest : public testing::Test {
24 public:
25 TextAnalysisSourceTest() {
msw 2016/06/27 20:45:37 nit: define a dtor or use "= default;"?
Ilya Kulshin 2016/06/28 18:08:01 This class does not require custom destruction log
26 mswr::ComPtr<IDWriteFactory> factory;
27 CreateDWriteFactory(&factory);
28
29 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution;
30 factory->CreateNumberSubstitution(DWRITE_NUMBER_SUBSTITUTION_METHOD_NONE,
31 kLocale, true /* ignoreUserOverride */,
32 &number_substitution);
33
34 mswr::MakeAndInitialize<TextAnalysisSource>(
35 &source_, kText, kLocale, number_substitution.Get(), kReadingDirection);
36 }
37
38 void CreateDWriteFactory(IUnknown** factory) {
msw 2016/06/27 20:45:37 Can you use gfx::win::CreateDWriteFactory instead?
Ilya Kulshin 2016/06/28 18:08:01 Done.
39 using DWriteCreateFactoryProc = decltype(DWriteCreateFactory)*;
40 HMODULE dwrite_dll = LoadLibraryW(L"dwrite.dll");
41 if (!dwrite_dll)
42 return;
43
44 DWriteCreateFactoryProc dwrite_create_factory_proc =
45 reinterpret_cast<DWriteCreateFactoryProc>(
46 GetProcAddress(dwrite_dll, "DWriteCreateFactory"));
47 if (!dwrite_create_factory_proc)
48 return;
49
50 dwrite_create_factory_proc(DWRITE_FACTORY_TYPE_SHARED,
51 __uuidof(IDWriteFactory), factory);
52 }
53
54 mswr::ComPtr<TextAnalysisSource> source_;
msw 2016/06/27 20:45:36 nit: make private; add a protected/public accessor
Ilya Kulshin 2016/06/28 18:08:01 Made protected.
55 };
msw 2016/06/27 20:45:37 nit: DISALLOW_COPY_AND_ASSIGN
Ilya Kulshin 2016/06/28 18:08:01 Done.
56
57 TEST_F(TextAnalysisSourceTest, TestGetLocaleName) {
58 UINT32 length = 0;
59 const wchar_t* locale_name = nullptr;
60 HRESULT hr;
msw 2016/06/27 20:45:36 nit: init to E_FAIL or E_UNEXPECTED; ditto elsewhe
Ilya Kulshin 2016/06/28 18:08:01 Done.
61 hr = source_->GetLocaleName(0, &length, &locale_name);
62
63 EXPECT_TRUE(SUCCEEDED(hr));
64 EXPECT_EQ(kTextLength, length);
65 EXPECT_STREQ(kLocale, locale_name);
66
67 hr = source_->GetLocaleName(kTextLength, &length, &locale_name);
msw 2016/06/27 20:45:37 nit: add a comment explaining why this fails? (is
Ilya Kulshin 2016/06/28 18:08:01 Done.
68
69 EXPECT_TRUE(FAILED(hr));
70 }
71
72 TEST_F(TextAnalysisSourceTest, TestGetNumberSubstitution) {
73 UINT32 length = 0;
74 mswr::ComPtr<IDWriteNumberSubstitution> number_substitution;
75 HRESULT hr;
76 hr = source_->GetNumberSubstitution(0, &length, &number_substitution);
77
78 EXPECT_TRUE(SUCCEEDED(hr));
79 EXPECT_EQ(kTextLength, length);
80 EXPECT_NE(nullptr, number_substitution.Get());
81
82 hr = source_->GetNumberSubstitution(kTextLength, &length,
msw 2016/06/27 20:45:36 ditto nit: add a simple comment on why this fails.
Ilya Kulshin 2016/06/28 18:08:01 Done.
83 &number_substitution);
84
85 EXPECT_TRUE(FAILED(hr));
86 }
87
88 TEST_F(TextAnalysisSourceTest, TestGetParagraphReadingDirection) {
89 EXPECT_EQ(kReadingDirection, source_->GetParagraphReadingDirection());
90 }
91
92 TEST_F(TextAnalysisSourceTest, TestGetTextAtPosition) {
93 UINT32 length = 0;
94 const wchar_t* text = nullptr;
95 HRESULT hr;
96 hr = source_->GetTextAtPosition(0, &text, &length);
97
98 EXPECT_TRUE(SUCCEEDED(hr));
99 EXPECT_EQ(kTextLength, length);
100 EXPECT_STREQ(kText, text);
101
102 hr = source_->GetTextAtPosition(5, &text, &length);
103
104 EXPECT_TRUE(SUCCEEDED(hr));
105 EXPECT_EQ(kTextLength - 5, length);
106 EXPECT_STREQ(kText + 5, text);
107
108 hr = source_->GetTextAtPosition(kTextLength, &text, &length);
109
110 EXPECT_TRUE(SUCCEEDED(hr));
msw 2016/06/27 20:45:37 nit: odd that this passes... should you check that
Ilya Kulshin 2016/06/28 18:08:01 My reading of https://msdn.microsoft.com/en-us/lib
111 EXPECT_EQ(nullptr, text);
112 }
113
114 TEST_F(TextAnalysisSourceTest, TestGetTextBeforePosition) {
115 UINT32 length = 0;
116 const wchar_t* text = nullptr;
117 HRESULT hr;
118 hr = source_->GetTextBeforePosition(0, &text, &length);
119
120 EXPECT_TRUE(SUCCEEDED(hr));
121 EXPECT_EQ(nullptr, text);
122
123 hr = source_->GetTextBeforePosition(5, &text, &length);
124
125 EXPECT_TRUE(SUCCEEDED(hr));
126 EXPECT_EQ(5u, length);
127 EXPECT_STREQ(kText, text);
128
129 hr = source_->GetTextBeforePosition(kTextLength, &text, &length);
130
131 EXPECT_TRUE(SUCCEEDED(hr));
132 EXPECT_EQ(kTextLength, length);
133 EXPECT_STREQ(kText, text);
134 }
135
136 } // namespace win
137 } // namespace gfx
OLDNEW
« ui/gfx/font_fallback_win.cc ('K') | « ui/gfx/win/text_analysis_source.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698