KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_richio.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
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
28
30
31#include <richio.h>
33
34#define wxUSE_BASE64 1
35#include <wx/base64.h>
36#include <wx/mstream.h>
37
38
40
41
42
48BOOST_AUTO_TEST_CASE( PrettifyLargeImageData )
49{
51
52 fmt.Print( "(kicad_sch (version 20231120) (generator \"eeschema\")" );
53 fmt.Print( "(image (at 0 0)" );
54
55 const size_t imageSize = 2 * 1024 * 1024;
56 std::vector<uint8_t> fakeImage( imageSize, 0x42 );
57
58 wxMemoryOutputStream stream;
59 stream.Write( fakeImage.data(), fakeImage.size() );
60
61 KICAD_FORMAT::FormatStreamData( fmt, *stream.GetOutputStreamBuffer() );
62
63 fmt.Print( ")" ); // close image
64 fmt.Print( ")" ); // close kicad_sch
65
66 std::string buf = fmt.GetString();
67
69
70 BOOST_CHECK_NO_THROW(
71 {
72 STRING_LINE_READER reader( buf, "test" );
73
74 while( reader.ReadLine() )
75 {
76 // just consume
77 }
78 } );
79}
80
81
88BOOST_AUTO_TEST_CASE( PrettifyLongQuotedString )
89{
90 const size_t longLen = 1100000;
91 std::string longValue( longLen, 'A' );
92
94
95 fmt.Print( "(kicad_sch (version 20231120)" );
96 fmt.Print( "(property \"Description\" %s (at 0 0 0))",
97 fmt.Quotes( longValue ).c_str() );
98 fmt.Print( ")" );
99
100 std::string buf = fmt.GetString();
101
103
104 BOOST_CHECK_NO_THROW(
105 {
106 STRING_LINE_READER reader( buf, "test" );
107
108 while( reader.ReadLine() )
109 {
110 // just consume
111 }
112 } );
113}
114
115
int PRINTF_FUNC_N Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition richio.cpp:422
virtual std::string Quotes(const std::string &aWrapee) const
Check aWrapee input string for a need to be quoted (e.g.
Definition richio.cpp:468
Implement an OUTPUTFORMATTER to a memory buffer.
Definition richio.h:422
const std::string & GetString()
Definition richio.h:445
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:226
char * ReadLine() override
Read a line of text into the buffer and increments the line number counter.
Definition richio.cpp:265
void Prettify(std::string &aSource, FORMAT_MODE aMode)
Pretty-prints s-expression text according to KiCad format rules.
void FormatStreamData(OUTPUTFORMATTER &aOut, const wxStreamBuffer &aStream)
Write binary data to the formatter as base 64 encoded string.
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(PrettifyLargeImageData)
Verify that Prettify produces well-formed output for large (data ...) blocks such as base64-encoded i...