public static Qualifiers parse(String qualifiers, boolean applyVersionForCompat) { final ResTable_config config = new ResTable_config(); if (!qualifiers.isEmpty() && !ConfigDescription.parse(qualifiers, config, applyVersionForCompat)) { throw new IllegalArgumentException("failed to parse qualifiers '" + qualifiers + "'." + " See https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules for expected format."); } return new Qualifiers(qualifiers, config); }
private static ResTable_config from(String qualifiers) { ResTable_config config = new ResTable_config(); if (!Strings.isNullOrEmpty(qualifiers) && !ConfigDescription.parse(qualifiers, config, false)) { throw new IllegalArgumentException("Invalid qualifiers \"" + qualifiers + "\""); } return config; } }
@Test public void parse_layoutDirection_rightToLeft() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("ldrtl", config); assertThat(config.screenLayout).isEqualTo(LAYOUTDIR_RTL); }
@Test public void parse_screenSize_large() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("large", config); assertThat(config.screenLayout).isEqualTo(SCREENSIZE_LARGE); }
@Test public void parse_screenLayoutLong_notlong() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("notlong", config); assertThat(config.screenLayout).isEqualTo(SCREENLONG_NO); }
@Test public void parse_orientation_port() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("port", config); assertThat(config.orientation).isEqualTo(ORIENTATION_PORT); }
@Test public void parse_uiModeType_television() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("television", config); assertThat(config.uiMode).isEqualTo(UI_MODE_TYPE_TELEVISION); }
@Test public void parse_density_xxhdpi() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("xxhdpi", config); assertThat(config.density).isEqualTo(DENSITY_XXHIGH); }
@Test public void parse_keysHidden_keysexposed() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("keysexposed", config); assertThat(config.inputFlags).isEqualTo(KEYSHIDDEN_NO); }
@Test public void parse_keyboard_qwerty() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("qwerty", config); assertThat(config.keyboard).isEqualTo(KEYBOARD_QWERTY); }
@Test public void parse_navigation_dpad() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("dpad", config); assertThat(config.navigation).isEqualTo(NAVIGATION_DPAD); }
@Test public void parse_screenSize_small() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("small", config); assertThat(config.screenLayout).isEqualTo(SCREENSIZE_SMALL); }
@Test public void parse_screenSize_normal() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("normal", config); assertThat(config.screenLayout).isEqualTo(SCREENSIZE_NORMAL); }
@Test public void shouldReturnRawResourcesWithExtensions() throws Exception { String f = (String) resourceTable.getValue(R.raw.raw_resource, new ResTable_config()).getData(); assertThat(f) .isEqualTo( TestUtil.testResources() .getResourceBase() .resolve("raw") .resolve("raw_resource.txt") .toString()); }
@Test public void shouldReturnRawResourcesWithoutExtensions() throws Exception { String f = (String) resourceTable.getValue(R.raw.raw_no_ext, new ResTable_config()).getData(); assertThat(f) .isEqualTo( TestUtil.testResources() .getResourceBase() .resolve("raw") .resolve("raw_no_ext") .toString()); } }
@Test public void parse_languageAndRegion() { ResTable_config config = new ResTable_config(); ConfigDescription.parse("fr-rFR", config); assertThat(config.languageString()).isEqualTo("fr"); assertThat(config.regionString()).isEqualTo("FR"); }
@Before public void setUp() { ResourceTableFactory resourceTableFactory = new ResourceTableFactory(); resourceTable = resourceTableFactory.newResourceTable("org.robolectric", testResources()); config = new ResTable_config(); }
@Test public void testStyleDataIsLoadedCorrectly() throws Exception { TypedResource typedResource = resourceTable.getValue(new ResName("android", "style", "Theme_Holo"), new ResTable_config()); StyleData styleData = (StyleData) typedResource.getData(); assertThat(styleData.getName()).isEqualTo("Theme_Holo"); assertThat(styleData.getParent()).isEqualTo("Theme"); assertThat(styleData.getPackageName()).isEqualTo("android"); assertThat(styleData.getAttrValue(new ResName("android", "attr", "colorForeground")).value) .isEqualTo("@android:color/bright_foreground_holo_dark"); } }
@Test public void shouldFindDrawableResources() throws Exception { Path testBaseDir = temporaryFolder.newFolder("res").toPath(); temporaryFolder.newFolder("res", "drawable"); temporaryFolder.newFile("res/drawable/foo.png"); ResourcePath resourcePath = new ResourcePath(null, testBaseDir, null); DrawableResourceLoader testLoader = new DrawableResourceLoader(resourceTable); testLoader.findDrawableResources(resourcePath); assertThat(resourceTable.getValue(new ResName("org.robolectric", "drawable", "foo"), new ResTable_config()).isFile()).isTrue(); } }
@Test public void ignoresXliffTags() throws Exception { topLevelNodeHandler.addHandler("resources", new NodeHandler() .addHandler("string", new StaxValueLoader(resourceTable, "string", ResType.CHAR_SEQUENCE)) ); parse("<resources xmlns:xliff=\"urn:oasis:names:tc:xliff:document:1.2\">" + "<string name=\"preposition_for_date\">on <xliff:g id=\"date\" example=\"May 29\">%s</xliff:g></string>" + "</resources>"); assertThat(resourceTable.getValue(new ResName("pkg:string/preposition_for_date"), new ResTable_config()).getData()) .isEqualTo("on %s"); }