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