svg-path-test.h revision d9aa18c623eea5d9abcf31c97305cd9eac77adb4
#include <cxxtest/TestSuite.h>
#include "libnr/n-art-bpath.h"
#include <string>
#include <vector>
{
SvgPathTest() {
// Lots of ways to define the same rectangle
}
{
}
}
{
}
}
{
}
}
{
}
}
void testReadConcatenatedPaths()
{
for(size_t i=0; i<4; i++) {
}
for(size_t i=0; i<5; i++) {
}
for(size_t i=0; i<5; i++) {
}
std::string path_str = rectanglesAbsoluteClosed[0] + rectanglesRelativeOpen[0] + rectanglesRelativeClosed[0] + rectanglesAbsoluteOpen[0];
}
void testReadZeroLengthSubpaths() {
// Per the SVG 1.1 specification (section F5) zero-length subpaths are relevant
{ // Test absolute version
char const * path_str = "M 0,0 M 1,1 L 2,2 M 3,3 z M 4,4 L 5,5 z M 6,6";
}
{ // Test relative version
char const * path_str = "m 0,0 m 1,1 l 1,1 m 1,1 z m 1,1 l 1,1 z m 2,2";
}
}
void testReadImplicitMoveto() {
{ // Test absolute version
char const * path_str = "M 1,1 L 2,2 z L 3,3 z";
}
{ // Test relative version
char const * path_str = "M 1,1 L 2,2 z L 3,3 z";
}
}
void testReadFloatingPoint() {
{ // Test decimals
char const * path_str = "M .01,.02 L 0.04,0.02 L.04,.08L0.01,0.08 z";
}
{ // Test exponent
char const * path_str = "M 1e-2,.2e-1 L 0.004e1,0.0002e+2 L04E-2,.08e0L1.0e-2,80e-3 z";
}
}
void testReadImplicitSeparation() {
// Coordinates need not be separated by whitespace if they can still be read unambiguously
{ // Test absolute
char const * path_str = "M .1.2+0.4.2e0.4e0+8e-1.1.8 z";
}
{ // Test relative
char const * path_str = "m .1.2+0.3.0e0.0e0+6e-1-.3.0 z";
}
}
void testReadErrorMisplacedCharacter() {
char const * path_str;
// Comma in the wrong place (commas may only appear between parameters)
path_str = "M 1,2 4,2 4,8 1,8 z , m 13,15";
// Comma in the wrong place (commas may only appear between parameters)
path_str = "M 1,2 4,2 4,8 1,8 z m,13,15";
// Period in the wrong place (no numbers after a 'z')
path_str = "M 1,2 4,2 4,8 1,8 z . m 13,15";
// Sign in the wrong place (no numbers after a 'z')
path_str = "M 1,2 4,2 4,8 1,8 z + - m 13,15";
// Digit in the wrong place (no numbers after a 'z')
path_str = "M 1,2 4,2 4,8 1,8 z 9809 m 13,15";
// Digit in the wrong place (no numbers after a 'z')
path_str = "M 1,2 4,2 4,8 1,8 z 9809 876 m 13,15";
}
void testReadErrorUnrecognizedCharacter() {
char const * path_str;
// Unrecognized character
path_str = "M 1,2 4,2 4,8 1,8 z&m 13,15";
// Unrecognized character
path_str = "M 1,2 4,2 4,8 1,8 z m &13,15";
}
void testReadErrorTypo() {
char const * path_str;
// Typo
path_str = "M 1,2 4,2 4,8 1,8 z j 13,15";
// Typo
path_str = "M 1,2 4,2 4,8 1,8 L 1,2 x m 13,15";
}
void testReadErrorIllformedNumbers() {
char const * path_str;
// Double exponent
path_str = "M 1,2 4,2 4,8 1,8 z m 13e4e5,15";
// Double sign
path_str = "M 1,2 4,2 4,8 1,8 z m +-13,15";
// Double sign
path_str = "M 1,2 4,2 4,8 1,8 z m 13e+-12,15";
// No digit
path_str = "M 1,2 4,2 4,8 1,8 z m .e12,15";
// No digit
path_str = "M 1,2 4,2 4,8 1,8 z m .,15";
// No digit
path_str = "M 1,2 4,2 4,8 1,8 z m +,15";
// No digit
path_str = "M 1,2 4,2 4,8 1,8 z m +.e+,15";
}
void testReadErrorJunk() {
char const * path_str;
// Junk
path_str = "M 1,2 4,2 4,8 1,8 z j 357 hkjh.,34e34 90ih6kj4 h5k6vlh4N.,6,45wikuyi3yere..3487 m 13,23";
}
void testReadErrorStopReading() {
char const * path_str;
// Unrecognized parameter
path_str = "M 1,2 4,2 4,8 1,8 z m #$%,23,34";
// Invalid parameter
path_str = "M 1,2 4,2 4,8 1,8 z m #$%,23,34";
// Illformed parameter
path_str = "M 1,2 4,2 4,8 1,8 z m +-12,23,34";
// "Third" parameter
path_str = "M 1,2 4,2 4,8 1,8 1,2,3 M 12,23";
}
void testRoundTrip() {
// This is the easiest way to (also) test writing path data, as a path can be written in more than one way.
char * path_str;
// Rectangle (closed)
// Rectangle (open)
// Concatenated rectangles
bpath = sp_svg_read_path((rectanglesAbsoluteClosed[0] + rectanglesRelativeOpen[0] + rectanglesRelativeClosed[0] + rectanglesAbsoluteOpen[0]).c_str());
// Zero-length subpaths
// Floating-point
bpath = sp_svg_read_path("M .01,.02 L 0.04,0.02 L.04,.08L0.01,0.08 z""M 1e-2,.2e-1 L 0.004e1,0.0002e+2 L04E-2,.08e0L1.0e-2,80e-3 z");
}
switch(a->code) {
case NR_MOVETO:
case NR_MOVETO_OPEN:
case NR_LINETO:
break;
case NR_CURVETO:
break;
default:
TS_FAIL("Unknown path code!");
}
a++;
b++;
}
}
};
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :