forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestCompiler.cs
102 lines (90 loc) · 3.45 KB
/
TestCompiler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
namespace MonoGame.Tests.ContentPipeline
{
class TestCompiler
{
class TestContentManager : ContentManager
{
class FakeGraphicsService : IGraphicsDeviceService
{
public GraphicsDevice GraphicsDevice { get; private set; }
#pragma warning disable 67
public event EventHandler<EventArgs> DeviceCreated;
public event EventHandler<EventArgs> DeviceDisposing;
public event EventHandler<EventArgs> DeviceReset;
public event EventHandler<EventArgs> DeviceResetting;
#pragma warning restore 67
}
class FakeServiceProvider : IServiceProvider
{
public object GetService(Type serviceType)
{
if (serviceType == typeof(IGraphicsDeviceService))
return new FakeGraphicsService();
throw new NotImplementedException();
}
}
private readonly MemoryStream _xnbStream;
public TestContentManager(MemoryStream xnbStream)
: base(new FakeServiceProvider(), "NONE")
{
_xnbStream = xnbStream;
}
protected override Stream OpenStream(string assetName)
{
return new MemoryStream(_xnbStream.GetBuffer(), false);
}
}
static readonly IReadOnlyCollection<TargetPlatform> Platforms = new[]
{
TargetPlatform.Windows,
TargetPlatform.Xbox360,
TargetPlatform.iOS,
TargetPlatform.Android,
TargetPlatform.DesktopGL,
TargetPlatform.MacOSX,
TargetPlatform.WindowsStoreApp,
TargetPlatform.NativeClient,
TargetPlatform.PlayStationMobile,
TargetPlatform.WindowsPhone8,
TargetPlatform.RaspberryPi,
TargetPlatform.PlayStation4,
TargetPlatform.PSVita,
TargetPlatform.XboxOne,
TargetPlatform.Switch,
TargetPlatform.Web
};
static readonly IReadOnlyCollection<GraphicsProfile> GraphicsProfiles = new[]
{
GraphicsProfile.HiDef,
GraphicsProfile.Reach
};
static readonly IReadOnlyCollection<bool> CompressContents = new[]
{
true,
false
};
public static void CompileAndLoadAssets<T>(T data, Action<T> validation)
{
ContentCompiler compiler = new ContentCompiler();
foreach (var platform in Platforms)
foreach (var gfxProfile in GraphicsProfiles)
foreach (var compress in CompressContents)
using (var xnbStream = new MemoryStream())
{
compiler.Compile(xnbStream, data, platform, gfxProfile, compress, "", "");
using (var content = new TestContentManager(xnbStream))
{
var result = content.Load<T>("foo");
validation(result);
}
}
}
}
}