OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "views/ime/character_composer.h" | 5 #include "views/ime/character_composer.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/base/gtk/gtk_integers.h" | |
Yusuke Sato
2011/07/07 06:54:32
alphabetical order.
hashimoto
2011/07/07 07:24:09
Fixed
| |
8 #include "third_party/gtk+/gdk/gdkkeysyms.h" | 9 #include "third_party/gtk+/gdk/gdkkeysyms.h" |
9 | 10 |
10 namespace views { | 11 namespace views { |
11 | 12 |
12 namespace { | 13 namespace { |
13 | 14 |
14 // Expects key is not filtered and no character is composed | 15 // Expects key is not filtered and no character is composed |
15 void ExpectKeyNotFiltered(CharacterComposer* character_composer, uint key) { | 16 void ExpectKeyNotFiltered(CharacterComposer* character_composer, uint key) { |
16 EXPECT_FALSE(character_composer->FilterKeyPress(key)); | 17 EXPECT_FALSE(character_composer->FilterKeyPress(key)); |
17 EXPECT_TRUE(character_composer->GetComposedCharacter().empty()); | 18 EXPECT_TRUE(character_composer->GetComposedCharacter().empty()); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 TEST(CharacterComposerTest, CompositionStateIsClearedAfterReset) { | 140 TEST(CharacterComposerTest, CompositionStateIsClearedAfterReset) { |
140 CharacterComposer character_composer; | 141 CharacterComposer character_composer; |
141 // Even though sequence ['dead acute', 'a'] will compose 'a with acute', | 142 // Even though sequence ['dead acute', 'a'] will compose 'a with acute', |
142 // no character is composed here because of reset. | 143 // no character is composed here because of reset. |
143 ExpectKeyFiltered(&character_composer, GDK_KEY_dead_acute); | 144 ExpectKeyFiltered(&character_composer, GDK_KEY_dead_acute); |
144 character_composer.Reset(); | 145 character_composer.Reset(); |
145 EXPECT_FALSE(character_composer.FilterKeyPress(GDK_KEY_a)); | 146 EXPECT_FALSE(character_composer.FilterKeyPress(GDK_KEY_a)); |
146 EXPECT_TRUE(character_composer.GetComposedCharacter().empty()); | 147 EXPECT_TRUE(character_composer.GetComposedCharacter().empty()); |
147 } | 148 } |
148 | 149 |
150 // ComposeCheckerWithCompactTable in character_composer.cc is depending on the | |
151 // assumption that the data in gtkimcontextsimpleseqs.h is correctly ordered. | |
152 TEST(CharacterComposerTest, MainTableIsCorrectlyOrdered) { | |
153 // This file is included here intentionally, instead of the top of the file, | |
Yusuke Sato
2011/07/07 06:54:32
then, can't we fix the generator script? if you ag
hashimoto
2011/07/07 07:24:09
Filed http://crosbug.com/17328
| |
154 // because including this file at the top of the file will define a | |
155 // global constant and contaminate the global namespace. | |
156 #include "third_party/gtk+/gtk/gtkimcontextsimpleseqs.h" | |
157 const int index_size = 26; | |
Yusuke Sato
2011/07/07 06:54:32
wondering why these constants are not in the gener
hashimoto
2011/07/07 07:24:09
Also filed in http://crosbug.com/17328
| |
158 const int index_stride = 6; | |
159 | |
160 // Verify that the index is correctly ordered | |
161 for (int i = 1; i < index_size; ++i) { | |
162 const int index_key_prev = gtk_compose_seqs_compact[(i - 1)*index_stride]; | |
163 const int index_key = gtk_compose_seqs_compact[i*index_stride]; | |
164 EXPECT_TRUE(index_key > index_key_prev); | |
165 } | |
166 | |
167 // Verify that the sequenes are correctly ordered | |
168 struct { | |
169 int operator()(const uint16* l, const uint16* r, int length) const{ | |
170 for (int i = 0; i < length; ++i) { | |
171 if (l[i] > r[i]) | |
172 return 1; | |
173 if (l[i] < r[i]) | |
174 return -1; | |
175 } | |
176 return 0; | |
177 } | |
178 } compare_sequence; | |
179 | |
180 for (int i = 0; i < index_size; ++i) { | |
181 for (int length = 1; length < index_stride - 1; ++length) { | |
182 const int index_begin = gtk_compose_seqs_compact[i*index_stride + length]; | |
183 const int index_end = | |
184 gtk_compose_seqs_compact[i*index_stride + length + 1]; | |
185 const int stride = length + 1; | |
186 for (int index = index_begin + stride; index < index_end; | |
187 index += stride) { | |
188 const uint16* sequence = >k_compose_seqs_compact[index]; | |
189 const uint16* sequence_prev = sequence - stride; | |
190 EXPECT_EQ(compare_sequence(sequence, sequence_prev, length), 1); | |
191 } | |
192 } | |
193 } | |
194 } | |
195 | |
149 } // namespace views | 196 } // namespace views |
OLD | NEW |