ConfigTest.java revision 3b12c3cd80c04ced7ba8fb120b6574bedda437e1
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.content.res.cts;
18
19import java.util.Locale;
20
21import android.content.res.AssetManager;
22import android.content.res.Configuration;
23import android.content.res.Resources;
24import android.content.res.TypedArray;
25import android.content.res.Resources.NotFoundException;
26import android.test.AndroidTestCase;
27import android.test.suitebuilder.annotation.MediumTest;
28import android.test.suitebuilder.annotation.SmallTest;
29import android.util.DisplayMetrics;
30import android.util.Log;
31
32import com.android.cts.stub.R;
33
34public class ConfigTest extends AndroidTestCase {
35    enum Properties {
36        LANGUAGE,
37        COUNTRY,
38        MCC,
39        MNC,
40        TOUCHSCREEN,
41        KEYBOARD,
42        KEYBOARDHIDDEN,
43        NAVIGATION,
44        ORIENTATION,
45        WIDTH,
46        HEIGHT,
47        DENSITY,
48        SCREENLAYOUT,
49        SWIDTH_DP,
50        WIDTH_DP,
51        HEIGHT_DP
52    }
53
54    private static void checkValue(final Resources res, final int resId,
55            final String expectedValue) {
56        try {
57            final String actual = res.getString(resId);
58            assertNotNull("Returned wrong configuration-based simple value: expected <nothing>, "
59                    + "got '" + actual + "' from resource 0x" + Integer.toHexString(resId),
60                    expectedValue);
61            assertEquals("Returned wrong configuration-based simple value: expected '"
62                    + expectedValue + "', got '" + actual + "' from resource 0x"
63                    + Integer.toHexString(resId), expectedValue, actual);
64        } catch (NotFoundException e) {
65            assertNull("Resource not found for configuration-based simple value: expecting \""
66                    + expectedValue + "\"", expectedValue);
67        }
68    }
69
70    private static void checkValue(final Resources res, final int resId,
71            final int[] styleable, final String[] expectedValues) {
72        final Resources.Theme theme = res.newTheme();
73        final TypedArray sa = theme.obtainStyledAttributes(resId, styleable);
74        for (int i = 0; i < styleable.length; i++) {
75            final String actual = sa.getString(i);
76            assertEquals("Returned wrong configuration-based style value: expected '"
77                    + expectedValues[i] + "', got '" + actual + "' from attr "
78                    + i + " of resource 0x" + Integer.toHexString(resId),
79                    actual, expectedValues[i]);
80        }
81        sa.recycle();
82    }
83
84    private class TotalConfig {
85        final Configuration mConfig;
86        final DisplayMetrics mMetrics;
87
88        public TotalConfig() {
89            mConfig = new Configuration();
90            mMetrics = new DisplayMetrics();
91            mConfig.locale = new Locale("++", "++");
92        }
93
94        public void setProperty(final Properties p, final int value) {
95            switch(p) {
96                case MCC:
97                    mConfig.mcc = value;
98                    break;
99                case MNC:
100                    mConfig.mnc = value;
101                    break;
102                case TOUCHSCREEN:
103                    mConfig.touchscreen = value;
104                    break;
105                case KEYBOARD:
106                    mConfig.keyboard = value;
107                    break;
108                case KEYBOARDHIDDEN:
109                    mConfig.keyboardHidden = value;
110                    break;
111                case NAVIGATION:
112                    mConfig.navigation = value;
113                    break;
114                case ORIENTATION:
115                    mConfig.orientation = value;
116                    break;
117                case WIDTH:
118                    mMetrics.widthPixels = value;
119                    break;
120                case HEIGHT:
121                    mMetrics.heightPixels = value;
122                    break;
123                case DENSITY:
124                    // this is the ratio from the standard
125                    mMetrics.density = (((float)value)/((float)DisplayMetrics.DENSITY_DEFAULT));
126                    mConfig.densityDpi = value;
127                    break;
128                case SCREENLAYOUT:
129                    mConfig.screenLayout = value;
130                    break;
131                case SWIDTH_DP:
132                    mConfig.smallestScreenWidthDp = value;
133                    break;
134                case WIDTH_DP:
135                    mConfig.screenWidthDp = value;
136                    break;
137                case HEIGHT_DP:
138                    mConfig.screenHeightDp = value;
139                    break;
140                default:
141                    assert(false);
142                    break;
143            }
144        }
145
146        public void setProperty(final Properties p, final String value) {
147            switch(p) {
148                case LANGUAGE:
149                    final String oldCountry = mConfig.locale.getCountry();
150                    mConfig.locale = new Locale(value, oldCountry);
151                    break;
152                case COUNTRY:
153                    final String oldLanguage = mConfig.locale.getLanguage();
154                    mConfig.locale = new Locale(oldLanguage, value);
155                    break;
156                default:
157                    assert(false);
158                    break;
159            }
160        }
161
162        public Resources getResources() {
163            final AssetManager assmgr = new AssetManager();
164            assmgr.addAssetPath(mContext.getPackageResourcePath());
165            return new Resources(assmgr, mMetrics, mConfig);
166        }
167    }
168
169    public TotalConfig makeEmptyConfig() {
170        return new TotalConfig();
171    }
172
173    public TotalConfig makeClassicConfig() {
174        TotalConfig config = new TotalConfig();
175        config.mConfig.locale = new Locale("en", "US");
176        config.mConfig.mcc = 310;
177        config.mConfig.mnc = 001; // unused
178        config.mConfig.touchscreen = Configuration.TOUCHSCREEN_FINGER;
179        config.mConfig.keyboard = Configuration.KEYBOARD_QWERTY;
180        config.mConfig.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES;
181        config.mConfig.navigation = Configuration.NAVIGATION_TRACKBALL;
182        config.mConfig.orientation = Configuration.ORIENTATION_PORTRAIT;
183        config.mConfig.smallestScreenWidthDp = 320;
184        config.mConfig.screenWidthDp = 320;
185        config.mConfig.screenHeightDp = 480;
186        config.mConfig.densityDpi = 160;
187        config.mMetrics.widthPixels = 200;
188        config.mMetrics.heightPixels = 320;
189        config.mMetrics.density = 1;
190        return config;
191    }
192
193    private static void checkPair(Resources res, int[] notResIds,
194            int simpleRes, String simpleString,
195            int bagRes, String bagString) {
196        boolean willHave = true;
197        if (notResIds != null) {
198            for (int i : notResIds) {
199                if (i == simpleRes) {
200                    willHave = false;
201                    break;
202                }
203            }
204        }
205        checkValue(res, simpleRes, willHave ? simpleString : null);
206        checkValue(res, bagRes, R.styleable.TestConfig,
207                new String[]{willHave ? bagString : null});
208    }
209
210    @SmallTest
211    public void testAllEmptyConfigs() {
212        /**
213         * Test a resource that contains a value for each possible single
214         * configuration value.
215         */
216        TotalConfig config = makeEmptyConfig();
217        Resources res = config.getResources();
218        checkValue(res, R.configVarying.simple, "simple default");
219        checkValue(res, R.configVarying.bag,
220                R.styleable.TestConfig, new String[]{"bag default"});
221
222        config = makeEmptyConfig();
223        config.setProperty(Properties.LANGUAGE, "xx");
224        res = config.getResources();
225        checkValue(res, R.configVarying.simple, "simple xx");
226        checkValue(res, R.configVarying.bag,
227                R.styleable.TestConfig, new String[]{"bag xx"});
228
229        config = makeEmptyConfig();
230        config.setProperty(Properties.LANGUAGE, "xx");
231        config.setProperty(Properties.COUNTRY, "YY");
232        res = config.getResources();
233        checkValue(res, R.configVarying.simple, "simple xx-rYY");
234        checkValue(res, R.configVarying.bag,
235                R.styleable.TestConfig, new String[]{"bag xx-rYY"});
236
237        config = makeEmptyConfig();
238        config.setProperty(Properties.MCC, 111);
239        res = config.getResources();
240        checkValue(res, R.configVarying.simple, "simple mcc111");
241        checkValue(res, R.configVarying.bag,
242                R.styleable.TestConfig, new String[]{"bag mcc111"});
243
244        config = makeEmptyConfig();
245        config.setProperty(Properties.MNC, 222);
246        res = config.getResources();
247        checkValue(res, R.configVarying.simple, "simple mnc222");
248        checkValue(res, R.configVarying.bag,
249                R.styleable.TestConfig, new String[]{"bag mnc222"});
250
251        config = makeEmptyConfig();
252        config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH);
253        res = config.getResources();
254        checkValue(res, R.configVarying.simple, "simple notouch");
255        checkValue(res, R.configVarying.bag,
256                R.styleable.TestConfig, new String[]{"bag notouch"});
257
258        config = makeEmptyConfig();
259        config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS);
260        res = config.getResources();
261        checkValue(res, R.configVarying.simple, "simple stylus");
262        checkValue(res, R.configVarying.bag,
263                R.styleable.TestConfig, new String[]{"bag stylus"});
264
265        config = makeEmptyConfig();
266        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS);
267        res = config.getResources();
268        checkValue(res, R.configVarying.simple, "simple nokeys");
269        checkValue(res, R.configVarying.bag,
270                R.styleable.TestConfig, new String[]{"bag nokeys"});
271
272        config = makeEmptyConfig();
273        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
274        res = config.getResources();
275        checkValue(res, R.configVarying.simple, "simple 12key");
276        checkValue(res, R.configVarying.bag,
277                R.styleable.TestConfig, new String[]{"bag 12key"});
278
279        config = makeEmptyConfig();
280        config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
281        res = config.getResources();
282        checkValue(res, R.configVarying.simple, "simple keysexposed");
283        checkValue(res, R.configVarying.bag,
284                R.styleable.TestConfig, new String[]{"bag keysexposed"});
285
286        config = makeEmptyConfig();
287        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV);
288        res = config.getResources();
289        checkValue(res, R.configVarying.simple, "simple nonav");
290        checkValue(res, R.configVarying.bag,
291                R.styleable.TestConfig, new String[]{"bag nonav"});
292
293        config = makeEmptyConfig();
294        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_DPAD);
295        res = config.getResources();
296        checkValue(res, R.configVarying.simple, "simple dpad");
297        checkValue(res, R.configVarying.bag,
298                R.styleable.TestConfig, new String[]{"bag dpad"});
299
300        config = makeEmptyConfig();
301        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_WHEEL);
302        res = config.getResources();
303        checkValue(res, R.configVarying.simple, "simple wheel");
304        checkValue(res, R.configVarying.bag,
305                R.styleable.TestConfig, new String[]{"bag wheel"});
306
307        config = makeEmptyConfig();
308        config.setProperty(Properties.HEIGHT, 480);
309        config.setProperty(Properties.WIDTH, 320);
310        res = config.getResources();
311        checkValue(res, R.configVarying.simple, "simple 480x320");
312        checkValue(res, R.configVarying.bag,
313                R.styleable.TestConfig, new String[]{"bag 480x320"});
314
315        config = makeEmptyConfig();
316        config.setProperty(Properties.DENSITY, 240);
317        res = config.getResources();
318        checkValue(res, R.configVarying.simple, "simple 240dpi");
319        checkValue(res, R.configVarying.bag,
320                R.styleable.TestConfig, new String[]{"bag 240dpi"});
321
322        config = makeEmptyConfig();
323        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
324        res = config.getResources();
325        checkValue(res, R.configVarying.simple, "simple landscape");
326        checkValue(res, R.configVarying.bag,
327                R.styleable.TestConfig, new String[]{"bag landscape"});
328
329        config = makeEmptyConfig();
330        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_SQUARE);
331        res = config.getResources();
332        checkValue(res, R.configVarying.simple, "simple square");
333        checkValue(res, R.configVarying.bag,
334                R.styleable.TestConfig, new String[]{"bag square"});
335
336        config = makeEmptyConfig();
337        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL);
338        res = config.getResources();
339        checkValue(res, R.configVarying.simple, "simple small");
340        checkValue(res, R.configVarying.bag,
341                R.styleable.TestConfig, new String[]{"bag small"});
342
343        config = makeEmptyConfig();
344        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL);
345        res = config.getResources();
346        checkValue(res, R.configVarying.simple, "simple normal");
347        checkValue(res, R.configVarying.bag,
348                R.styleable.TestConfig, new String[]{"bag normal"});
349
350        config = makeEmptyConfig();
351        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
352        res = config.getResources();
353        checkValue(res, R.configVarying.simple, "simple large");
354        checkValue(res, R.configVarying.bag,
355                R.styleable.TestConfig, new String[]{"bag large"});
356
357        config = makeEmptyConfig();
358        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE);
359        res = config.getResources();
360        checkValue(res, R.configVarying.simple, "simple xlarge");
361        checkValue(res, R.configVarying.bag,
362                R.styleable.TestConfig, new String[]{"bag xlarge"});
363
364        config = makeEmptyConfig();
365        config.setProperty(Properties.SWIDTH_DP, 600);
366        res = config.getResources();
367        checkValue(res, R.configVarying.simple, "simple sw600");
368        checkValue(res, R.configVarying.bag,
369                R.styleable.TestConfig, new String[]{"bag sw600"});
370
371        config = makeEmptyConfig();
372        config.setProperty(Properties.SWIDTH_DP, 600);
373        res = config.getResources();
374        checkValue(res, R.configVarying.simple, "simple sw600");
375        checkValue(res, R.configVarying.bag,
376                R.styleable.TestConfig, new String[]{"bag sw600"});
377
378        config = makeEmptyConfig();
379        config.setProperty(Properties.SWIDTH_DP, 720);
380        res = config.getResources();
381        checkValue(res, R.configVarying.simple, "simple sw720");
382        checkValue(res, R.configVarying.bag,
383                R.styleable.TestConfig, new String[]{"bag sw720"});
384
385        config = makeEmptyConfig();
386        config.setProperty(Properties.WIDTH_DP, 600);
387        res = config.getResources();
388        checkValue(res, R.configVarying.simple, "simple w600");
389        checkValue(res, R.configVarying.bag,
390                R.styleable.TestConfig, new String[]{"bag w600"});
391
392        config = makeEmptyConfig();
393        config.setProperty(Properties.WIDTH_DP, 720);
394        res = config.getResources();
395        checkValue(res, R.configVarying.simple, "simple w720");
396        checkValue(res, R.configVarying.bag,
397                R.styleable.TestConfig, new String[]{"bag w720"});
398
399        config = makeEmptyConfig();
400        config.setProperty(Properties.HEIGHT_DP, 550);
401        res = config.getResources();
402        checkValue(res, R.configVarying.simple, "simple h550");
403        checkValue(res, R.configVarying.bag,
404                R.styleable.TestConfig, new String[]{"bag h550"});
405
406        config = makeEmptyConfig();
407        config.setProperty(Properties.HEIGHT_DP, 670);
408        res = config.getResources();
409        checkValue(res, R.configVarying.simple, "simple h670");
410        checkValue(res, R.configVarying.bag,
411                R.styleable.TestConfig, new String[]{"bag h670"});
412    }
413
414    @SmallTest
415    public void testAllClassicConfigs() {
416        /**
417         * Test a resource that contains a value for each possible single
418         * configuration value.
419         */
420        TotalConfig config = makeClassicConfig();
421        Resources res = config.getResources();
422        checkValue(res, R.configVarying.simple, "simple default");
423        checkValue(res, R.configVarying.bag,
424                R.styleable.TestConfig, new String[]{"bag default"});
425
426        config = makeClassicConfig();
427        config.setProperty(Properties.LANGUAGE, "xx");
428        res = config.getResources();
429        checkValue(res, R.configVarying.simple, "simple xx");
430        checkValue(res, R.configVarying.bag,
431                R.styleable.TestConfig, new String[]{"bag xx"});
432
433        config = makeClassicConfig();
434        config.setProperty(Properties.LANGUAGE, "xx");
435        config.setProperty(Properties.COUNTRY, "YY");
436        res = config.getResources();
437        checkValue(res, R.configVarying.simple, "simple xx-rYY");
438        checkValue(res, R.configVarying.bag,
439                R.styleable.TestConfig, new String[]{"bag xx-rYY"});
440
441        config = makeClassicConfig();
442        config.setProperty(Properties.MCC, 111);
443        res = config.getResources();
444        checkValue(res, R.configVarying.simple, "simple mcc111");
445        checkValue(res, R.configVarying.bag,
446                R.styleable.TestConfig, new String[]{"bag mcc111"});
447
448        config = makeClassicConfig();
449        config.setProperty(Properties.MNC, 222);
450        res = config.getResources();
451        checkValue(res, R.configVarying.simple, "simple mnc222");
452        checkValue(res, R.configVarying.bag,
453                R.styleable.TestConfig, new String[]{"bag mnc222"});
454
455        config = makeClassicConfig();
456        config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH);
457        res = config.getResources();
458        checkValue(res, R.configVarying.simple, "simple notouch");
459        checkValue(res, R.configVarying.bag,
460                R.styleable.TestConfig, new String[]{"bag notouch"});
461
462        config = makeClassicConfig();
463        config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS);
464        res = config.getResources();
465        checkValue(res, R.configVarying.simple, "simple stylus");
466        checkValue(res, R.configVarying.bag,
467                R.styleable.TestConfig, new String[]{"bag stylus"});
468
469        config = makeClassicConfig();
470        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS);
471        res = config.getResources();
472        checkValue(res, R.configVarying.simple, "simple nokeys");
473        checkValue(res, R.configVarying.bag,
474                R.styleable.TestConfig, new String[]{"bag nokeys"});
475
476        config = makeClassicConfig();
477        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
478        res = config.getResources();
479        checkValue(res, R.configVarying.simple, "simple 12key 63x57");
480        checkValue(res, R.configVarying.bag,
481                R.styleable.TestConfig, new String[]{"bag 12key 63x57"});
482
483        config = makeClassicConfig();
484        config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
485        res = config.getResources();
486        checkValue(res, R.configVarying.simple, "simple keysexposed");
487        checkValue(res, R.configVarying.bag,
488                R.styleable.TestConfig, new String[]{"bag keysexposed"});
489
490        config = makeClassicConfig();
491        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV);
492        res = config.getResources();
493        checkValue(res, R.configVarying.simple, "simple nonav");
494        checkValue(res, R.configVarying.bag,
495                R.styleable.TestConfig, new String[]{"bag nonav"});
496
497        config = makeClassicConfig();
498        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_DPAD);
499        res = config.getResources();
500        checkValue(res, R.configVarying.simple, "simple dpad 63x57");
501        checkValue(res, R.configVarying.bag,
502                R.styleable.TestConfig, new String[]{"bag dpad 63x57"});
503
504        config = makeClassicConfig();
505        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_WHEEL);
506        res = config.getResources();
507        checkValue(res, R.configVarying.simple, "simple wheel");
508        checkValue(res, R.configVarying.bag,
509                R.styleable.TestConfig, new String[]{"bag wheel"});
510
511        config = makeClassicConfig();
512        config.setProperty(Properties.HEIGHT, 480);
513        config.setProperty(Properties.WIDTH, 320);
514        res = config.getResources();
515        checkValue(res, R.configVarying.simple, "simple 480x320");
516        checkValue(res, R.configVarying.bag,
517                R.styleable.TestConfig, new String[]{"bag 480x320"});
518
519        config = makeClassicConfig();
520        config.setProperty(Properties.DENSITY, 240);
521        res = config.getResources();
522        checkValue(res, R.configVarying.simple, "simple 240dpi");
523        checkValue(res, R.configVarying.bag,
524                R.styleable.TestConfig, new String[]{"bag 240dpi"});
525
526        config = makeClassicConfig();
527        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
528        res = config.getResources();
529        checkValue(res, R.configVarying.simple, "simple landscape");
530        checkValue(res, R.configVarying.bag,
531                R.styleable.TestConfig, new String[]{"bag landscape"});
532
533        config = makeClassicConfig();
534        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_SQUARE);
535        res = config.getResources();
536        checkValue(res, R.configVarying.simple, "simple square");
537        checkValue(res, R.configVarying.bag,
538                R.styleable.TestConfig, new String[]{"bag square"});
539
540        config = makeClassicConfig();
541        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL);
542        res = config.getResources();
543        checkValue(res, R.configVarying.simple, "simple small");
544        checkValue(res, R.configVarying.bag,
545                R.styleable.TestConfig, new String[]{"bag small"});
546
547        config = makeClassicConfig();
548        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL);
549        res = config.getResources();
550        checkValue(res, R.configVarying.simple, "simple normal");
551        checkValue(res, R.configVarying.bag,
552                R.styleable.TestConfig, new String[]{"bag normal"});
553
554        config = makeClassicConfig();
555        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
556        res = config.getResources();
557        checkValue(res, R.configVarying.simple, "simple large");
558        checkValue(res, R.configVarying.bag,
559                R.styleable.TestConfig, new String[]{"bag large"});
560
561        config = makeClassicConfig();
562        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE);
563        res = config.getResources();
564        checkValue(res, R.configVarying.simple, "simple xlarge");
565        checkValue(res, R.configVarying.bag,
566                R.styleable.TestConfig, new String[]{"bag xlarge"});
567
568        config = makeClassicConfig();
569        config.setProperty(Properties.SWIDTH_DP, 600);
570        res = config.getResources();
571        checkValue(res, R.configVarying.simple, "simple sw600");
572        checkValue(res, R.configVarying.bag,
573                R.styleable.TestConfig, new String[]{"bag sw600"});
574
575        config = makeClassicConfig();
576        config.setProperty(Properties.SWIDTH_DP, 600);
577        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
578        res = config.getResources();
579        checkValue(res, R.configVarying.simple, "simple sw600 land");
580        checkValue(res, R.configVarying.bag,
581                R.styleable.TestConfig, new String[]{"bag sw600 land"});
582
583        config = makeClassicConfig();
584        config.setProperty(Properties.SWIDTH_DP, 720);
585        res = config.getResources();
586        checkValue(res, R.configVarying.simple, "simple sw720");
587        checkValue(res, R.configVarying.bag,
588                R.styleable.TestConfig, new String[]{"bag sw720"});
589
590        config = makeClassicConfig();
591        config.setProperty(Properties.WIDTH_DP, 600);
592        res = config.getResources();
593        checkValue(res, R.configVarying.simple, "simple w600");
594        checkValue(res, R.configVarying.bag,
595                R.styleable.TestConfig, new String[]{"bag w600"});
596
597        config = makeClassicConfig();
598        config.setProperty(Properties.WIDTH_DP, 720);
599        res = config.getResources();
600        checkValue(res, R.configVarying.simple, "simple w720");
601        checkValue(res, R.configVarying.bag,
602                R.styleable.TestConfig, new String[]{"bag w720"});
603
604        config = makeClassicConfig();
605        config.setProperty(Properties.HEIGHT_DP, 550);
606        res = config.getResources();
607        checkValue(res, R.configVarying.simple, "simple h550");
608        checkValue(res, R.configVarying.bag,
609                R.styleable.TestConfig, new String[]{"bag h550"});
610
611        config = makeClassicConfig();
612        config.setProperty(Properties.HEIGHT_DP, 670);
613        res = config.getResources();
614        checkValue(res, R.configVarying.simple, "simple h670");
615        checkValue(res, R.configVarying.bag,
616                R.styleable.TestConfig, new String[]{"bag h670"});
617    }
618
619    @MediumTest
620    public void testDensity() throws Exception {
621        // have 32, 240 and the default 160 content.
622        // rule is that closest wins, with down scaling (larger content)
623        // being twice as nice as upscaling.
624        // transition at H/2 * (-1 +/- sqrt(1+8L/H))
625        // SO, X < 49 goes to 32
626        // 49 >= X < 182 goes to 160
627        // X >= 182 goes to 240
628        TotalConfig config = makeClassicConfig();
629        config.setProperty(Properties.DENSITY, 2);
630        Resources res = config.getResources();
631        checkValue(res, R.configVarying.simple, "simple 32dpi");
632        checkValue(res, R.configVarying.bag,
633                R.styleable.TestConfig, new String[]{"bag 32dpi"});
634
635        config = makeClassicConfig();
636        config.setProperty(Properties.DENSITY, 32);
637        res = config.getResources();
638        checkValue(res, R.configVarying.simple, "simple 32dpi");
639        checkValue(res, R.configVarying.bag,
640                R.styleable.TestConfig, new String[]{"bag 32dpi"});
641
642        config = makeClassicConfig();
643        config.setProperty(Properties.DENSITY, 48);
644        res = config.getResources();
645        checkValue(res, R.configVarying.simple, "simple 32dpi");
646        checkValue(res, R.configVarying.bag,
647                R.styleable.TestConfig, new String[]{"bag 32dpi"});
648
649        config = makeClassicConfig();
650        config.setProperty(Properties.DENSITY, 49);
651        res = config.getResources();
652        checkValue(res, R.configVarying.simple, "simple default");
653        checkValue(res, R.configVarying.bag,
654                R.styleable.TestConfig, new String[]{"bag default"});
655
656        config = makeClassicConfig();
657        config.setProperty(Properties.DENSITY, 150);
658        res = config.getResources();
659        checkValue(res, R.configVarying.simple, "simple default");
660        checkValue(res, R.configVarying.bag,
661                R.styleable.TestConfig, new String[]{"bag default"});
662
663        config = makeClassicConfig();
664        config.setProperty(Properties.DENSITY, 181);
665        res = config.getResources();
666        checkValue(res, R.configVarying.simple, "simple default");
667        checkValue(res, R.configVarying.bag,
668                R.styleable.TestConfig, new String[]{"bag default"});
669
670        config = makeClassicConfig();
671        config.setProperty(Properties.DENSITY, 182);
672        res = config.getResources();
673        checkValue(res, R.configVarying.simple, "simple 240dpi");
674        checkValue(res, R.configVarying.bag,
675                R.styleable.TestConfig, new String[]{"bag 240dpi"});
676
677        config = makeClassicConfig();
678        config.setProperty(Properties.DENSITY, 239);
679        res = config.getResources();
680        checkValue(res, R.configVarying.simple, "simple 240dpi");
681        checkValue(res, R.configVarying.bag,
682                R.styleable.TestConfig, new String[]{"bag 240dpi"});
683
684        config = makeClassicConfig();
685        config.setProperty(Properties.DENSITY, 490);
686        res = config.getResources();
687        checkValue(res, R.configVarying.simple, "simple 240dpi");
688        checkValue(res, R.configVarying.bag,
689                R.styleable.TestConfig, new String[]{"bag 240dpi"});
690    }
691
692    @MediumTest
693    public void testScreenSize() throws Exception {
694        // ensure that we fall back to the best available screen size
695        // for a given configuration.
696        TotalConfig config = makeClassicConfig();
697        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL);
698        Resources res = config.getResources();
699        checkValue(res, R.configVarying.simple, "simple small");
700        checkValue(res, R.configVarying.small, "small");
701        checkValue(res, R.configVarying.normal, "default");
702        checkValue(res, R.configVarying.large, "default");
703        checkValue(res, R.configVarying.xlarge, "default");
704
705        config = makeClassicConfig();
706        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL);
707        res = config.getResources();
708        checkValue(res, R.configVarying.simple, "simple normal");
709        checkValue(res, R.configVarying.small, "default");
710        checkValue(res, R.configVarying.normal, "normal");
711        checkValue(res, R.configVarying.large, "default");
712        checkValue(res, R.configVarying.xlarge, "default");
713
714        config = makeClassicConfig();
715        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
716        res = config.getResources();
717        checkValue(res, R.configVarying.simple, "simple large");
718        checkValue(res, R.configVarying.small, "default");
719        checkValue(res, R.configVarying.normal, "normal");
720        checkValue(res, R.configVarying.large, "large");
721        checkValue(res, R.configVarying.xlarge, "default");
722
723        config = makeClassicConfig();
724        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE);
725        res = config.getResources();
726        checkValue(res, R.configVarying.simple, "simple xlarge");
727        checkValue(res, R.configVarying.small, "default");
728        checkValue(res, R.configVarying.normal, "normal");
729        checkValue(res, R.configVarying.large, "large");
730        checkValue(res, R.configVarying.xlarge, "xlarge");
731    }
732
733    @MediumTest
734    public void testNewScreenSize() throws Exception {
735        // ensure that swNNNdp, wNNNdp, and hNNNdp are working correctly
736        // for various common screen configurations.
737        TotalConfig config = makeClassicConfig();
738        config.setProperty(Properties.SWIDTH_DP, 589);
739        config.setProperty(Properties.WIDTH_DP, 589);
740        config.setProperty(Properties.HEIGHT_DP, 500);
741        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
742        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
743        Resources res = config.getResources();
744        checkValue(res, R.configVarying.simple, "simple large");
745        checkValue(res, R.configVarying.sw, "default");
746        checkValue(res, R.configVarying.w, "default");
747        checkValue(res, R.configVarying.h, "default");
748        checkValue(res, R.configVarying.wh, "default");
749
750        config = makeClassicConfig();
751        config.setProperty(Properties.SWIDTH_DP, 590);
752        config.setProperty(Properties.WIDTH_DP, 590);
753        config.setProperty(Properties.HEIGHT_DP, 500);
754        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
755        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
756        config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_MEDIUM);
757        res = config.getResources();
758        checkValue(res, R.configVarying.simple, "simple sw590 mdpi");
759        checkValue(res, R.configVarying.sw, "590 mdpi");
760
761        config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_HIGH);
762        res = config.getResources();
763        checkValue(res, R.configVarying.simple, "simple sw590 hdpi");
764        checkValue(res, R.configVarying.sw, "590 hdpi");
765
766        config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_XHIGH);
767        res = config.getResources();
768        checkValue(res, R.configVarying.simple, "simple sw590 xhdpi");
769        checkValue(res, R.configVarying.sw, "590 xhdpi");
770
771        config.setProperty(Properties.SWIDTH_DP, 591);
772        config.setProperty(Properties.WIDTH_DP, 591);
773        config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_MEDIUM);
774        res = config.getResources();
775        checkValue(res, R.configVarying.simple, "simple sw591");
776        checkValue(res, R.configVarying.sw, "591");
777
778        config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_HIGH);
779        res = config.getResources();
780        checkValue(res, R.configVarying.simple, "simple sw591 hdpi");
781        checkValue(res, R.configVarying.sw, "591 hdpi");
782
783        config.setProperty(Properties.DENSITY, DisplayMetrics.DENSITY_XHIGH);
784        res = config.getResources();
785        checkValue(res, R.configVarying.simple, "simple sw591 hdpi");
786        checkValue(res, R.configVarying.sw, "591 hdpi");
787
788        config = makeClassicConfig();
789        config.setProperty(Properties.SWIDTH_DP, 480);
790        config.setProperty(Properties.WIDTH_DP, 800);
791        config.setProperty(Properties.HEIGHT_DP, 480);
792        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
793        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
794        res = config.getResources();
795        checkValue(res, R.configVarying.simple, "simple w720");
796        checkValue(res, R.configVarying.sw, "default");
797        checkValue(res, R.configVarying.w, "720");
798        checkValue(res, R.configVarying.h, "default");
799        checkValue(res, R.configVarying.wh, "600");
800
801        config = makeClassicConfig();
802        config.setProperty(Properties.SWIDTH_DP, 600);
803        config.setProperty(Properties.WIDTH_DP, 1024);
804        config.setProperty(Properties.HEIGHT_DP, 552);
805        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
806        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
807        res = config.getResources();
808        checkValue(res, R.configVarying.simple, "simple sw600 land");
809        checkValue(res, R.configVarying.sw, "600 land");
810        checkValue(res, R.configVarying.w, "720");
811        checkValue(res, R.configVarying.h, "550");
812        checkValue(res, R.configVarying.wh, "600-550");
813
814        config = makeClassicConfig();
815        config.setProperty(Properties.SWIDTH_DP, 600);
816        config.setProperty(Properties.WIDTH_DP, 600);
817        config.setProperty(Properties.HEIGHT_DP, 974);
818        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_PORTRAIT);
819        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
820        res = config.getResources();
821        checkValue(res, R.configVarying.simple, "simple sw600");
822        checkValue(res, R.configVarying.sw, "600");
823        checkValue(res, R.configVarying.w, "600");
824        checkValue(res, R.configVarying.h, "670");
825        checkValue(res, R.configVarying.wh, "600-550");
826
827        config = makeClassicConfig();
828        config.setProperty(Properties.SWIDTH_DP, 719);
829        config.setProperty(Properties.WIDTH_DP, 1279);
830        config.setProperty(Properties.HEIGHT_DP, 669);
831        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
832        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE);
833        res = config.getResources();
834        checkValue(res, R.configVarying.simple, "simple sw600 land");
835        checkValue(res, R.configVarying.sw, "600 land");
836        checkValue(res, R.configVarying.w, "720");
837        checkValue(res, R.configVarying.h, "550");
838        checkValue(res, R.configVarying.wh, "600-550");
839
840        config = makeClassicConfig();
841        config.setProperty(Properties.SWIDTH_DP, 800);
842        config.setProperty(Properties.WIDTH_DP, 1280);
843        config.setProperty(Properties.HEIGHT_DP, 672);
844        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
845        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE);
846        res = config.getResources();
847        checkValue(res, R.configVarying.simple, "simple sw720");
848        checkValue(res, R.configVarying.sw, "720");
849        checkValue(res, R.configVarying.w, "720");
850        checkValue(res, R.configVarying.h, "670");
851        checkValue(res, R.configVarying.wh, "720-670");
852
853        config = makeClassicConfig();
854        config.setProperty(Properties.SWIDTH_DP, 800);
855        config.setProperty(Properties.WIDTH_DP, 720);
856        config.setProperty(Properties.HEIGHT_DP, 1230);
857        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_PORTRAIT);
858        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE);
859        res = config.getResources();
860        checkValue(res, R.configVarying.simple, "simple sw720");
861        checkValue(res, R.configVarying.sw, "720");
862        checkValue(res, R.configVarying.w, "720");
863        checkValue(res, R.configVarying.h, "670");
864        checkValue(res, R.configVarying.wh, "720-670");
865    }
866
867// TODO - add tests for special cases - ie, other key params seem ignored if
868// nokeys is set
869
870    @MediumTest
871    public void testPrecidence() {
872        /**
873         * Check for precidence of resources selected when there are multiple
874         * options matching the current config.
875         */
876        TotalConfig config = makeEmptyConfig();
877        config.setProperty(Properties.HEIGHT, 640);
878        config.setProperty(Properties.WIDTH, 400);
879        Resources res = config.getResources();
880        checkValue(res, R.configVarying.simple, "simple 640x400");
881        checkValue(res, R.configVarying.bag,
882                R.styleable.TestConfig, new String[]{"bag 640x400"});
883
884        config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV);
885        res = config.getResources();
886        checkValue(res, R.configVarying.simple, "simple nonav");
887        checkValue(res, R.configVarying.bag,
888                R.styleable.TestConfig, new String[]{"bag nonav"});
889
890        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS);
891        res = config.getResources();
892        checkValue(res, R.configVarying.simple, "simple nokeys");
893        checkValue(res, R.configVarying.bag,
894                R.styleable.TestConfig, new String[]{"bag nokeys"});
895
896        config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO);
897        res = config.getResources();
898        checkValue(res, R.configVarying.simple, "simple keysexposed");
899        checkValue(res, R.configVarying.bag,
900                R.styleable.TestConfig, new String[]{"bag keysexposed"});
901
902        config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH);
903        res = config.getResources();
904        checkValue(res, R.configVarying.simple, "simple notouch");
905        checkValue(res, R.configVarying.bag,
906                R.styleable.TestConfig, new String[]{"bag notouch"});
907
908        config.setProperty(Properties.DENSITY, 240);
909        res = config.getResources();
910        checkValue(res, R.configVarying.simple, "simple 240dpi");
911        checkValue(res, R.configVarying.bag,
912                R.styleable.TestConfig, new String[]{"bag 240dpi"});
913
914        config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE);
915        res = config.getResources();
916        checkValue(res, R.configVarying.simple, "simple landscape");
917        checkValue(res, R.configVarying.bag,
918                R.styleable.TestConfig, new String[]{"bag landscape"});
919
920        config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE);
921        res = config.getResources();
922        checkValue(res, R.configVarying.simple, "simple xlarge");
923        checkValue(res, R.configVarying.bag,
924                R.styleable.TestConfig, new String[]{"bag xlarge"});
925
926        config.setProperty(Properties.HEIGHT_DP, 670);
927        res = config.getResources();
928        checkValue(res, R.configVarying.simple, "simple h670");
929        checkValue(res, R.configVarying.bag,
930                R.styleable.TestConfig, new String[]{"bag h670"});
931
932        config.setProperty(Properties.WIDTH_DP, 720);
933        res = config.getResources();
934        checkValue(res, R.configVarying.simple, "simple 720-670");
935        checkValue(res, R.configVarying.bag,
936                R.styleable.TestConfig, new String[]{"bag 720-670"});
937
938        config.setProperty(Properties.SWIDTH_DP, 720);
939        res = config.getResources();
940        checkValue(res, R.configVarying.simple, "simple sw720");
941        checkValue(res, R.configVarying.bag,
942                R.styleable.TestConfig, new String[]{"bag sw720"});
943
944        config.setProperty(Properties.LANGUAGE, "xx");
945        config.setProperty(Properties.COUNTRY, "YY");
946        res = config.getResources();
947        checkValue(res, R.configVarying.simple, "simple xx-rYY");
948        checkValue(res, R.configVarying.bag,
949                R.styleable.TestConfig, new String[]{"bag xx-rYY"});
950
951        config.setProperty(Properties.MCC, 111);
952        res = config.getResources();
953        checkValue(res, R.configVarying.simple, "simple mcc111 xx-rYY");
954        checkValue(res, R.configVarying.bag,
955                R.styleable.TestConfig, new String[]{"bag mcc111 xx-rYY"});
956
957        config.setProperty(Properties.MNC, 222);
958        res = config.getResources();
959        checkValue(res, R.configVarying.simple, "simple mcc111 mnc222");
960        checkValue(res, R.configVarying.bag,
961                R.styleable.TestConfig, new String[]{"bag mcc111 mnc222"});
962    }
963
964    @MediumTest
965    public void testCombinations() {
966        /**
967         * Verify that in cases of ties, the specific ordering is followed
968         */
969
970        /**
971         * Precidence order: mcc, mnc, locale, swdp, wdp, hdp, screenlayout-size,
972         * screenlayout-long, orientation, density,
973         * touchscreen, hidden, keyboard, navigation, width-height
974         */
975
976        /**
977         * verify mcc trumps mnc.  Have 110-xx, 220-xx but no 110-220
978         * so which is selected?  Should be mcc110-xx.
979         */
980        TotalConfig config = makeClassicConfig();
981        config.setProperty(Properties.MCC, 110);
982        config.setProperty(Properties.MNC, 220);
983        config.setProperty(Properties.LANGUAGE, "xx");
984        Resources res = config.getResources();
985        checkValue(res, R.configVarying.simple, "simple mcc110 xx");
986        checkValue(res, R.configVarying.bag,
987                R.styleable.TestConfig, new String[]{"bag mcc110 xx"});
988
989        /* full A + B + C doesn't exist.  Do we get A + C or B + C?
990         */
991        config = makeClassicConfig();
992        config.setProperty(Properties.MCC, 111);
993        config.setProperty(Properties.MNC, 222);
994        config.setProperty(Properties.LANGUAGE, "xx");
995        res = config.getResources();
996        checkValue(res, R.configVarying.simple, "simple mcc111 mnc222");
997        checkValue(res, R.configVarying.bag,
998                R.styleable.TestConfig, new String[]{"bag mcc111 mnc222"});
999
1000        config = makeClassicConfig();
1001        config.setProperty(Properties.MNC, 222);
1002        config.setProperty(Properties.LANGUAGE, "xx");
1003        config.setProperty(Properties.ORIENTATION,
1004                Configuration.ORIENTATION_SQUARE);
1005        res = config.getResources();
1006        checkValue(res, R.configVarying.simple, "simple mnc222 xx");
1007        checkValue(res, R.configVarying.bag,
1008                R.styleable.TestConfig, new String[]{"bag mnc222 xx"});
1009
1010        config = makeClassicConfig();
1011        config.setProperty(Properties.LANGUAGE, "xx");
1012        config.setProperty(Properties.ORIENTATION,
1013                Configuration.ORIENTATION_SQUARE);
1014        config.setProperty(Properties.DENSITY, 32);
1015        res = config.getResources();
1016        checkValue(res, R.configVarying.simple, "simple xx square");
1017        checkValue(res, R.configVarying.bag,
1018                R.styleable.TestConfig, new String[]{"bag xx square"});
1019
1020        /**
1021         * Verify that proper strings are found for multiple-selectivity case
1022         * (ie, a string set for locale and mcc is found only when both are
1023         * true).
1024         */
1025        config = makeClassicConfig();
1026        config.setProperty(Properties.LANGUAGE, "xx");
1027        config.setProperty(Properties.COUNTRY, "YY");
1028        config.setProperty(Properties.MCC, 111);
1029        res = config.getResources();
1030        checkValue(res, R.configVarying.simple, "simple mcc111 xx-rYY");
1031        checkValue(res, R.configVarying.bag, R.styleable.TestConfig,
1032                new String[] { "bag mcc111 xx-rYY" });
1033
1034        config = makeClassicConfig();
1035        config.setProperty(Properties.LANGUAGE, "xx");
1036        config.setProperty(Properties.COUNTRY, "YY");
1037        config.setProperty(Properties.MCC, 333);
1038        res = config.getResources();
1039        checkValue(res, R.configVarying.simple, "simple xx-rYY");
1040        checkValue(res, R.configVarying.bag,
1041                R.styleable.TestConfig, new String[] { "bag xx-rYY" });
1042
1043        config = makeClassicConfig();
1044        config.setProperty(Properties.MNC, 333);
1045        res = config.getResources();
1046        checkValue(res, R.configVarying.simple, "simple default");
1047        checkValue(res, R.configVarying.bag,
1048                R.styleable.TestConfig, new String[]{"bag default"});
1049
1050        config = makeClassicConfig();
1051        config.setProperty(Properties.ORIENTATION,
1052                Configuration.ORIENTATION_SQUARE);
1053        config.setProperty(Properties.DENSITY, 32);
1054        config.setProperty(Properties.TOUCHSCREEN,
1055                Configuration.TOUCHSCREEN_STYLUS);
1056        res = config.getResources();
1057        checkValue(res, R.configVarying.simple, "simple square 32dpi");
1058        checkValue(res, R.configVarying.bag,
1059                R.styleable.TestConfig, new String[]{"bag square 32dpi"});
1060
1061        config = makeClassicConfig();
1062        config.setProperty(Properties.DENSITY, 32);
1063        config.setProperty(Properties.TOUCHSCREEN,
1064                Configuration.TOUCHSCREEN_STYLUS);
1065        config.setProperty(Properties.KEYBOARDHIDDEN,
1066                Configuration.KEYBOARDHIDDEN_NO);
1067        res = config.getResources();
1068        checkValue(res, R.configVarying.simple, "simple 32dpi stylus");
1069        checkValue(res, R.configVarying.bag,
1070                R.styleable.TestConfig, new String[]{"bag 32dpi stylus"});
1071
1072        config = makeClassicConfig();
1073        config.setProperty(Properties.TOUCHSCREEN,
1074                Configuration.TOUCHSCREEN_STYLUS);
1075        config.setProperty(Properties.KEYBOARDHIDDEN,
1076                Configuration.KEYBOARDHIDDEN_NO);
1077        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
1078        res = config.getResources();
1079        checkValue(res, R.configVarying.simple, "simple stylus keysexposed");
1080        checkValue(res, R.configVarying.bag,
1081                R.styleable.TestConfig, new String[]{"bag stylus keysexposed"});
1082
1083        config = makeClassicConfig();
1084        config.setProperty(Properties.KEYBOARDHIDDEN,
1085                Configuration.KEYBOARDHIDDEN_NO);
1086        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
1087        config.setProperty(Properties.NAVIGATION,
1088                Configuration.NAVIGATION_DPAD);
1089        res = config.getResources();
1090        checkValue(res, R.configVarying.simple, "simple keysexposed 12key");
1091        checkValue(res, R.configVarying.bag,
1092                R.styleable.TestConfig, new String[]{"bag keysexposed 12key"});
1093
1094        config = makeClassicConfig();
1095        config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY);
1096        config.setProperty(Properties.NAVIGATION,
1097                Configuration.NAVIGATION_DPAD);
1098        config.setProperty(Properties.HEIGHT, 63);
1099        config.setProperty(Properties.WIDTH, 57);
1100        res = config.getResources();
1101        checkValue(res, R.configVarying.simple, "simple 12key dpad");
1102        checkValue(res, R.configVarying.bag,
1103                R.styleable.TestConfig, new String[]{"bag 12key dpad"});
1104
1105        config = makeClassicConfig();
1106        config.setProperty(Properties.NAVIGATION,
1107                Configuration.NAVIGATION_DPAD);
1108        config.setProperty(Properties.HEIGHT, 640);
1109        config.setProperty(Properties.WIDTH, 400);
1110        res = config.getResources();
1111        checkValue(res, R.configVarying.simple, "simple dpad 63x57");
1112        checkValue(res, R.configVarying.bag,
1113                R.styleable.TestConfig, new String[]{"bag dpad 63x57"});
1114    }
1115
1116    @MediumTest
1117    public void testVersions() {
1118        // Check that we get the most recent resources that are <= our
1119        // current version.  Note the special version adjustment, so that
1120        // during development the resource version is incremented to the
1121        // next one.
1122        int vers = android.os.Build.VERSION.SDK_INT;
1123        if (!"REL".equals(android.os.Build.VERSION.CODENAME)) {
1124            vers++;
1125        }
1126        String expected = "v" + vers + "cur";
1127        assertEquals(expected, mContext.getResources().getString(R.string.version_cur));
1128        assertEquals("base",  mContext.getResources().getString(R.string.version_old));
1129        assertEquals("v3",  mContext.getResources().getString(R.string.version_v3));
1130    }
1131}
1132