/***************************************************************************
 *   Copyright (C) 2005 by Ian Reinhart Geiser                             *
 *   geiseri@sourcextreme.com                                              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   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.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <QPolygonF>
#include <QString>
#include <QApplication>

#include <QtTest/QtTest>
#include "svgexport.h"

QTEST_MAIN(TestSVGExport)

/**
 * Base svg template.
 * <?xml version="1.0" standalone="no"?>
 * <svg width="10cm" height="10cm" viewBox="0 0 %{width} %{height}" xmlns="http://www.w3.org/2000/svg" version="1.2" baseProfile="tiny">
 * 	<title>%{title}</title>
 * 	<desc>%{description}</desc>
 * 	<!-- %{pointlist} =  100,200 100,100 ...-->
 * 	<!-- %{polyline} =  <polyline fill="none" stroke="#000000" stroke-width="2" points="%{polylist}" />-->
 * 	%{polyline}
 * </svg>
*/

QString buildPloyList( const QPolygonF &poly )
{
	QString pointTemplate = "%1,%2";
	QStringList polylist;
	foreach( QPointF point, poly )
		polylist << pointTemplate.arg(point.x()).arg(point.y());
	
	return polylist.join(" ");
}

QString buildPloyLine( const QPolygonF &poly )
{
	QString lineTemplate = "<polyline fill=\"none\" stroke=\"#000000\" stroke-width=\"2\" points=\"%1\" />";
	
	return lineTemplate.arg(buildPloyList(poly));
}

void TestSVGExport::testMakePollyList()
{
	QPolygonF poly;
	poly << QPointF(0,0) << QPointF(10,10) << QPointF(5,5);
	
	QCOMPARE( buildPloyList( poly ), QString("0,0 10,10 5,5") );
}

void TestSVGExport::testMakePollyLine()
{
	QPolygonF poly;
	poly << QPointF(0,0) << QPointF(10,10) << QPointF(5,5);
	
	QCOMPARE( buildPloyLine( poly ), QString("<polyline fill=\"none\" stroke=\"#000000\" stroke-width=\"2\" points=\"0,0 10,10 5,5\" />") );
}

