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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: views/ime/character_composer_unittest.cc
diff --git a/views/ime/character_composer_unittest.cc b/views/ime/character_composer_unittest.cc
index 05dc3c11618b74f2382f8aa93bf8d679c2e2786b..ed2b4d1f2d291ce0f5eef584f6c72b6627085dd1 100644
--- a/views/ime/character_composer_unittest.cc
+++ b/views/ime/character_composer_unittest.cc
@@ -6,6 +6,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/gtk+/gdk/gdkkeysyms.h"
+#include "ui/base/gtk/gtk_integers.h"
namespace views {
@@ -146,4 +147,50 @@ TEST(CharacterComposerTest, CompositionStateIsClearedAfterReset) {
EXPECT_TRUE(character_composer.GetComposedCharacter().empty());
}
+// ComposeCheckerWithCompactTable in character_composer.cc is depending on the
+// assumption that the data in gtkimcontextsimpleseqs.h is correctly ordered.
+TEST(CharacterComposerTest, MainTableIsCorrectlyOrdered) {
+ // This file is included here intentionally, instead of the top of the file,
+ // because including this file at the top of the file will define a
+ // global constant and contaminate the global namespace.
+#include "third_party/gtk+/gtk/gtkimcontextsimpleseqs.h"
+ const int index_size = 26;
+ const int index_stride = 6;
+
+ // Verify that the index is correctly ordered
+ for (int i = 1; i < index_size; ++i) {
+ const int index_key_prev = gtk_compose_seqs_compact[(i - 1)*index_stride];
+ const int index_key = gtk_compose_seqs_compact[i*index_stride];
+ EXPECT_TRUE(index_key > index_key_prev);
+ }
+
+ // Verify that the sequenes are correctly ordered
+ struct {
+ int operator()(const uint16* l, const uint16* r, int length) const{
+ for (int i = 0; i < length; ++i) {
+ if (l[i] > r[i])
+ return 1;
+ if (l[i] < r[i])
+ return -1;
+ }
+ return 0;
+ }
+ } compare_sequence;
+
+ for (int i = 0; i < index_size; ++i) {
+ for (int length = 1; length < index_stride - 1; ++length) {
+ const int index_begin = gtk_compose_seqs_compact[i*index_stride + length];
+ const int index_end =
+ gtk_compose_seqs_compact[i*index_stride + length + 1];
+ const int stride = length + 1;
+ for (int index = index_begin + stride; index < index_end;
+ index += stride) {
+ const uint16* sequence = &gtk_compose_seqs_compact[index];
+ const uint16* sequence_prev = sequence - stride;
+ EXPECT_EQ(compare_sequence(sequence, sequence_prev, length), 1);
+ }
+ }
+ }
+}
+
} // namespace views
« 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