[Chlor-commits] SF.net SVN: chlor: [547] trunk/src
Status: Pre-Alpha
Brought to you by:
lenny222
From: Chlor c. to s. <chl...@li...> - 2007-06-02 23:41:24
|
Revision: 547 http://svn.sourceforge.net/chlor/?rev=547&view=rev Author: lenny222 Date: 2007-06-02 16:41:08 -0700 (Sat, 02 Jun 2007) Log Message: ----------- add SVG unit test Modified Paths: -------------- trunk/src/Chlor.xcodeproj/project.pbxproj trunk/src/io/console/CConsoleExport.m trunk/src/io/svg/import/CSvgImport.m trunk/src/notes/TODO.txt Added Paths: ----------- trunk/src/tests/CSvgImportTest.h trunk/src/tests/CSvgImportTest.m Modified: trunk/src/Chlor.xcodeproj/project.pbxproj =================================================================== (Binary files differ) Modified: trunk/src/io/console/CConsoleExport.m =================================================================== --- trunk/src/io/console/CConsoleExport.m 2007-05-28 14:28:28 UTC (rev 546) +++ trunk/src/io/console/CConsoleExport.m 2007-06-02 23:41:08 UTC (rev 547) @@ -116,6 +116,7 @@ } else { + [self output: @"TODO: unhandled paint."]; [self endOutputGroup: @"fill"]; return; } Modified: trunk/src/io/svg/import/CSvgImport.m =================================================================== --- trunk/src/io/svg/import/CSvgImport.m 2007-05-28 14:28:28 UTC (rev 546) +++ trunk/src/io/svg/import/CSvgImport.m 2007-06-02 23:41:08 UTC (rev 547) @@ -49,26 +49,19 @@ { // Create the XML parser using the given data. NSXMLParser* xmlParser = [[NSXMLParser alloc] initWithData: theData]; - // Set self as XML delegate. [xmlParser setDelegate: self]; - // Parse the XML data. This calls the "parser:" method which creates and fills m_svgDocument. [xmlParser parse]; - // Release the XML parser. [xmlParser release]; - xmlParser = nil; - // Create the SVG import visitor. + // Create the SVG import visitor for the just created internal SVG data. CSvgImportVisitor* svgImportVisitor = [[CSvgImportVisitor alloc] initWithChlorDocument: aDocument]; - - // Visit the SVG document. + // Visit the internal SVG document data. [svgImportVisitor visitSvgDocument: m_svgDocument]; - // Release the SVG import visitor. [svgImportVisitor release]; - svgImportVisitor = nil; // TODO: remove after debugging. #if 1 Modified: trunk/src/notes/TODO.txt =================================================================== --- trunk/src/notes/TODO.txt 2007-05-28 14:28:28 UTC (rev 546) +++ trunk/src/notes/TODO.txt 2007-06-02 23:41:08 UTC (rev 547) @@ -10,7 +10,8 @@ - TODO: draw the CPage - BUG: clicking in in the bbox of an ellipse selects the ellipse even when the click is outside (this test fails in CShapeTest) - - maybe this has something to do with NSArray clear/adding in CSelection + - create Unit Tests breaking down to bezier/line interesections + - maybe this has something to do with NSArray clear/adding in CSelection? - BUG: undo/redo of deleting objects doesnt repaint - TODO: create CUnkownFill, CUnknownStroke, CUnknownPaint - CGroup's fill: and stroke: need to use these if the group contains many objects Added: trunk/src/tests/CSvgImportTest.h =================================================================== --- trunk/src/tests/CSvgImportTest.h (rev 0) +++ trunk/src/tests/CSvgImportTest.h 2007-06-02 23:41:08 UTC (rev 547) @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2007 Lennart Kudling + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * 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 + * + * $Id$ + */ + +#import <SenTestingKit/SenTestingKit.h> +@class CSvgImport; + +@interface CSvgImportTest : SenTestCase +{ + /** + * The SVG importer. + */ + CSvgImport* m_svgImporter; +} + +@end Property changes on: trunk/src/tests/CSvgImportTest.h ___________________________________________________________________ Name: svn:keywords + Id Added: trunk/src/tests/CSvgImportTest.m =================================================================== --- trunk/src/tests/CSvgImportTest.m (rev 0) +++ trunk/src/tests/CSvgImportTest.m 2007-06-02 23:41:08 UTC (rev 547) @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2007 Lennart Kudling + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * 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 + * + * $Id$ + */ + +#import "ChlorDocument.h" +#import "CGeometry.h" +#import "CLayer.h" +#import "CLayers.h" +#import "CPath.h" +#import "CSvgImport.h" +#import "CSvgImportTest.h" + +@implementation CSvgImportTest + +- (void) setUp +{ + m_svgImporter = [[CSvgImport alloc] init]; +} + +- (void) tearDown +{ + [m_svgImporter release]; +} + +// Tests the document import. +- (void) testDocument +{ + // The SVG document. + NSString* svgDocument = + @"<svg width=\"42.0\" height=\"120\">" + @"</svg>"; + + // Create the Chlor document. + ChlorDocument* chlorDocument = [[ChlorDocument alloc] init]; + + // Import the SVG document into the chlor document. + [m_svgImporter + importData: [svgDocument dataUsingEncoding: NSASCIIStringEncoding] + intoDocument: chlorDocument]; + + @try + { + // Check the document width and height. + STAssertEqualsWithAccuracy( [chlorDocument width], 42.0, [CGeometry accuracy], nil ); + STAssertEqualsWithAccuracy( [chlorDocument height], 120.0, [CGeometry accuracy], nil ); + } + @finally + { + [chlorDocument release]; + } +} + +// Tests the import of a "rect". +- (void) testRect +{ + // The SVG document. + NSString* svgDocument = + @"<svg width=\"300.0\" height=\"400\">" + @" <rect x=\"1.5\" y=\"0\" width=\"54\" height=\"260.75\" fill=\"none\" stroke=\"blue\" stroke-width=\"2\"/>" + @"</svg>"; + + // Create the Chlor document. + ChlorDocument* chlorDocument = [[ChlorDocument alloc] init]; + + // Import the SVG document into the chlor document. + [m_svgImporter + importData: [svgDocument dataUsingEncoding: NSASCIIStringEncoding] + intoDocument: chlorDocument]; + + @try + { + // There must be exactly one layer. + STAssertEquals( [[[chlorDocument layers] objects] count], (unsigned) 1, nil ); + + // Get the layer. + CLayer* layer = (CLayer*) [[[chlorDocument layers] objects] objectAtIndex: 0]; + + // There must be exactly one object. + STAssertEquals( [[layer objects] count], (unsigned) 1, nil ); + + // Get the object. + CObject* object = (CObject*) [[layer objects] objectAtIndex: 0]; + + CPath* path; + + if( [object isKindOfClass: [CPath class]] ) + path = (CPath*) object; + else + path = nil; + + // The object must be a CPath. + STAssertNotNil( path, nil ); + + // Verify the shape boundary of the path + CRect* shapeBoundary = [path shapeBoundary]; + + STAssertEqualsWithAccuracy( [shapeBoundary left], 1.5f, [CGeometry accuracy], nil ); + STAssertEqualsWithAccuracy( [shapeBoundary bottom], (float) [chlorDocument height] - 260.75f, [CGeometry accuracy], nil ); + STAssertEqualsWithAccuracy( [shapeBoundary width], 54.0f, [CGeometry accuracy], nil ); + STAssertEqualsWithAccuracy( [shapeBoundary height], 260.75f, [CGeometry accuracy], nil ); + } + @finally + { + [chlorDocument release]; + } +} + +@end Property changes on: trunk/src/tests/CSvgImportTest.m ___________________________________________________________________ Name: svn:keywords + Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |