[banshee] [tests] Unit test db migrations
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] [tests] Unit test db migrations
- Date: Tue, 23 Mar 2010 00:14:19 +0000 (UTC)
commit e8109306750776762808cd299be61905877fe02a
Author: Gabriel Burt <gabriel burt gmail com>
Date: Mon Mar 22 17:11:28 2010 -0700
[tests] Unit test db migrations
So far just have a 1.4.3 database; should add some more.
.../Banshee.Database/BansheeDbConnection.cs | 8 ++-
.../Banshee.Database/SortKeyUpdater.cs | 6 ++
.../Banshee.Services/Banshee.Database/Tests.cs | 69 ++++++++++++++++++++
src/Core/Banshee.Services/Makefile.am | 1 +
tests/data/banshee-1.4.3.db | Bin 0 -> 110592 bytes
5 files changed, 82 insertions(+), 2 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs b/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
index 6c32cd3..36c338a 100644
--- a/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/BansheeDbConnection.cs
@@ -49,7 +49,11 @@ namespace Banshee.Database
get { return configuration; }
}
- public BansheeDbConnection () : base (DatabaseFile)
+ public BansheeDbConnection () : this (DatabaseFile)
+ {
+ }
+
+ internal BansheeDbConnection (string db_path) : base (db_path)
{
// Each cache page is about 1.5K, so 32768 pages = 49152K = 48M
int cache_size = (TableExists ("CoreTracks") && Query<long> ("SELECT COUNT(*) FROM CoreTracks") > 10000) ? 32768 : 16384;
@@ -61,7 +65,7 @@ namespace Banshee.Database
// don't want this on because it breaks searching/smart playlists. See BGO #526371
//Execute ("PRAGMA case_sensitive_like=ON");
- Log.DebugFormat ("Opened SQLite connection to {0}", DatabaseFile);
+ Log.DebugFormat ("Opened SQLite connection to {0}", db_path);
migrator = new BansheeDbFormatMigrator (this);
configuration = new DatabaseConfigurationClient (this);
diff --git a/src/Core/Banshee.Services/Banshee.Database/SortKeyUpdater.cs b/src/Core/Banshee.Services/Banshee.Database/SortKeyUpdater.cs
index 0982868..cebd0ca 100644
--- a/src/Core/Banshee.Services/Banshee.Database/SortKeyUpdater.cs
+++ b/src/Core/Banshee.Services/Banshee.Database/SortKeyUpdater.cs
@@ -35,6 +35,8 @@ namespace Banshee.Database
{
internal class SortKeyUpdater
{
+ internal static bool Disable;
+
public static void Update ()
{
string locale = CultureInfo.CurrentCulture.Name;
@@ -51,6 +53,10 @@ namespace Banshee.Database
protected static void ForceUpdate (string new_locale)
{
+ if (Disable) {
+ return;
+ }
+
ServiceManager.DbConnection.Execute (@"
UPDATE CoreArtists SET
NameSortKey = HYENA_COLLATION_KEY(COALESCE(NameSort, Name, ?)),
diff --git a/src/Core/Banshee.Services/Banshee.Database/Tests.cs b/src/Core/Banshee.Services/Banshee.Database/Tests.cs
new file mode 100644
index 0000000..e2a459d
--- /dev/null
+++ b/src/Core/Banshee.Services/Banshee.Database/Tests.cs
@@ -0,0 +1,69 @@
+//
+// Tests.cs
+//
+// Author:
+// Gabriel Burt <gburt novell com>
+//
+// Copyright (C) 2010 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+#if ENABLE_TESTS
+
+using System;
+using System.IO;
+using NUnit.Framework;
+
+using Hyena;
+
+using Banshee.ServiceStack;
+
+namespace Banshee.Database
+{
+ [TestFixture]
+ public class DatabaseTests : Hyena.Tests.TestBase
+ {
+ [Test]
+ public void Migrate ()
+ {
+ foreach (string file in Directory.GetFiles (Path.Combine (TestsDir, "data"))) {
+ if (file.EndsWith (".db")) {
+ var db_file = file + ".test-tmp-copy";
+ try {
+ File.Delete (db_file);
+ File.Copy (file, db_file);
+
+ // Call the magic methods to test the migration path
+ var db = new BansheeDbConnection (db_file);
+ SortKeyUpdater.Disable = true;
+ ((IInitializeService)db).Initialize ();
+ } catch (Exception e) {
+ Assert.Fail (String.Format ("Failed to migrate db: {0}", e));
+ } finally {
+ File.Delete (db_file);
+ }
+ }
+ }
+ }
+ }
+}
+
+#endif
diff --git a/src/Core/Banshee.Services/Makefile.am b/src/Core/Banshee.Services/Makefile.am
index d6f1a8f..428adad 100644
--- a/src/Core/Banshee.Services/Makefile.am
+++ b/src/Core/Banshee.Services/Makefile.am
@@ -59,6 +59,7 @@ SOURCES = \
Banshee.Database/BansheeModelCache.cs \
Banshee.Database/BansheeModelProvider.cs \
Banshee.Database/SortKeyUpdater.cs \
+ Banshee.Database/Tests.cs \
Banshee.Equalizer/EqualizerManager.cs \
Banshee.Equalizer/EqualizerSetting.cs \
Banshee.Hardware/DeviceCommand.cs \
diff --git a/tests/data/banshee-1.4.3.db b/tests/data/banshee-1.4.3.db
new file mode 100644
index 0000000..927b48a
Binary files /dev/null and b/tests/data/banshee-1.4.3.db differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]