Exemplo n.º 1
0
        public void TestGenerateBitmap()
        {
            Init();

            var       fontManager = new FontManager(CreateDatabaseProvider());
            const int waitTime    = 250;
            const int defaultSize = 4;

            // test that a simple bitmap generation success
            var characterA = new CharacterSpecification('a', "Arial", new Vector2(1.73f, 3.57f), FontStyle.Regular, FontAntiAliasMode.Default);

            fontManager.GenerateBitmap(characterA, false);
            WaitAndCheck(characterA, waitTime);
            Assert.Equal(4, characterA.Bitmap.Width);
            Assert.Equal(6, characterA.Bitmap.Rows);

            // test that rendering an already existing character to a new size works
            var characterA2 = new CharacterSpecification('a', "Arial", 10f * Vector2.One, FontStyle.Regular, FontAntiAliasMode.Default);

            fontManager.GenerateBitmap(characterA2, false);
            WaitAndCheck(characterA2, waitTime);
            Assert.NotEqual(2, characterA2.Bitmap.Width);
            Assert.NotEqual(4, characterA2.Bitmap.Rows);

            // test that trying to render a character that does not exist does not crash the system
            var characterTo = new CharacterSpecification('都', "Arial", defaultSize * Vector2.One, FontStyle.Regular, FontAntiAliasMode.Default);
            var characterB  = new CharacterSpecification('b', "Arial", defaultSize * Vector2.One, FontStyle.Regular, FontAntiAliasMode.Default);

            fontManager.GenerateBitmap(characterTo, false);
            fontManager.GenerateBitmap(characterB, false);
            WaitAndCheck(characterB, 2 * waitTime);
            Assert.Null(characterTo.Bitmap);

            // test that trying to render a character that does not exist does not crash the system
            var characterC = new CharacterSpecification('c', "Arial", -1 * Vector2.One, FontStyle.Regular, FontAntiAliasMode.Default);
            var characterD = new CharacterSpecification('d', "Arial", defaultSize * Vector2.One, FontStyle.Regular, FontAntiAliasMode.Default);

            fontManager.GenerateBitmap(characterC, false);
            fontManager.GenerateBitmap(characterD, false);
            WaitAndCheck(characterD, 2 * waitTime);
            Assert.Null(characterC.Bitmap);

            fontManager.Dispose();
        }
Exemplo n.º 2
0
 private void WaitAndCheck(CharacterSpecification character, int sleepTime)
 {
     Thread.Sleep(sleepTime);
     Assert.NotNull(character.Bitmap);
 }
Exemplo n.º 3
0
 private void WaitAndCheck(CharacterSpecification character, int sleepTime)
 {
     Thread.Sleep(sleepTime);
     Assert.AreNotEqual(null, character.Bitmap);
 }