mirror of https://github.com/ppy/osu
Add test data to db for VisualTests
Also fixes the broken IPC condition
This commit is contained in:
parent
d559903ebc
commit
063fdd9a2d
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using osu.Framework.Desktop;
|
||||
using osu.Framework.Desktop.Platform;
|
||||
using osu.Framework.Platform;
|
||||
|
||||
namespace osu.Framework.VisualTests
|
||||
|
|
|
@ -5,15 +5,77 @@
|
|||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Game.Database;
|
||||
using osu.Game;
|
||||
using osu.Framework.Desktop.Platform;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.GameModes.Play;
|
||||
using SQLiteNetExtensions.Extensions;
|
||||
|
||||
namespace osu.Framework.VisualTests
|
||||
{
|
||||
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)
|
||||
{
|
||||
(Host.Storage as DesktopStorage).InMemorySQL = true;
|
||||
base.Load(game);
|
||||
|
||||
for (int i = 0; i < 100; i += 10)
|
||||
InsertTestMap(i);
|
||||
Add(new TestBrowser());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,15 +81,22 @@
|
|||
<ItemGroup>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="OpenTK, Version=2.0.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ppy.OpenTK.2.0.50727.1337\lib\net20\OpenTK.dll</HintPath>
|
||||
<HintPath>$(SolutionDir)\packages\ppy.OpenTK.2.0.50727.1337\lib\net20\OpenTK.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="SQLite.Net">
|
||||
<HintPath>$(SolutionDir)\packages\SQLite.Net.Core-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SQLiteNetExtensions">
|
||||
<HintPath>$(SolutionDir)\packages\SQLiteNetExtensions.1.3.0\lib\portable-net45+netcore45+wpa81+wp8+MonoAndroid1+MonoTouch1\SQLiteNetExtensions.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\osu.licenseheader">
|
||||
<Link>osu.licenseheader</Link>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
@ -170,4 +177,4 @@
|
|||
<PostBuildEvent>
|
||||
</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
|
||||
<package id="SQLite.Net.Core-PCL" version="3.1.1" targetFramework="net45" />
|
||||
<package id="SQLite.Net-PCL" version="3.0.5" targetFramework="net45" />
|
||||
<package id="SQLiteNetExtensions" version="1.3.0" targetFramework="net45" />
|
||||
</packages>
|
|
@ -25,7 +25,7 @@ public static int Main(string[] args)
|
|||
var importer = new BeatmapImporter(host);
|
||||
|
||||
foreach (var file in args)
|
||||
if (importer.Import(file).Wait(1000))
|
||||
if (!importer.Import(file).Wait(1000))
|
||||
throw new TimeoutException(@"IPC took too long to send");
|
||||
Console.WriteLine(@"Sent import requests to running instance");
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace osu.Game.Database
|
|||
{
|
||||
public class BeatmapDatabase
|
||||
{
|
||||
private static SQLiteConnection connection { get; set; }
|
||||
public static SQLiteConnection Connection { get; set; }
|
||||
private BasicStorage storage;
|
||||
public event Action<BeatmapSetInfo> BeatmapSetAdded;
|
||||
|
||||
|
@ -29,13 +29,13 @@ public BeatmapDatabase(BasicGameHost host)
|
|||
|
||||
ipc = new BeatmapImporter(host, this);
|
||||
|
||||
if (connection == null)
|
||||
if (Connection == null)
|
||||
{
|
||||
connection = storage.GetDatabase(@"beatmaps");
|
||||
connection.CreateTable<BeatmapMetadata>();
|
||||
connection.CreateTable<BaseDifficulty>();
|
||||
connection.CreateTable<BeatmapSetInfo>();
|
||||
connection.CreateTable<BeatmapInfo>();
|
||||
Connection = storage.GetDatabase(@"beatmaps");
|
||||
Connection.CreateTable<BeatmapMetadata>();
|
||||
Connection.CreateTable<BaseDifficulty>();
|
||||
Connection.CreateTable<BeatmapSetInfo>();
|
||||
Connection.CreateTable<BeatmapInfo>();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,10 @@ public void Reset()
|
|||
foreach (var setInfo in Query<BeatmapSetInfo>())
|
||||
storage.Delete(setInfo.Path);
|
||||
|
||||
connection.DeleteAll<BeatmapMetadata>();
|
||||
connection.DeleteAll<BaseDifficulty>();
|
||||
connection.DeleteAll<BeatmapSetInfo>();
|
||||
connection.DeleteAll<BeatmapInfo>();
|
||||
Connection.DeleteAll<BeatmapMetadata>();
|
||||
Connection.DeleteAll<BaseDifficulty>();
|
||||
Connection.DeleteAll<BeatmapSetInfo>();
|
||||
Connection.DeleteAll<BeatmapInfo>();
|
||||
}
|
||||
|
||||
public void Import(params string[] paths)
|
||||
|
@ -62,7 +62,7 @@ public void Import(params string[] paths)
|
|||
using (var reader = ArchiveReader.GetReader(storage, path))
|
||||
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
|
||||
|
||||
if (File.Exists(path)) // Not always the case, i.e. for LegacyFilesystemReader
|
||||
|
@ -104,7 +104,7 @@ public void Import(params string[] paths)
|
|||
}
|
||||
}
|
||||
}
|
||||
connection.InsertWithChildren(beatmapSet, true);
|
||||
Connection.InsertWithChildren(beatmapSet, true);
|
||||
BeatmapSetAdded?.Invoke(beatmapSet);
|
||||
}
|
||||
}
|
||||
|
@ -136,25 +136,25 @@ public Beatmap GetBeatmap(BeatmapInfo beatmapInfo)
|
|||
|
||||
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
|
||||
{
|
||||
return connection.GetWithChildren<T>(id);
|
||||
return Connection.GetWithChildren<T>(id);
|
||||
}
|
||||
|
||||
public List<T> GetAllWithChildren<T>(Expression<Func<T, bool>> filter = null,
|
||||
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)
|
||||
{
|
||||
if (item == null) return default(T);
|
||||
|
||||
connection.GetChildren(item, recursive);
|
||||
Connection.GetChildren(item, recursive);
|
||||
return item;
|
||||
}
|
||||
|
||||
|
@ -171,9 +171,9 @@ public void Update<T>(T record, bool cascade = true) where T : class
|
|||
if (!validTypes.Any(t => t == typeof(T)))
|
||||
throw new ArgumentException(nameof(T), "Must be a type managed by BeatmapDatabase");
|
||||
if (cascade)
|
||||
connection.UpdateWithChildren(record);
|
||||
Connection.UpdateWithChildren(record);
|
||||
else
|
||||
connection.Update(record);
|
||||
Connection.Update(record);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue