ConfigTest.java revision 9e357fa63f60e01c61fc11ce304398233b779558
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; 30 31import com.android.cts.stub.R; 32 33public class ConfigTest extends AndroidTestCase { 34 enum Properties { 35 LANGUAGE, 36 COUNTRY, 37 MCC, 38 MNC, 39 TOUCHSCREEN, 40 KEYBOARD, 41 KEYBOARDHIDDEN, 42 NAVIGATION, 43 ORIENTATION, 44 WIDTH, 45 HEIGHT, 46 DENSITY, 47 SCREENLAYOUT 48 } 49 50 private static void checkValue(final Resources res, final int resId, 51 final String expectedValue) { 52 try { 53 final String actual = res.getString(resId); 54 assertNotNull("Returned wrong configuration-based simple value: expected <nothing>, " 55 + "got '" + actual + "' from resource 0x" + Integer.toHexString(resId), 56 expectedValue); 57 assertEquals("Returned wrong configuration-based simple value: expected '" 58 + expectedValue + "', got '" + actual + "' from resource 0x" 59 + Integer.toHexString(resId), expectedValue, actual); 60 } catch (NotFoundException e) { 61 assertNull("Resource not found for configuration-based simple value: expecting \"" 62 + expectedValue + "\"", expectedValue); 63 } 64 } 65 66 private static void checkValue(final Resources res, final int resId, 67 final int[] styleable, final String[] expectedValues) { 68 final Resources.Theme theme = res.newTheme(); 69 final TypedArray sa = theme.obtainStyledAttributes(resId, styleable); 70 for (int i = 0; i < styleable.length; i++) { 71 final String actual = sa.getString(i); 72 assertEquals("Returned wrong configuration-based style value: expected '" 73 + expectedValues[i] + "', got '" + actual + "' from attr " 74 + i + " of resource 0x" + Integer.toHexString(resId), 75 actual, expectedValues[i]); 76 } 77 sa.recycle(); 78 } 79 80 private class TotalConfig { 81 private Configuration mConfig; 82 private DisplayMetrics mMetrics; 83 84 public TotalConfig() { 85 mConfig = new Configuration(); 86 // don't rely on build settings - they may change 87 mConfig.locale = new Locale("en", "US"); 88 mConfig.mcc = 310; 89 mConfig.mnc = 001; // unused 90 mConfig.touchscreen = Configuration.TOUCHSCREEN_FINGER; 91 mConfig.keyboard = Configuration.KEYBOARD_QWERTY; 92 mConfig.keyboardHidden = Configuration.KEYBOARDHIDDEN_YES; 93 mConfig.navigation = Configuration.NAVIGATION_TRACKBALL; 94 mConfig.orientation = Configuration.ORIENTATION_PORTRAIT; 95 96 mMetrics = new DisplayMetrics(); 97 mMetrics.widthPixels = 200; 98 mMetrics.heightPixels = 320; 99 mMetrics.density = 1; 100 } 101 102 public void setProperty(final Properties p, final int value) { 103 switch(p) { 104 case MCC: 105 mConfig.mcc = value; 106 break; 107 case MNC: 108 mConfig.mnc = value; 109 break; 110 case TOUCHSCREEN: 111 mConfig.touchscreen = value; 112 break; 113 case KEYBOARD: 114 mConfig.keyboard = value; 115 break; 116 case KEYBOARDHIDDEN: 117 mConfig.keyboardHidden = value; 118 break; 119 case NAVIGATION: 120 mConfig.navigation = value; 121 break; 122 case ORIENTATION: 123 mConfig.orientation = value; 124 break; 125 case WIDTH: 126 mMetrics.widthPixels = value; 127 break; 128 case HEIGHT: 129 mMetrics.heightPixels = value; 130 break; 131 case DENSITY: 132 // this is the ratio from the standard 133 mMetrics.density = (((float)value)/((float)DisplayMetrics.DENSITY_DEFAULT)); 134 break; 135 case SCREENLAYOUT: 136 mConfig.screenLayout = value; 137 break; 138 default: 139 assert(false); 140 break; 141 } 142 } 143 144 public void setProperty(final Properties p, final String value) { 145 switch(p) { 146 case LANGUAGE: 147 final String oldCountry = mConfig.locale.getCountry(); 148 mConfig.locale = new Locale(value, oldCountry); 149 break; 150 case COUNTRY: 151 final String oldLanguage = mConfig.locale.getLanguage(); 152 mConfig.locale = new Locale(oldLanguage, value); 153 break; 154 default: 155 assert(false); 156 break; 157 } 158 } 159 160 public Resources getResources() { 161 final AssetManager assmgr = new AssetManager(); 162 assmgr.addAssetPath(mContext.getPackageResourcePath()); 163 return new Resources(assmgr, mMetrics, mConfig); 164 } 165 } 166 167 private static void checkPair(Resources res, int[] notResIds, 168 int simpleRes, String simpleString, 169 int bagRes, String bagString) { 170 boolean willHave = true; 171 if (notResIds != null) { 172 for (int i : notResIds) { 173 if (i == simpleRes) { 174 willHave = false; 175 break; 176 } 177 } 178 } 179 checkValue(res, simpleRes, willHave ? simpleString : null); 180 checkValue(res, bagRes, R.styleable.TestConfig, 181 new String[]{willHave ? bagString : null}); 182 } 183 184 @SmallTest 185 public void testAllConfigs() { 186 /** 187 * Test a resource that contains a value for each possible single 188 * configuration value. 189 */ 190 TotalConfig config = new TotalConfig(); 191 Resources res = config.getResources(); 192 checkValue(res, R.configVarying.simple, "simple default"); 193 checkValue(res, R.configVarying.bag, 194 R.styleable.TestConfig, new String[]{"bag default"}); 195 196 config = new TotalConfig(); 197 config.setProperty(Properties.LANGUAGE, "xx"); 198 res = config.getResources(); 199 checkValue(res, R.configVarying.simple, "simple xx"); 200 checkValue(res, R.configVarying.bag, 201 R.styleable.TestConfig, new String[]{"bag xx"}); 202 203 config = new TotalConfig(); 204 config.setProperty(Properties.LANGUAGE, "xx"); 205 config.setProperty(Properties.COUNTRY, "YY"); 206 res = config.getResources(); 207 checkValue(res, R.configVarying.simple, "simple xx-rYY"); 208 checkValue(res, R.configVarying.bag, 209 R.styleable.TestConfig, new String[]{"bag xx-rYY"}); 210 211 config = new TotalConfig(); 212 config.setProperty(Properties.MCC, 111); 213 res = config.getResources(); 214 checkValue(res, R.configVarying.simple, "simple mcc111"); 215 checkValue(res, R.configVarying.bag, 216 R.styleable.TestConfig, new String[]{"bag mcc111"}); 217 218 config = new TotalConfig(); 219 config.setProperty(Properties.MNC, 222); 220 res = config.getResources(); 221 checkValue(res, R.configVarying.simple, "simple mnc222"); 222 checkValue(res, R.configVarying.bag, 223 R.styleable.TestConfig, new String[]{"bag mnc222"}); 224 225 config = new TotalConfig(); 226 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_NOTOUCH); 227 res = config.getResources(); 228 checkValue(res, R.configVarying.simple, "simple notouch"); 229 checkValue(res, R.configVarying.bag, 230 R.styleable.TestConfig, new String[]{"bag notouch"}); 231 232 config = new TotalConfig(); 233 config.setProperty(Properties.TOUCHSCREEN, Configuration.TOUCHSCREEN_STYLUS); 234 res = config.getResources(); 235 checkValue(res, R.configVarying.simple, "simple stylus"); 236 checkValue(res, R.configVarying.bag, 237 R.styleable.TestConfig, new String[]{"bag stylus"}); 238 239 config = new TotalConfig(); 240 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_NOKEYS); 241 res = config.getResources(); 242 checkValue(res, R.configVarying.simple, "simple nokeys"); 243 checkValue(res, R.configVarying.bag, 244 R.styleable.TestConfig, new String[]{"bag nokeys"}); 245 246 config = new TotalConfig(); 247 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 248 res = config.getResources(); 249 checkValue(res, R.configVarying.simple, "simple 12key"); 250 checkValue(res, R.configVarying.bag, 251 R.styleable.TestConfig, new String[]{"bag 12key"}); 252 253 config = new TotalConfig(); 254 config.setProperty(Properties.KEYBOARDHIDDEN, Configuration.KEYBOARDHIDDEN_NO); 255 res = config.getResources(); 256 checkValue(res, R.configVarying.simple, "simple keysexposed"); 257 checkValue(res, R.configVarying.bag, 258 R.styleable.TestConfig, new String[]{"bag keysexposed"}); 259 260 config = new TotalConfig(); 261 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_NONAV); 262 res = config.getResources(); 263 checkValue(res, R.configVarying.simple, "simple nonav"); 264 checkValue(res, R.configVarying.bag, 265 R.styleable.TestConfig, new String[]{"bag nonav"}); 266 267 config = new TotalConfig(); 268 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_DPAD); 269 res = config.getResources(); 270 checkValue(res, R.configVarying.simple, "simple dpad"); 271 checkValue(res, R.configVarying.bag, 272 R.styleable.TestConfig, new String[]{"bag dpad"}); 273 274 config = new TotalConfig(); 275 config.setProperty(Properties.NAVIGATION, Configuration.NAVIGATION_WHEEL); 276 res = config.getResources(); 277 checkValue(res, R.configVarying.simple, "simple wheel"); 278 checkValue(res, R.configVarying.bag, 279 R.styleable.TestConfig, new String[]{"bag wheel"}); 280 281 config = new TotalConfig(); 282 config.setProperty(Properties.HEIGHT, 480); 283 config.setProperty(Properties.WIDTH, 320); 284 res = config.getResources(); 285 checkValue(res, R.configVarying.simple, "simple 480x320"); 286 checkValue(res, R.configVarying.bag, 287 R.styleable.TestConfig, new String[]{"bag 480x320"}); 288 289 config = new TotalConfig(); 290 config.setProperty(Properties.DENSITY, 240); 291 res = config.getResources(); 292 checkValue(res, R.configVarying.simple, "simple 240dpi"); 293 checkValue(res, R.configVarying.bag, 294 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 295 296 config = new TotalConfig(); 297 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_LANDSCAPE); 298 res = config.getResources(); 299 checkValue(res, R.configVarying.simple, "simple landscape"); 300 checkValue(res, R.configVarying.bag, 301 R.styleable.TestConfig, new String[]{"bag landscape"}); 302 303 config = new TotalConfig(); 304 config.setProperty(Properties.ORIENTATION, Configuration.ORIENTATION_SQUARE); 305 res = config.getResources(); 306 checkValue(res, R.configVarying.simple, "simple square"); 307 checkValue(res, R.configVarying.bag, 308 R.styleable.TestConfig, new String[]{"bag square"}); 309 310 config = new TotalConfig(); 311 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL); 312 res = config.getResources(); 313 checkValue(res, R.configVarying.simple, "simple small"); 314 checkValue(res, R.configVarying.bag, 315 R.styleable.TestConfig, new String[]{"bag small"}); 316 317 config = new TotalConfig(); 318 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL); 319 res = config.getResources(); 320 checkValue(res, R.configVarying.simple, "simple normal"); 321 checkValue(res, R.configVarying.bag, 322 R.styleable.TestConfig, new String[]{"bag normal"}); 323 324 config = new TotalConfig(); 325 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 326 res = config.getResources(); 327 checkValue(res, R.configVarying.simple, "simple large"); 328 checkValue(res, R.configVarying.bag, 329 R.styleable.TestConfig, new String[]{"bag large"}); 330 331 config = new TotalConfig(); 332 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 333 res = config.getResources(); 334 checkValue(res, R.configVarying.simple, "simple xlarge"); 335 checkValue(res, R.configVarying.bag, 336 R.styleable.TestConfig, new String[]{"bag xlarge"}); 337 } 338 339 @MediumTest 340 public void testDensity() throws Exception { 341 // have 32, 240 and the default 160 content. 342 // rule is that closest wins, with down scaling (larger content) 343 // being twice as nice as upscaling. 344 // transition at H/2 * (-1 +/- sqrt(1+8L/H)) 345 // SO, X < 49 goes to 32 346 // 49 >= X < 182 goes to 160 347 // X >= 182 goes to 240 348 TotalConfig config = new TotalConfig(); 349 config.setProperty(Properties.DENSITY, 2); 350 Resources res = config.getResources(); 351 checkValue(res, R.configVarying.simple, "simple 32dpi"); 352 checkValue(res, R.configVarying.bag, 353 R.styleable.TestConfig, new String[]{"bag 32dpi"}); 354 355 config = new TotalConfig(); 356 config.setProperty(Properties.DENSITY, 32); 357 res = config.getResources(); 358 checkValue(res, R.configVarying.simple, "simple 32dpi"); 359 checkValue(res, R.configVarying.bag, 360 R.styleable.TestConfig, new String[]{"bag 32dpi"}); 361 362 config = new TotalConfig(); 363 config.setProperty(Properties.DENSITY, 48); 364 res = config.getResources(); 365 checkValue(res, R.configVarying.simple, "simple 32dpi"); 366 checkValue(res, R.configVarying.bag, 367 R.styleable.TestConfig, new String[]{"bag 32dpi"}); 368 369 config = new TotalConfig(); 370 config.setProperty(Properties.DENSITY, 49); 371 res = config.getResources(); 372 checkValue(res, R.configVarying.simple, "simple default"); 373 checkValue(res, R.configVarying.bag, 374 R.styleable.TestConfig, new String[]{"bag default"}); 375 376 config = new TotalConfig(); 377 config.setProperty(Properties.DENSITY, 150); 378 res = config.getResources(); 379 checkValue(res, R.configVarying.simple, "simple default"); 380 checkValue(res, R.configVarying.bag, 381 R.styleable.TestConfig, new String[]{"bag default"}); 382 383 config = new TotalConfig(); 384 config.setProperty(Properties.DENSITY, 181); 385 res = config.getResources(); 386 checkValue(res, R.configVarying.simple, "simple default"); 387 checkValue(res, R.configVarying.bag, 388 R.styleable.TestConfig, new String[]{"bag default"}); 389 390 config = new TotalConfig(); 391 config.setProperty(Properties.DENSITY, 182); 392 res = config.getResources(); 393 checkValue(res, R.configVarying.simple, "simple 240dpi"); 394 checkValue(res, R.configVarying.bag, 395 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 396 397 config = new TotalConfig(); 398 config.setProperty(Properties.DENSITY, 239); 399 res = config.getResources(); 400 checkValue(res, R.configVarying.simple, "simple 240dpi"); 401 checkValue(res, R.configVarying.bag, 402 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 403 404 config = new TotalConfig(); 405 config.setProperty(Properties.DENSITY, 490); 406 res = config.getResources(); 407 checkValue(res, R.configVarying.simple, "simple 240dpi"); 408 checkValue(res, R.configVarying.bag, 409 R.styleable.TestConfig, new String[]{"bag 240dpi"}); 410 } 411 412 @MediumTest 413 public void testScreenSize() throws Exception { 414 // ensure that we fall back to the best available screen size 415 // for a given configuration. 416 TotalConfig config = new TotalConfig(); 417 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_SMALL); 418 Resources res = config.getResources(); 419 checkValue(res, R.configVarying.simple, "simple small"); 420 checkValue(res, R.configVarying.small, "small"); 421 checkValue(res, R.configVarying.normal, "default"); 422 checkValue(res, R.configVarying.large, "default"); 423 checkValue(res, R.configVarying.xlarge, "default"); 424 425 config = new TotalConfig(); 426 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_NORMAL); 427 res = config.getResources(); 428 checkValue(res, R.configVarying.simple, "simple normal"); 429 checkValue(res, R.configVarying.small, "default"); 430 checkValue(res, R.configVarying.normal, "normal"); 431 checkValue(res, R.configVarying.large, "default"); 432 checkValue(res, R.configVarying.xlarge, "default"); 433 434 config = new TotalConfig(); 435 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_LARGE); 436 res = config.getResources(); 437 checkValue(res, R.configVarying.simple, "simple large"); 438 checkValue(res, R.configVarying.small, "default"); 439 checkValue(res, R.configVarying.normal, "normal"); 440 checkValue(res, R.configVarying.large, "large"); 441 checkValue(res, R.configVarying.xlarge, "default"); 442 443 config = new TotalConfig(); 444 config.setProperty(Properties.SCREENLAYOUT, Configuration.SCREENLAYOUT_SIZE_XLARGE); 445 res = config.getResources(); 446 checkValue(res, R.configVarying.simple, "simple xlarge"); 447 checkValue(res, R.configVarying.small, "default"); 448 checkValue(res, R.configVarying.normal, "normal"); 449 checkValue(res, R.configVarying.large, "large"); 450 checkValue(res, R.configVarying.xlarge, "xlarge"); 451 } 452 453// TODO - add tests for special cases - ie, other key params seem ignored if 454// nokeys is set 455 456 @MediumTest 457 public void testCombinations() { 458 /** 459 * Verify that proper strings are found for multiple-selectivity case 460 * (ie, a string set for locale and mcc is found only when both are 461 * true). 462 */ 463 TotalConfig config = new TotalConfig(); 464 config.setProperty(Properties.LANGUAGE, "xx"); 465 config.setProperty(Properties.COUNTRY, "YY"); 466 config.setProperty(Properties.MCC, 111); 467 Resources res = config.getResources(); 468 checkValue(res, R.configVarying.simple, "simple mcc111 xx-rYY"); 469 checkValue(res, R.configVarying.bag, R.styleable.TestConfig, 470 new String[] { "bag mcc111 xx-rYY" }); 471 472 config = new TotalConfig(); 473 config.setProperty(Properties.LANGUAGE, "xx"); 474 config.setProperty(Properties.COUNTRY, "YY"); 475 config.setProperty(Properties.MCC, 333); 476 res = config.getResources(); 477 checkValue(res, R.configVarying.simple, "simple xx-rYY"); 478 checkValue(res, R.configVarying.bag, 479 R.styleable.TestConfig, new String[] { "bag xx-rYY" }); 480 481 config = new TotalConfig(); 482 config.setProperty(Properties.MNC, 333); 483 res = config.getResources(); 484 checkValue(res, R.configVarying.simple, "simple default"); 485 checkValue(res, R.configVarying.bag, 486 R.styleable.TestConfig, new String[]{"bag default"}); 487 } 488 489 @MediumTest 490 public void testPrecidence() { 491 /** 492 * Verify that in cases of ties, the specific ordering is followed 493 */ 494 495 /** 496 * Precidence order: mcc, mnc, locale, screenlayout-size, 497 * screenlayout-long, orientation, density, 498 * touchscreen, hidden, keyboard, navigation, width-height 499 */ 500 501 /** 502 * verify mcc trumps mnc. Have 110-xx, 220-xx but no 110-220 503 * so with is selected? Should be mcc110-xx. 504 */ 505 TotalConfig config = new TotalConfig(); 506 config.setProperty(Properties.MCC, 110); 507 config.setProperty(Properties.MNC, 220); 508 config.setProperty(Properties.LANGUAGE, "xx"); 509 Resources res = config.getResources(); 510 checkValue(res, R.configVarying.simple, "simple mcc110 xx"); 511 checkValue(res, R.configVarying.bag, 512 R.styleable.TestConfig, new String[]{"bag mcc110 xx"}); 513 514 /* full A + B + C doesn't exist. Do we get A + C or B + C? 515 */ 516 config = new TotalConfig(); 517 config.setProperty(Properties.MCC, 111); 518 config.setProperty(Properties.MNC, 222); 519 config.setProperty(Properties.LANGUAGE, "xx"); 520 res = config.getResources(); 521 checkValue(res, R.configVarying.simple, "simple mcc111 mnc222"); 522 checkValue(res, R.configVarying.bag, 523 R.styleable.TestConfig, new String[]{"bag mcc111 mnc222"}); 524 525 config = new TotalConfig(); 526 config.setProperty(Properties.MNC, 222); 527 config.setProperty(Properties.LANGUAGE, "xx"); 528 config.setProperty(Properties.ORIENTATION, 529 Configuration.ORIENTATION_SQUARE); 530 res = config.getResources(); 531 checkValue(res, R.configVarying.simple, "simple mnc222 xx"); 532 checkValue(res, R.configVarying.bag, 533 R.styleable.TestConfig, new String[]{"bag mnc222 xx"}); 534 535 config = new TotalConfig(); 536 config.setProperty(Properties.LANGUAGE, "xx"); 537 config.setProperty(Properties.ORIENTATION, 538 Configuration.ORIENTATION_SQUARE); 539 config.setProperty(Properties.DENSITY, 32); 540 res = config.getResources(); 541 checkValue(res, R.configVarying.simple, "simple xx square"); 542 checkValue(res, R.configVarying.bag, 543 R.styleable.TestConfig, new String[]{"bag xx square"}); 544 545 config = new TotalConfig(); 546 config.setProperty(Properties.ORIENTATION, 547 Configuration.ORIENTATION_SQUARE); 548 config.setProperty(Properties.DENSITY, 32); 549 config.setProperty(Properties.TOUCHSCREEN, 550 Configuration.TOUCHSCREEN_STYLUS); 551 res = config.getResources(); 552 checkValue(res, R.configVarying.simple, "simple square 32dpi"); 553 checkValue(res, R.configVarying.bag, 554 R.styleable.TestConfig, new String[]{"bag square 32dpi"}); 555 556 config = new TotalConfig(); 557 config.setProperty(Properties.DENSITY, 32); 558 config.setProperty(Properties.TOUCHSCREEN, 559 Configuration.TOUCHSCREEN_STYLUS); 560 config.setProperty(Properties.KEYBOARDHIDDEN, 561 Configuration.KEYBOARDHIDDEN_NO); 562 res = config.getResources(); 563 checkValue(res, R.configVarying.simple, "simple 32dpi stylus"); 564 checkValue(res, R.configVarying.bag, 565 R.styleable.TestConfig, new String[]{"bag 32dpi stylus"}); 566 567 config = new TotalConfig(); 568 config.setProperty(Properties.TOUCHSCREEN, 569 Configuration.TOUCHSCREEN_STYLUS); 570 config.setProperty(Properties.KEYBOARDHIDDEN, 571 Configuration.KEYBOARDHIDDEN_NO); 572 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 573 res = config.getResources(); 574 checkValue(res, R.configVarying.simple, "simple stylus keysexposed"); 575 checkValue(res, R.configVarying.bag, 576 R.styleable.TestConfig, new String[]{"bag stylus keysexposed"}); 577 578 config = new TotalConfig(); 579 config.setProperty(Properties.KEYBOARDHIDDEN, 580 Configuration.KEYBOARDHIDDEN_NO); 581 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 582 config.setProperty(Properties.NAVIGATION, 583 Configuration.NAVIGATION_DPAD); 584 res = config.getResources(); 585 checkValue(res, R.configVarying.simple, "simple keysexposed 12key"); 586 checkValue(res, R.configVarying.bag, 587 R.styleable.TestConfig, new String[]{"bag keysexposed 12key"}); 588 589 config = new TotalConfig(); 590 config.setProperty(Properties.KEYBOARD, Configuration.KEYBOARD_12KEY); 591 config.setProperty(Properties.NAVIGATION, 592 Configuration.NAVIGATION_DPAD); 593 config.setProperty(Properties.HEIGHT, 63); 594 config.setProperty(Properties.WIDTH, 57); 595 res = config.getResources(); 596 checkValue(res, R.configVarying.simple, "simple 12key dpad"); 597 checkValue(res, R.configVarying.bag, 598 R.styleable.TestConfig, new String[]{"bag 12key dpad"}); 599 600 config = new TotalConfig(); 601 config.setProperty(Properties.NAVIGATION, 602 Configuration.NAVIGATION_DPAD); 603 config.setProperty(Properties.HEIGHT, 640); 604 config.setProperty(Properties.WIDTH, 400); 605 res = config.getResources(); 606 checkValue(res, R.configVarying.simple, "simple dpad"); 607 checkValue(res, R.configVarying.bag, 608 R.styleable.TestConfig, new String[]{"bag dpad"}); 609 } 610 611 @MediumTest 612 public void testVersions() { 613 // Check that we get the most recent resources that are <= our 614 // current version. Note the special version adjustment, so that 615 // during development the resource version is incremented to the 616 // next one. 617 int vers = android.os.Build.VERSION.SDK_INT; 618 if (!"REL".equals(android.os.Build.VERSION.CODENAME)) { 619 vers++; 620 } 621 String expected = "v" + vers + "cur"; 622 assertEquals(expected, mContext.getResources().getString(R.string.version_cur)); 623 assertEquals("base", mContext.getResources().getString(R.string.version_old)); 624 assertEquals("v3", mContext.getResources().getString(R.string.version_v3)); 625 } 626} 627