diff --git a/src/com/keepassdroid/database/PwDate.java b/src/com/keepassdroid/database/PwDate.java
index 81698c04b..bf1005263 100644
--- a/src/com/keepassdroid/database/PwDate.java
+++ b/src/com/keepassdroid/database/PwDate.java
@@ -19,6 +19,7 @@
*/
package com.keepassdroid.database;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
@@ -162,4 +163,28 @@ public class PwDate implements Cloneable {
return buf;
}
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null ) {
+ return false;
+ }
+ if ( getClass() != o.getClass() ) {
+ return false;
+ }
+
+ PwDate date = (PwDate) o;
+ if ( cDateBuilt && date.cDateBuilt ) {
+ return cDate.equals(date.cDate);
+ } else if ( jDateBuilt && date.jDateBuilt ) {
+ return jDate.equals(date.jDate);
+ } else if ( cDateBuilt && date.jDateBuilt ) {
+ return Arrays.equals(date.getCDate(), cDate);
+ } else {
+ return date.getJDate().equals(jDate);
+ }
+ }
+
}
diff --git a/src/com/keepassdroid/database/PwEntry.java b/src/com/keepassdroid/database/PwEntry.java
index 4af3a23cc..fd8abafe4 100644
--- a/src/com/keepassdroid/database/PwEntry.java
+++ b/src/com/keepassdroid/database/PwEntry.java
@@ -46,8 +46,11 @@ public abstract class PwEntry implements Cloneable {
}
public void assign(PwEntry source) {
+ imageId = source.imageId;
}
-
+
+
+
public abstract void stampLastAccess();
public abstract UUID getUUID();
@@ -70,4 +73,20 @@ public abstract class PwEntry implements Cloneable {
return false;
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PwEntry other = (PwEntry) obj;
+ if (imageId != other.imageId)
+ return false;
+ return true;
+ }
+
+
+
}
diff --git a/src/com/keepassdroid/database/PwEntryV3.java b/src/com/keepassdroid/database/PwEntryV3.java
index d60a1906f..6556ec04c 100644
--- a/src/com/keepassdroid/database/PwEntryV3.java
+++ b/src/com/keepassdroid/database/PwEntryV3.java
@@ -264,7 +264,6 @@ public class PwEntryV3 extends PwEntry {
title = source.title;
url = source.url;
groupId = source.groupId;
- imageId = source.imageId;
username = source.username;
additional = source.additional;
uuid = source.uuid;
diff --git a/src/com/keepassdroid/database/PwEntryV4.java b/src/com/keepassdroid/database/PwEntryV4.java
index 8ce28d81c..a01e612af 100644
--- a/src/com/keepassdroid/database/PwEntryV4.java
+++ b/src/com/keepassdroid/database/PwEntryV4.java
@@ -64,6 +64,59 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
public void put(String key, String value) {
windowSeqPairs.put(key, value);
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + getOuterType().hashCode();
+ result = prime
+ * result
+ + ((defaultSequence == null) ? 0 : defaultSequence
+ .hashCode());
+ result = prime * result + (enabled ? 1231 : 1237);
+ result = prime * result
+ + (int) (obfuscationOptions ^ (obfuscationOptions >>> 32));
+ result = prime
+ * result
+ + ((windowSeqPairs == null) ? 0 : windowSeqPairs.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ AutoType other = (AutoType) obj;
+ if (!getOuterType().equals(other.getOuterType()))
+ return false;
+ if (defaultSequence == null) {
+ if (other.defaultSequence != null)
+ return false;
+ } else if (!defaultSequence.equals(other.defaultSequence))
+ return false;
+ if (enabled != other.enabled)
+ return false;
+ if (obfuscationOptions != other.obfuscationOptions)
+ return false;
+ if (windowSeqPairs == null) {
+ if (other.windowSeqPairs != null)
+ return false;
+ } else if (!windowSeqPairs.equals(other.windowSeqPairs))
+ return false;
+ return true;
+ }
+
+ private PwEntryV4 getOuterType() {
+ return PwEntryV4.this;
+ }
+
+
+
}
public PwEntryV4() {
@@ -72,20 +125,22 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
@Override
public void assign(PwEntry source) {
- super.assign(source);
if ( ! (source instanceof PwEntryV4) ) {
throw new RuntimeException("DB version mix.");
}
+ super.assign(source);
+
PwEntryV4 src = (PwEntryV4) source;
assign(src);
}
-
+
private void assign(PwEntryV4 source) {
parent = source.parent;
uuid = source.uuid;
strings = source.strings;
+ binaries = source.binaries;
customIconUuid = source.customIconUuid;
foregroundColor = source.foregroundColor;
backgroupColor = source.backgroupColor;
@@ -99,9 +154,11 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
expireDate = source.expireDate;
expires = source.expires;
usageCount = source.usageCount;
+ url = source.url;
+ additional = source.additional;
}
-
+
@Override
public Object clone() {
PwEntryV4 newEntry = (PwEntryV4) super.clone();
@@ -260,4 +317,104 @@ public class PwEntryV4 extends PwEntry implements ITimeLogger {
return getString(STR_URL);
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PwEntryV4 other = (PwEntryV4) obj;
+ if (additional == null) {
+ if (other.additional != null)
+ return false;
+ } else if (!additional.equals(other.additional))
+ return false;
+ if (autoType == null) {
+ if (other.autoType != null)
+ return false;
+ } else if (!autoType.equals(other.autoType))
+ return false;
+ if (backgroupColor == null) {
+ if (other.backgroupColor != null)
+ return false;
+ } else if (!backgroupColor.equals(other.backgroupColor))
+ return false;
+ if (binaries == null) {
+ if (other.binaries != null)
+ return false;
+ } else if (!binaries.equals(other.binaries))
+ return false;
+ if (creation == null) {
+ if (other.creation != null)
+ return false;
+ } else if (!creation.equals(other.creation))
+ return false;
+ if (customIconUuid == null) {
+ if (other.customIconUuid != null)
+ return false;
+ } else if (!customIconUuid.equals(other.customIconUuid))
+ return false;
+ if (expireDate == null) {
+ if (other.expireDate != null)
+ return false;
+ } else if (!expireDate.equals(other.expireDate))
+ return false;
+ if (expires != other.expires)
+ return false;
+ if (foregroundColor == null) {
+ if (other.foregroundColor != null)
+ return false;
+ } else if (!foregroundColor.equals(other.foregroundColor))
+ return false;
+ if (history == null) {
+ if (other.history != null)
+ return false;
+ } else if (!history.equals(other.history))
+ return false;
+ if (lastAccess == null) {
+ if (other.lastAccess != null)
+ return false;
+ } else if (!lastAccess.equals(other.lastAccess))
+ return false;
+ if (lastMod == null) {
+ if (other.lastMod != null)
+ return false;
+ } else if (!lastMod.equals(other.lastMod))
+ return false;
+ if (overrideURL == null) {
+ if (other.overrideURL != null)
+ return false;
+ } else if (!overrideURL.equals(other.overrideURL))
+ return false;
+ if (parent == null) {
+ if (other.parent != null)
+ return false;
+ } else if (!parent.equals(other.parent))
+ return false;
+ if (parentGroupLastMod == null) {
+ if (other.parentGroupLastMod != null)
+ return false;
+ } else if (!parentGroupLastMod.equals(other.parentGroupLastMod))
+ return false;
+ if (strings == null) {
+ if (other.strings != null)
+ return false;
+ } else if (!strings.equals(other.strings))
+ return false;
+ if (url == null) {
+ if (other.url != null)
+ return false;
+ } else if (!url.equals(other.url))
+ return false;
+ if (usageCount != other.usageCount)
+ return false;
+ if (uuid == null) {
+ if (other.uuid != null)
+ return false;
+ } else if (!uuid.equals(other.uuid))
+ return false;
+ return true;
+ }
}
diff --git a/src/com/keepassdroid/database/PwGroupV4.java b/src/com/keepassdroid/database/PwGroupV4.java
index a92f6a43f..862338c45 100644
--- a/src/com/keepassdroid/database/PwGroupV4.java
+++ b/src/com/keepassdroid/database/PwGroupV4.java
@@ -190,4 +190,97 @@ public class PwGroupV4 extends PwGroup implements ITimeLogger {
expires = exp;
}
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ PwGroupV4 other = (PwGroupV4) obj;
+ if (creation == null) {
+ if (other.creation != null)
+ return false;
+ } else if (!creation.equals(other.creation))
+ return false;
+ if (customIconUuid == null) {
+ if (other.customIconUuid != null)
+ return false;
+ } else if (!customIconUuid.equals(other.customIconUuid))
+ return false;
+ if (defaultAutoTypeSequence == null) {
+ if (other.defaultAutoTypeSequence != null)
+ return false;
+ } else if (!defaultAutoTypeSequence
+ .equals(other.defaultAutoTypeSequence))
+ return false;
+ if (enableAutoType == null) {
+ if (other.enableAutoType != null)
+ return false;
+ } else if (!enableAutoType.equals(other.enableAutoType))
+ return false;
+ if (enableSearching == null) {
+ if (other.enableSearching != null)
+ return false;
+ } else if (!enableSearching.equals(other.enableSearching))
+ return false;
+ if (expireDate == null) {
+ if (other.expireDate != null)
+ return false;
+ } else if (!expireDate.equals(other.expireDate))
+ return false;
+ if (expires != other.expires)
+ return false;
+ if (iconId != other.iconId)
+ return false;
+ if (isExpanded != other.isExpanded)
+ return false;
+ if (lastAccess == null) {
+ if (other.lastAccess != null)
+ return false;
+ } else if (!lastAccess.equals(other.lastAccess))
+ return false;
+ if (lastMod == null) {
+ if (other.lastMod != null)
+ return false;
+ } else if (!lastMod.equals(other.lastMod))
+ return false;
+ if (lastTopVisibleEntry == null) {
+ if (other.lastTopVisibleEntry != null)
+ return false;
+ } else if (!lastTopVisibleEntry.equals(other.lastTopVisibleEntry))
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (notes == null) {
+ if (other.notes != null)
+ return false;
+ } else if (!notes.equals(other.notes))
+ return false;
+ if (parent == null) {
+ if (other.parent != null)
+ return false;
+ } else if (!parent.equals(other.parent))
+ return false;
+ if (parentGroupLastMod == null) {
+ if (other.parentGroupLastMod != null)
+ return false;
+ } else if (!parentGroupLastMod.equals(other.parentGroupLastMod))
+ return false;
+ if (usageCount != other.usageCount)
+ return false;
+ if (uuid == null) {
+ if (other.uuid != null)
+ return false;
+ } else if (!uuid.equals(other.uuid))
+ return false;
+ return true;
+ }
+
+
+
}
diff --git a/src/com/keepassdroid/database/edit/LoadDB.java b/src/com/keepassdroid/database/edit/LoadDB.java
index 5d4884185..adf8218ec 100644
--- a/src/com/keepassdroid/database/edit/LoadDB.java
+++ b/src/com/keepassdroid/database/edit/LoadDB.java
@@ -88,6 +88,9 @@ public class LoadDB extends RunnableOnFinish {
} catch (InvalidDBException e) {
finish(false, mCtx.getString(R.string.error_invalid_db));
return;
+ } catch (OutOfMemoryError e) {
+ finish(false, mCtx.getString(R.string.error_out_of_memory));
+ return;
}
finish(true);
diff --git a/tests/src/com/keepassdroid/tests/PwDateTest.java b/tests/src/com/keepassdroid/tests/PwDateTest.java
new file mode 100644
index 000000000..a5015f067
--- /dev/null
+++ b/tests/src/com/keepassdroid/tests/PwDateTest.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2010 Brian Pellin.
+ *
+ * This file is part of KeePassDroid.
+ *
+ * KeePassDroid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KeePassDroid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with KeePassDroid. If not, see .
+ *
+ */
+package com.keepassdroid.tests;
+
+import junit.framework.TestCase;
+
+import com.keepassdroid.database.PwDate;
+
+public class PwDateTest extends TestCase {
+ public void testDate() {
+ PwDate jDate = new PwDate(System.currentTimeMillis());
+
+ PwDate intermediate = (PwDate) jDate.clone();
+
+ PwDate cDate = new PwDate(intermediate.getCDate(), 0);
+
+ assertTrue("jDate and intermediate not equal", jDate.equals(intermediate));
+ assertTrue("jDate and cDate not equal", cDate.equals(jDate));
+
+ }
+}
diff --git a/tests/src/com/keepassdroid/tests/PwEntryTest.java b/tests/src/com/keepassdroid/tests/PwEntryTestV3.java
similarity index 97%
rename from tests/src/com/keepassdroid/tests/PwEntryTest.java
rename to tests/src/com/keepassdroid/tests/PwEntryTestV3.java
index 32a39a3d0..053f17deb 100644
--- a/tests/src/com/keepassdroid/tests/PwEntryTest.java
+++ b/tests/src/com/keepassdroid/tests/PwEntryTestV3.java
@@ -30,7 +30,7 @@ import android.test.AndroidTestCase;
import com.keepassdroid.database.PwEntryV3;
import com.keepassdroid.tests.database.TestData;
-public class PwEntryTest extends AndroidTestCase {
+public class PwEntryTestV3 extends AndroidTestCase {
PwEntryV3 mPE;
@Override
diff --git a/tests/src/com/keepassdroid/tests/PwEntryTestV4.java b/tests/src/com/keepassdroid/tests/PwEntryTestV4.java
new file mode 100644
index 000000000..63d20c188
--- /dev/null
+++ b/tests/src/com/keepassdroid/tests/PwEntryTestV4.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2010 Brian Pellin.
+ *
+ * This file is part of KeePassDroid.
+ *
+ * KeePassDroid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * KeePassDroid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with KeePassDroid. If not, see .
+ *
+ */
+package com.keepassdroid.tests;
+
+import java.util.UUID;
+
+import junit.framework.TestCase;
+
+import com.keepassdroid.database.PwEntryV4;
+import com.keepassdroid.database.PwGroupV4;
+
+public class PwEntryTestV4 extends TestCase {
+ public void testAssign() {
+ PwEntryV4 entry = new PwEntryV4();
+
+ entry.additional = "test223";
+
+ entry.autoType = entry.new AutoType();
+ entry.autoType.defaultSequence = "1324";
+ entry.autoType.enabled = true;
+ entry.autoType.obfuscationOptions = 123412432109L;
+ entry.autoType.put("key", "value");
+
+ entry.backgroupColor = "blue";
+ entry.binaries.put("key1", new byte[] {0,1});
+ entry.customIconUuid = UUID.randomUUID();
+ entry.foregroundColor = "red";
+ entry.history.add(new PwEntryV4());
+ entry.imageId = 5;
+ entry.overrideURL = "override";
+ entry.parent = new PwGroupV4();
+ entry.strings.put("key2", "value2");
+ entry.url = "http://localhost";
+ entry.uuid = UUID.randomUUID();
+
+ PwEntryV4 target = new PwEntryV4();
+ target.assign(entry);
+
+ assertTrue("Entries do not match.", entry.equals(target));
+
+ }
+
+}