use of java.io.StringReader in project platform_frameworks_base by android.
the class FullBackupTest method testparseBackupSchemeFromXml_lotsOfIncludesAndExcludes.
public void testparseBackupSchemeFromXml_lotsOfIncludesAndExcludes() throws Exception {
mXpp.setInput(new StringReader("<full-backup-content>" + "<exclude path=\"exclude1.txt\" domain=\"file\"/>" + "<include path=\"include1.txt\" domain=\"file\"/>" + "<exclude path=\"exclude2.txt\" domain=\"database\"/>" + "<include path=\"include2.txt\" domain=\"database\"/>" + "<exclude path=\"exclude3\" domain=\"sharedpref\"/>" + "<include path=\"include3\" domain=\"sharedpref\"/>" + "<exclude path=\"exclude4.xml\" domain=\"sharedpref\"/>" + "<include path=\"include4.xml\" domain=\"sharedpref\"/>" + "</full-backup-content>"));
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
Set<String> fileDomainIncludes = includeMap.get(FullBackup.FILES_TREE_TOKEN);
assertEquals("Didn't find expected file domain include.", 1, fileDomainIncludes.size());
assertEquals("Invalid path parsed for <include/>", new File(mContext.getFilesDir(), "include1.txt").getCanonicalPath(), fileDomainIncludes.iterator().next());
Set<String> databaseDomainIncludes = includeMap.get(FullBackup.DATABASE_TREE_TOKEN);
// Three expected here because of "-journal" and "-wal" files
assertEquals("Didn't find expected database domain include.", 3, databaseDomainIncludes.size());
assertTrue("Invalid path parsed for <include/>", databaseDomainIncludes.contains(new File(mContext.getDatabasePath("foo").getParentFile(), "include2.txt").getCanonicalPath()));
assertTrue("Invalid path parsed for <include/>", databaseDomainIncludes.contains(new File(mContext.getDatabasePath("foo").getParentFile(), "include2.txt-journal").getCanonicalPath()));
assertTrue("Invalid path parsed for <include/>", databaseDomainIncludes.contains(new File(mContext.getDatabasePath("foo").getParentFile(), "include2.txt-wal").getCanonicalPath()));
List<String> sharedPrefDomainIncludes = new ArrayList<String>(includeMap.get(FullBackup.SHAREDPREFS_TREE_TOKEN));
Collections.sort(sharedPrefDomainIncludes);
assertEquals("Didn't find expected sharedpref domain include.", 3, sharedPrefDomainIncludes.size());
assertEquals("Invalid path parsed for <include/>", new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include3").getCanonicalPath(), sharedPrefDomainIncludes.get(0));
assertEquals("Invalid path parsed for <include/>", new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include3.xml").getCanonicalPath(), sharedPrefDomainIncludes.get(1));
assertEquals("Invalid path parsed for <include/>", new File(mContext.getSharedPrefsFile("foo").getParentFile(), "include4.xml").getCanonicalPath(), sharedPrefDomainIncludes.get(2));
assertEquals("Unexpected number of <exclude/>s", 7, excludesSet.size());
// Sets are annoying to iterate over b/c order isn't enforced - convert to an array and
// sort lexicographically.
List<String> arrayedSet = new ArrayList<String>(excludesSet);
Collections.sort(arrayedSet);
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getDatabasePath("foo").getParentFile(), "exclude2.txt").getCanonicalPath(), arrayedSet.get(0));
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getDatabasePath("foo").getParentFile(), "exclude2.txt-journal").getCanonicalPath(), arrayedSet.get(1));
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getDatabasePath("foo").getParentFile(), "exclude2.txt-wal").getCanonicalPath(), arrayedSet.get(2));
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getFilesDir(), "exclude1.txt").getCanonicalPath(), arrayedSet.get(3));
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude3").getCanonicalPath(), arrayedSet.get(4));
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude3.xml").getCanonicalPath(), arrayedSet.get(5));
assertEquals("Invalid path parsed for <exclude/>", new File(mContext.getSharedPrefsFile("foo").getParentFile(), "exclude4.xml").getCanonicalPath(), arrayedSet.get(6));
}
use of java.io.StringReader in project platform_frameworks_base by android.
the class FullBackupTest method testDoubleSlashInPath_isIgnored.
public void testDoubleSlashInPath_isIgnored() throws Exception {
mXpp.setInput(new StringReader("<full-backup-content>" + // Invalid use of "//"
"<exclude path=\"//hello.txt\" domain=\"file\"/>" + "</full-backup-content>"));
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
assertEquals("Didn't throw away invalid path containing \"//\".", 0, excludesSet.size());
}
use of java.io.StringReader in project platform_frameworks_base by android.
the class FullBackupTest method testParseBackupSchemeFromXml_invalidXmlFails.
public void testParseBackupSchemeFromXml_invalidXmlFails() throws Exception {
// Invalid root tag.
mXpp.setInput(new StringReader("<full-weird-tag>" + "<exclude path=\"invalidRootTag.txt\" domain=\"file\"/>" + "</ffull-weird-tag>"));
try {
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
fail("Invalid root xml tag should throw an XmlPullParserException");
} catch (XmlPullParserException expected) {
}
// Invalid exclude tag.
mXpp.setInput(new StringReader("<full-backup-content>" + "<excluded path=\"invalidExcludeTag.txt\" domain=\"file\"/>" + "</full-backup-conten>t"));
try {
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
fail("Misspelled xml exclude tag should throw an XmlPullParserException");
} catch (XmlPullParserException expected) {
}
// Just for good measure - invalid include tag.
mXpp.setInput(new StringReader("<full-backup-content>" + "<yinclude path=\"invalidIncludeTag.txt\" domain=\"file\"/>" + "</full-backup-conten>t"));
try {
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
fail("Misspelled xml exclude tag should throw an XmlPullParserException");
} catch (XmlPullParserException expected) {
}
}
use of java.io.StringReader in project platform_frameworks_base by android.
the class FullBackupTest method testDoubleDotInPath_isIgnored.
public void testDoubleDotInPath_isIgnored() throws Exception {
mXpp.setInput(new StringReader("<full-backup-content>" + // Invalid use of ".." dir.
"<include path=\"..\" domain=\"file\"/>" + "</full-backup-content>"));
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
assertEquals("Didn't throw away invalid \"..\" path.", 0, includeMap.size());
Set<String> fileDomainIncludes = includeMap.get(FullBackup.FILES_TREE_TOKEN);
assertNull("Didn't throw away invalid \"..\" path.", fileDomainIncludes);
}
use of java.io.StringReader in project platform_frameworks_base by android.
the class FullBackupTest method testInvalidPath_doesNotBackup.
public void testInvalidPath_doesNotBackup() throws Exception {
mXpp.setInput(new StringReader("<full-backup-content>" + // Invalid use of ".." dir.
"<exclude path=\"..\" domain=\"file\"/>" + "</full-backup-content>"));
FullBackup.BackupScheme bs = FullBackup.getBackupSchemeForTest(mContext);
bs.parseBackupSchemeFromXmlLocked(mXpp, excludesSet, includeMap);
assertEquals("Didn't throw away invalid \"..\" path.", 0, includeMap.size());
Set<String> fileDomainIncludes = includeMap.get(FullBackup.FILES_TREE_TOKEN);
assertNull("Didn't throw away invalid \"..\" path.", fileDomainIncludes);
}
Aggregations