>From d09ada1b64a28b34e4dbbb70af0afd95a36fdf8a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 1 Jul 2015 01:24:26 +0200 Subject: [PATCH 4/4] Add a simple unit test for wxPdfDocument. While the test is trivial, it is still useful if only to allow checking that linking with the library succeeds, especially as it is relatively non trivial because we need to painstakingly manually construct its name in our makefile. --- objects.make | 5 +++++ workhorse.make | 11 +++++++++++ wx_pdfdoc_test.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 wx_pdfdoc_test.cpp diff --git a/objects.make b/objects.make index 4d8eb57..f81228e 100644 --- a/objects.make +++ b/objects.make @@ -454,6 +454,7 @@ unit_test_targets := \ value_cast_test \ vector_test \ wx_new_test \ + wx_pdfdoc_test \ xml_serialize_test \ zero_test \ @@ -913,6 +914,10 @@ wx_new_test$(EXEEXT): \ $(common_test_objects) \ wx_new_test.o \ +wx_pdfdoc_test$(EXEEXT): \ + $(common_test_objects) \ + wx_pdfdoc_test.o \ + xml_serialize_test$(EXEEXT): \ $(common_test_objects) \ $(xmlwrapp_objects) \ diff --git a/workhorse.make b/workhorse.make index 23e706d..dcc24f1 100644 --- a/workhorse.make +++ b/workhorse.make @@ -172,6 +172,12 @@ wx_config_script := \ ifeq (gcc,$(toolset)) wx_config_cxxflags := $(shell $(wx_config_script) --cxxflags) wx_config_libs := $(shell $(wx_config_script) --libs) + wx_config_basename := $(shell $(wx_config_script) --basename) + wx_config_version := $(shell $(wx_config_script) --version) + + # Define the variables used to construct the names of wxCode libraries. + wxcode_basename := $(shell echo $(wx_config_basename) | sed 's/^wx/wxcode/') + wxcode_version := $(shell echo $(wx_config_version) | sed 's/\.[0-9]*$$//') endif # ...combines options that we prefer to keep separate. @@ -612,6 +618,9 @@ wx_ldflags = \ $(platform_wx_libraries) \ $(platform_gui_ldflags) \ +wx_pdfdoc_ldflags := \ + -l$(wxcode_basename)_pdfdoc-$(wxcode_version) + ################################################################################ # Flags. @@ -853,6 +862,8 @@ antediluvian_cli_monolithic$(EXEEXT): $(cli_objects) $(antediluvian_common_objec wx_new$(SHREXT): wx_new.o +wx_pdfdoc_test$(EXEEXT): EXTRA_LDFLAGS := $(wx_pdfdoc_ldflags) $(wx_ldflags) + wx_test$(EXEEXT): lmi_so_attributes := -DLMI_USE_SO wx_test$(EXEEXT): EXTRA_LDFLAGS := $(wx_ldflags) wx_test$(EXEEXT): $(wx_test_objects) skeleton$(SHREXT) liblmi$(SHREXT) diff --git a/wx_pdfdoc_test.cpp b/wx_pdfdoc_test.cpp new file mode 100644 index 0000000..b69012c --- /dev/null +++ b/wx_pdfdoc_test.cpp @@ -0,0 +1,55 @@ +// wxPdfDocument library unit test. +// +// Copyright (C) 2015 Gregory W. Chicares. +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License version 2 as +// published by the Free Software Foundation. +// +// 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 St, Fifth Floor, Boston, MA 02110-1301, USA +// +// http://savannah.nongnu.org/projects/lmi +// email: +// snail: Chicares, 186 Belle Woods Drive, Glastonbury CT 06033, USA + +// $Id$ + +// This unit test checks that linking with wxPdfDocument library and generating +// the simplest possible document with it works. + +#ifdef __BORLANDC__ +# include "pchfile.hpp" +# pragma hdrstop +#endif + +#include "platform_dependent.hpp" // access() +#include "test_tools.hpp" + +#include + +#include + +int test_main(int argc, char* argv[]) +{ + wxInitializer init(argc, argv); + BOOST_TEST( init ); + + wxPdfDocument pdf_doc(wxLANDSCAPE, "pt", wxPAPER_LETTER); + pdf_doc.AddPage(); + pdf_doc.SetFont("Helvetica", "", 16); + pdf_doc.Text(20, 20, "Hello PDF!"); + + char const* const p = "/tmp/eraseme.pdf"; + pdf_doc.SaveAsFile(p); + BOOST_TEST_EQUAL(0, access(p, R_OK)); + BOOST_TEST(0 == std::remove(p)); + + return 0; +} -- 2.1.0