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, see <https://www.gnu.org/licenses/>.
18 */
19
24
26
27#include <richio.h>
29
30#define wxUSE_BASE64 1
31#include <wx/base64.h>
32#include <wx/mstream.h>
33
34
36
37
38
44BOOST_AUTO_TEST_CASE( PrettifyLargeImageData )
45{
47
48 fmt.Print( "(kicad_sch (version 20231120) (generator \"eeschema\")" );
49 fmt.Print( "(image (at 0 0)" );
50
51 const size_t imageSize = 2 * 1024 * 1024;
52 std::vector<uint8_t> fakeImage( imageSize, 0x42 );
53
54 wxMemoryOutputStream stream;
55 stream.Write( fakeImage.data(), fakeImage.size() );
56
57 KICAD_FORMAT::FormatStreamData( fmt, *stream.GetOutputStreamBuffer() );
58
59 fmt.Print( ")" ); // close image
60 fmt.Print( ")" ); // close kicad_sch
61
62 std::string buf = fmt.GetString();
63
65
66 BOOST_CHECK_NO_THROW(
67 {
68 STRING_LINE_READER reader( buf, "test" );
69
70 while( reader.ReadLine() )
71 {
72 // just consume
73 }
74 } );
75}
76
77
84BOOST_AUTO_TEST_CASE( PrettifyLongQuotedString )
85{
86 const size_t longLen = 1100000;
87 std::string longValue( longLen, 'A' );
88
90
91 fmt.Print( "(kicad_sch (version 20231120)" );
92 fmt.Print( "(property \"Description\" %s (at 0 0 0))",
93 fmt.Quotes( longValue ).c_str() );
94 fmt.Print( ")" );
95
96 std::string buf = fmt.GetString();
97
99
100 BOOST_CHECK_NO_THROW(
101 {
102 STRING_LINE_READER reader( buf, "test" );
103
104 while( reader.ReadLine() )
105 {
106 // just consume
107 }
108 } );
109}
110
111
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:418
const std::string & GetString()
Definition richio.h:441
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:222
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...