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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
///////////////////////////////////////////////////////////////////////////////
// Name: tests/graphics/boundingbox.cpp
// Purpose: wxGCDC bounding box unit tests
// Author: Vadim Zeitlin / Maarten Spoek / Toni Ruža
// Created: 2011-01-36
// RCS-ID: $Id$
// Copyright: (c) 2011 Vadim Zeitlin <vadim@wxwidgets.org>
// (c) 2014 Toni Ruža <toni.ruza@gmail.com>
///////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
#include "testprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#include "wx/bitmap.h"
#include "wx/dcmemory.h"
#include "wx/dcgraph.h"
#include "wx/icon.h"
#include "wx/colour.h"
#include "wx/gdicmn.h"
// ----------------------------------------------------------------------------
// test class
// ----------------------------------------------------------------------------
class GCDCBoundingBoxTestCase : public CppUnit::TestCase
{
public:
GCDCBoundingBoxTestCase()
{
m_bmp.Create(100, 100);
m_dc.SelectObject(m_bmp);
m_gcdc = new wxGCDC(m_dc);
}
~GCDCBoundingBoxTestCase()
{
delete m_gcdc;
m_dc.SelectObject(wxNullBitmap);
m_bmp = wxNullBitmap;
}
virtual void setUp()
{
m_gcdc->ResetBoundingBox();
}
private:
wxBitmap m_bmp;
wxMemoryDC m_dc;
wxGCDC *m_gcdc;
void AssertBox(int minX, int minY, int width, int height, int margin = 0)
{
int maxX = minX + width;
int maxY = minY + height;
// Allow for a margin of error due to different implementation
// specificities regarding drawing paths.
if ( margin )
{
#define WX_ASSERT_CLOSE(expected, actual, delta) \
WX_ASSERT_MESSAGE(("%d != %d", actual, expected), \
abs(actual - expected) <= delta)
WX_ASSERT_CLOSE(minX, m_gcdc->MinX(), margin);
WX_ASSERT_CLOSE(minY, m_gcdc->MinY(), margin);
WX_ASSERT_CLOSE(maxX, m_gcdc->MaxX(), margin);
WX_ASSERT_CLOSE(maxY, m_gcdc->MaxY(), margin);
#undef WX_ASSERT_CLOSE
}
else
{
CPPUNIT_ASSERT_EQUAL(minX, m_gcdc->MinX());
CPPUNIT_ASSERT_EQUAL(minY, m_gcdc->MinY());
CPPUNIT_ASSERT_EQUAL(maxX, m_gcdc->MaxX());
CPPUNIT_ASSERT_EQUAL(maxY, m_gcdc->MaxY());
}
}
CPPUNIT_TEST_SUITE( GCDCBoundingBoxTestCase );
CPPUNIT_TEST( DrawBitmap );
CPPUNIT_TEST( DrawIcon );
CPPUNIT_TEST( DrawLine );
CPPUNIT_TEST( CrossHair );
CPPUNIT_TEST( DrawArc );
CPPUNIT_TEST( DrawEllipticArc );
CPPUNIT_TEST( DrawPoint );
CPPUNIT_TEST( DrawLines );
#if wxUSE_SPLINES
CPPUNIT_TEST( DrawSpline );
#endif
CPPUNIT_TEST( DrawPolygon );
CPPUNIT_TEST( DrawPolyPolygon );
CPPUNIT_TEST( DrawRectangle );
CPPUNIT_TEST( DrawRoundedRectangle );
CPPUNIT_TEST( DrawEllipse );
CPPUNIT_TEST( Blit );
CPPUNIT_TEST( StretchBlit );
CPPUNIT_TEST( DrawRotatedText );
CPPUNIT_TEST( DrawText );
CPPUNIT_TEST( GradientFillLinear );
CPPUNIT_TEST( GradientFillConcentric );
CPPUNIT_TEST( DrawCheckMark );
CPPUNIT_TEST_SUITE_END();
void DrawBitmap();
void DrawIcon();
void DrawLine();
void CrossHair();
void DrawArc();
void DrawEllipticArc();
void DrawPoint();
void DrawLines();
#if wxUSE_SPLINES
void DrawSpline();
#endif
void DrawPolygon();
void DrawPolyPolygon();
void DrawRectangle();
void DrawRoundedRectangle();
void DrawEllipse();
void Blit();
void StretchBlit();
void DrawRotatedText();
void DrawText();
void GradientFillLinear();
void GradientFillConcentric();
void DrawCheckMark();
DECLARE_NO_COPY_CLASS(GCDCBoundingBoxTestCase)
};
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( GCDCBoundingBoxTestCase );
// also include in it's own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( GCDCBoundingBoxTestCase, "GCDCBoundingBoxTestCase" );
void GCDCBoundingBoxTestCase::DrawBitmap()
{
wxBitmap bitmap;
bitmap.Create(12, 12);
m_gcdc->DrawBitmap(bitmap, 5, 5);
AssertBox(5, 5, 12, 12);
}
void GCDCBoundingBoxTestCase::DrawIcon()
{
wxBitmap bitmap;
bitmap.Create(16, 16);
wxIcon icon;
icon.CopyFromBitmap(bitmap);
m_gcdc->DrawIcon(icon, 42, 42);
AssertBox(42, 42, 16, 16);
}
void GCDCBoundingBoxTestCase::DrawLine()
{
m_gcdc->DrawLine(10, 10, 20, 15);
AssertBox(10, 10, 10, 5);
}
void GCDCBoundingBoxTestCase::CrossHair()
{
int w, h;
m_gcdc->GetSize(&w, &h);
m_gcdc->CrossHair(33, 33);
AssertBox(0, 0, w, h);
}
void GCDCBoundingBoxTestCase::DrawArc()
{
m_gcdc->DrawArc(25, 30, 15, 40, 25, 40); // quarter circle
AssertBox(15, 30, 10, 10, 3);
}
void GCDCBoundingBoxTestCase::DrawEllipticArc()
{
m_gcdc->DrawEllipticArc(40, 50, 30, 20, 0, 180); // half circle
AssertBox(40, 50, 30, 10, 3);
}
void GCDCBoundingBoxTestCase::DrawPoint()
{
m_gcdc->DrawPoint(20, 20);
AssertBox(20, 20, 0, 0);
}
void GCDCBoundingBoxTestCase::DrawLines()
{
wxPoint points[4];
points[0] = wxPoint(10, 20);
points[1] = wxPoint(20, 10);
points[2] = wxPoint(30, 20);
points[3] = wxPoint(20, 30);
m_gcdc->DrawLines(4, points, 7, 8);
AssertBox(17, 18, 20, 20);
}
#if wxUSE_SPLINES
void GCDCBoundingBoxTestCase::DrawSpline()
{
wxPoint points[3];
points[0] = wxPoint(10, 30);
points[1] = wxPoint(20, 20);
points[2] = wxPoint(40, 50);
m_gcdc->DrawSpline(3, points);
AssertBox(10, 20, 30, 30, 5);
}
#endif // wxUSE_SPLINES
void GCDCBoundingBoxTestCase::DrawPolygon()
{
wxPoint points[3];
points[0] = wxPoint(10, 30);
points[1] = wxPoint(20, 10);
points[2] = wxPoint(30, 30);
m_gcdc->DrawPolygon(3, points, -5, -7);
AssertBox(5, 3, 20, 20);
}
void GCDCBoundingBoxTestCase::DrawPolyPolygon()
{
int lenghts[2];
lenghts[0] = 3;
lenghts[1] = 3;
wxPoint points[6];
points[0] = wxPoint(10, 30);
points[1] = wxPoint(20, 10);
points[2] = wxPoint(30, 30);
points[3] = wxPoint(20, 60);
points[4] = wxPoint(30, 40);
points[5] = wxPoint(40, 60);
m_gcdc->DrawPolyPolygon(2, lenghts, points, 12, 5);
AssertBox(22, 15, 30, 50, 4);
}
void GCDCBoundingBoxTestCase::DrawRectangle()
{
m_gcdc->DrawRectangle(2, 2, 12, 12);
AssertBox(2, 2, 12, 12);
}
void GCDCBoundingBoxTestCase::DrawRoundedRectangle()
{
m_gcdc->DrawRoundedRectangle(27, 27, 12, 12, 2);
AssertBox(27, 27, 12, 12);
}
void GCDCBoundingBoxTestCase::DrawEllipse()
{
m_gcdc->DrawEllipse(54, 45, 23, 12);
AssertBox(54, 45, 23, 12);
}
void GCDCBoundingBoxTestCase::Blit()
{
wxBitmap bitmap;
bitmap.Create(20, 20);
wxMemoryDC dc(bitmap);
m_gcdc->Blit(20, 10, 12, 7, &dc, 0, 0);
AssertBox(20, 10, 12, 7);
dc.SelectObject(wxNullBitmap);
}
void GCDCBoundingBoxTestCase::StretchBlit()
{
wxBitmap bitmap;
bitmap.Create(20, 20);
wxMemoryDC dc(bitmap);
m_gcdc->StretchBlit(30, 50, 5, 5, &dc, 0, 0, 12, 4);
AssertBox(30, 50, 5, 5);
dc.SelectObject(wxNullBitmap);
}
void GCDCBoundingBoxTestCase::DrawRotatedText()
{
wxString text("vertical");
wxCoord w, h;
m_gcdc->GetTextExtent(text, &w, &h);
m_gcdc->DrawRotatedText(text, 43, 22, -90);
AssertBox(43 - h, 22, h, w, 3);
}
void GCDCBoundingBoxTestCase::DrawText()
{
wxString text("H");
wxCoord w, h;
m_gcdc->GetTextExtent(text, &w, &h);
m_gcdc->DrawText(text, 3, 3);
AssertBox(3, 3, w, h, 3);
}
void GCDCBoundingBoxTestCase::GradientFillLinear()
{
wxRect rect(16, 16, 30, 40);
m_gcdc->GradientFillLinear(rect, *wxWHITE, *wxBLACK, wxNORTH);
AssertBox(16, 16, 30, 40);
}
void GCDCBoundingBoxTestCase::GradientFillConcentric()
{
wxRect rect(6, 6, 30, 40);
m_gcdc->GradientFillConcentric(rect, *wxWHITE, *wxBLACK, wxPoint(10, 10));
AssertBox(6, 6, 30, 40);
}
void GCDCBoundingBoxTestCase::DrawCheckMark()
{
m_gcdc->DrawCheckMark(32, 24, 16, 16);
AssertBox(32, 24, 16, 16);
}
|