Add a simple unit test for wxHtmlPrintout pagination logic
Verify that the number of pages to be printed is as expected.
This commit is contained in:
parent
048b7f44ec
commit
dd92a269c3
@ -243,6 +243,7 @@ TEST_GUI_OBJECTS = \
|
||||
test_gui_rawbmp.o \
|
||||
test_gui_htmlparser.o \
|
||||
test_gui_htmlwindow.o \
|
||||
test_gui_htmprint.o \
|
||||
test_gui_accelentry.o \
|
||||
test_gui_menu.o \
|
||||
test_gui_guifuncs.o \
|
||||
@ -997,6 +998,9 @@ test_gui_htmlparser.o: $(srcdir)/html/htmlparser.cpp $(TEST_GUI_ODEP)
|
||||
test_gui_htmlwindow.o: $(srcdir)/html/htmlwindow.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/html/htmlwindow.cpp
|
||||
|
||||
test_gui_htmprint.o: $(srcdir)/html/htmprint.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/html/htmprint.cpp
|
||||
|
||||
test_gui_accelentry.o: $(srcdir)/menu/accelentry.cpp $(TEST_GUI_ODEP)
|
||||
$(CXXC) -c -o $@ $(TEST_GUI_CXXFLAGS) $(srcdir)/menu/accelentry.cpp
|
||||
|
||||
|
82
tests/html/htmprint.cpp
Normal file
82
tests/html/htmprint.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Name: tests/html/htmprint.cpp
|
||||
// Purpose: wxHtmlPrintout tests
|
||||
// Author: Vadim Zeitlin
|
||||
// Created: 2018-05-22
|
||||
// Copyright: (c) 2018 Vadim Zeitlin <vadim@wxwidgets.org>
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// headers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#include "testprec.h"
|
||||
|
||||
#if wxUSE_HTML
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dcmemory.h"
|
||||
#endif // WX_PRECOMP
|
||||
|
||||
#include "wx/html/htmprint.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Return the number of pages in the printout.
|
||||
int CountPages(wxHtmlPrintout& pr)
|
||||
{
|
||||
REQUIRE_NOTHROW( pr.OnPreparePrinting() );
|
||||
|
||||
int pageMin = -1,
|
||||
pageMax = -1,
|
||||
selFrom = -1,
|
||||
selTo = -1;
|
||||
REQUIRE_NOTHROW( pr.GetPageInfo(&pageMin, &pageMax, &selFrom, &selTo) );
|
||||
|
||||
// This should be always the case.
|
||||
CHECK( pageMin == 1 );
|
||||
|
||||
// Return the really interesting value to the caller.
|
||||
return pageMax;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST_CASE("wxHtmlPrintout::Pagination", "[html][print]")
|
||||
{
|
||||
wxHtmlPrintout pr;
|
||||
|
||||
wxBitmap bmp(1000, 1000);
|
||||
wxMemoryDC dc(bmp);
|
||||
pr.SetUp(dc);
|
||||
|
||||
// Empty or short HTML documents should be printed on a single page only.
|
||||
CHECK( CountPages(pr) == 1 );
|
||||
|
||||
pr.SetHtmlText("<p>Hello world!</p>");
|
||||
CHECK( CountPages(pr) == 1 );
|
||||
|
||||
// This one should be too big to fit on a single page.
|
||||
pr.SetHtmlText
|
||||
(
|
||||
"<img width=\"100\" height=\"600\" src=\"dummy\"/>"
|
||||
"<br/>"
|
||||
"<img width=\"100\" height=\"600\" src=\"dummy\"/>"
|
||||
);
|
||||
CHECK( CountPages(pr) == 2 );
|
||||
|
||||
// Special case: normally images are not split, but if the image height is
|
||||
// greater than the page height, it should be.
|
||||
pr.SetHtmlText
|
||||
(
|
||||
"<img width=\"100\" height=\"2500\" src=\"dummy\"/>"
|
||||
);
|
||||
CHECK( CountPages(pr) == 3 );
|
||||
}
|
||||
|
||||
#endif //wxUSE_HTML
|
@ -229,6 +229,7 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_rawbmp.obj \
|
||||
$(OBJS)\test_gui_htmlparser.obj \
|
||||
$(OBJS)\test_gui_htmlwindow.obj \
|
||||
$(OBJS)\test_gui_htmprint.obj \
|
||||
$(OBJS)\test_gui_accelentry.obj \
|
||||
$(OBJS)\test_gui_menu.obj \
|
||||
$(OBJS)\test_gui_guifuncs.obj \
|
||||
@ -1050,6 +1051,9 @@ $(OBJS)\test_gui_htmlparser.obj: .\html\htmlparser.cpp
|
||||
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp
|
||||
|
||||
$(OBJS)\test_gui_htmprint.obj: .\html\htmprint.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\html\htmprint.cpp
|
||||
|
||||
$(OBJS)\test_gui_accelentry.obj: .\menu\accelentry.cpp
|
||||
$(CXX) -q -c -P -o$@ $(TEST_GUI_CXXFLAGS) .\menu\accelentry.cpp
|
||||
|
||||
|
@ -224,6 +224,7 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_rawbmp.o \
|
||||
$(OBJS)\test_gui_htmlparser.o \
|
||||
$(OBJS)\test_gui_htmlwindow.o \
|
||||
$(OBJS)\test_gui_htmprint.o \
|
||||
$(OBJS)\test_gui_accelentry.o \
|
||||
$(OBJS)\test_gui_menu.o \
|
||||
$(OBJS)\test_gui_guifuncs.o \
|
||||
@ -1027,6 +1028,9 @@ $(OBJS)\test_gui_htmlparser.o: ./html/htmlparser.cpp
|
||||
$(OBJS)\test_gui_htmlwindow.o: ./html/htmlwindow.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_htmprint.o: ./html/htmprint.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
$(OBJS)\test_gui_accelentry.o: ./menu/accelentry.cpp
|
||||
$(CXX) -c -o $@ $(TEST_GUI_CXXFLAGS) $(CPPDEPS) $<
|
||||
|
||||
|
@ -235,6 +235,7 @@ TEST_GUI_OBJECTS = \
|
||||
$(OBJS)\test_gui_rawbmp.obj \
|
||||
$(OBJS)\test_gui_htmlparser.obj \
|
||||
$(OBJS)\test_gui_htmlwindow.obj \
|
||||
$(OBJS)\test_gui_htmprint.obj \
|
||||
$(OBJS)\test_gui_accelentry.obj \
|
||||
$(OBJS)\test_gui_menu.obj \
|
||||
$(OBJS)\test_gui_guifuncs.obj \
|
||||
@ -1229,6 +1230,9 @@ $(OBJS)\test_gui_htmlparser.obj: .\html\htmlparser.cpp
|
||||
$(OBJS)\test_gui_htmlwindow.obj: .\html\htmlwindow.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\html\htmlwindow.cpp
|
||||
|
||||
$(OBJS)\test_gui_htmprint.obj: .\html\htmprint.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\html\htmprint.cpp
|
||||
|
||||
$(OBJS)\test_gui_accelentry.obj: .\menu\accelentry.cpp
|
||||
$(CXX) /c /nologo /TP /Fo$@ $(TEST_GUI_CXXFLAGS) .\menu\accelentry.cpp
|
||||
|
||||
|
@ -249,6 +249,7 @@
|
||||
image/rawbmp.cpp
|
||||
html/htmlparser.cpp
|
||||
html/htmlwindow.cpp
|
||||
html/htmprint.cpp
|
||||
menu/accelentry.cpp
|
||||
menu/menu.cpp
|
||||
misc/guifuncs.cpp
|
||||
|
@ -535,6 +535,7 @@
|
||||
<ClCompile Include="graphics\measuring.cpp" />
|
||||
<ClCompile Include="html\htmlparser.cpp" />
|
||||
<ClCompile Include="html\htmlwindow.cpp" />
|
||||
<ClCompile Include="html\htmprint.cpp" />
|
||||
<ClCompile Include="image\image.cpp" />
|
||||
<ClCompile Include="image\rawbmp.cpp" />
|
||||
<ClCompile Include="menu\accelentry.cpp" />
|
||||
@ -564,4 +565,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -293,10 +293,13 @@
|
||||
<ClCompile Include="graphics\graphmatrix.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="html\htmprint.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="..\samples\sample.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
@ -439,6 +439,9 @@
|
||||
<File
|
||||
RelativePath=".\html\htmlwindow.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\html\htmprint.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\hyperlinkctrltest.cpp">
|
||||
</File>
|
||||
|
@ -1054,6 +1054,10 @@
|
||||
RelativePath=".\html\htmlwindow.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\html\htmprint.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\hyperlinkctrltest.cpp"
|
||||
>
|
||||
|
@ -1026,6 +1026,10 @@
|
||||
RelativePath=".\html\htmlwindow.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\html\htmprint.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\controls\hyperlinkctrltest.cpp"
|
||||
>
|
||||
|
Loading…
Reference in New Issue
Block a user