summaryrefslogtreecommitdiff
path: root/tikzit/src/common/test
diff options
context:
space:
mode:
authorrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-01-09 11:00:50 +0000
committerrandomguy3 <randomguy3@7c02a99a-9b00-45e3-bf44-6f3dd7fddb64>2012-01-09 11:00:50 +0000
commita8a8dfb90d6a51ae369c042c95162f45754c7c4b (patch)
tree0e7a5f82febebe7129ebfb015f05b114064c39fd /tikzit/src/common/test
parente1cf0babff63e670e0d550b4072c22649a117fa7 (diff)
Move tikzit into "trunk" directory
git-svn-id: https://tikzit.svn.sourceforge.net/svnroot/tikzit/trunk@365 7c02a99a-9b00-45e3-bf44-6f3dd7fddb64
Diffstat (limited to 'tikzit/src/common/test')
-rw-r--r--tikzit/src/common/test/color.m76
-rw-r--r--tikzit/src/common/test/common.m32
-rw-r--r--tikzit/src/common/test/parser.m78
-rw-r--r--tikzit/src/common/test/test.h41
-rw-r--r--tikzit/src/common/test/test.m104
5 files changed, 331 insertions, 0 deletions
diff --git a/tikzit/src/common/test/color.m b/tikzit/src/common/test/color.m
new file mode 100644
index 0000000..e7a80ba
--- /dev/null
+++ b/tikzit/src/common/test/color.m
@@ -0,0 +1,76 @@
+//
+// color.m
+// TikZiT
+//
+// Copyright 2010 Aleks Kissinger. All rights reserved.
+//
+//
+// This file is part of TikZiT.
+//
+// TikZiT 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 3 of the License, or
+// (at your option) any later version.
+//
+// TikZiT 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 TikZiT. If not, see <http://www.gnu.org/licenses/>.
+//
+#import "test/test.h"
+#import "ColorRGB.h"
+
+void testColor() {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ startTestBlock(@"color");
+
+ ColorRGB *red = [ColorRGB colorWithRed:255 green:0 blue:0];
+ ColorRGB *lime = [ColorRGB colorWithRed:0 green:255 blue:0];
+ ColorRGB *green = [ColorRGB colorWithRed:0 green:128 blue:0];
+ TEST(@"Recognised red",
+ [red name] != nil &&
+ [[red name] isEqualToString:@"Red"]);
+ TEST(@"Recognised lime",
+ [lime name] != nil &&
+ [[lime name] isEqualToString:@"Lime"]);
+ TEST(@"Recognised green",
+ [green name] != nil &&
+ [[green name] isEqualToString:@"Green"]);
+
+ ColorRGB *floatRed = [ColorRGB colorWithFloatRed:1.0f green:0.0f blue:0.0f];
+ ColorRGB *floatLime = [ColorRGB colorWithFloatRed:0.0f green:1.0f blue:0.0f];
+ ColorRGB *floatGreen = [ColorRGB colorWithFloatRed:0.0f green:0.5f blue:0.0f];
+
+ TEST(@"Float red equal to int red", [floatRed isEqual:red]);
+ TEST(@"Float lime equal to int lime", [floatLime isEqual:lime]);
+ TEST(@"Float green equal to int green", [floatGreen isEqual:green]);
+
+ TEST(@"Recognised float red",
+ [floatRed name] != nil &&
+ [[floatRed name] isEqualToString:@"Red"]);
+
+ TEST(@"Recognised float lime",
+ [floatLime name] != nil &&
+ [[floatLime name] isEqualToString:@"Lime"]);
+
+ TEST(@"Recognised float green",
+ [floatGreen name] != nil &&
+ [[floatGreen name] isEqualToString:@"Green"]);
+
+ [floatRed setRedFloat:0.99f];
+ TEST(@"Nudged red, not recognised now", [floatRed name] == nil);
+ [floatRed setToClosestHashed];
+ TEST(@"Set to closest hashed, reconised again",
+ [floatRed name] != nil &&
+ [[floatRed name] isEqualToString:@"Red"]);
+
+ TEST(@"Red has correct hex (ff0000)", [[red hexName] isEqualToString:@"hexcolor0xff0000"]);
+ TEST(@"Lime has correct hex (00ff00)", [[lime hexName] isEqualToString:@"hexcolor0x00ff00"]);
+ TEST(@"Green has correct hex (008000)", [[green hexName] isEqualToString:@"hexcolor0x008000"]);
+
+ endTestBlock(@"color");
+ [pool drain];
+} \ No newline at end of file
diff --git a/tikzit/src/common/test/common.m b/tikzit/src/common/test/common.m
new file mode 100644
index 0000000..ee6cb5f
--- /dev/null
+++ b/tikzit/src/common/test/common.m
@@ -0,0 +1,32 @@
+//
+// common.m
+// TikZiT
+//
+// Copyright 2010 Aleks Kissinger. All rights reserved.
+//
+//
+// This file is part of TikZiT.
+//
+// TikZiT 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 3 of the License, or
+// (at your option) any later version.
+//
+// TikZiT 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 TikZiT. If not, see <http://www.gnu.org/licenses/>.
+//
+#import "test/test.h"
+void testParser();
+void testColor();
+
+void testCommon() {
+ startTestBlock(@"common");
+ testParser();
+ testColor();
+ endTestBlock(@"common");
+} \ No newline at end of file
diff --git a/tikzit/src/common/test/parser.m b/tikzit/src/common/test/parser.m
new file mode 100644
index 0000000..fc9e76e
--- /dev/null
+++ b/tikzit/src/common/test/parser.m
@@ -0,0 +1,78 @@
+//
+// parser.m
+// TikZiT
+//
+// Copyright 2010 Aleks Kissinger. All rights reserved.
+//
+//
+// This file is part of TikZiT.
+//
+// TikZiT 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 3 of the License, or
+// (at your option) any later version.
+//
+// TikZiT 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 TikZiT. If not, see <http://www.gnu.org/licenses/>.
+//
+#import "test/test.h"
+#import "TikzGraphAssembler.h"
+
+void testParser() {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ startTestBlock(@"parser");
+
+ [TikzGraphAssembler setup];
+
+ NodeStyle *rn = [NodeStyle defaultStyleWithName:@"rn"];
+ NSArray *styles = [NSArray arrayWithObject:rn];
+
+ NSString *tikz =
+ @"\\begin{tikzpicture}[dotpic]"
+ @" \\begin{pgfonlayer}{foo}" //ignored
+ @" \\node [style=rn] (0) at (-2,3.4) {stuff{$\\alpha$ in here}};"
+ @" \\node (b) at (1,1) {};"
+ @" \\end{pgfonlayer}" //ignored
+ @" \\draw [bend right=20] (0) to node[tick]{-} (b.center);"
+ @"\\end{tikzpicture}";
+
+ TikzGraphAssembler *ga = [[TikzGraphAssembler alloc] init];
+ TEST(@"Parsing TikZ", [ga parseTikz:tikz]);
+
+ Graph *g = [ga graph];
+ TEST(@"Graph is non-nil", g != nil);
+ TEST(@"Graph has correct number of nodes", [[g nodes] count]==2);
+ TEST(@"Graph has correct number of edges", [[g edges] count]==1);
+
+ NSEnumerator *en = [[g nodes] objectEnumerator];
+ Node *n;
+ Node *n1, *n2;
+ while ((n=[en nextObject])) {
+ [n attachStyleFromTable:styles];
+ if ([n style] == rn) n1 = n;
+ else if ([n style] == nil) n2 = n;
+ }
+
+ TEST(@"Styles attached correctly", n1!=nil && n2!=nil);
+
+ TEST(@"Nodes labeled correctly",
+ [[n1 label] isEqualToString:@"stuff{$\\alpha$ in here}"] &&
+ [[n2 label] isEqualToString:@""]
+ );
+
+ Edge *e1 = [[[g edges] objectEnumerator] nextObject];
+
+ TEST(@"Edge has edge node", [e1 edgeNode]!=nil);
+ TEST(@"Edge node labeled correctly", [[[e1 edgeNode] label] isEqualToString:@"-"]);
+ NSString *sty = [[[[[e1 edgeNode] data] atoms] objectEnumerator] nextObject];
+ TEST(@"Edge node styled correctly", sty!=nil && [sty isEqualToString:@"tick"]);
+
+ endTestBlock(@"parser");
+
+ [pool drain];
+} \ No newline at end of file
diff --git a/tikzit/src/common/test/test.h b/tikzit/src/common/test/test.h
new file mode 100644
index 0000000..4fddc92
--- /dev/null
+++ b/tikzit/src/common/test/test.h
@@ -0,0 +1,41 @@
+//
+// test.h
+// TikZiT
+//
+// Copyright 2010 Aleks Kissinger. All rights reserved.
+//
+//
+// This file is part of TikZiT.
+//
+// TikZiT 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 3 of the License, or
+// (at your option) any later version.
+//
+// TikZiT 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 TikZiT. If not, see <http://www.gnu.org/licenses/>.
+//
+#import <Foundation/Foundation.h>
+
+@interface Allocator : NSObject
+{}
+@end
+
+void setColorEnabled(BOOL b);
+void TEST(NSString *msg, BOOL test);
+
+void startTests();
+void endTests();
+
+void startTestBlock(NSString *name);
+void endTestBlock(NSString *name);
+
+#define PUTS(fmt, ...) { \
+ NSString *_str = [[NSString alloc] initWithFormat:fmt, ##__VA_ARGS__]; \
+ printf("%s\n", [_str UTF8String]); \
+ [_str release]; }
diff --git a/tikzit/src/common/test/test.m b/tikzit/src/common/test/test.m
new file mode 100644
index 0000000..5e05c6e
--- /dev/null
+++ b/tikzit/src/common/test/test.m
@@ -0,0 +1,104 @@
+//
+// test.m
+// TikZiT
+//
+// Copyright 2010 Aleks Kissinger. All rights reserved.
+//
+//
+// This file is part of TikZiT.
+//
+// TikZiT 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 3 of the License, or
+// (at your option) any later version.
+//
+// TikZiT 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 TikZiT. If not, see <http://www.gnu.org/licenses/>.
+//
+#import "test/test.h"
+
+static int PASSES;
+static int FAILS;
+
+static int ALLOC_INSTANCES = 0;
+
+static BOOL colorEnabled = YES;
+static int depth = 0;
+
+static NSString *RED, *GREEN, *BLUE, *OFF;
+
+static NSString *indents[6] =
+ {@"", @" ", @" ", @" ",
+ @" ", @" "};
+
+#define INDENT ((depth >= 6) ? indents[5] : indents[depth])
+
+
+@implementation Allocator
+
++ (id)alloc {
+ ++ALLOC_INSTANCES;
+ return [super alloc];
+}
+
+- (void)dealloc {
+ --ALLOC_INSTANCES;
+ [super dealloc];
+}
+
++ (Allocator*)allocator {
+ return [[[Allocator alloc] init] autorelease];
+}
+
+@end
+
+void TEST(NSString *msg, BOOL test) {
+ if (test) {
+ PUTS(@"%@[%@PASS%@] %@", INDENT, GREEN, OFF, msg);
+ ++PASSES;
+ } else {
+ PUTS(@"%@[%@FAIL%@] %@", INDENT, RED, OFF, msg);
+ ++FAILS;
+ }
+}
+
+void startTests() {
+ PASSES = 0;
+ FAILS = 0;
+}
+
+void endTests() {
+ PUTS(@"Done testing. %@%d%@ passed, %@%d%@ failed.",
+ GREEN, PASSES, OFF,
+ RED, FAILS, OFF);
+}
+
+void startTestBlock(NSString *name) {
+ PUTS(@"%@Starting %@%@%@ tests.", INDENT, BLUE, name, OFF);
+ ++depth;
+}
+
+void endTestBlock(NSString *name) {
+ --depth;
+ PUTS(@"%@Done with %@%@%@ tests.", INDENT, BLUE, name, OFF);
+}
+
+void setColorEnabled(BOOL b) {
+ colorEnabled = b;
+ if (b) {
+ RED = @"\033[31;1m";
+ GREEN = @"\033[32;1m";
+ BLUE = @"\033[36;1m";
+ OFF = @"\033[0m";
+ } else {
+ RED = @"";
+ GREEN = @"";
+ BLUE = @"";
+ OFF = @"";
+ }
+}