mirror of
https://github.com/osukey/osukey.git
synced 2025-05-05 21:57:24 +09:00
Stop using memory database. Load sample data local to TestCase.
Also makes the connection private.
This commit is contained in:
parent
e333f97364
commit
f16cc430f8
@ -1,31 +1,96 @@
|
|||||||
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using OpenTK;
|
|
||||||
using osu.Framework.GameModes.Testing;
|
using osu.Framework.GameModes.Testing;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Threading;
|
|
||||||
using osu.Game;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using osu.Game.Database;
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Game.Online.Chat.Display;
|
|
||||||
using osu.Framework;
|
|
||||||
using osu.Game.GameModes.Play;
|
using osu.Game.GameModes.Play;
|
||||||
|
using SQLiteNetExtensions.Extensions;
|
||||||
|
using osu.Framework;
|
||||||
|
using osu.Game;
|
||||||
|
|
||||||
namespace osu.Desktop.Tests
|
namespace osu.Desktop.Tests
|
||||||
{
|
{
|
||||||
class TestCasePlaySongSelect : TestCase
|
class TestCasePlaySongSelect : TestCase
|
||||||
{
|
{
|
||||||
|
private BeatmapDatabase db;
|
||||||
public override string Name => @"Song Select";
|
public override string Name => @"Song Select";
|
||||||
public override string Description => @"Testing song selection UI";
|
public override string Description => @"Testing song selection UI";
|
||||||
|
|
||||||
|
public override void Load(BaseGame game)
|
||||||
|
{
|
||||||
|
base.Load(game);
|
||||||
|
|
||||||
|
db = (game as OsuGameBase).Beatmaps;
|
||||||
|
}
|
||||||
|
|
||||||
public override void Reset()
|
public override void Reset()
|
||||||
{
|
{
|
||||||
base.Reset();
|
base.Reset();
|
||||||
|
|
||||||
|
db.Reset();
|
||||||
|
|
||||||
|
var sets = new List<BeatmapSetInfo>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i += 10)
|
||||||
|
sets.Add(createTestBeatmapSet(i));
|
||||||
|
|
||||||
|
db.Import(sets);
|
||||||
|
|
||||||
Add(new PlaySongSelect());
|
Add(new PlaySongSelect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BeatmapSetInfo createTestBeatmapSet(int i)
|
||||||
|
{
|
||||||
|
return new BeatmapSetInfo
|
||||||
|
{
|
||||||
|
BeatmapSetID = 1234 + i,
|
||||||
|
Hash = "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
||||||
|
Path = string.Empty,
|
||||||
|
Metadata = new BeatmapMetadata
|
||||||
|
{
|
||||||
|
BeatmapSetID = 1234 + i,
|
||||||
|
Artist = "MONACA",
|
||||||
|
Title = "Black Song",
|
||||||
|
Author = "Some Guy",
|
||||||
|
},
|
||||||
|
Beatmaps = new List<BeatmapInfo>(new[]
|
||||||
|
{
|
||||||
|
new BeatmapInfo
|
||||||
|
{
|
||||||
|
BeatmapID = 1234 + i,
|
||||||
|
Mode = PlayMode.Osu,
|
||||||
|
Path = "normal.osu",
|
||||||
|
Version = "Normal",
|
||||||
|
BaseDifficulty = new BaseDifficulty
|
||||||
|
{
|
||||||
|
OverallDifficulty = 3.5f,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BeatmapInfo
|
||||||
|
{
|
||||||
|
BeatmapID = 1235 + i,
|
||||||
|
Mode = PlayMode.Osu,
|
||||||
|
Path = "hard.osu",
|
||||||
|
Version = "Hard",
|
||||||
|
BaseDifficulty = new BaseDifficulty
|
||||||
|
{
|
||||||
|
OverallDifficulty = 5,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new BeatmapInfo
|
||||||
|
{
|
||||||
|
BeatmapID = 1236 + i,
|
||||||
|
Mode = PlayMode.Osu,
|
||||||
|
Path = "insane.osu",
|
||||||
|
Version = "Insane",
|
||||||
|
BaseDifficulty = new BaseDifficulty
|
||||||
|
{
|
||||||
|
OverallDifficulty = 7,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,66 +18,9 @@ namespace osu.Desktop.VisualTests
|
|||||||
{
|
{
|
||||||
class VisualTestGame : OsuGameBase
|
class VisualTestGame : OsuGameBase
|
||||||
{
|
{
|
||||||
private void InsertTestMap(int i)
|
|
||||||
{
|
|
||||||
var beatmapSet = new BeatmapSetInfo
|
|
||||||
{
|
|
||||||
BeatmapSetID = 1234 + i,
|
|
||||||
Hash = "d8e8fca2dc0f896fd7cb4cb0031ba249",
|
|
||||||
Path = "/foo/bar/baz",
|
|
||||||
Metadata = new BeatmapMetadata
|
|
||||||
{
|
|
||||||
BeatmapSetID = 1234 + i,
|
|
||||||
Artist = "MONACA",
|
|
||||||
Title = "Black Song",
|
|
||||||
Author = "Some Guy",
|
|
||||||
},
|
|
||||||
Beatmaps = new List<BeatmapInfo>(new[]
|
|
||||||
{
|
|
||||||
new BeatmapInfo
|
|
||||||
{
|
|
||||||
BeatmapID = 1234 + i,
|
|
||||||
Mode = PlayMode.Osu,
|
|
||||||
Path = "normal.osu",
|
|
||||||
Version = "Normal",
|
|
||||||
BaseDifficulty = new BaseDifficulty
|
|
||||||
{
|
|
||||||
OverallDifficulty = 3.5f,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new BeatmapInfo
|
|
||||||
{
|
|
||||||
BeatmapID = 1235 + i,
|
|
||||||
Mode = PlayMode.Osu,
|
|
||||||
Path = "hard.osu",
|
|
||||||
Version = "Hard",
|
|
||||||
BaseDifficulty = new BaseDifficulty
|
|
||||||
{
|
|
||||||
OverallDifficulty = 5,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new BeatmapInfo
|
|
||||||
{
|
|
||||||
BeatmapID = 1236 + i,
|
|
||||||
Mode = PlayMode.Osu,
|
|
||||||
Path = "insane.osu",
|
|
||||||
Version = "Insane",
|
|
||||||
BaseDifficulty = new BaseDifficulty
|
|
||||||
{
|
|
||||||
OverallDifficulty = 7,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
BeatmapDatabase.Connection.InsertWithChildren(beatmapSet, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Load(BaseGame game)
|
public override void Load(BaseGame game)
|
||||||
{
|
{
|
||||||
Host.Storage = new TestStorage(@"visual-tests");
|
|
||||||
base.Load(game);
|
base.Load(game);
|
||||||
for (int i = 0; i < 100; i += 10)
|
|
||||||
InsertTestMap(i);
|
|
||||||
Add(new TestBrowser());
|
Add(new TestBrowser());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
public class BeatmapDatabase
|
public class BeatmapDatabase
|
||||||
{
|
{
|
||||||
public static SQLiteConnection Connection { get; set; }
|
private static SQLiteConnection connection { get; set; }
|
||||||
private BasicStorage storage;
|
private BasicStorage storage;
|
||||||
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
||||||
|
|
||||||
@ -29,25 +29,28 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
ipc = new BeatmapImporter(host, this);
|
ipc = new BeatmapImporter(host, this);
|
||||||
|
|
||||||
if (Connection == null)
|
if (connection == null)
|
||||||
{
|
{
|
||||||
Connection = storage.GetDatabase(@"beatmaps");
|
connection = storage.GetDatabase(@"beatmaps");
|
||||||
Connection.CreateTable<BeatmapMetadata>();
|
connection.CreateTable<BeatmapMetadata>();
|
||||||
Connection.CreateTable<BaseDifficulty>();
|
connection.CreateTable<BaseDifficulty>();
|
||||||
Connection.CreateTable<BeatmapSetInfo>();
|
connection.CreateTable<BeatmapSetInfo>();
|
||||||
Connection.CreateTable<BeatmapInfo>();
|
connection.CreateTable<BeatmapInfo>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
foreach (var setInfo in Query<BeatmapSetInfo>())
|
foreach (var setInfo in Query<BeatmapSetInfo>())
|
||||||
|
{
|
||||||
|
if (storage.Exists(setInfo.Path))
|
||||||
storage.Delete(setInfo.Path);
|
storage.Delete(setInfo.Path);
|
||||||
|
}
|
||||||
|
|
||||||
Connection.DeleteAll<BeatmapMetadata>();
|
connection.DeleteAll<BeatmapMetadata>();
|
||||||
Connection.DeleteAll<BaseDifficulty>();
|
connection.DeleteAll<BaseDifficulty>();
|
||||||
Connection.DeleteAll<BeatmapSetInfo>();
|
connection.DeleteAll<BeatmapSetInfo>();
|
||||||
Connection.DeleteAll<BeatmapInfo>();
|
connection.DeleteAll<BeatmapInfo>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Import(params string[] paths)
|
public void Import(params string[] paths)
|
||||||
@ -62,7 +65,7 @@ namespace osu.Game.Database
|
|||||||
using (var reader = ArchiveReader.GetReader(storage, path))
|
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||||
metadata = reader.ReadMetadata();
|
metadata = reader.ReadMetadata();
|
||||||
|
|
||||||
if (Connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
if (connection.Table<BeatmapSetInfo>().Count(b => b.BeatmapSetID == metadata.BeatmapSetID) != 0)
|
||||||
return; // TODO: Update this beatmap instead
|
return; // TODO: Update this beatmap instead
|
||||||
|
|
||||||
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||||
@ -104,11 +107,24 @@ namespace osu.Game.Database
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Connection.InsertWithChildren(beatmapSet, true);
|
|
||||||
BeatmapSetAdded?.Invoke(beatmapSet);
|
Import(new[] { beatmapSet });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Import(IEnumerable<BeatmapSetInfo> beatmapSets)
|
||||||
|
{
|
||||||
|
connection.BeginTransaction();
|
||||||
|
|
||||||
|
foreach (var s in beatmapSets)
|
||||||
|
{
|
||||||
|
connection.InsertWithChildren(s, true);
|
||||||
|
BeatmapSetAdded?.Invoke(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.Commit();
|
||||||
|
}
|
||||||
|
|
||||||
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
|
public ArchiveReader GetReader(BeatmapSetInfo beatmapSet)
|
||||||
{
|
{
|
||||||
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
return ArchiveReader.GetReader(storage, beatmapSet.Path);
|
||||||
@ -136,25 +152,25 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
public TableQuery<T> Query<T>() where T : class
|
public TableQuery<T> Query<T>() where T : class
|
||||||
{
|
{
|
||||||
return Connection.Table<T>();
|
return connection.Table<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetWithChildren<T>(object id) where T : class
|
public T GetWithChildren<T>(object id) where T : class
|
||||||
{
|
{
|
||||||
return Connection.GetWithChildren<T>(id);
|
return connection.GetWithChildren<T>(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null,
|
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null,
|
||||||
bool recursive = true) where T : class
|
bool recursive = true) where T : class
|
||||||
{
|
{
|
||||||
return Connection.GetAllWithChildren<T>(filter, recursive);
|
return connection.GetAllWithChildren<T>(filter, recursive);
|
||||||
}
|
}
|
||||||
|
|
||||||
public T GetChildren<T>(T item, bool recursive = true)
|
public T GetChildren<T>(T item, bool recursive = true)
|
||||||
{
|
{
|
||||||
if (item == null) return default(T);
|
if (item == null) return default(T);
|
||||||
|
|
||||||
Connection.GetChildren(item, recursive);
|
connection.GetChildren(item, recursive);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,9 +187,9 @@ namespace osu.Game.Database
|
|||||||
if (!validTypes.Any(t => t == typeof(T)))
|
if (!validTypes.Any(t => t == typeof(T)))
|
||||||
throw new ArgumentException(nameof(T), "Must be a type managed by BeatmapDatabase");
|
throw new ArgumentException(nameof(T), "Must be a type managed by BeatmapDatabase");
|
||||||
if (cascade)
|
if (cascade)
|
||||||
Connection.UpdateWithChildren(record);
|
connection.UpdateWithChildren(record);
|
||||||
else
|
else
|
||||||
Connection.Update(record);
|
connection.Update(record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using osu.Framework.Configuration;
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -16,6 +17,7 @@ using OpenTK.Graphics;
|
|||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Game.Beatmaps.Drawable;
|
using osu.Game.Beatmaps.Drawable;
|
||||||
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
|
|
||||||
namespace osu.Game.GameModes.Play
|
namespace osu.Game.GameModes.Play
|
||||||
{
|
{
|
||||||
@ -122,7 +124,7 @@ namespace osu.Game.GameModes.Play
|
|||||||
}
|
}
|
||||||
|
|
||||||
beatmaps = (game as OsuGameBase).Beatmaps;
|
beatmaps = (game as OsuGameBase).Beatmaps;
|
||||||
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
beatmaps.BeatmapSetAdded += s => Scheduler.Add(() => addBeatmapSet(s));
|
||||||
Task.Factory.StartNew(addBeatmapSets);
|
Task.Factory.StartNew(addBeatmapSets);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user