KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_reset_print_to_file.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#include <printing.h>
23
24#include <wx/print.h>
25#include <wx/cmndata.h>
26
27#if defined( __WXGTK__ ) && wxUSE_GTKPRINT
28#include <wx/gtk/print.h>
29#include <gtk/gtk.h>
30#endif
31
32
33BOOST_AUTO_TEST_SUITE( ResetPrintToFile )
34
35
36// A destination the user typed has to survive so that the print dialog reopens on it.
37BOOST_AUTO_TEST_CASE( KeepsWxFilename )
38{
39 const wxString chosen( wxT( "/home/user/Documents/output.pdf" ) );
40
41 wxPrintData data;
42 data.SetFilename( chosen );
43
45
46 BOOST_CHECK_EQUAL( data.GetFilename(), chosen );
47}
48
49
50#ifdef __WXGTK__
51
52BOOST_AUTO_TEST_CASE( ClearsWxSpoolFilename )
53{
54 wxPrintData data;
55 data.SetFilename( wxT( "/tmp/gtkprintCG3W42" ) );
56
58
59 BOOST_CHECK( data.GetFilename().IsEmpty() );
60}
61
62
63// Only the whole g_mkstemp() template is a spool name, so a file the user happened to name this
64// way is still theirs.
65BOOST_AUTO_TEST_CASE( KeepsWxSpoolPrefixedFilename )
66{
67 const wxString chosen( wxT( "/tmp/gtkprint-report.pdf" ) );
68
69 wxPrintData data;
70 data.SetFilename( chosen );
71
73
74 BOOST_CHECK_EQUAL( data.GetFilename(), chosen );
75}
76
77#endif
78
79
80#if defined( __WXGTK__ ) && wxUSE_GTKPRINT
81
82// GTK carries the print-to-file destination in the native GtkPrintSettings output URI, which the
83// wx-level filename does not track.
84static void setGtkOutputUri( wxPrintData& aData, const char* aUri )
85{
86 wxGtkPrintNativeData* nativeData = dynamic_cast<wxGtkPrintNativeData*>( aData.GetNativeData() );
87 BOOST_REQUIRE( nativeData );
88 BOOST_REQUIRE( nativeData->GetPrintConfig() );
89
90 gtk_print_settings_set( nativeData->GetPrintConfig(), GTK_PRINT_SETTINGS_OUTPUT_URI, aUri );
91}
92
93
94static const gchar* getGtkOutputUri( wxPrintData& aData )
95{
96 wxGtkPrintNativeData* nativeData = dynamic_cast<wxGtkPrintNativeData*>( aData.GetNativeData() );
97 BOOST_REQUIRE( nativeData );
98 BOOST_REQUIRE( nativeData->GetPrintConfig() );
99
100 return gtk_print_settings_get( nativeData->GetPrintConfig(), GTK_PRINT_SETTINGS_OUTPUT_URI );
101}
102
103
104BOOST_AUTO_TEST_CASE( KeepsGtkOutputUri )
105{
106 wxPrintData data;
107 setGtkOutputUri( data, "file:///home/user/Documents/output.pdf" );
108
110
111 const gchar* uri = getGtkOutputUri( data );
112
113 BOOST_REQUIRE( uri != nullptr );
114 BOOST_CHECK_EQUAL( uri, "file:///home/user/Documents/output.pdf" );
115}
116
117
118// The scratch file GTK spools through would otherwise become the suggested output file on the
119// next print, which is issue 22985.
120BOOST_AUTO_TEST_CASE( ClearsGtkSpoolUri )
121{
122 wxPrintData data;
123 setGtkOutputUri( data, "file:///tmp/gtkprintCG3W42" );
124
126
127 BOOST_CHECK( getGtkOutputUri( data ) == nullptr );
128}
129
130
131// The underscored template is the one gtkprintjob.c uses.
132BOOST_AUTO_TEST_CASE( ClearsGtkUnderscoredSpoolUri )
133{
134 wxPrintData data;
135 setGtkOutputUri( data, "file:///tmp/gtkprint_CG3W42" );
136
138
139 BOOST_CHECK( getGtkOutputUri( data ) == nullptr );
140}
141
142
143BOOST_AUTO_TEST_CASE( KeepsGtkSpoolPrefixedOutputUri )
144{
145 wxPrintData data;
146 setGtkOutputUri( data, "file:///tmp/gtkprint-report.pdf" );
147
149
150 const gchar* uri = getGtkOutputUri( data );
151
152 BOOST_REQUIRE( uri != nullptr );
153 BOOST_CHECK_EQUAL( uri, "file:///tmp/gtkprint-report.pdf" );
154}
155
156#endif
157
158
void ResetPrintToFilePath(wxPrintData &aData)
Discard a "print to file" destination in aData that the platform print backend generated for its own ...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(KeepsWxFilename)
BOOST_CHECK_EQUAL(result, "25.4")