mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-29 12:32:21 -05:00
Added test for merge with kdbp file and fixed it in SaveDB
This commit is contained in:
parent
30cdc6136f
commit
99cbe84879
@ -11,7 +11,7 @@ using ProtoBuf.Meta;
|
||||
|
||||
namespace KeePassLib.Serialization
|
||||
{
|
||||
internal class KdbpFile
|
||||
public class KdbpFile
|
||||
{
|
||||
public const string FileNameExtension = "kdbp";
|
||||
|
||||
|
@ -175,7 +175,7 @@ namespace keepass2android
|
||||
pwImp.MemoryProtection = pwDatabase.MemoryProtection.CloneDeep();
|
||||
pwImp.MasterKey = pwDatabase.MasterKey;
|
||||
KdbxFile kdbx = new KdbxFile(pwImp);
|
||||
kdbx.Load(fileStorage.OpenFileForRead(ioc), KdbxFormat.Default, null);
|
||||
kdbx.Load(fileStorage.OpenFileForRead(ioc), KdbpFile.GetFormatToUse(ioc), null);
|
||||
|
||||
pwDatabase.MergeIn(pwImp, PwMergeMethod.Synchronize, null);
|
||||
|
||||
|
@ -18,10 +18,10 @@ namespace Kp2aUnitTests
|
||||
{
|
||||
TestRunner runner = new TestRunner();
|
||||
// Run all tests from this assembly
|
||||
runner.AddTests(Assembly.GetExecutingAssembly());
|
||||
//runner.AddTests(Assembly.GetExecutingAssembly());
|
||||
//runner.AddTests(new List<Type> { typeof(TestSaveDb)});
|
||||
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadEditSaveWithSyncConflict"));
|
||||
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadEditSave"));
|
||||
runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadEditSaveWithSyncKdbp"));
|
||||
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadKdbxAndSaveKdbp_TestIdenticalFiles"));
|
||||
return runner;
|
||||
}
|
||||
}
|
||||
|
@ -105,9 +105,17 @@ namespace Kp2aUnitTests
|
||||
}
|
||||
|
||||
protected IKp2aApp SetupAppWithDefaultDatabase()
|
||||
{
|
||||
string filename = DefaultFilename;
|
||||
|
||||
return SetupAppWithDatabase(filename);
|
||||
}
|
||||
|
||||
protected IKp2aApp SetupAppWithDatabase(string filename)
|
||||
{
|
||||
IKp2aApp app = new TestKp2aApp();
|
||||
IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename};
|
||||
|
||||
IOConnectionInfo ioc = new IOConnectionInfo {Path = filename};
|
||||
Database db = app.CreateNewDatabase();
|
||||
|
||||
db.KpDatabase = new PwDatabase();
|
||||
|
@ -44,13 +44,25 @@ namespace Kp2aUnitTests
|
||||
[TestMethod]
|
||||
public void TestLoadEditSaveWithSync()
|
||||
{
|
||||
TestSync(DefaultFilename);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestLoadEditSaveWithSyncKdbp()
|
||||
{
|
||||
TestSync(DefaultDirectory+"savetest.kdbp");
|
||||
}
|
||||
|
||||
|
||||
private void TestSync(string filename)
|
||||
{
|
||||
//create the default database:
|
||||
IKp2aApp app = SetupAppWithDefaultDatabase();
|
||||
IKp2aApp app = SetupAppWithDatabase(filename);
|
||||
//save it and reload it so we have a base version
|
||||
SaveDatabase(app);
|
||||
app = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
|
||||
app = LoadDatabase(filename, DefaultPassword, DefaultKeyfile);
|
||||
//load it once again:
|
||||
IKp2aApp app2 = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
|
||||
IKp2aApp app2 = LoadDatabase(filename, DefaultPassword, DefaultKeyfile);
|
||||
|
||||
//modify the database by adding a group in both databases:
|
||||
app.GetDb().KpDatabase.RootGroup.AddGroup(new PwGroup(true, true, "TestGroup", PwIcon.Apple), true);
|
||||
@ -71,11 +83,10 @@ namespace Kp2aUnitTests
|
||||
app.GetDb().KpDatabase.RootGroup.AddGroup(group2, true);
|
||||
|
||||
//load database to a new app instance:
|
||||
IKp2aApp resultApp = LoadDatabase(DefaultFilename, DefaultPassword, DefaultKeyfile);
|
||||
IKp2aApp resultApp = LoadDatabase(filename, DefaultPassword, DefaultKeyfile);
|
||||
|
||||
//ensure the sync was successful:
|
||||
AssertDatabasesAreEqual(app.GetDb().KpDatabase, resultApp.GetDb().KpDatabase);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user