Introduced IDatabaseLoader

(kdb not yet working)
This commit is contained in:
Philipp Crocoll
2014-01-25 19:38:12 -08:00
parent ee4d40eb32
commit 6e0645559d
19 changed files with 255 additions and 65 deletions

View File

@@ -16,6 +16,13 @@
<AndroidResgenFile>Resources\Resource.Designer.cs</AndroidResgenFile>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
<AndroidUseLatestPlatformSdk />
<TargetFrameworkVersion>v4.2</TargetFrameworkVersion>
<AndroidSupportedAbis>armeabi,armeabi-v7a,x86</AndroidSupportedAbis>
<AndroidStoreUncompressedFileExtensions />
<MandroidI18n />
<JavaMaximumHeapSize />
<JavaOptions />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -96,8 +103,12 @@
<Project>{53A9CB7F-6553-4BC0-B56B-9410BB2E59AA}</Project>
<Name>Kp2aBusinessLogic</Name>
</ProjectReference>
<ProjectReference Include="..\KP2AKdbLibraryBinding\KP2AKdbLibraryBinding.csproj">
<Project>{70d3844a-d9fa-4a64-b205-a84c6a822196}</Project>
<Name>KP2AKdbLibraryBinding</Name>
</ProjectReference>
<ProjectReference Include="..\monodroid-unittesting\MonoDroidUnitTesting\MonoDroidUnitTesting.csproj">
<Project>{a5f8fb02-00e0-4335-91ef-aeaa2c2f3c48}</Project>
<Project>{A5F8FB02-00E0-4335-91EF-AEAA2C2F3C48}</Project>
<Name>MonoDroidUnitTesting</Name>
</ProjectReference>
</ItemGroup>

View File

@@ -20,13 +20,14 @@ namespace Kp2aUnitTests
// Run all tests from this assembly
//runner.AddTests(Assembly.GetExecutingAssembly());
//runner.AddTests(new List<Type> { typeof(TestSynchronizeCachedDatabase)});
runner.AddTests(typeof(TestLoadDb).GetMethod("LoadErrorWithCertificateTrustFailure"));
//runner.AddTests(new List<Type> { typeof(TestSaveDb) });
//runner.AddTests(typeof(TestLoadDb).GetMethod("LoadErrorWithCertificateTrustFailure"));
//runner.AddTests(new List<Type> { typeof(TestLoadDb) });
//runner.AddTests(new List<Type> { typeof(TestCachingFileStorage) });
//runner.AddTests(typeof(TestCachingFileStorage).GetMethod("TestSaveToRemote"));
//runner.AddTests(typeof(TestLoadDb).GetMethod("TestLoadKdbpWithPasswordOnly"));
//runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadKdbxAndSaveKdbp_TestIdenticalFiles"));
runner.AddTests(typeof(TestLoadDb).GetMethod("TestLoadKdb1"));
runner.AddTests(typeof(TestLoadDb).GetMethod("TestLoadWithKeyfileOnly"));
runner.AddTests(typeof(TestLoadDb).GetMethod("TestLoadKdbpWithPasswordOnly"));
runner.AddTests(typeof(TestSaveDb).GetMethod("TestLoadKdbxAndSaveKdbp_TestIdenticalFiles"));
return runner;
}
}

View File

@@ -43,7 +43,7 @@ namespace Kp2aUnitTests
//ensure the the database can be loaded from file:
PwDatabase loadedDb = new PwDatabase();
loadedDb.Open(ioc, new CompositeKey(), null);
loadedDb.Open(ioc, new CompositeKey(), null, new KdbxDatabaseLoader(KdbxFormat.Default));
//Check whether the databases are equal
AssertDatabasesAreEqual(loadedDb, app.GetDb().KpDatabase);

View File

@@ -5,6 +5,7 @@ using System.Net.Security;
using Android.App;
using Android.Content;
using Android.OS;
using KeePassLib;
using KeePassLib.Keys;
using KeePassLib.Serialization;
using keepass2android;
@@ -48,10 +49,9 @@ namespace Kp2aUnitTests
throw new NotImplementedException();
}
public void LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compKey,
ProgressDialogStatusLogger statusLogger)
public void LoadDatabase(IOConnectionInfo ioConnectionInfo, MemoryStream memoryStream, CompositeKey compKey, ProgressDialogStatusLogger statusLogger, IDatabaseLoader databaseLoader)
{
_db.LoadData(this, ioConnectionInfo, memoryStream, compKey, statusLogger);
_db.LoadData(this, ioConnectionInfo, memoryStream, compKey, statusLogger, databaseLoader);
}
public Database GetDb()
{

View File

@@ -20,10 +20,12 @@ namespace Kp2aUnitTests
app.CreateNewDatabase();
bool loadSuccesful = false;
var key = CreateKey(password, keyfile);
string loadErrorMessage = "";
LoadDb task = new LoadDb(app, new IOConnectionInfo { Path = TestDbDirectory+filenameWithoutDir }, null,
key, keyfile, new ActionOnFinish((success, message) =>
{
loadErrorMessage = message;
if (!success)
Android.Util.Log.Debug("KP2ATest", "error loading db: " + message);
loadSuccesful = success;
@@ -34,7 +36,7 @@ namespace Kp2aUnitTests
pt.Run();
pt.JoinWorkerThread();
Android.Util.Log.Debug("KP2ATest", "PT.run finished");
Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-(");
Assert.IsTrue(loadSuccesful, "didn't succesfully load database :-( "+loadErrorMessage);
Assert.AreEqual(6,app.GetDb().KpDatabase.RootGroup.Groups.Count());
Assert.AreEqual(2,app.GetDb().KpDatabase.RootGroup.Entries.Count());
@@ -48,6 +50,14 @@ namespace Kp2aUnitTests
{
RunLoadTest("passwordonly.kdbx", DefaultPassword, "");
}
[TestMethod]
public void TestLoadKdb1()
{
RunLoadTest("test1.kdb", "12345", "");
}
[TestMethod]
public void TestLoadWithKeyfileOnly()
{