24#include <boost/test/unit_test.hpp>
32#include <wx/filename.h>
33#include <wx/stdpaths.h>
50 explicit ScopedTmpFile(
const wxString& aExt )
52 wxString tmp = wxStandardPaths::Get().GetTempDir();
53 static int counter = 0;
54 wxString
name = wxString::Format( wxS(
"kicad_render_%d_%d.%s" ),
static_cast<int>( wxGetProcessId() ),
56 m_path = tmp + wxFILE_SEP_PATH +
name;
61 if( !m_path.IsEmpty() && wxFileExists( m_path ) )
62 wxRemoveFile( m_path );
65 const wxString& Path()
const {
return m_path; }
73std::string readHeaderBytes(
const wxString& aPath,
size_t aBytes )
80 std::string buf( aBytes,
'\0' );
81 ssize_t got = f.Read( buf.data(), aBytes );
86 buf.resize(
static_cast<size_t>( got ) );
108 auto add = [&]( std::vector<SCENE_SHAPE>& aBucket,
const BOX2I& bb,
114 aBucket.push_back( s );
152std::string readWholeFile(
const wxString& aPath )
161 if( !f.ReadAll( &content ) )
164 return std::string( content.utf8_str() );
171double largestSvgRectWidthMM(
const std::string& aSvg )
173 std::regex rectWidth(
"<rect[^>]*width=\"([0-9.]+)\"" );
175 auto begin = std::sregex_iterator( aSvg.begin(), aSvg.end(), rectWidth );
176 auto end = std::sregex_iterator();
178 for(
auto it = begin; it !=
end; ++it )
179 best = std::max( best, std::stod( ( *it )[1].str() ) );
197 constexpr int oneMillimetreSchIU = 10000;
199 ScopedTmpFile schOut( wxS(
"svg" ) );
205 double schWidthMM = largestSvgRectWidthMM( readWholeFile( schOut.Path() ) );
209 BOOST_CHECK_GT( schWidthMM, 0.5 );
214 ScopedTmpFile pcbOut( wxS(
"svg" ) );
218 double pcbWidthMM = largestSvgRectWidthMM( readWholeFile( pcbOut.Path() ) );
220 BOOST_CHECK_GT( pcbWidthMM, 0.0 );
225 const double ratio = schWidthMM / pcbWidthMM;
234 ScopedTmpFile out( wxS(
"png" ) );
242 std::string
header = readHeaderBytes( out.Path(), 8 );
243 BOOST_REQUIRE_GE(
header.size(), 8u );
256 ScopedTmpFile out( wxS(
"png" ) );
266 wxFileName fn( out.Path() );
267 wxULongLong size = fn.GetSize();
271 BOOST_CHECK_GT( size.GetValue(), 67u );
274 std::string
header = readHeaderBytes( out.Path(), 8 );
282 ScopedTmpFile out( wxS(
"svg" ) );
289 std::string content = readHeaderBytes( out.Path(), 256 );
293 BOOST_CHECK( content.find(
"<?xml" ) == 0 );
294 BOOST_CHECK( content.find(
"<svg" ) != std::string::npos );
300 ScopedTmpFile out( wxS(
"svg" ) );
312 std::string content = readHeaderBytes( out.Path(), 4096 );
314 BOOST_CHECK( content.find(
"<svg" ) != std::string::npos );
318 wxFileName fn( out.Path() );
319 BOOST_CHECK_GT( fn.GetSize().GetValue(), 80u );
constexpr EDA_IU_SCALE schIUScale
constexpr EDA_IU_SCALE pcbIUScale
A color representation with 4 components: red, green, blue, alpha.
bool RenderSceneToSvg(const DIFF_SCENE &aScene, const wxString &aOutputPath, const PLOTTER_RENDER_OPTIONS &aOptions)
Render a DIFF_SCENE to an SVG file.
bool RenderSceneToPng(const DIFF_SCENE &aScene, const wxString &aOutputPath, const PLOTTER_RENDER_OPTIONS &aOptions)
Render a DIFF_SCENE to a PNG file.
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
std::vector< SCENE_SHAPE > modifiedShapes
std::vector< SCENE_SHAPE > conflictShapes
std::vector< SCENE_SHAPE > addedShapes
DOC_KIND docKind
Source document type.
std::vector< SCENE_SHAPE > removedShapes
Options controlling the headless PNG/SVG renderer.
Shared rendering model consumed by both the GAL renderer (interactive widget) and the plotter rendere...
BOOST_AUTO_TEST_CASE(HorizontalAlignment)
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
std::vector< std::string > header
BOOST_AUTO_TEST_CASE(SvgSchematicSceneUsesSchematicScale)
BOOST_CHECK_EQUAL(result, "25.4")
VECTOR2< int32_t > VECTOR2I