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