#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 Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using NUnit.Framework;
using Nuclex.Graphics;
using Nuclex.Testing.Xna;
using KerningEntry = System.Collections.Generic.KeyValuePair<
Nuclex.Fonts.VectorFont.KerningPair, Microsoft.Xna.Framework.Vector2
>;
namespace Nuclex.Fonts {
/// Unit tests for the vector font character class
[TestFixture]
public class VectorFontCharacterTest {
/// Verifies that the tested character has a valid advancement
[Test]
public void TestAdvancement() {
Assert.Greater(this.vectorCharacter.Advancement.X, 0);
}
/// Verifies that the tested character has a face list
[Test]
public void TestFaces() {
Assert.Greater(this.vectorCharacter.Faces.Count, 0);
}
/// Verifies that the tested character has an outline list
[Test]
public void TestOutlines() {
Assert.Greater(this.vectorCharacter.Outlines.Count, 0);
}
/// Verifies that the tested character has vertices
[Test]
public void TestVertices() {
Assert.Greater(this.vectorCharacter.Vertices.Count, 0);
}
/// Called before each test is run
[SetUp]
public void Setup() {
this.mockedGraphicsDeviceService = new MockedGraphicsDeviceService();
this.mockedGraphicsDeviceService.CreateDevice();
this.contentManager = new ResourceContentManager(
GraphicsDeviceServiceHelper.MakePrivateServiceProvider(
this.mockedGraphicsDeviceService
),
Resources.UnitTestResources.ResourceManager
);
this.vectorFont = this.contentManager.Load("UnitTestVectorFont");
char character = getFirstVisibleCharacter();
int characterIndex = this.vectorFont.CharacterMap[character];
this.vectorCharacter = this.vectorFont.Characters[characterIndex];
}
/// Called after each test has run
[TearDown]
public void Teardown() {
if(this.contentManager != null) {
this.contentManager.Dispose();
this.contentManager = null;
}
if(this.mockedGraphicsDeviceService != null) {
this.mockedGraphicsDeviceService.DestroyDevice();
this.mockedGraphicsDeviceService = null;
}
}
/// Retrieves the first visible character in the font
/// The first visible character in the font
private char getFirstVisibleCharacter() {
foreach(KeyValuePair character in this.vectorFont.CharacterMap) {
int index = character.Value;
if(this.vectorFont.Characters[index].Outlines.Count > 0) {
return character.Key;
}
}
throw new InvalidOperationException("No visible characters found");
}
/// Mocked graphics device service used for unit testing
private MockedGraphicsDeviceService mockedGraphicsDeviceService;
/// Content manager used to load the vector font
private ResourceContentManager contentManager;
/// Vector font the tested character is taken from
private VectorFont vectorFont;
/// Vector font character being tested
private VectorFontCharacter vectorCharacter;
}
} // namespace Nuclex.Fonts
#endif // UNITTEST