Gfx: Add some tests for TextFormatD2D

This commit is contained in:
Birunthan Mohanathas 2013-08-11 14:10:05 +03:00
parent 176a9414f5
commit 0afbdac9fe
4 changed files with 83 additions and 0 deletions

View File

@ -47,6 +47,8 @@ public:
private:
friend class CanvasD2D;
friend class Common_Gfx_TextFormatD2D_Test;
TextFormatD2D(const TextFormatD2D& other) {}
void Dispose();

View File

@ -0,0 +1,75 @@
/*
Copyright (C) 2013 Birunthan Mohanathas
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "Canvas.h"
#include "TextFormatD2D.h"
#include <CppUnitTest.h>
#include <memory>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace Gfx {
TEST_CLASS(Common_Gfx_TextFormatD2D_Test)
{
public:
std::unique_ptr<Canvas> m_D2D;
Common_Gfx_TextFormatD2D_Test() :
m_D2D(Canvas::Create(Gfx::Renderer::D2D))
{
// TODO: Handle this in CanvasD2D.
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
m_D2D->Resize(10, 10);
m_D2D->SetAntiAliasing(true);
}
TEST_METHOD(TestInaccurateText)
{
std::unique_ptr<TextFormatD2D> textFormat((TextFormatD2D*)m_D2D->CreateTextFormat());
textFormat->SetProperties(L"Arial", 10, false, false, nullptr);
DWRITE_TEXT_METRICS metrics = textFormat->GetMetrics(L"test", 4, true);
Assert::AreEqual(26, (int)metrics.width);
Assert::AreEqual(16, (int)metrics.height);
metrics = textFormat->GetMetrics(L"test", 4, false);
Assert::AreEqual(21, (int)metrics.width);
Assert::AreEqual(14, (int)metrics.height);
}
TEST_METHOD(TestTrailingNewlineGdipCompatibility)
{
std::unique_ptr<TextFormatD2D> textFormat((TextFormatD2D*)m_D2D->CreateTextFormat());
textFormat->SetProperties(L"Arial", 10, false, false, nullptr);
DWRITE_TEXT_METRICS metrics = textFormat->GetMetrics(L"test\n", 5, false);
Assert::AreEqual(15, (int)metrics.height);
metrics = textFormat->GetMetrics(L"test\n ", 6, false);
Assert::AreEqual(30, (int)metrics.height);
metrics = textFormat->GetMetrics(L"test\n\n", 6, false);
Assert::AreEqual(30, (int)metrics.height);
}
};
} // namespace Gfx

View File

@ -74,6 +74,9 @@
<ClCompile Include="..\Common\Gfx\FontCollectionGDIP.cpp" />
<ClCompile Include="..\Common\Gfx\TextFormat.cpp" />
<ClCompile Include="..\Common\Gfx\TextFormatD2D.cpp" />
<ClCompile Include="..\Common\Gfx\TextFormatD2D_Test.cpp">
<ExcludedFromBuild>$(ExcludeTests)</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\Common\Gfx\TextFormatGDIP.cpp" />
<ClCompile Include="..\Common\Gfx\Util\DWriteHelpers.cpp" />
<ClCompile Include="..\Common\Gfx\Util\DWriteFontCollectionLoader.cpp" />

View File

@ -354,6 +354,9 @@
<ClCompile Include="..\Common\Gfx\TextFormatD2D.cpp">
<Filter>Common\Gfx</Filter>
</ClCompile>
<ClCompile Include="..\Common\Gfx\TextFormatD2D_Test.cpp">
<Filter>Common\Gfx</Filter>
</ClCompile>
<ClCompile Include="..\Common\Gfx\TextFormatGDIP.cpp">
<Filter>Common\Gfx</Filter>
</ClCompile>