#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2009 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
#if UNITTEST
using System;
using System.Collections.Generic;
using System.IO;
using System.Resources;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using NUnit.Framework;
using Nuclex.Graphics;
using Nuclex.Testing.Xna;
namespace Nuclex.Fonts.Content {
/// Unit tests for the vector font reader
[TestFixture]
public class VectorFontReaderTest {
#region class MemoryContentManager
/// Content manager for loading content from arrays
private class MemoryContentManager : ContentManager {
///
/// Initializes a new embedded content manager using a directly specified
/// graphics device service for the resources.
///
///
/// Graphics device service to load the content asset in
///
public MemoryContentManager(IGraphicsDeviceService graphicsDeviceService) :
this(makePrivateServiceContainer(graphicsDeviceService)) { }
///
/// Initializes a new embedded content manager using the provided game services
/// container for providing services for the loaded asset.
///
///
/// Service container containing the services the asset may access
///
public MemoryContentManager(IServiceProvider services) :
base(services) { }
/// Loads the asset the embedded content manager was created for
/// Type of the asset to load
/// Content that will be loaded as an asset
/// The loaded asset
public AssetType Load(byte[] content) {
lock(this) {
using(this.memoryStream = new MemoryStream(content, false)) {
return base.ReadAsset("null", null);
}
} // lock(this)
}
/// Opens a stream for reading the specified asset
/// The name of the asset to be read
/// The opened stream for the asset
protected override Stream OpenStream(string assetName) {
return this.memoryStream;
}
///
/// Creates a new game service container containing the specified graphics device
/// service only.
///
/// Service to add to the service container
/// A service container with the specified graphics device service
private static IServiceProvider makePrivateServiceContainer(
IGraphicsDeviceService graphicsDeviceService
) {
GameServiceContainer gameServices = new GameServiceContainer();
gameServices.AddService(typeof(IGraphicsDeviceService), graphicsDeviceService);
return gameServices;
}
/// Content that will be loaded by the embedded content manager
private MemoryStream memoryStream;
}
#endregion // class MemoryContentManager
///
/// Tests whether the constructor if the vector font reader is working
///
[Test]
public void TestConstructor() {
VectorFontReader reader = new VectorFontReader();
Assert.IsNotNull(reader); // nonsense; avoids compiler warning
}
/// Verifies that the vector font reader can load a vector font
[Test]
public void TestVectorFontReading() {
MockedGraphicsDeviceService service = new MockedGraphicsDeviceService();
using(IDisposable keeper = service.CreateDevice()) {
using(
ResourceContentManager contentManager = new ResourceContentManager(
GraphicsDeviceServiceHelper.MakePrivateServiceProvider(service),
Resources.UnitTestResources.ResourceManager
)
) {
VectorFont font = contentManager.Load("UnitTestVectorFont");
Assert.IsNotNull(font);
}
}
}
}
} // namespace Nuclex.Fonts.Content
#endif // UNITTEST