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

Side by Side Diff: views/ime/character_composer_unittest.cc

Issue 7307016: Add a test to verify that the data in gtkimcontextsimpleseqs.h is correctly ordered (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed the order of includes Created 9 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "third_party/gtk+/gdk/gdkkeysyms.h" 8 #include "third_party/gtk+/gdk/gdkkeysyms.h"
9 #include "ui/base/gtk/gtk_integers.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());
18 } 19 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
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;
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 = &gtk_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
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698