Add orientation	to regression tests

Change-Id: Iaf2cb7841c4622eedeb4bf880d55988bfa61e823
diff --git a/tests/src/com/android/inputmethod/latin/SuggestPerformanceTests.java b/tests/src/com/android/inputmethod/latin/SuggestPerformanceTests.java
index 99bcc61..7af566b 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestPerformanceTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestPerformanceTests.java
@@ -18,6 +18,7 @@
 import com.android.inputmethod.latin.tests.R;
 
 import android.content.res.AssetFileDescriptor;
+import android.content.res.Configuration;
 import android.text.TextUtils;
 import android.util.Slog;
 
@@ -38,7 +39,7 @@
         final AssetFileDescriptor dict = openTestRawResourceFd(R.raw.test);
         mHelper = new SuggestHelper(
                 getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(),
-                createKeyboardId(Locale.US));
+                createKeyboardId(Locale.US, Configuration.ORIENTATION_PORTRAIT));
         loadString(R.raw.testtext);
     }
 
diff --git a/tests/src/com/android/inputmethod/latin/SuggestTests.java b/tests/src/com/android/inputmethod/latin/SuggestTests.java
index 6e9a127..cf45580 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestTests.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestTests.java
@@ -19,6 +19,7 @@
 import com.android.inputmethod.latin.tests.R;
 
 import android.content.res.AssetFileDescriptor;
+import android.content.res.Configuration;
 
 import java.util.Locale;
 
@@ -31,7 +32,7 @@
         final AssetFileDescriptor dict = openTestRawResourceFd(R.raw.test);
         mHelper = new SuggestHelper(
                 getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(),
-                createKeyboardId(Locale.US));
+                createKeyboardId(Locale.US, Configuration.ORIENTATION_PORTRAIT));
         mHelper.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
     }
 
diff --git a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
index 7d61d00..058a3e7 100644
--- a/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
+++ b/tests/src/com/android/inputmethod/latin/SuggestTestsBase.java
@@ -20,6 +20,7 @@
 import android.content.res.Configuration;
 import android.test.AndroidTestCase;
 import android.text.TextUtils;
+import android.util.DisplayMetrics;
 import android.view.inputmethod.EditorInfo;
 
 import com.android.inputmethod.keyboard.KeyboardId;
@@ -37,12 +38,22 @@
         mTestPackageFile = new File(getTestContext().getApplicationInfo().sourceDir);
     }
 
-    protected KeyboardId createKeyboardId(Locale locale) {
-        final int displayWidth = getContext().getResources().getDisplayMetrics().widthPixels;
+    protected KeyboardId createKeyboardId(Locale locale, int orientation) {
+        final DisplayMetrics dm = getContext().getResources().getDisplayMetrics();
+        final int width;
+        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
+            width = Math.max(dm.widthPixels, dm.heightPixels);
+        } else if (orientation == Configuration.ORIENTATION_PORTRAIT) {
+            width = Math.min(dm.widthPixels, dm.heightPixels);
+        } else {
+            fail("Orientation should be ORIENTATION_LANDSCAPE or ORIENTATION_PORTRAIT: "
+                    + "orientation=" + orientation);
+            return null;
+        }
         return new KeyboardId(locale.toString() + " keyboard",
-                com.android.inputmethod.latin.R.xml.kbd_qwerty, locale,
-                Configuration.ORIENTATION_LANDSCAPE, displayWidth, KeyboardId.MODE_TEXT,
-                new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE, false, false, false);
+                com.android.inputmethod.latin.R.xml.kbd_qwerty, locale, orientation, width,
+                KeyboardId.MODE_TEXT, new EditorInfo(), false, KeyboardId.F2KEY_MODE_NONE,
+                false, false, false);
     }
 
     protected InputStream openTestRawResource(int resIdInTest) {
diff --git a/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java b/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java
index 9bd8538..0b97e41 100644
--- a/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java
+++ b/tests/src/com/android/inputmethod/latin/UserBigramSuggestTests.java
@@ -15,9 +15,10 @@
  */
 
 package com.android.inputmethod.latin;
-import com.android.inputmethod.latin.tests.R;
-
 import android.content.res.AssetFileDescriptor;
+import android.content.res.Configuration;
+
+import com.android.inputmethod.latin.tests.R;
 
 import java.util.Locale;
 
@@ -34,7 +35,8 @@
         final AssetFileDescriptor dict = openTestRawResourceFd(R.raw.test);
         mHelper = new UserBigramSuggestHelper(
                 getContext(), mTestPackageFile, dict.getStartOffset(), dict.getLength(),
-                MAX_DATA, DELETE_DATA, createKeyboardId(Locale.US));
+                MAX_DATA, DELETE_DATA,
+                createKeyboardId(Locale.US, Configuration.ORIENTATION_PORTRAIT));
     }
 
     /************************** Tests ************************/