use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.
the class SearchTest method testBackupExcluded.
public void testBackupExcluded() {
updateOmitSetting(true);
PwGroup results = mDb.Search("BackupOnly");
assertFalse("Search result found, but should not have been.", results.numbersOfChildEntries() > 0);
}
use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.
the class SearchTest method testBackupIncluded.
public void testBackupIncluded() {
updateOmitSetting(false);
PwGroup results = mDb.Search("BackupOnly");
assertTrue("Search result not found.", results.numbersOfChildEntries() > 0);
}
use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.
the class DeleteEntry method testDelete.
public void testDelete() {
Database db;
Context ctx = getContext();
try {
db = TestData.GetDb(ctx, ASSET, PASSWORD, KEYFILE, FILENAME);
} catch (Exception e) {
assertTrue("Failed to open database: " + e.getMessage(), false);
return;
}
PwDatabaseV3 pm = (PwDatabaseV3) db.pm;
PwGroup group1 = getGroup(pm, GROUP1_NAME);
assertNotNull("Could not find group1", group1);
// Delete the group
DeleteGroup task = new DeleteGroup(db, group1, null, true);
task.run();
// Verify the entries were deleted
PwEntry entry1 = getEntry(pm, ENTRY1_NAME);
assertNull("Entry 1 was not removed", entry1);
PwEntry entry2 = getEntry(pm, ENTRY2_NAME);
assertNull("Entry 2 was not removed", entry2);
// Verify the entries were removed from the search index
SearchDbHelper dbHelp = new SearchDbHelper(ctx);
PwGroup results1 = dbHelp.search(db, ENTRY1_NAME);
PwGroup results2 = dbHelp.search(db, ENTRY2_NAME);
assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries());
assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries());
// Verify the group was deleted
group1 = getGroup(pm, GROUP1_NAME);
assertNull("Group 1 was not removed.", group1);
}
use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.
the class PwDbV3Output method outputPlanGroupAndEntries.
public void outputPlanGroupAndEntries(OutputStream os) throws PwDbOutputException {
LEDataOutputStream los = new LEDataOutputStream(os);
if (useHeaderHash() && headerHashBlock != null) {
try {
los.writeUShort(0x0000);
los.writeInt(headerHashBlock.length);
los.write(headerHashBlock);
} catch (IOException e) {
throw new PwDbOutputException("Failed to output header hash: " + e.getMessage());
}
}
// Groups
List<PwGroup> groups = mPM.getGroups();
for (int i = 0; i < groups.size(); i++) {
PwGroupV3 pg = (PwGroupV3) groups.get(i);
PwGroupOutputV3 pgo = new PwGroupOutputV3(pg, os);
try {
pgo.output();
} catch (IOException e) {
throw new PwDbOutputException("Failed to output a tree: " + e.getMessage());
}
}
// Entries
for (int i = 0; i < mPM.entries.size(); i++) {
PwEntryV3 pe = (PwEntryV3) mPM.entries.get(i);
PwEntryOutputV3 peo = new PwEntryOutputV3(pe, os);
try {
peo.output();
} catch (IOException e) {
throw new PwDbOutputException("Failed to output an entry.");
}
}
}
use of com.keepassdroid.database.PwGroup in project KeePassDX by Kunzisoft.
the class SearchDbHelper method search.
public PwGroup search(Database db, String qStr) {
PwDatabase pm = db.pm;
PwGroup group;
if (pm instanceof PwDatabaseV3) {
group = new PwGroupV3();
} else if (pm instanceof PwDatabaseV4) {
group = new PwGroupV4();
} else {
Log.d("SearchDbHelper", "Tried to search with unknown db");
return null;
}
group.setName(mCtx.getString(R.string.search_results));
group.setEntries(new ArrayList<>());
// Search all entries
Locale loc = Locale.getDefault();
qStr = qStr.toLowerCase(loc);
boolean isOmitBackup = omitBackup();
Queue<PwGroup> worklist = new LinkedList<PwGroup>();
if (pm.rootGroup != null) {
worklist.add(pm.rootGroup);
}
while (worklist.size() != 0) {
PwGroup top = worklist.remove();
if (pm.isGroupSearchable(top, isOmitBackup)) {
for (PwEntry entry : top.getChildEntries()) {
processEntries(entry, group.getChildEntries(), qStr, loc);
}
for (PwGroup childGroup : top.getChildGroups()) {
if (childGroup != null) {
worklist.add(childGroup);
}
}
}
}
return group;
}
Aggregations