diff --git a/ChangeLog b/ChangeLog index 02961d429..a4d39242a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2011-02-19 Richard Frith-Macdonald + + * Tests/GNUmakefile: Run/clean tests + * Tests/gui: Imported from testsuite + 2011-02-15 Fred Kiefer * Headers/Additions/GNUstepGUI/GSDisplayServer.h, diff --git a/Tests/GNUmakefile b/Tests/GNUmakefile new file mode 100644 index 000000000..a0ba64bef --- /dev/null +++ b/Tests/GNUmakefile @@ -0,0 +1,49 @@ +# +# Tests Makefile for GNUstep GUI Library. +# +# Copyright (C) 2011 Free Software Foundation, Inc. +# +# Written by: Richard Frith-Macdonald +# +# This file is part of the GNUstep Base Library. +# +# This library 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 library 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 library; if not, write to the Free +# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02111 USA +# + +ifeq ($(GNUSTEP_MAKEFILES),) + GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null) + ifeq ($(GNUSTEP_MAKEFILES),) + $(warning ) + $(warning Unable to obtain GNUSTEP_MAKEFILES setting from gnustep-config!) + $(warning Perhaps gnustep-make is not properly installed,) + $(warning so gnustep-config is not in your PATH.) + $(warning ) + $(warning Your PATH is currently $(PATH)) + $(warning ) + endif +endif + +ifeq ($(GNUSTEP_MAKEFILES),) + $(error You need to set GNUSTEP_MAKEFILES before running this!) +endif + + +check: + gnustep-tests gui + +clean: + gnustep-tests --clean + diff --git a/Tests/gui/GNUmakefile.postamble b/Tests/gui/GNUmakefile.postamble new file mode 100644 index 000000000..6b14b1623 --- /dev/null +++ b/Tests/gui/GNUmakefile.postamble @@ -0,0 +1,32 @@ +# +# GNUmakefile.postamble for base tests +# +# Find all all subdirectories and run a clean in them independantly +# + +after-clean:: + $(ECHO_NOTHING)\ + RUNDIR=`pwd`; \ + TESTDIRS=`find . -type d`; \ + for dir in $$TESTDIRS __done; do \ + if [ $$dir != . -a -f $$dir/GNUmakefile ]; then \ + echo Cleaning $$dir; cd $$dir; make clean; cd $$RUNDIR; \ + fi \ + done \ + $(END_ECHO) + +after-distclean:: + $(ECHO_NOTHING)\ + RUNDIR=`pwd`; \ + TESTDIRS=`find . -type d`; \ + for dir in $$TESTDIRS __done; do \ + if [ $$dir != . -a -f $$dir/GNUmakefile ]; then \ + echo Cleaning $$dir; cd $$dir; make distclean; \ + if [ \! -f IGNORE ]; then \ + $(RM) GNUmakefile; \ + fi; \ + cd $$RUNDIR; \ + fi \ + done \ + $(END_ECHO) + diff --git a/Tests/gui/GNUmakefile.super b/Tests/gui/GNUmakefile.super new file mode 100644 index 000000000..1b02abd3f --- /dev/null +++ b/Tests/gui/GNUmakefile.super @@ -0,0 +1,6 @@ +# +# +# +-include $(GNUSTEP_MAKEFILES)/Additional/gui.make +AUXILIARY_TOOL_LIBS += $(GUI_LIBS) + diff --git a/Tests/gui/GNUmakefile.tests b/Tests/gui/GNUmakefile.tests new file mode 100644 index 000000000..1d1dd4972 --- /dev/null +++ b/Tests/gui/GNUmakefile.tests @@ -0,0 +1,13 @@ +# +# Top-level base testsuite makefile +# +# Run this before loading any tests +# + +include $(GNUSTEP_MAKEFILES)/common.make + +-include GNUmakefile.preamble + +include $(GNUSTEP_MAKEFILES)/rules.make + +-include GNUmakefile.postamble diff --git a/Tests/gui/NSAffineTransform/affine.m b/Tests/gui/NSAffineTransform/affine.m new file mode 100644 index 000000000..37500cd41 --- /dev/null +++ b/Tests/gui/NSAffineTransform/affine.m @@ -0,0 +1,102 @@ +#include "Testing.h" +#include +#include + +static BOOL +is_equal_struct(NSAffineTransformStruct as, NSAffineTransformStruct bs) +{ + if (EQ(as.m11, bs.m11) && EQ(as.m12, bs.m12) && EQ(as.m21, bs.m21) + && EQ(as.m22, bs.m22) && EQ(as.tX, bs.tX) && EQ(as.tY, bs.tY)) + return YES; + return NO; +} + +#if 0 +static void +print_matrix (const char *str, NSAffineTransformStruct MM) +{ + printf("%s = %f %f %f %f %f %f\n", str, MM.m11, MM.m12, + MM.m21, MM.m22, MM.tX, MM.tY); +} +#endif + +int main(int argc, char *argv[]) +{ + NSAffineTransform *aa, *bb, *cc; + NSAffineTransformStruct as = {2, 3, 4, 5, 10, 20}; + NSAffineTransformStruct bs = {6, 7, 8, 9, 14, 15}; + NSAffineTransformStruct cs; + + NSAffineTransformStruct answer1 = + {36.000000, 41.000000, 64.000000, 73.000000, 234.000000, 265.000000}; + NSAffineTransformStruct answer2 = + {40.000000, 53.000000, 52.000000, 69.000000, 98.000000, 137.000000}; + NSAffineTransformStruct answer3 = + {6.000000, 9.000000, 8.000000, 10.000000, 10.000000, 20.000000}; + NSAffineTransformStruct answer4 = + {6.000000, 9.000000, 8.000000, 10.000000, 194.000000, 268.000000}; + NSAffineTransformStruct answer5 = + {2.172574, 3.215242, 3.908954, 4.864383, 10.000000, 20.000000}; + NSAffineTransformStruct answer6 = + {2.172574, 3.215242, 3.908954, 4.864383, 90.796249, 126.684265}; + NSAffineTransformStruct answer7 = + {1.651156, 2.443584, 1.329044, 1.653890, 90.796249, 126.684265}; + + NSAutoreleasePool *pool = [NSAutoreleasePool new]; + + + aa = [NSAffineTransform transform]; + bb = [NSAffineTransform transform]; + [aa setTransformStruct: as]; + [bb setTransformStruct: bs]; + + /* Append matrix */ + cc = [aa copy]; + [cc appendTransform: bb]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer1), + "appendTransform:"); + + /* Prepend matrix */ + cc = [aa copy]; + [cc prependTransform: bb]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer2), + "prependTransform:"); + + /* scaling */ + cc = [aa copy]; + [cc scaleXBy: 3 yBy: 2]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer3), + "scaleXBy:yBy:"); + //print_matrix ("Scale X A", cs); + [cc translateXBy: 12 yBy: 14]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer4), + "translateXBy:yBy:"); + //print_matrix ("Trans X Scale X A", cs); + + /* rotation */ + cc = [aa copy]; + [cc rotateByDegrees: 2.5]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer5), + "rotateByDegrees"); + //print_matrix ("Rotate X A", cs); + [cc translateXBy: 12 yBy: 14]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer6), + "Translate X Rotate X A"); + //print_matrix ("Trans X Rotate X A", cs); + + /* multiple */ + [cc scaleXBy: .76 yBy: .34]; + cs = [cc transformStruct]; + pass(is_equal_struct(cs, answer7), + "Scale X Translate X Rotate X A"); + //print_matrix ("Scale X Trans X Rotate X A", cs); + + [pool release]; + return 0; +} diff --git a/Tests/gui/NSBezierPath/bounds.m b/Tests/gui/NSBezierPath/bounds.m new file mode 100644 index 000000000..d14ced39a --- /dev/null +++ b/Tests/gui/NSBezierPath/bounds.m @@ -0,0 +1,169 @@ +/* +copyright 2004 Alexander Malmberg +*/ + +#include "Testing.h" + +#include +#include + +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + NSBezierPath *p=[[NSBezierPath alloc] init]; + NSRect r; + + pass(NSIsEmptyRect([p bounds]),"empty path gives empty bounds"); + + [p moveToPoint: NSMakePoint(100,100)]; + [p lineToPoint: NSMakePoint(150,150)]; + + pass(NSEqualRects([p bounds],NSMakeRect(100,100,50,50)),"bounds accuracy (1)"); + pass(NSEqualRects([p controlPointBounds],NSMakeRect(100,100,50,50)),"control-point bounds accuracy (1)"); + + [p removeAllPoints]; + pass(NSIsEmptyRect([p bounds]),"empty path gives empty bounds (2)"); + + [p moveToPoint: NSMakePoint(100,100)]; + [p curveToPoint: NSMakePoint(200,100) + controlPoint1: NSMakePoint(125,50) + controlPoint2: NSMakePoint(175,150)]; + + /* Basic checking Y. */ + r=[p bounds]; + if (fabs(r.origin.x - 100.0000) > 0.001 || + fabs(r.origin.y - 85.5662) > 0.001 || + fabs(r.size.width - 100.0000) > 0.001 || + fabs(r.size.height - 28.8678) > 0.001) + { + pass(0,"bounds accuracy (2)"); + printf("expected %s, got %s\n", + [NSStringFromRect(NSMakeRect(100.0000, 85.5662, 100.0000, 28.8678)) lossyCString], + [NSStringFromRect(r) lossyCString]); + } + else + pass(1,"bounds accuracy (2)"); + + pass(NSEqualRects([p controlPointBounds],NSMakeRect(100,50,100,100)),"control-point bounds accuracy (2)"); + + /* Basic checking X. */ + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(100,100)]; + [p curveToPoint: NSMakePoint(100,200) + controlPoint1: NSMakePoint(50,125) + controlPoint2: NSMakePoint(150,175)]; + + r=[p bounds]; + if (fabs(r.origin.y - 100.0000) > 0.001 || + fabs(r.origin.x - 85.5662) > 0.001 || + fabs(r.size.height - 100.0000) > 0.001 || + fabs(r.size.width - 28.8678) > 0.001) + { + pass(0,"bounds accuracy (3)"); + printf("expected %s, got %s\n", + [NSStringFromRect(NSMakeRect(85.5662, 100.0000, 28.8678, 100.0000)) lossyCString], + [NSStringFromRect(r) lossyCString]); + } + else + pass(1,"bounds accuracy (3)"); + + + /* A bit of both, and extreme values beyond the initial points. */ + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(-100,0)]; + [p curveToPoint: NSMakePoint(100,0) + controlPoint1: NSMakePoint(-118.2, 10.393) + controlPoint2: NSMakePoint( 118.2,-10.393)]; + + r=[p bounds]; + if (fabs(r.origin.x + 101.0) > 0.001 || + fabs(r.origin.y + 3.0) > 0.001 || + fabs(r.size.width - 202.0) > 0.001 || + fabs(r.size.height - 6.0) > 0.001) + { + pass(0,"bounds accuracy (4)"); + printf("expected %s, got %s\n", + [NSStringFromRect(NSMakeRect(-101.0, -3.0, 202.0, 6.0)) lossyCString], + [NSStringFromRect(r) lossyCString]); + } + else + pass(1,"bounds accuracy (4)"); + + + /* Check the control-point bounding box. */ + r=[p controlPointBounds]; + if (fabs(r.origin.x + 118.2 ) > 0.001 || + fabs(r.origin.y + 10.393) > 0.001 || + fabs(r.size.width - 236.4 ) > 0.001 || + fabs(r.size.height - 20.786) > 0.001) + { + pass(0,"control-point bounds accuracy (3)"); + printf("expected %s, got %s\n", + [NSStringFromRect(NSMakeRect(-118.2, -10.393, 236.4, 20.786)) lossyCString], + [NSStringFromRect(r) lossyCString]); + } + else + pass(1,"control-point bounds accuracy (3)"); + + + /* + + p=(1-t)^3*a + 3*(1-t)^2*t*b + 3*(1-t)*t^2*c + t^3*d + + c-2b+a +- sqrt(a(d-c)+b(-d-c)+c^2+b^2) + t= -------------------------------------- + -d+3c-3b+a + + */ + + + if (0) + { + NSPoint a,b,c,d; + double t1,t2; + double t,ti; + NSPoint p; + + a=NSMakePoint(-100,0); + b=NSMakePoint(-118.2,10.39); + c=NSMakePoint(118.2,-10.39); + d=NSMakePoint(100,0); + +#define D \ + ti=1.0-t; \ + p.x=ti*ti*ti*a.x + 3*ti*ti*t*b.x + 3*ti*t*t*c.x + t*t*t*d.x; \ + p.y=ti*ti*ti*a.y + 3*ti*ti*t*b.y + 3*ti*t*t*c.y + t*t*t*d.y; \ + printf(" t=%15.7f (%15.7f %15.7f)\n",t,p.x,p.y); + + t=0; D + t=1; D + t=0.5; D + + t1=(c.x-2*b.x+a.x + sqrt(a.x*(d.x-c.x)+b.x*(-d.x-c.x)+c.x*c.x+b.x*b.x)) / (-d.x+3*c.x-3*b.x+a.x); + t2=(c.x-2*b.x+a.x - sqrt(a.x*(d.x-c.x)+b.x*(-d.x-c.x)+c.x*c.x+b.x*b.x)) / (-d.x+3*c.x-3*b.x+a.x); + printf("x:\n"); + + + t=t1; + D + t=t2; + D + + t1=(c.y-2*b.y+a.y + sqrt(a.y*(d.y-c.y)+b.y*(-d.y-c.y)+c.y*c.y+b.y*b.y)) / (-d.y+3*c.y-3*b.y+a.y); + t2=(c.y-2*b.y+a.y - sqrt(a.y*(d.y-c.y)+b.y*(-d.y-c.y)+c.y*c.y+b.y*b.y)) / (-d.y+3*c.y-3*b.y+a.y); + printf("y:\n"); + t=t1; + D + t=t2; + D + } + +// printf("bounds=%@\n",NSStringFromRect([p bounds])); + + DESTROY(arp); + + return 0; +} + diff --git a/Tests/gui/NSBezierPath/windingCountAtPoint.m b/Tests/gui/NSBezierPath/windingCountAtPoint.m new file mode 100644 index 000000000..5782b204b --- /dev/null +++ b/Tests/gui/NSBezierPath/windingCountAtPoint.m @@ -0,0 +1,709 @@ +/* +copyright 2004 Alexander Malmberg +*/ + +#include "Testing.h" + +#include +#include + +#include + + +#define nextafterf(x,y) next(x,y) + +static float next(float x,float y) +{ + if (yx) + return x+(x?0.00001:0.000005); +// return x+(x?0.0001:0.00001); + else + return y; +} + + +//#define DRAW + +#ifdef DRAW + +#include +#include +#include +#include +#include + +@interface MyView : NSView +-(void) clear; +-(void) drawPath: (NSBezierPath *)p; +-(void) drawPoint: (NSPoint)p count: (int)c; +-(void) pause; +@end + +#define MOVE \ + { \ + double x0,y0,x1,y1; \ + double w=800,h=800; \ + \ + x0=76.980; \ + x1=76.981; \ + y0=-0.0005; \ + y1=0.0005; \ + \ + ww=w/(x1-x0); \ + hh=h/(y1-y0); \ + PSscale(ww,hh); \ + PStranslate(-x0,-y0); \ + } + +@implementation MyView +-(void) clear +{ + [self lockFocus]; + PSsetrgbcolor(1,1,1); + NSRectFill([self bounds]); + [self unlockFocus]; + [[self window] flushWindow]; +} +-(void) drawPath: (NSBezierPath *)p +{ + double ww,hh; + [self lockFocus]; + MOVE + PSsetrgbcolor(0.8,0.4,0.4); + [p fill]; + PSsetrgbcolor(0.3,1.0,0.3); + PSsetalpha(0.5); + [[p bezierPathByFlatteningPath] fill]; + [self unlockFocus]; + [[self window] flushWindow]; +} +-(void) drawPoint: (NSPoint)p count: (int)c +{ +#define NC 3 +static float colors[NC][3]={ +{1,0,0}, +{0,1,0}, +{0,0,1}, +}; + double ww,hh; + c%=NC; + if (c<0) + c+=NC; + [self lockFocus]; + MOVE + PSsetrgbcolor(colors[c][0],colors[c][1],colors[c][2]); + PSrectfill(p.x-4/ww,p.y-4/hh,8/ww,8/hh); + [self unlockFocus]; + [[self window] flushWindow]; +#undef NC +} +-(void) pause +{ + char buf[128]; + gets(buf); +} +@end + +MyView *view; + +#endif + + + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + NSBezierPath *p=[[NSBezierPath alloc] init]; + NSRect r; + float x; + int i; + const char *str; + int X=-1000; + + +#ifdef DRAW + { + NSWindow *w; + + [NSApplication sharedApplication]; + w=[[NSWindow alloc] initWithContentRect: NSMakeRect(50,50,800,800) + styleMask: NSTitledWindowMask + backing: NSBackingStoreRetained + defer: YES]; + + view=[[MyView alloc] init]; + [w setContentView: view]; + [w orderFront: nil]; + } +#endif + +#ifdef DRAW +#define DP(e,x,y) [view drawPoint: NSMakePoint(x,y) count: e]; +#define CLEAR [view clear]; +#define PAUSE [view pause]; +#define DRAWPATH [view drawPath: p]; +#else +#define DP(e,x,y) +#define CLEAR +#define PAUSE +#define DRAWPATH +#endif + +#define T(e,x,y) \ + { \ + int i,r; \ + DP(e,x,y) \ + r=[p windingCountAtPoint: NSMakePoint(x,y)]; \ + for (i=5;i;i--) \ + { \ + if ([p windingCountAtPoint: NSMakePoint(x,y)]!=r) \ + break; \ + } \ + if (i) \ + { \ + pass(NO, \ + "path '%s', %15.8e %15.8e, expected %i, got inconsistant results", \ + str,(double)x,(double)y, \ + e); \ + } \ + else \ + { \ + pass(r == e, \ + "path '%s', %15.8e %15.8e, expected %i, got %i", \ + str,(double)x,(double)y, \ + e,r); \ + } \ + } + +#define CHECK_AROUND(x,y, p00,p10,p20, p01,p11,p21, p02,p12,p22) \ + if (p00!=X) T(p00,nextafterf(x,-1000),nextafterf(y, 1000)) \ + if (p10!=X) T(p10, x ,nextafterf(y, 1000)) \ + if (p20!=X) T(p20,nextafterf(x, 1000),nextafterf(y, 1000)) \ + \ + if (p01!=X) T(p01,nextafterf(x,-1000), y ) \ + if (p11!=X) T(p11, x , y ) \ + if (p21!=X) T(p21,nextafterf(x, 1000), y ) \ + \ + if (p02!=X) T(p02,nextafterf(x,-1000),nextafterf(y,-1000)) \ + if (p12!=X) T(p12, x ,nextafterf(y,-1000)) \ + if (p22!=X) T(p22,nextafterf(x, 1000),nextafterf(y,-1000)) + +#if 1 + str="empty"; + T(0,0,0) + + + for (i=0;i<3;i++) + { + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(100,100)]; + [p lineToPoint: NSMakePoint(100,200)]; + [p lineToPoint: NSMakePoint(200,200)]; + [p lineToPoint: NSMakePoint(200,100)]; + + if (i==0) + { + str="(u) rect"; + } + else if (i==1) + { + [p closePath]; + str="(c) rect"; + } + else + { + [p lineToPoint: NSMakePoint(100,100)]; + [p closePath]; + str="(d) rect"; + } + + /* Obvious stuff. */ + T(0,0,0) + T(1,150,150) + + /* Check around each corner. */ + CHECK_AROUND(100,100, + 0,X,1, + 0,X,X, + 0,0,0) + + CHECK_AROUND(200,100, + 1,X,0, + X,X,0, + 0,0,0) + + CHECK_AROUND(200,200, + 0,0,0, + X,X,0, + 1,X,0) + + CHECK_AROUND(100,200, + 0,0,0, + 0,X,X, + 0,X,1) + + if (!i) + [p closePath]; + } + + + for (i=0;i<3;i++) + { + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(0,-100)]; + [p lineToPoint: NSMakePoint(-100,0)]; + [p lineToPoint: NSMakePoint(0,100)]; + [p lineToPoint: NSMakePoint(100,0)]; + + if (i==0) + { + str="(u) tilted rect"; + } + else if (i==1) + { + [p closePath]; + str="(c) tilted rect"; + } + else + { + [p lineToPoint: NSMakePoint(0,-100)]; + [p closePath]; + str="(d) tilted rect"; + } + + /* Obvious stuff. */ + T(1,0,0) + T(0,200,200) + + /* Check around each corner. */ + CHECK_AROUND(0,-100, + 1,1,1, + 0,X,0, + 0,0,0) + + CHECK_AROUND(0,100, + 0,0,0, + 0,X,0, + 1,1,1) + + CHECK_AROUND(-100,0, + 0,0,1, + 0,X,1, + 0,0,1) + + CHECK_AROUND(100,0, + 1,0,0, + 1,X,0, + 1,0,0) + + /* Check some points on the edges. */ + CHECK_AROUND(50,50, + X,0,0, + 1,X,0, + 1,1,X) + + CHECK_AROUND(-50,50, + 0,0,X, + 0,X,1, + X,1,1) + + CHECK_AROUND(-50,-50, + X,1,1, + 0,X,1, + 0,0,X) + + CHECK_AROUND(50,-50, + 1,1,X, + 1,X,0, + X,0,0) + } + + for (i=0;i<3;i++) + { + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(200,200)]; + [p lineToPoint: NSMakePoint(200,100)]; + [p lineToPoint: NSMakePoint(100,100)]; + [p lineToPoint: NSMakePoint(100,200)]; + if (i==2) + [p lineToPoint: NSMakePoint(200,200)]; + if (i>=1) + [p closePath]; + + [p moveToPoint: NSMakePoint(200,200)]; + [p lineToPoint: NSMakePoint(300,200)]; + [p lineToPoint: NSMakePoint(300,100)]; + [p lineToPoint: NSMakePoint(200,100)]; + if (i==2) + [p lineToPoint: NSMakePoint(200,200)]; + if (i>=1) + [p closePath]; + + if (i==0) + str="(u) touching rects"; + else if (i==1) + str="(c) touching rects"; + else + str="(d) touching rects"; + + /* Obvious stuff. */ + T(0,0,0) + T(1,150,150) + T(1,250,150) + + /* Check around the touching corners and edge. */ + CHECK_AROUND(200,200, + 0,0,0, + X,X,X, + 1,1,1) + + CHECK_AROUND(200,100, + 1,1,1, + X,X,X, + 0,0,0) + + CHECK_AROUND(200,150, + 1,1,1, + 1,1,1, + 1,1,1) + } + + for (i=0;i<3;i++) + { + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(-100,200)]; + [p lineToPoint: NSMakePoint(100,200)]; + [p lineToPoint: NSMakePoint(100,-200)]; + [p lineToPoint: NSMakePoint(-100,-200)]; + if (i==2) + [p lineToPoint: NSMakePoint(-100,200)]; + if (i>=1) + [p closePath]; + + [p moveToPoint: NSMakePoint(200,100)]; + [p lineToPoint: NSMakePoint(200,-100)]; + [p lineToPoint: NSMakePoint(-200,-100)]; + [p lineToPoint: NSMakePoint(-200,100)]; + if (i==2) + [p lineToPoint: NSMakePoint(200,100)]; + if (i>=1) + [p closePath]; + + if (i==0) + str="(u) intersecting rects"; + else if (i==1) + str="(c) intersecting rects"; + else + str="(d) intersecting rects"; + + /* Obvious stuff. */ + T(2,0,0) + T(0,200,200) + T(1,150,0) + T(1,0,150) + } + + for (i=0;i<3;i++) + { + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(200,0)]; + [p lineToPoint: NSMakePoint(100,-100)]; + [p lineToPoint: NSMakePoint(100,100)]; + if (i==2) + [p lineToPoint: NSMakePoint(200,0)]; + if (i>=1) + [p closePath]; + + [p moveToPoint: NSMakePoint(200,0)]; + [p lineToPoint: NSMakePoint(300,100)]; + [p lineToPoint: NSMakePoint(300,-100)]; + if (i==2) + [p lineToPoint: NSMakePoint(200,0)]; + if (i>=1) + [p closePath]; + + if (i==0) + str="(u) touching triangles"; + else if (i==1) + str="(c) touching triangles"; + else + str="(d) touching triangles"; + + /* Obvious stuff. */ + T(0,0,0) + T(1,150,0) + T(1,250,0) + + CHECK_AROUND(200,0, + 1,0,1, + 1,X,1, + 1,0,1) + } + + for (i=0;i<3;i++) + { + CLEAR + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(100,100)]; + [p lineToPoint: NSMakePoint(300,100)]; + [p lineToPoint: NSMakePoint(100,-100)]; + [p lineToPoint: NSMakePoint(300,-100)]; + if (i==2) + [p lineToPoint: NSMakePoint(100,100)]; + if (i>=1) + [p closePath]; +// [view drawPath: p]; + + if (i==0) + str="(u) self-intersection"; + else if (i==1) + str="(c) self-intersection"; + else + str="(d) self-intersection"; + + /* Obvious stuff. */ + T(0,0,0) + T(1,200,50) + T(-1,200,-50) + + CHECK_AROUND(200,0, + 0,1,0, + 0,X,0, + 0,-1,0) +// [view pause]; + } + + for (i=0;i<3;i++) + { + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(-100,200)]; + [p lineToPoint: NSMakePoint(100,200)]; + [p lineToPoint: NSMakePoint(100,-200)]; + [p lineToPoint: NSMakePoint(-100,-200)]; + if (i==2) + [p lineToPoint: NSMakePoint(-100,200)]; + if (i>=1) + [p closePath]; + + [p moveToPoint: NSMakePoint(200,100)]; + [p lineToPoint: NSMakePoint(200,-100)]; + [p lineToPoint: NSMakePoint(-200,-100)]; + [p lineToPoint: NSMakePoint(-200,100)]; + if (i==2) + [p lineToPoint: NSMakePoint(200,100)]; + if (i>=1) + [p closePath]; + + if (i==0) + str="(u) intersecting rects"; + else if (i==1) + str="(c) intersecting rects"; + else + str="(d) intersecting rects"; + + /* Obvious stuff. */ + T(2,0,0) + T(0,200,200) + T(1,150,0) + T(1,0,150) + + /* Intersection corners. */ + CHECK_AROUND(100,100, + 1,X,0, + X,X,X, + 2,X,1) + + CHECK_AROUND(100,-100, + 2,X,1, + X,X,X, + 1,X,0) + + CHECK_AROUND(-100,-100, + 1,X,2, + X,X,X, + 0,X,1) + + CHECK_AROUND(-100,100, + 0,X,1, + X,X,X, + 1,X,2) + } + + for (i=0;i<3;i++) + { +// CLEAR + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(100,100)]; + [p curveToPoint: NSMakePoint(100,-100) + controlPoint1: NSMakePoint(200,100) + controlPoint2: NSMakePoint(200,-100)]; + if (i==2) + [p lineToPoint: NSMakePoint(100,100)]; + if (i>=1) + [p closePath]; + + +// DRAWPATH + + if (i==0) + str="(u) curve 1"; + else if (i==1) + str="(c) curve 1"; + else + str="(d) curve 1"; + + /* Obvious stuff. */ + T(0,0,0) + T(0,210,0) + T(0,190,0) + T(1,110,0) + + /* "Extreme" point is at 175, 0. This is at the half-way point, so + any tesselation by the standard method should get it right. */ + CHECK_AROUND(175, 0, + 1,0,0, + 1,X,0, + 1,0,0) + +// PAUSE + } + + for (i=0;i<3;i++) + { + CLEAR + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(-100,100)]; + [p curveToPoint: NSMakePoint(100,100) + controlPoint1: NSMakePoint(-100,-100) + controlPoint2: NSMakePoint(100,-100)]; + [p lineToPoint: NSMakePoint(100,-100)]; + [p curveToPoint: NSMakePoint(-100,-100) + controlPoint1: NSMakePoint(100,100) + controlPoint2: NSMakePoint(-100,100)]; + if (i==2) + [p lineToPoint: NSMakePoint(-100,100)]; + if (i>=1) + [p closePath]; + + + DRAWPATH + + if (i==0) + str="(u) curve 2"; + else if (i==1) + str="(c) curve 2"; + else + str="(d) curve 2"; + + /* Obvious stuff. */ + T(-1,0,0) + T(1,-90,0) + T(1, 90,0) + + /* The two curves intersect at y=0, x= +- 400 * sqrt(3) / 9. */ + + CHECK_AROUND(-400*sqrt(3)/9, 0, + 1,0,-1, + 1,X,-1, + 1,0,-1) + + CHECK_AROUND( 400*sqrt(3)/9, 0, + -1,0,1, + -1,X,1, + -1,0,1) + + PAUSE + } + + for (i=0;i<3;i++) + { + CLEAR + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(100,100)]; + [p curveToPoint: NSMakePoint(100,100) + controlPoint1: NSMakePoint(100,200) + controlPoint2: NSMakePoint(200,100)]; + if (i==2) + [p lineToPoint: NSMakePoint(100,100)]; + if (i>=1) + [p closePath]; + + + DRAWPATH + + if (i==0) + str="(u) curve 3"; + else if (i==1) + str="(c) curve 3"; + else + str="(d) curve 3"; + + /* Obvious stuff. */ + T(0,0,0) + T(1,105,105) + + CHECK_AROUND(100,100, + 0,0,1, + 0,X,0, + 0,0,0) + + PAUSE + } +#endif + + for (i=0;i<3;i++) + { + CLEAR + + /* + + +-+ + | | + +-* | + | | + +---+ + + */ + + [p removeAllPoints]; + [p moveToPoint: NSMakePoint(0,0)]; + [p lineToPoint: NSMakePoint(0,100)]; + [p lineToPoint: NSMakePoint(100,100)]; + [p lineToPoint: NSMakePoint(100,-100)]; + [p lineToPoint: NSMakePoint(-100,-100)]; + [p lineToPoint: NSMakePoint(-100,0)]; + if (i==2) + [p lineToPoint: NSMakePoint(0,0)]; + if (i>=1) + [p closePath]; + + + DRAWPATH + + if (i==0) + str="(u) curve 3"; + else if (i==1) + str="(c) curve 3"; + else + str="(d) curve 3"; + + /* Obvious stuff. */ + T(0,-5,5) + T(1,5,-5) + + CHECK_AROUND(0,0, + 0,X,1, + X,X,1, + 1,1,1) + + PAUSE + } + + DESTROY(arp); + + return 0; +} + diff --git a/Tests/gui/NSCell/objectValue.m b/Tests/gui/NSCell/objectValue.m new file mode 100644 index 000000000..2a43006df --- /dev/null +++ b/Tests/gui/NSCell/objectValue.m @@ -0,0 +1,37 @@ +#include "Testing.h" + +#include +#include + +#include +#include +#include + +int main() +{ + CREATE_AUTORELEASE_POOL(arp); + NSCell *cell; + NSNumber *num; + + [NSApplication sharedApplication]; + cell = [[NSCell alloc] init]; + num = [NSNumber numberWithFloat:55.0]; + [cell setObjectValue:num]; + pass([[cell objectValue] isEqual:num], + "-objectValue with NSNumber works"); + pass([cell floatValue] == 55.0, "-floatValue works"); + pass([cell intValue] == 55, "-intValue works"); + pass([cell doubleValue] == 55.0, "-doubleValue works"); + + [cell setObjectValue:@"foo"]; + + pass ([[cell objectValue] isEqual:@"foo"], "-objectValue with NSString works"); + + [cell setObjectValue:[NSImage imageNamed:@"GNUstep"]]; + pass ([[cell objectValue] isEqual:[NSImage imageNamed:@"GNUstep"]], + "-objectValue with NSImage works"); + + DESTROY(arp); + return 0; +} + diff --git a/Tests/gui/NSEvent/delta.m b/Tests/gui/NSEvent/delta.m new file mode 100644 index 000000000..c9f569e7c --- /dev/null +++ b/Tests/gui/NSEvent/delta.m @@ -0,0 +1,44 @@ +#include "Testing.h" + +#include +#include + +#include +#include + +int main() +{ + CREATE_AUTORELEASE_POOL(arp); + NSEvent *ev; + + [NSApplication sharedApplication]; + ev = [NSEvent mouseEventWithType: NSLeftMouseDown + location: NSMakePoint(0.0, 0.0) + modifierFlags: 0 + timestamp: 0 + windowNumber: 0 + context: nil + eventNumber: 0 + clickCount: 0 + pressure: 0.0]; + pass([ev deltaX] == 0.0, "-deltaX with NSLeftMouseDown event works"); + pass([ev deltaY] == 0.0, "-deltaY with NSLeftMouseDown event works"); + pass([ev deltaZ] == 0.0, "-deltaZ with NSLeftMouseDown event works"); + + ev = [NSEvent keyEventWithType: NSKeyDown + location: NSMakePoint(0.0, 0.0) + modifierFlags: 0 + timestamp: 0 + windowNumber: 0 + context: nil + characters: @"a" + charactersIgnoringModifiers: @"a" + isARepeat: NO + keyCode: 65]; + pass([ev deltaX] == 0.0, "-deltaX with NSKeyDown event works"); + pass([ev deltaY] == 0.0, "-deltaY with NSKeyDown event works"); + pass([ev deltaZ] == 0.0, "-deltaZ with NSKeyDown event works"); + + DESTROY(arp); + return 0; +} diff --git a/Tests/gui/NSParagraphStyle/NSParagraphStyle_defaultWritingDirection.m b/Tests/gui/NSParagraphStyle/NSParagraphStyle_defaultWritingDirection.m new file mode 100644 index 000000000..fc2429d90 --- /dev/null +++ b/Tests/gui/NSParagraphStyle/NSParagraphStyle_defaultWritingDirection.m @@ -0,0 +1,24 @@ +/* +copyright 2004 Alexander Malmberg +*/ + +#include "Testing.h" + +#include +#include + +int main(int argc, char **argv) +{ + int ok; + + CREATE_AUTORELEASE_POOL(arp); + + ok = [NSParagraphStyle defaultWritingDirectionForLanguage: @"en"]==NSWritingDirectionLeftToRight + && [NSParagraphStyle defaultWritingDirectionForLanguage: @"ar"]==NSWritingDirectionRightToLeft; + + pass(ok,"[NSParagraphStyle defaultWritingDirectionForLanguage:] works"); + + DESTROY(arp); + return 0; +} + diff --git a/Tests/gui/NSPasteboard/lazy_copy.m b/Tests/gui/NSPasteboard/lazy_copy.m new file mode 100644 index 000000000..183451919 --- /dev/null +++ b/Tests/gui/NSPasteboard/lazy_copy.m @@ -0,0 +1,49 @@ +/* +copyright 2004 Alexander Malmberg +*/ + +#include "Testing.h" + +#include +#include +#include +#include + +static NSString *theString=@"QUUX!!1!!\"$!"; + +@interface Foo : NSObject +@end + +@implementation Foo ++(void) pasteboard: (NSPasteboard *)pb + provideDataForType: (NSString *)type +{ +// printf("pasteboard: %@ provideDataForType: %@\n",pb,type); + [pb setString: theString + forType: NSStringPboardType]; +} +@end + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + NSPasteboard *pb=[NSPasteboard pasteboardWithName: @"lazy copy test"]; + int i; + NSString *s; + + i=[pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] + owner: [Foo self]]; + DESTROY(arp); + + arp=[NSAutoreleasePool new]; + pb=[NSPasteboard pasteboardWithName: @"lazy copy test"]; + s=[pb stringForType: NSStringPboardType]; + + pass([s isEqual: theString], "NSPasteboard handles lazy setting of data"); + + DESTROY(arp); + + return 0; +} + diff --git a/Tests/gui/NSPopUpButton/defaultSelection.m b/Tests/gui/NSPopUpButton/defaultSelection.m new file mode 100644 index 000000000..a80545783 --- /dev/null +++ b/Tests/gui/NSPopUpButton/defaultSelection.m @@ -0,0 +1,28 @@ +/* +copyright 2005 Alexander Malmberg +*/ + +#include "Testing.h" + +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + NSPopUpButton *b; + + [NSApplication sharedApplication]; + + b=[[NSPopUpButton alloc] init]; + + [b addItemWithTitle: @"foo"]; + [b addItemWithTitle: @"bar"]; + + pass([b indexOfSelectedItem] == 0,"first item is selected by default"); + + DESTROY(arp); + + return 0; +} + diff --git a/Tests/gui/NSPrintInfo/sharedPrintInfo.m b/Tests/gui/NSPrintInfo/sharedPrintInfo.m new file mode 100644 index 000000000..be5a3e829 --- /dev/null +++ b/Tests/gui/NSPrintInfo/sharedPrintInfo.m @@ -0,0 +1,18 @@ +/* +copyright 2004 Alexander Malmberg +*/ + +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + /* Should run without causing any exceptions. */ + [NSPrintInfo sharedPrintInfo]; + + DESTROY(arp); + return 0; +} + diff --git a/Tests/gui/NSSavePanel/dummy/A b/Tests/gui/NSSavePanel/dummy/A new file mode 100644 index 000000000..257cc5642 --- /dev/null +++ b/Tests/gui/NSSavePanel/dummy/A @@ -0,0 +1 @@ +foo diff --git a/Tests/gui/NSSavePanel/dummy/B b/Tests/gui/NSSavePanel/dummy/B new file mode 100644 index 000000000..257cc5642 --- /dev/null +++ b/Tests/gui/NSSavePanel/dummy/B @@ -0,0 +1 @@ +foo diff --git a/Tests/gui/NSSavePanel/setDelegate_reload.m b/Tests/gui/NSSavePanel/setDelegate_reload.m new file mode 100644 index 000000000..fa9e6c223 --- /dev/null +++ b/Tests/gui/NSSavePanel/setDelegate_reload.m @@ -0,0 +1,124 @@ +/* +copyright 2005 Alexander Malmberg + +Test that the file lists in NSSavePanel are reloaded properly when the +delegate changes. +*/ + +#include "Testing.h" + +/*#include +#include +#include +#include +#include +#include +#include */ +#include + +/* Ugly but automatable. :) */ +typedef struct +{ + @defs(NSSavePanel); +} NSSavePanel_ivars; + +@interface Delegate : NSObject +@end + +@implementation Delegate + +static BOOL pressed; +static NSSavePanel *sp; + ++(BOOL) panel: (NSSavePanel *)p + shouldShowFilename: (NSString *)fname +{ +// printf("should show '%s'?\n",[fname cString]); + if ([[fname lastPathComponent] isEqual: @"B"]) + { + return NO; + } + return YES; +} + +/*+(void) foo +{ + printf("did press button\n"); + pressed=YES; + [sp validateVisibleColumns]; +}*/ + +@end + +int main(int argc, char **argv) +{ + NSAutoreleasePool *arp=[NSAutoreleasePool new]; + NSSavePanel *p; + NSBrowser *b; + NSMatrix *m; + + [NSApplication sharedApplication]; + + sp=p=[NSSavePanel savePanel]; + [p setDirectory: [[[[[NSBundle mainBundle] bundlePath] + stringByDeletingLastPathComponent] stringByDeletingLastPathComponent] + stringByAppendingPathComponent: @"dummy"]]; +#if 0 + [p makeKeyAndOrderFront: nil]; + [p setDelegate: [Delegate self]]; + { + NSButton *b=[[NSButton alloc] initWithFrame: NSMakeRect(0,0,50,50)]; + [b setTitle: @"Click me"]; + [b setTarget: [Delegate self]]; + [b setAction: @selector(foo)]; + [p setAccessoryView: b]; + } +// [p validateVisibleColumns]; + [p runModal]; +#else + + b=((NSSavePanel_ivars *)p)->_browser; + m=[b matrixInColumn: [b lastColumn]]; + pass([m numberOfRows] == 3 + && [[[m cellAtRow: 0 column: 0] stringValue] isEqual: @"A"] + && [[[m cellAtRow: 1 column: 0] stringValue] isEqual: @"B"] + && [[[m cellAtRow: 2 column: 0] stringValue] isEqual: @".svn"], + "browser initially contains all files"); + + [p setDelegate: [Delegate self]]; + + b=((NSSavePanel_ivars *)p)->_browser; + m=[b matrixInColumn: [b lastColumn]]; + pass([m numberOfRows] == 2 + && [[[m cellAtRow: 0 column: 0] stringValue] isEqual: @"A"] + && [[[m cellAtRow: 1 column: 0] stringValue] isEqual: @".svn"], + "browser is reloaded after -setDelegate:"); + + + /* Not really a -setDelegate: issue, but the other methods involved are + documented as doing the wrong thing. */ + [p setDelegate: nil]; + b=((NSSavePanel_ivars *)p)->_browser; + m=[b matrixInColumn: [b lastColumn]]; + pass([m numberOfRows] == 3 + && [[[m cellAtRow: 0 column: 0] stringValue] isEqual: @"A"] + && [[[m cellAtRow: 1 column: 0] stringValue] isEqual: @"B"] + && [[[m cellAtRow: 2 column: 0] stringValue] isEqual: @".svn"], + "browser contains all files after resetting delegate"); + + [b scrollColumnsLeftBy: [b lastColumn]]; + [p setDelegate: [Delegate self]]; + b=((NSSavePanel_ivars *)p)->_browser; + m=[b matrixInColumn: [b lastColumn]]; + pass([m numberOfRows] == 2 + && [[[m cellAtRow: 0 column: 0] stringValue] isEqual: @"A"] + && [[[m cellAtRow: 1 column: 0] stringValue] isEqual: @".svn"], + "browser is reloaded after -setDelegate: (2)"); +#endif + +// [p validateVisibleColumns]; + + [arp release]; + return 0; +} + diff --git a/Tests/gui/NSSliderCell/minMax.m b/Tests/gui/NSSliderCell/minMax.m new file mode 100644 index 000000000..b125d0d7d --- /dev/null +++ b/Tests/gui/NSSliderCell/minMax.m @@ -0,0 +1,128 @@ +#include "Testing.h" + +#include +#include + +#include +#include +#include + +int main() +{ + CREATE_AUTORELEASE_POOL(arp); + NSSliderCell *cell; + NSNumber *num; + + [NSApplication sharedApplication]; + cell = [[NSSliderCell alloc] init]; + + pass([cell isContinuous], "slider continuous by default"); + + pass([cell minValue] == 0.0, "default min value is 0"); + pass([cell maxValue] == 1.0, "default max value is 1"); + pass([cell doubleValue] == 0.0, "default value is 0"); + pass([[cell objectValue] isEqual: [NSNumber numberWithDouble: 0]], "default objectValue is NSNumber 0"); + + [cell setMinValue: 2]; + pass([cell minValue] == 2.0, "set min value to 2"); + pass([cell maxValue] == 1.0, "max value is still 1"); + pass([cell doubleValue] == 2.0, "when min < max, value should always be min"); + + [cell setDoubleValue: -100.0]; + pass([cell doubleValue] == 2.0, "when min < max, value should always be min"); + [cell setDoubleValue: 1]; + pass([cell doubleValue] == 2.0, "when min < max, value should always be min"); + [cell setDoubleValue: 1.5]; + pass([cell doubleValue] == 2.0, "when min < max, value should always be min"); + [cell setDoubleValue: 2.0]; + pass([cell doubleValue] == 2.0, "when min < max, value should always be min"); + [cell setDoubleValue: 2.5]; + pass([cell doubleValue] == 2.0, "when min < max, value should always be min"); + + [cell setMaxValue: 10]; + pass([cell doubleValue] == 2.0, "value is still 2.0"); + + [cell setMinValue: 3.0]; + pass([cell doubleValue] == 3.0, "changing minimum clamps value to 3.0"); + pass([cell floatValue] == 3.0, "changing minimum clamps value to 3.0"); + + [cell setDoubleValue: 10]; + [cell setMaxValue: 9]; + pass([cell doubleValue] == 9.0, "changing max clamps value to 9.0"); + pass([cell floatValue] == 9.0, "changing max clamps value to 9.0"); + + // Test value setters + + [cell setObjectValue: @"hello"]; + pass([cell doubleValue] == 3.0, "setting nonsense string objectValue sets value to min"); + [cell setDoubleValue: 9.0]; + + [cell setStringValue: @"hello"]; + pass([cell doubleValue] == 3.0, "setting nonsense string stringValue sets value to min"); + [cell setDoubleValue: 9.0]; + + [cell setObjectValue: nil]; + pass([cell doubleValue] == 3.0, "setting nil objectValue sets value to min"); + [cell setDoubleValue: 9.0]; + + [cell setObjectValue: @"3.5"]; + pass([cell doubleValue] == 3.5, "setting @'3.5' objectValue sets value to 3.5"); + [cell setDoubleValue: 9.0]; + + [cell setStringValue: @"3.5"]; + pass([cell doubleValue] == 3.5, "setting @'3.5' stringValue sets value to 3.5"); + [cell setDoubleValue: 9.0]; + + [cell setIntValue: 3]; + pass([cell doubleValue] == 3.0, "setting 3 intValue sets value to 3.0"); + [cell setDoubleValue: 9.0]; + + // Test setting the value out of bounds with different setters + + [cell setDoubleValue: 3.5]; + [cell setObjectValue: @"-5"]; + pass([cell doubleValue] == 3.0, "setting @'-5' objectValue sets value to min"); + pass([cell intValue] == 3, "setting @'-5' objectValue sets value to min (integer)"); + [cell setDoubleValue: 3.5]; + [cell setStringValue: @"-5"]; + pass([cell doubleValue] == 3.0, "setting @'-5' stringValue sets value to min"); + pass([cell intValue] == 3, "setting @'-5' objectValue sets value to min (integer)"); + [cell setDoubleValue: 3.5]; + [cell setIntValue: -5]; + pass([cell doubleValue] == 3.0, "setting -5 intValue sets value to min"); + pass([cell intValue] == 3, "setting @'-5' objectValue sets value to min (integer)"); + [cell setDoubleValue: 3.5]; + [cell setDoubleValue: -5]; + pass([cell doubleValue] == 3.0, "setting -5 doubleValue sets value to min"); + pass([cell intValue] == 3, "setting @'-5' objectValue sets value to min (integer)"); + [cell setDoubleValue: 3.5]; + [cell setFloatValue: -5]; + pass([cell doubleValue] == 3.0, "setting -5 floatValue sets value to min"); + pass([cell intValue] == 3, "setting @'-5' objectValue sets value to min (integer)"); + + [cell setDoubleValue: 3.5]; + [cell setObjectValue: @"15"]; + pass([cell doubleValue] == 9.0, "setting @'15' objectValue sets value to max"); + pass([cell intValue] == 9, "setting @'15' objectValue sets value to max (integer)"); + [cell setDoubleValue: 3.5]; + [cell setStringValue: @"15"]; + pass([cell doubleValue] == 9.0, "setting @'15' stringValue sets value to max"); + pass([cell intValue] == 9, "setting @'15' stringValue sets value to max (integer)"); + [cell setDoubleValue: 3.5]; + [cell setIntValue: 15]; + pass([cell doubleValue] == 9.0, "setting 15 intValue sets value to max"); + pass([cell intValue] == 9, "setting 15 intValue sets value to max (integer)"); + [cell setDoubleValue: 3.5]; + [cell setDoubleValue: 15]; + pass([cell doubleValue] == 9.0, "setting 15 doubleValue sets value to max"); + pass([cell intValue] == 9, "setting 15 doubleValue sets value to max (integer)"); + [cell setDoubleValue: 3.5]; + [cell setFloatValue: 15]; + pass([cell doubleValue] == 9.0, "setting 15 floatValue sets value to max"); + pass([cell intValue] == 9, "setting 15 floatValue sets value to max (integer)"); + + + DESTROY(arp); + return 0; +} + diff --git a/Tests/gui/NSView/NSView_convertRect.m b/Tests/gui/NSView/NSView_convertRect.m new file mode 100644 index 000000000..420ee1dc9 --- /dev/null +++ b/Tests/gui/NSView/NSView_convertRect.m @@ -0,0 +1,136 @@ +/* +copyright 2004 Alexander Malmberg +*/ +#include "Testing.h" + +#include + +#include +#include +#include +#include +#include + +#if 0 +NSView *view1,*view2; + +@interface TestView1 : NSView +@end +@implementation TestView1 +-(void) drawRect: (NSRect)dr +{ + NSRect r; + PSsetrgbcolor(1,0,0); + PSrectfill(0,0,100,100); + + PSsetrgbcolor(1,1,1); + PSsetlinewidth(3.0); +// printf("********* convert\n"); + r=[self convertRect: NSMakeRect(0,0,50,50) fromView: view2]; + printf("got rect (%g %g)+(%g %g)\n",r.origin.x,r.origin.y,r.size.width,r.size.height); + PSrectstroke(r.origin.x,r.origin.y,r.size.width,r.size.height); + PSsetrgbcolor(0,1,0); + PSrectfill(r.origin.x-4,r.origin.y-4,8,8); +} +-(BOOL) isFlipped +{ + return YES; +} +@end + +@interface TestView2 : NSView +@end +@implementation TestView2 +-(void) drawRect: (NSRect)r +{ + PSsetrgbcolor(0,0,1); + PSrectfill(0,0,50,50); +} +-(BOOL) isFlipped +{ + return YES; +} +@end +#endif + + +int check(NSView *from,NSView *to,NSRect rfrom,NSRect rto) +{ + NSRect r; + + r=[to convertRect: rfrom fromView: from]; + if (fabs(r.origin.x - rto.origin.x)>0.001 + || fabs(r.origin.y - rto.origin.y)>0.001 + || fabs(r.size.width - rto.size.width)>0.001 + || fabs(r.size.height - rto.size.height)>0.001) + { + printf("(1) expected (%g %g)+(%g %g) to convert to (%g %g)+(%g %g), got (%g %g)+(%g %g)\n", + rfrom.origin.x,rfrom.origin.y,rfrom.size.width,rfrom.size.height, + rto.origin.x,rto.origin.y,rto.size.width,rto.size.height, + r.origin.x,r.origin.y,r.size.width,r.size.height); + + return 0; + } + + r=[from convertRect: rfrom toView: to]; + if (fabs(r.origin.x - rto.origin.x)>0.001 + || fabs(r.origin.y - rto.origin.y)>0.001 + || fabs(r.size.width - rto.size.width)>0.001 + || fabs(r.size.height - rto.size.height)>0.001) + { + printf("(2) expected (%g %g)+(%g %g) to convert to (%g %g)+(%g %g), got (%g %g)+(%g %g)\n", + rfrom.origin.x,rfrom.origin.y,rfrom.size.width,rfrom.size.height, + rto.origin.x,rto.origin.y,rto.size.width,rto.size.height, + r.origin.x,r.origin.y,r.size.width,r.size.height); + + return 0; + } + + return 1; +} + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + NSWindow *window; + NSView *view1,*view2; + int passed=1; + + [NSApplication sharedApplication]; + window=[[NSWindow alloc] initWithContentRect: NSMakeRect(100,100,200,200) + styleMask: NSClosableWindowMask + backing: NSBackingStoreRetained + defer: YES]; + view1=[[NSView alloc] initWithFrame: NSMakeRect(20,20,100,100)]; + view2=[[NSView alloc] initWithFrame: NSMakeRect(25,25,50,50)]; + + [view1 addSubview: view2]; + [[window contentView] addSubview: view1]; + + passed=check(view2,view1,NSMakeRect(0,0,10,10),NSMakeRect(25,25,10,10)) && passed; + passed=check(view1,view2,NSMakeRect(25,25,10,10),NSMakeRect(0,0,10,10)) && passed; + + [view2 setFrameRotation: 45.0]; + passed=check(view2,view1,NSMakeRect(0,0,10,10),NSMakeRect(17.9289,25,14.1421,14.1421)) && passed; + + [view2 setFrameRotation: 0.0]; + passed=check(view2,view1,NSMakeRect(0,0,10,10),NSMakeRect(25,25,10,10)) && passed; + passed=check(view1,view2,NSMakeRect(25,25,10,10),NSMakeRect(0,0,10,10)) && passed; + + [view1 setFrameRotation: 45.0]; + [view2 setFrameRotation: 45.0]; + passed=check(view2,view1,NSMakeRect(0,0,10,10),NSMakeRect(17.9289,25,14.1421,14.1421)) && passed; + + [view2 setFrameRotation: -45.0]; + passed=check(view2,view1,NSMakeRect(0,0,10,10),NSMakeRect(25,17.9289,14.1421,14.1421)) && passed; + + passed=check(view2,[window contentView],NSMakeRect(0,0,10,10),NSMakeRect(20,55.3553,10,10)) && passed; + passed=check([window contentView],view2,NSMakeRect(20,55.3553,10,10),NSMakeRect(0,0,10,10)) && passed; + + pass(passed,"NSView -convertRect:fromView: and -convertRect:toView: work"); + + DESTROY(arp); + return 0; +} + diff --git a/Tests/gui/NSView/NSView_frame_bounds.m b/Tests/gui/NSView/NSView_frame_bounds.m new file mode 100755 index 000000000..c041d1117 --- /dev/null +++ b/Tests/gui/NSView/NSView_frame_bounds.m @@ -0,0 +1,105 @@ +// +// NSView_frame_bounds.m +// +// Created by Fred Kiefer on 13.11.08. +// +#include "Testing.h" + +#include + +#include +#include +#include +#include + + +int CHECK(NSView *view, NSRect frame, NSRect bounds) +{ + NSRect r; + + r = [view frame]; + if (fabs(r.origin.x - frame.origin.x)>0.001 + || fabs(r.origin.y - frame.origin.y)>0.001 + || fabs(r.size.width - frame.size.width)>0.001 + || fabs(r.size.height - frame.size.height)>0.001) + { + printf("(1) expected frame (%g %g)+(%g %g), got (%g %g)+(%g %g)\n", + frame.origin.x, frame.origin.y, frame.size.width, frame.size.height, + r.origin.x, r.origin.y, r.size.width, r.size.height); + + return 0; + } + + r = [view bounds]; + if (fabs(r.origin.x - bounds.origin.x)>0.001 + || fabs(r.origin.y - bounds.origin.y)>0.001 + || fabs(r.size.width - bounds.size.width)>0.001 + || fabs(r.size.height - bounds.size.height)>0.001) + { + printf("(2) expected bounds (%g %g)+(%g %g), got (%g %g)+(%g %g)\n", + bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height, + r.origin.x, r.origin.y, r.size.width, r.size.height); + + return 0; + } + + return 1; +} + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + NSWindow *window; + NSView *view1; + int passed = 1; + + [NSApplication sharedApplication]; + window = [[NSWindow alloc] initWithContentRect: NSMakeRect(100,100,200,200) + styleMask: NSClosableWindowMask + backing: NSBackingStoreRetained + defer: YES]; + view1 = [[NSView alloc] initWithFrame: NSMakeRect(20,20,100,100)]; + + [[window contentView] addSubview: view1]; + + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(0,0,100,100)) && passed; + + [view1 setFrameOrigin: NSMakePoint(10, 10)]; + passed = CHECK(view1, NSMakeRect(10,10,100,100),NSMakeRect(0,0,100,100)) && passed; + + [view1 setFrameSize: NSMakeSize(80, 80)]; + passed = CHECK(view1, NSMakeRect(10,10,80,80),NSMakeRect(0,0,80,80)) && passed; + + [view1 setFrameRotation: 45.0]; + passed = CHECK(view1, NSMakeRect(10,10,80,80),NSMakeRect(0,0,80,80)) && passed; + + [view1 setBoundsRotation: -45.0]; + passed = CHECK(view1, NSMakeRect(10,10,80,80),NSMakeRect(-56.5685,0,113.137,113.137)) && passed; + + [view1 setFrameSize: NSMakeSize(100, 100)]; + passed = CHECK(view1, NSMakeRect(10,10,100,100),NSMakeRect(-70.7107,0,141.421,141.421)) && passed; + + [view1 setFrameOrigin: NSMakePoint(20, 20)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(-70.7107,0,141.421,141.421)) && passed; + + [view1 setBoundsOrigin: NSMakePoint(20, 20)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(-50.7107,20,141.421,141.421)) && passed; + + [view1 setBoundsSize: NSMakeSize(100, 100)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(-50.7107,20,141.421,141.421)) && passed; + + [view1 setBounds: NSMakeRect(10, 10, 100, 100)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(-60.7107,10,141.421,141.421)) && passed; + + [view1 translateOriginToPoint: NSMakePoint(20, 20)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(-80.7107,-10,141.421,141.421)) && passed; + + [view1 scaleUnitSquareToSize: NSMakeSize(2, 3)]; + passed = CHECK(view1, NSMakeRect(20,20,100,100),NSMakeRect(-40.3553,-3.33333,70.7107,47.1405)) && passed; + + pass(passed,"NSView -frame and -bounds work"); + + DESTROY(arp); + return 0; +} diff --git a/Tests/gui/NSView/NSView_frame_rotation.m b/Tests/gui/NSView/NSView_frame_rotation.m new file mode 100644 index 000000000..2198de36b --- /dev/null +++ b/Tests/gui/NSView/NSView_frame_rotation.m @@ -0,0 +1,60 @@ +/* +copyright 2004 Alexander Malmberg +*/ +#include "Testing.h" + +#include + +#include +#include +#include +#include + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + + NSWindow *window; + NSView *view; + int passed; + + [NSApplication sharedApplication]; + window=[[NSWindow alloc] init]; + view=[[NSView alloc] init]; + + [[window contentView] addSubview: view]; + +#define CHECK(f) \ + if (fabs(f-[view frameRotation])>0.0001 \ + && fabs(f-[view frameRotation]-360.0)>0.0001 \ + && fabs(f-[view frameRotation]+360.0)>0.0001) \ + { \ + passed=0; \ + printf("expected rotation %30.25f, got %30.25f\n",f,[view frameRotation]); \ + } + + passed=1; + CHECK(0.0) + [view setFrameRotation: 45.0]; + CHECK(45.0) + [view setFrameRotation: 0.0]; + CHECK(0.0) + [view setFrameRotation: 90.0]; + CHECK(90.0) + [view setFrameRotation: 180.0]; + CHECK(180.0) + [view setFrameRotation: 360.0]; + CHECK(0.0) + [view setFrameRotation: 0.0]; + CHECK(0.0) + [view setFrameRotation: -45.0]; + CHECK(315.0) + [view setFrameRotation: 0.0]; + CHECK(0.0) + + pass(passed,"-frameRotation/-setFrameRotation work"); + + DESTROY(arp); + return 0; +} + diff --git a/Tests/gui/NSView/scrollRectToVisible.m b/Tests/gui/NSView/scrollRectToVisible.m new file mode 100644 index 000000000..e4028933b --- /dev/null +++ b/Tests/gui/NSView/scrollRectToVisible.m @@ -0,0 +1,82 @@ +/* +copyright 2004 Alexander Malmberg +*/ + +#include "Testing.h" + +#include +#include +#include + +#define TEST(r,s) \ + if (!NSEqualRects([v visibleRect],r)) \ + { \ + printf("%s: got %s, expected %s\n", \ + s, \ + [NSStringFromRect([v visibleRect]) lossyCString], \ + [NSStringFromRect(r) lossyCString]); \ + pass(0,s); \ + } \ + else \ + pass(1,s); + +int main(int argc, char **argv) +{ + CREATE_AUTORELEASE_POOL(arp); + NSClipView *cv=[[NSClipView alloc] initWithFrame: NSMakeRect(0,0,10,10)]; + NSView *v=[[NSView alloc] initWithFrame: NSMakeRect(0,0,100,100)]; + [cv setDocumentView: v]; + + /* Initial position. */ + TEST(NSMakeRect(0,0,10,10),"1") + + /* Basic scrolling. */ + [v scrollRectToVisible: NSMakeRect(50,50,10,10)]; + TEST(NSMakeRect(50,50,10,10),"2"); + + /* No scrolling necessary. */ + [v scrollRectToVisible: NSMakeRect(55,55,5,5)]; + TEST(NSMakeRect(50,50,10,10),"3"); + + /* No scrolling necessary. */ + [v scrollRectToVisible: NSMakeRect(50,50,5,5)]; + TEST(NSMakeRect(50,50,10,10),"4"); + + /* No scrolling necessary. */ + [v scrollRectToVisible: NSMakeRect(52,52,5,5)]; + TEST(NSMakeRect(50,50,10,10),"5"); + + /* Minimal scrolling means that the "small-coordinate" corner should be + visible. */ + [v scrollRectToVisible: NSMakeRect(80,80,20,20)]; + TEST(NSMakeRect(80,80,10,10),"6"); + + /* And in this case, the "large-coordinate" corner. */ + [v scrollRectToVisible: NSMakeRect(0,0,20,20)]; + TEST(NSMakeRect(10,10,10,10),"7"); + + /* If the visible rect is inside the target rect, no scrolling should + occur. */ + [v scrollRectToVisible: NSMakeRect(5,5,20,20)]; + TEST(NSMakeRect(10,10,10,10),"8"); + + /* Nor for a target rect on the edge of the visible rect. */ + [v scrollRectToVisible: NSMakeRect(10,10,20,20)]; + TEST(NSMakeRect(10,10,10,10),"9"); + + /* Repeating the call shouldn't cause any scrolling. */ + [v scrollRectToVisible: NSMakeRect(10,10,20,20)]; + TEST(NSMakeRect(10,10,10,10),"10"); + + /* Minimal scrolling and partial overlap. */ + [v scrollRectToVisible: NSMakeRect(7,7,5,5)]; + TEST(NSMakeRect(7,7,10,10),"11"); + + [v scrollRectToVisible: NSMakeRect(15,15,5,5)]; + TEST(NSMakeRect(10,10,10,10),"12"); + + DESTROY(arp); + + return 0; +} + diff --git a/Tests/gui/TextSystem/repeatedAttachmentCellHeight.m b/Tests/gui/TextSystem/repeatedAttachmentCellHeight.m new file mode 100644 index 000000000..f1907f74b --- /dev/null +++ b/Tests/gui/TextSystem/repeatedAttachmentCellHeight.m @@ -0,0 +1,69 @@ +/* +copyright 2004 Alexander Malmberg + +Check that the layour process doesn't get stuck if we try to make a cell fill +the entire height of a line frag. +*/ + +#include +#include +#include +#include +#include +#include +#include + +@interface MyCell : NSTextAttachmentCell +@end + +@implementation MyCell + +-(NSRect) cellFrameForTextContainer: (NSTextContainer *)textContainer + proposedLineFragment: (NSRect)lineFrag + glyphPosition: (NSPoint)p + characterIndex: (unsigned int)charIndex +{ +static int count; + /* This should only be called once. */ + if (count) + exit(1); + count++; + return NSMakeRect(0,-p.y,50,lineFrag.size.height); +} + +@end + +int main(int argc, char **argv) +{ + unichar chars[4]={'a','b','c',NSAttachmentCharacter}; + CREATE_AUTORELEASE_POOL(arp); + NSTextStorage *text; + NSLayoutManager *lm; + NSTextContainer *tc; + NSTextAttachment *ta; + + [NSApplication sharedApplication]; + + text=[[NSTextStorage alloc] init]; + lm=[[NSLayoutManager alloc] init]; + tc=[[NSTextContainer alloc] initWithContainerSize: NSMakeSize(500,5000)]; + [lm addTextContainer: tc]; + [text addLayoutManager: lm]; + + ta=[[NSTextAttachment alloc] init]; + [ta setAttachmentCell: [[MyCell alloc] init]]; + + [text beginEditing]; + [text appendAttributedString: + [[NSAttributedString alloc] initWithString: + [NSString stringWithCharacters: chars length: 4]]]; + [text addAttribute: NSAttachmentAttributeName + value: ta + range: NSMakeRange(3,1)]; + [text endEditing]; + [lm usedRectForTextContainer: tc]; + + DESTROY(arp); + return 0; +} +