mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-23 09:04:13 +00:00
remove obsolete test code
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@27732 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
4006fb9f00
commit
53d2e0a7e0
86 changed files with 22 additions and 11242 deletions
14
ChangeLog
14
ChangeLog
|
@ -1,3 +1,17 @@
|
|||
2009-01-30 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Documentation/readme.texi:
|
||||
* README: Remove reference to Testing
|
||||
* Examples/nsconnection_server.m:
|
||||
* Examples/diningPhilosophers.m:
|
||||
* Examples/nsconnection_client.m:
|
||||
* Examples/nsconnection.m: Transferred from Testing
|
||||
* Testing: removed
|
||||
Removed Testing subdirectory. Now that locking tests are in the
|
||||
testsuite all the code here is probably obsolete. If we find any
|
||||
cases where that's not the case, we should recover anything we
|
||||
need from svn and add it to the testsuite.
|
||||
|
||||
2009-01-30 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/NSLock.m: Fixed last change to match MacOS-X behavior.
|
||||
|
|
|
@ -35,7 +35,7 @@ GNUstep tools, test programs, and other files are covered under the
|
|||
GNU Public License. This means if you make changes to these programs,
|
||||
you cannot charge a fee, other than distribution fees, for others to
|
||||
use the program. You should read the COPYING file for more information.
|
||||
All files in the @file{Documentation}, @file{Examples}, @file{Testing},
|
||||
All files in the @file{Documentation}, @file{Examples},
|
||||
@file{Tools}, @file{config}, and @file{macosx} directories are covered
|
||||
under the GPL.
|
||||
|
||||
|
|
8
README
8
README
|
@ -10,6 +10,12 @@ remote object messaging support (distributed objects), and event loops.
|
|||
It provides functionality that aims to implement the non-graphical
|
||||
portion of the OpenStep standard (the Foundation library).
|
||||
|
||||
Regression testing is available in the GNUstep testsuite.
|
||||
You can check this out using subversion with the following command:
|
||||
svn co svn://svn.gna.org/gnustep/tests/testsuite/trunk testsuite
|
||||
or view it in a web browser at
|
||||
http://svn.gna.org/viewcvs/gnustep/tests/testsuite/trunk
|
||||
|
||||
1.1 Initial reading
|
||||
===================
|
||||
|
||||
|
@ -34,7 +40,7 @@ and subdirectories under this are covered under the GLPL.
|
|||
GNU Public License. This means if you make changes to these programs,
|
||||
you cannot charge a fee, other than distribution fees, for others to
|
||||
use the program. You should read the COPYING file for more information.
|
||||
All files in the `Documentation', `Examples', `Testing', `Tools',
|
||||
All files in the `Documentation', `Examples', `Tools',
|
||||
`config', and `macosx' directories are covered under the GPL.
|
||||
|
||||
With GNUstep-Base, we strongly recommend the use of the ffcall
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
|
||||
*.txt *.dat
|
||||
LoadMe.bundle
|
||||
nsprocessinfo nsarchiver invocation diningPhilosophers nsmaptable nshashtable
|
||||
nstimer nsnotification nxst fref heap basic
|
||||
pipes server client string values nsarray nsbundle nsdictionary nsset
|
||||
release nsscanner nsdate awake thread-except nscharacterset
|
||||
shared_debug_obj
|
||||
shared_obj
|
||||
tcpport-server tcpport-client coder cstream float prepend randoms
|
||||
test??
|
|
@ -1 +0,0 @@
|
|||
directory . ..
|
|
@ -1,21 +0,0 @@
|
|||
/* This is an example of a string table file. Everything inside a comment
|
||||
is completely ignored, even if in "quotes", or \escape characters, etc.
|
||||
*/
|
||||
|
||||
"title" = "pattern II target 1";
|
||||
|
||||
/* This is an example of excape codes in the string table, codes */
|
||||
/* that are not one of abfnrtv are stripped of the \ character */
|
||||
"escapes" = "This is a tab \t and a return \n or a \a but not a \p";
|
||||
"escapes2" = "Well how about a \0? Guess not.";
|
||||
|
||||
/* more parameters, white space between tokens is ignored */
|
||||
"actualSize"
|
||||
=
|
||||
"0.000250 0.000250";
|
||||
|
||||
/* a key with no value assumes the value is the same as the key */
|
||||
"hoe322070.element";
|
||||
|
||||
/* this will produce an error */
|
||||
"unterminated"= "this is a string with no ending quote;
|
|
@ -1,165 +0,0 @@
|
|||
#
|
||||
# checks makefile for the GNUstep Base Library
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This file 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.
|
||||
#
|
||||
# This file 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., 675 Mass Ave, Cambridge, MA 02111, USA.
|
||||
#
|
||||
|
||||
ifeq ($(GNUSTEP_MAKEFILES),)
|
||||
GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null)$(warning computed GNUSTEP_MAKEFILES)
|
||||
endif
|
||||
|
||||
ifeq ($(GNUSTEP_MAKEFILES),)
|
||||
$(error You need to set GNUSTEP_MAKEFILES before compiling!)
|
||||
endif
|
||||
|
||||
PACKAGE_NAME = gnustep-base
|
||||
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../base.make
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
include ../Version
|
||||
include ../config.mak
|
||||
include ../Source/pathconfig/pathconfig.mak
|
||||
|
||||
# The tools to be compiled
|
||||
CHECKABLE_TOOLS = \
|
||||
awake \
|
||||
basic \
|
||||
benchmark \
|
||||
call \
|
||||
containers \
|
||||
exported-strings \
|
||||
fref \
|
||||
gsbehavior \
|
||||
gslock \
|
||||
nsarchiver \
|
||||
nsarray \
|
||||
nsattributedstring \
|
||||
nsbundle \
|
||||
nscharacterset \
|
||||
nsconnection \
|
||||
nsdata \
|
||||
nsdate \
|
||||
nsdictionary \
|
||||
nsfilehandle \
|
||||
nsfilemanager \
|
||||
nshashtable \
|
||||
nshost \
|
||||
nsindexset \
|
||||
nsinvocation \
|
||||
nsmaptable \
|
||||
nsmethodsignature \
|
||||
nsnotification \
|
||||
nspathutilities \
|
||||
nsprocessinfo \
|
||||
nsscanner \
|
||||
nsset \
|
||||
nstask \
|
||||
nstimer \
|
||||
nstimezone \
|
||||
nsundomanager \
|
||||
nsxmlparser \
|
||||
release \
|
||||
string \
|
||||
thread \
|
||||
thread-except \
|
||||
values \
|
||||
|
||||
TEST_TOOL_NAME = $(CHECKABLE_TOOLS)
|
||||
|
||||
# Don't make these normally
|
||||
ADDITIONAL_TOOLS = \
|
||||
diningPhilosophers \
|
||||
nsconnection_client \
|
||||
nsconnection_server \
|
||||
|
||||
TEST_TOOL_NAME += $(ADDITIONAL_TOOLS)
|
||||
|
||||
# The tool Objective-C source files to be compiled
|
||||
awake_OBJC_FILES = awake.m
|
||||
basic_OBJC_FILES = basic.m
|
||||
benchmark_OBJC_FILES = benchmark.m
|
||||
call_OBJC_FILES = call.m
|
||||
containers_OBJC_FILES = containers.m
|
||||
diningPhilosophers_OBJC_FILES = diningPhilosophers.m
|
||||
exported-strings_OBJC_FILES = exported-strings.m
|
||||
fref_OBJC_FILES = fref.m
|
||||
gsbehavior_OBJC_FILES = gsbehavior.m
|
||||
gslock_OBJC_FILES = gslock.m
|
||||
nsarchiver_OBJC_FILES = nsarchiver.m
|
||||
nsarray_OBJC_FILES = nsarray.m
|
||||
nsattributedstring_OBJC_FILES = nsattributedstring.m
|
||||
nsbundle_OBJC_FILES = nsbundle.m
|
||||
nscharacterset_OBJC_FILES = nscharacterset.m
|
||||
nsconnection_OBJC_FILES = nsconnection.m
|
||||
nsconnection_client_OBJC_FILES = nsconnection_client.m
|
||||
nsconnection_server_OBJC_FILES = nsconnection_server.m
|
||||
nsdata_OBJC_FILES = nsdata.m
|
||||
nsdate_OBJC_FILES = nsdate.m
|
||||
nsdictionary_OBJC_FILES = nsdictionary.m
|
||||
nsfilehandle_OBJC_FILES = nsfilehandle.m
|
||||
nsfilemanager_OBJC_FILES = nsfilemanager.m
|
||||
nshashtable_OBJC_FILES = nshashtable.m
|
||||
nshost_OBJC_FILES = nshost.m
|
||||
nsindexset_OBJC_FILES = nsindexset.m
|
||||
nsinvocation_OBJC_FILES = nsinvocation.m
|
||||
nskvo_OBJC_FILES = nskvo.m
|
||||
nsmaptable_OBJC_FILES = nsmaptable.m
|
||||
nsmethodsignature_OBJC_FILES = nsmethodsignature.m
|
||||
nsnotification_OBJC_FILES = nsnotification.m
|
||||
nspathutilities_OBJC_FILES = nspathutilities.m
|
||||
nsprocessinfo_OBJC_FILES = nsprocessinfo.m
|
||||
nsscanner_OBJC_FILES = nsscanner.m
|
||||
nsset_OBJC_FILES = nsset.m
|
||||
nstask_OBJC_FILES = nstask.m
|
||||
nstimer_OBJC_FILES = nstimer.m
|
||||
nstimezone_OBJC_FILES = nstimezone.m
|
||||
nsxmlparser_OBJC_FILES = nsxmlparser.m
|
||||
nsundomanager_OBJC_FILES = nsundomanager.m
|
||||
prepend_OBJC_FILES = prepend.m
|
||||
release_OBJC_FILES = release.m
|
||||
string_OBJC_FILES = string.m
|
||||
testtool_OBJC_FILES = testtool.m
|
||||
thread_OBJC_FILES = thread.m
|
||||
thread-except_OBJC_FILES = thread-except.m
|
||||
values_OBJC_FILES = values.m
|
||||
|
||||
# The bundles to be compiled
|
||||
BUNDLE_NAME=LoadMe
|
||||
|
||||
# The bundle Objective-C source files to be compiled
|
||||
LoadMe_OBJC_FILES = LoadMe.m MyCategory.m SecondClass.m
|
||||
|
||||
# The bundle resource files and directories
|
||||
LoadMe_RESOURCE_FILES = English.lproj/NXStringTable.example
|
||||
LoadMe_RESOURCE_DIRS = English.lproj
|
||||
|
||||
# Manually disable installation of LoadMe bundle
|
||||
LoadMe_STANDARD_INSTALL = no
|
||||
|
||||
-include Makefile.preamble
|
||||
|
||||
-include GNUmakefile.local
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/test-tool.make
|
||||
include $(GNUSTEP_MAKEFILES)/bundle.make
|
||||
|
||||
-include Makefile.postamble
|
|
@ -1,24 +0,0 @@
|
|||
/* Test Class for NSBundle.
|
||||
Copyright (C) 1993,1994,1995 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
@interface LoadMe : NSObject
|
||||
{
|
||||
int var;
|
||||
}
|
||||
|
||||
- init;
|
||||
- afterLoad;
|
||||
|
||||
@end
|
|
@ -1,33 +0,0 @@
|
|||
/* Test Class for NSBundle.
|
||||
Copyright (C) 1993,1994,1995 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include "LoadMe.h"
|
||||
|
||||
@implementation LoadMe
|
||||
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
var = 10;
|
||||
return self;
|
||||
}
|
||||
|
||||
- afterLoad
|
||||
{
|
||||
printf("%s's instance variable is %i\n", [[self description] cString], var);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,79 +0,0 @@
|
|||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Author: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# This file is part of the GNUstep Base Library.
|
||||
#
|
||||
# This file 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.
|
||||
#
|
||||
# This file 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.
|
||||
#
|
||||
# If you are interested in a warranty or support for this source code,
|
||||
# contact Scott Christley at scottc@net-community.com
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this library; see the file COPYING.LIB.
|
||||
# If not, write to the Free Software Foundation,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#
|
||||
# Makefile.postamble
|
||||
#
|
||||
# Project specific makefile rules
|
||||
#
|
||||
# Uncomment the targets you want.
|
||||
# The double colons (::) are important, do not make them single colons
|
||||
# otherwise the normal makefile rules will not be performed.
|
||||
#
|
||||
|
||||
# Things to do before compiling
|
||||
# before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
# before-install::
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
after-distclean::
|
||||
rm -f cstream.dat fref.dat nsarchiver.dat
|
||||
|
||||
check:: $(CHECKABLE_TOOLS)
|
||||
for f in $(CHECKABLE_TOOLS); do \
|
||||
obj/$$f ; \
|
||||
done
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
#
|
||||
# checks makefile for the GNUstep Base Library
|
||||
#
|
||||
# Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
#
|
||||
# Written by: Scott Christley <scottc@net-community.com>
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
#
|
||||
# Makefile.preamble
|
||||
#
|
||||
# Project specific makefile variables, and additional
|
||||
#
|
||||
# Do not put any Makefile rules in this file, instead they should
|
||||
# be put into Makefile.postamble.
|
||||
#
|
||||
|
||||
#
|
||||
# Flags dealing with compiling and linking
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS =
|
||||
|
||||
# Additional flags to pass to the Objective-C compiler
|
||||
ADDITIONAL_OBJCFLAGS = -g
|
||||
|
||||
# Additional flags to pass to the C compiler
|
||||
ADDITIONAL_CFLAGS =
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS = -I../Headers/Additions \
|
||||
-I../Source/$(GNUSTEP_TARGET_DIR)
|
||||
|
||||
ifeq ($(FOUNDATION_LIB),gnu)
|
||||
ADDITIONAL_INCLUDE_DIRS += -I../Headers
|
||||
endif
|
||||
|
||||
|
||||
# Additional LDFLAGS to pass to the linker
|
||||
ADDITIONAL_LDFLAGS =
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS = -L../Source/$(GNUSTEP_OBJ_DIR)
|
||||
|
||||
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
|
||||
BUNDLE_LIBS += -lgnustep-base -lobjc
|
||||
endif
|
||||
ifeq ($(GNUSTEP_TARGET_OS),cygwin)
|
||||
BUNDLE_LIBS += -lgnustep-base -lobjc
|
||||
endif
|
||||
|
||||
#
|
||||
# Flags dealing with installing and uninstalling
|
||||
#
|
||||
|
||||
# Additional directories to be created during installation
|
||||
ADDITIONAL_INSTALL_DIRS =
|
|
@ -1,20 +0,0 @@
|
|||
/* Test Category for NSBundle.
|
||||
Copyright (C) 1993,1994,1995 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
@interface NSObject(MyCategory)
|
||||
|
||||
- printMyName;
|
||||
|
||||
@end
|
|
@ -1,25 +0,0 @@
|
|||
/* Test Category for NSBundle.
|
||||
Copyright (C) 1993,1994,1995 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#include "MyCategory.h"
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
@implementation NSObject(MyCategory)
|
||||
|
||||
- printMyName
|
||||
{
|
||||
printf("Class %s had MyCategory added to it\n", [[self description] cString]);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,404 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/******************************************************************************
|
||||
* Module : NSMutableData(NSData) --- Black Box test module for the
|
||||
* *Data classes to make sure that methods that raise exceptions
|
||||
* do so, and that the exceptions are raised properly.
|
||||
*
|
||||
* Author : John W. M. Stevens
|
||||
|
||||
...............................................................................
|
||||
15 April 1997
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSRange.h>
|
||||
#include <Foundation/NSSerialization.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
/* Data for stuffing into *Data objects. I like printable data, as it
|
||||
* gives a quick visual check mechanism, but it has the disadvantage
|
||||
* of not checking for 8 bit cleanliness.
|
||||
*/
|
||||
char *testString = "Test string for mutable data and archiver classes.";
|
||||
char *subString = "Sub String";
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
| Routine : TestNSMutableData() --- Create an instance of an NSMutableData
|
||||
| class, initialize it with a C string (to have something
|
||||
| printable for tests) and invoke the two methods that
|
||||
| should raise NSRangeException exceptions using ranges that
|
||||
| cross both edges of the buffer boundary.
|
||||
|
|
||||
| Notes : Please see work logs for discussion.
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
TestNSMutableData(void)
|
||||
{
|
||||
auto NSMutableData *nsMutData;
|
||||
auto char *str;
|
||||
auto NSRange range;
|
||||
|
||||
/* Allocate and initialize an instance of an NSMutableData
|
||||
* class.
|
||||
*/
|
||||
nsMutData = [NSMutableData dataWithLength: strlen( testString ) + 1];
|
||||
str = (char *) [nsMutData mutableBytes];
|
||||
strcpy(str, testString);
|
||||
|
||||
/* Get contents, display. */
|
||||
str = NULL;
|
||||
str = (char *) [nsMutData mutableBytes];
|
||||
printf("NSMutableData Test ---------------------------------------------"
|
||||
"---------------\n"
|
||||
"1) String: (%s)\n", str);
|
||||
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
range = NSMakeRange(-2, strlen( subString ));
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about a length that is less than zero? */
|
||||
NS_DURING
|
||||
range = NSMakeRange(6, -3.0);
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
range = NSMakeRange(-2, strlen( subString ));
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about a length less than zero? */
|
||||
NS_DURING
|
||||
range = NSMakeRange(6.0, -3.0);
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Get contents, display. */
|
||||
str = NULL;
|
||||
str = (char *) [nsMutData mutableBytes];
|
||||
printf("2) String: (%s)\n", str);
|
||||
|
||||
/* Attempt to force an out of memory exception. */
|
||||
#if 0
|
||||
for ( ; ; )
|
||||
{
|
||||
/* Append. */
|
||||
[nsMutData appendBytes: testString
|
||||
length : strlen( testString ) + 1];
|
||||
|
||||
/* Show current value. */
|
||||
printf("%9u\r", [nsMutData length]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
| Routine : TestNSData() --- Create an instance of an NSData
|
||||
| class, initialize it with a C string (to have something
|
||||
| printable for tests) and invoke the two methods that
|
||||
| should raise NSRangeException exceptions using ranges that
|
||||
| cross both edges of the buffer boundary.
|
||||
|
|
||||
| Notes : Please see work logs for discussion.
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
TestNSData(void)
|
||||
{
|
||||
auto NSData *nsData;
|
||||
auto NSData *newNsData;
|
||||
auto char *str;
|
||||
auto char bfr[128];
|
||||
auto NSRange range;
|
||||
|
||||
/* Allocate and initialize an instance of an NSData
|
||||
* class.
|
||||
*/
|
||||
nsData = [NSData dataWithBytes: testString
|
||||
length : (unsigned int) strlen( testString ) + 1];
|
||||
|
||||
/* Get contents, display. */
|
||||
str = (char *) [nsData bytes];
|
||||
printf("NSData Test ----------------------------------------------------"
|
||||
"---------------\n"
|
||||
"1) String: (%s)\n", str);
|
||||
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(-2.0, 6.0);
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[6] = '\0';
|
||||
printf(" A) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
/* Get piece. */
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" B) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" C) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about less than zero length? */
|
||||
NS_DURING
|
||||
range = NSMakeRange(5.0, -4.0);
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" C) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/*=================== subDataWithRange ======================================*/
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(-2.0, 6.0);
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[6] = '\0';
|
||||
printf(" D) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" E) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" F) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about a length less than zero? */
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(9.0, -6.0);
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" F) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Get contents, display. */
|
||||
str = NULL;
|
||||
str = (char *) [nsData bytes];
|
||||
printf("2) String: (%s)\n", str);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc,
|
||||
char **argv)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
/* Test NSMutableData. */
|
||||
TestNSMutableData();
|
||||
|
||||
/* Test NSData. */
|
||||
TestNSData();
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
|
||||
These tests are mostly just samples of code that developers put together
|
||||
to do quick checks to make sure things are working. This is not a
|
||||
comprehensive test suite. Some tests don't say if they have passed or
|
||||
not. Some tests do not even output anything. Some tests never quit!
|
||||
|
||||
If you want to run a comprehensive testsuite, run the gnustep testsuite
|
||||
http://svn.gna.org/viewcvs/gnustep/tests/testsuite
|
||||
(also ftp://ftp.gnustep.org/pub/gnustep/test).
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/* Test Class for NSBundle.
|
||||
Copyright (C) 1993,1994,1995 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#include <Foundation/NSObject.h>
|
||||
|
||||
@interface SecondClass : NSObject
|
||||
{
|
||||
int h;
|
||||
char *dummy;
|
||||
}
|
||||
|
||||
- init;
|
||||
- printName;
|
||||
|
||||
@end
|
|
@ -1,33 +0,0 @@
|
|||
/* Test Class for NSBundle.
|
||||
Copyright (C) 1993,1994,1995 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#include "SecondClass.h"
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
@implementation SecondClass
|
||||
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
h = 25;
|
||||
return self;
|
||||
}
|
||||
|
||||
- printName
|
||||
|
||||
{
|
||||
printf("Hi my name is %s\n", [[self description] cString]);
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
313
Testing/awake.m
313
Testing/awake.m
|
@ -1,313 +0,0 @@
|
|||
/* Test use of -awakeAfterUsingCoder:
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This is a rather complicated, strenuous test, borrowing elements
|
||||
from the fref.m test.
|
||||
*/
|
||||
|
||||
|
||||
/* Beginning of some parameters to vary. */
|
||||
/* 0 and 0 works.
|
||||
1 and 0 works for the first test, but has no way of getting the
|
||||
super_foo in second test right, because we haven't resolved the
|
||||
forward reference when -awakeAfterUsingCoder is called; this is
|
||||
an inherent problem of decoding.
|
||||
0 and 1 crashes, as does NeXT's (for reasons related to forward
|
||||
references, having nothing to do with awakeAfterUsingCoder). */
|
||||
|
||||
/* Use GNU Archiving features, if they are available. */
|
||||
#define TRY_GNU_ARCHIVING 0
|
||||
|
||||
/* In the forward self-reference test, -initWithCoder substitutes
|
||||
another object for self. */
|
||||
#define SELF_REF_INITWITHCODER_SUBSTITUTES 0
|
||||
|
||||
/* End of some parameters to vary. */
|
||||
|
||||
#ifdef NX_CURRENT_COMPILER_RELEASE
|
||||
#include <foundation/NSArchiver.h>
|
||||
#include <foundation/NSArray.h>
|
||||
#include <foundation/NSAutoreleasePool.h>
|
||||
#else
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#endif
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
#define GNU_ARCHIVING \
|
||||
(TRY_GNU_ARCHIVING && defined(GNUSTEP_BASE_MAJOR_VERSION))
|
||||
|
||||
#if GNU_ARCHIVING
|
||||
#include <GNUstepBase/Archiver.h>
|
||||
#endif /* GNU_ARCHIVING */
|
||||
|
||||
|
||||
/* The -initWithCoder methods substitutes another object for self. */
|
||||
int initWithCoder_substitutes;
|
||||
int Foo_awakeAfterUsingCoder_substitutes = 0;
|
||||
int SubFoo_awakeAfterUsingCoder_substitutes = 1;
|
||||
|
||||
/* This object encodes an -encodeConditionalObject: reference to a Foo. */
|
||||
@interface SubFoo : NSObject
|
||||
{
|
||||
id super_foo;
|
||||
int label;
|
||||
}
|
||||
@end
|
||||
|
||||
/* This object encodes an -encodeObject: reference to a SubFoo */
|
||||
/* Object may offer a replacement of itself using -awakeAfterUsingCoder: */
|
||||
@interface Foo : NSObject
|
||||
{
|
||||
id sub_foo;
|
||||
int label;
|
||||
}
|
||||
- (int) label;
|
||||
- (void) setLabel: (int)l;
|
||||
@end
|
||||
|
||||
|
||||
/* Object may offer a replacement of itself using -awakeAfterUsingCoder: */
|
||||
@implementation SubFoo
|
||||
|
||||
- initWithSuperFoo: o label: (int)l
|
||||
{
|
||||
[super init];
|
||||
super_foo = o;
|
||||
label = l;
|
||||
return self;
|
||||
}
|
||||
|
||||
- awakeAfterUsingCoder: coder
|
||||
{
|
||||
if (SubFoo_awakeAfterUsingCoder_substitutes)
|
||||
{
|
||||
SubFoo *replacement = [[[self class] alloc]
|
||||
initWithSuperFoo: super_foo
|
||||
label: label + 100];
|
||||
/* NOTE: We can't use the ivar SUPER_FOO here because it won't have
|
||||
been resolved by the Decoder yet. */
|
||||
[self release];
|
||||
return replacement;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- superFoo
|
||||
{
|
||||
return super_foo;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: coder
|
||||
{
|
||||
printf ("In [SubFoo encodeWithCoder:]\n");
|
||||
#if GNU_ARCHIVING
|
||||
[coder encodeObjectReference: super_foo
|
||||
withName: @"super foo"];
|
||||
#else
|
||||
[coder encodeConditionalObject: super_foo];
|
||||
#endif
|
||||
[coder encodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
}
|
||||
|
||||
- initWithCoder: coder
|
||||
{
|
||||
if (initWithCoder_substitutes)
|
||||
{
|
||||
id o = self;
|
||||
self = [[[self class] alloc] init];
|
||||
[o release];
|
||||
}
|
||||
#if GNU_ARCHIVING
|
||||
[coder decodeObjectAt: &super_foo
|
||||
withName: NULL];
|
||||
#else
|
||||
super_foo = [coder decodeObject];
|
||||
#endif
|
||||
[coder decodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) print
|
||||
{
|
||||
printf ("SubFoo label = %d, super label = %d\n",
|
||||
label, [super_foo label]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation Foo
|
||||
|
||||
- init
|
||||
{
|
||||
[super init];
|
||||
sub_foo = nil;
|
||||
label = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
- awakeAfterUsingCoder: coder
|
||||
{
|
||||
if (Foo_awakeAfterUsingCoder_substitutes)
|
||||
{
|
||||
Foo *replacement = [[[self class] alloc] init];
|
||||
[replacement setLabel: label + 100];
|
||||
/* NOTE: We can't use the ivar SUPER_FOO here because it won't have
|
||||
been resolved by the Decoder yet. */
|
||||
[self release];
|
||||
return replacement;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setSubFoo: o
|
||||
{
|
||||
sub_foo = o;
|
||||
}
|
||||
|
||||
- subFoo
|
||||
{
|
||||
return sub_foo;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: coder
|
||||
{
|
||||
printf ("In [Foo encodeWithCoder:]\n");
|
||||
[coder encodeObject: sub_foo];
|
||||
[coder encodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
}
|
||||
|
||||
- initWithCoder: coder
|
||||
{
|
||||
if (initWithCoder_substitutes)
|
||||
{
|
||||
id o = self;
|
||||
self = [[[self class] alloc] init];
|
||||
[o release];
|
||||
}
|
||||
sub_foo = [coder decodeObject];
|
||||
[coder decodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) label
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
- (void) setLabel: (int)l
|
||||
{
|
||||
label = l;
|
||||
}
|
||||
|
||||
- (void) print
|
||||
{
|
||||
printf (" Foo label = %d, sub label = %d\n",
|
||||
label, [sub_foo label]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/* Test the use of -encodeConditional to encode a forward reference
|
||||
to an object. */
|
||||
void
|
||||
test_fref ()
|
||||
{
|
||||
id array;
|
||||
id foo, sub_foo;
|
||||
printf ("\nTest awakeAfterUsingCoder substitution of objects that will\n"
|
||||
" satisfy backward references\n");
|
||||
initWithCoder_substitutes = 0;
|
||||
|
||||
array = [[NSMutableArray alloc] init];
|
||||
foo = [[Foo alloc] init];
|
||||
[foo setLabel: 4];
|
||||
sub_foo = [[SubFoo alloc] initWithSuperFoo: nil label: 3];
|
||||
[array addObject: foo];
|
||||
[array addObject: sub_foo];
|
||||
|
||||
#if GNU_ARCHIVING
|
||||
[Archiver archiveRootObject: array toFile: @"fref.dat"];
|
||||
#else
|
||||
[NSArchiver archiveRootObject: array toFile: @"fref.dat"];
|
||||
#endif
|
||||
printf ("Encoded: ");
|
||||
[sub_foo print];
|
||||
[foo release];
|
||||
[sub_foo release];
|
||||
[array release];
|
||||
|
||||
array = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"];
|
||||
foo = [array objectAtIndex: 0];
|
||||
sub_foo = [array objectAtIndex: 1];
|
||||
printf ("Decoded: ");
|
||||
[sub_foo print];
|
||||
}
|
||||
|
||||
/* Test awakeAfterUsingCoder of a self-referential forward reference. */
|
||||
void
|
||||
test_self_fref ()
|
||||
{
|
||||
id foo, sub_foo;
|
||||
printf ("\nTest awakeAfterUsingCoder substitution of objects that\n"
|
||||
" will satisfy self-referential forward references\n");
|
||||
initWithCoder_substitutes = SELF_REF_INITWITHCODER_SUBSTITUTES;
|
||||
|
||||
foo = [[Foo alloc] init];
|
||||
[foo setLabel: 4];
|
||||
sub_foo = [[SubFoo alloc] initWithSuperFoo: foo label: 3];
|
||||
[foo setSubFoo: sub_foo];
|
||||
|
||||
#if GNU_ARCHIVING
|
||||
[Archiver archiveRootObject: foo toFile: @"fref.dat"];
|
||||
#else
|
||||
[NSArchiver archiveRootObject: foo toFile: @"fref.dat"];
|
||||
#endif
|
||||
printf ("Encoded: ");
|
||||
[sub_foo print];
|
||||
[foo release];
|
||||
[sub_foo release];
|
||||
|
||||
foo = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"];
|
||||
sub_foo = [foo subFoo];
|
||||
printf ("Decoded: ");
|
||||
[sub_foo print];
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
id arp;
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
GSDebugAllocationActive(YES);
|
||||
|
||||
#if TEXTCSTREAM
|
||||
[Archiver setDefaultCStreamClass: [TextCStream class]];
|
||||
#endif
|
||||
|
||||
[arp release];
|
||||
arp = [NSAutoreleasePool new];
|
||||
printf ("Decoded SubFoo label's should be 100 more than Encoded.\n");
|
||||
test_fref ();
|
||||
[arp release];
|
||||
arp = [NSAutoreleasePool new];
|
||||
test_self_fref ();
|
||||
[arp release];
|
||||
printf("Object allocation info -\n%s\n", GSDebugAllocationList(0));
|
||||
exit (0);
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
/* Demonstration of windows NSTask launching bug */
|
||||
|
||||
#include "Foundation/Foundation.h"
|
||||
|
||||
static void
|
||||
handler(NSException *e)
|
||||
{
|
||||
NSLog(@"Caught %@", e);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
|
||||
NSTask *task;
|
||||
NSProcessInfo *info;
|
||||
NSDictionary *env;
|
||||
NSString *path;
|
||||
|
||||
info = [NSProcessInfo processInfo];
|
||||
env = [info environment];
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
path = @"C:\\WINDOWS\\system32\\net.exe";
|
||||
// path = @"E:\\WINNT\\system32\\net.exe";
|
||||
#else
|
||||
path = @"/bin/ls";
|
||||
#endif
|
||||
printf("Determined command to run as '%s'\n",[path lossyCString]);
|
||||
|
||||
task = [NSTask launchedTaskWithLaunchPath: path
|
||||
arguments: [NSArray array]];
|
||||
[task waitUntilExit];
|
||||
|
||||
printf("First task has completed\n");
|
||||
|
||||
|
||||
#if defined(__MINGW32__)
|
||||
path = @"C:\\WINDOWS\\system32\\mem.exe";
|
||||
// path = @"E:\\WINNT\\system32\\mem.exe";
|
||||
#else
|
||||
path = @"/bin/ls";
|
||||
#endif
|
||||
printf("Determined command to run as '%s'\n",[path lossyCString]);
|
||||
|
||||
task = [NSTask launchedTaskWithLaunchPath: path
|
||||
arguments: [NSArray array]];
|
||||
[task waitUntilExit];
|
||||
|
||||
printf("Second task has completed\n");
|
||||
|
||||
NSSetUncaughtExceptionHandler(handler);
|
||||
[NSException raise: NSGenericException format: @"an exception"];
|
||||
|
||||
IF_NO_GC(DESTROY(arp));
|
||||
return 0;
|
||||
}
|
|
@ -1,767 +0,0 @@
|
|||
/* Simple benchmark program.
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Modified: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Modified: Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This file 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.
|
||||
|
||||
This file 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 file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <objc/Object.h>
|
||||
|
||||
#define MAX_COUNT 100000
|
||||
|
||||
#define START_TIMER sTime = [NSDate date]
|
||||
#define END_TIMER eTime = [NSDate date]
|
||||
#define PRINT_TIMER(str) printf(" %-20s\t %6.3f \t %6.3f\n", str, \
|
||||
[eTime timeIntervalSinceDate: sTime], \
|
||||
[eTime timeIntervalSinceDate: sTime]/baseline)
|
||||
#define PRINT_TIMER_NO_BASELINE(str) \
|
||||
printf(" %-20s\t %6.3f \t %6.3f\n", str, \
|
||||
[eTime timeIntervalSinceDate: sTime] - baseline, \
|
||||
[eTime timeIntervalSinceDate: sTime]/baseline - 1)
|
||||
|
||||
#define AUTO_START id pool = [NSAutoreleasePool new]
|
||||
#define AUTO_END [pool release]
|
||||
|
||||
NSDate *sTime = nil;
|
||||
NSDate *eTime = nil;
|
||||
/* Set to a baseline to null out speed of runtime */
|
||||
NSTimeInterval baseline = 0.0;
|
||||
|
||||
NSZone *myZone;
|
||||
Class rootClass;
|
||||
Class stringClass;
|
||||
IMP cstring;
|
||||
|
||||
@interface MyObject : NSObject
|
||||
@end
|
||||
|
||||
@implementation MyObject
|
||||
@end
|
||||
|
||||
@implementation MyObject (Category)
|
||||
- (id) self
|
||||
{
|
||||
return [super self];
|
||||
}
|
||||
@end
|
||||
|
||||
void
|
||||
bench_object()
|
||||
{
|
||||
int i;
|
||||
id obj;
|
||||
objc_mutex_t mutex;
|
||||
AUTO_START;
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[rootClass class];
|
||||
}
|
||||
END_TIMER;
|
||||
baseline = [eTime timeIntervalSinceDate: sTime];
|
||||
PRINT_TIMER("Baseline: 10 method calls\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
/* Ten class methods with the more common class names */
|
||||
id i;
|
||||
i = [NSObject class];
|
||||
i = [NSString class];
|
||||
i = [NSDictionary class];
|
||||
i = [NSArray class];
|
||||
i = [NSData class];
|
||||
i = [NSUserDefaults class];
|
||||
i = [NSMutableArray class];
|
||||
i = [NSFileManager class];
|
||||
i = [NSMutableString class];
|
||||
i = [NSMutableDictionary class];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("Class: 10 class method calls\t\t");
|
||||
|
||||
obj = [MyObject new];
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT * 10; i++)
|
||||
{
|
||||
id i;
|
||||
i = [obj self];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER_NO_BASELINE("Category: 10 super calls\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
/* Corresponding look ups */
|
||||
id i;
|
||||
i = NSClassFromString (@"NSObject");
|
||||
i = NSClassFromString (@"NSString");
|
||||
i = NSClassFromString (@"NSDictionary");
|
||||
i = NSClassFromString (@"NSArray");
|
||||
i = NSClassFromString (@"NSData");
|
||||
i = NSClassFromString (@"NSUserDefaults");
|
||||
i = NSClassFromString (@"NSMutableArray");
|
||||
i = NSClassFromString (@"NSFileManager");
|
||||
i = NSClassFromString (@"NSMutableString");
|
||||
i = NSClassFromString (@"NSMutableDictionary");
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("Function: 10 NSClassFromStr\t\t");
|
||||
|
||||
START_TIMER;
|
||||
myZone = NSCreateZone(2048, 2048, 1);
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
void *mem = NSZoneMalloc(myZone, 32);
|
||||
NSZoneFree(myZone, mem);
|
||||
}
|
||||
NSRecycleZone(myZone);
|
||||
END_TIMER;
|
||||
PRINT_TIMER("Function: 1 zone alloc/free\t\t");
|
||||
|
||||
START_TIMER;
|
||||
myZone = NSCreateZone(2048, 2048, 0);
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
void *mem = NSZoneMalloc(myZone, 32);
|
||||
NSZoneFree(myZone, mem);
|
||||
}
|
||||
NSRecycleZone(myZone);
|
||||
END_TIMER;
|
||||
PRINT_TIMER("Function: 1 zone2alloc/free\t\t");
|
||||
|
||||
myZone = NSDefaultMallocZone();
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
void *mem = NSZoneMalloc(myZone, 32);
|
||||
NSZoneFree(myZone, mem);
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("Function: 1 def alloc/free\t\t");
|
||||
|
||||
START_TIMER;
|
||||
myZone = NSCreateZone(2048, 2048, 1);
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
obj = [[rootClass allocWithZone: myZone] init];
|
||||
[obj release];
|
||||
}
|
||||
NSRecycleZone(myZone);
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSObject: 1 zone all/init/rel\t\t");
|
||||
|
||||
START_TIMER;
|
||||
myZone = NSCreateZone(2048, 2048, 0);
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
obj = [[rootClass allocWithZone: myZone] init];
|
||||
[obj release];
|
||||
}
|
||||
NSRecycleZone(myZone);
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSObject: 1 zone2all/init/rel\t\t");
|
||||
|
||||
myZone = NSDefaultMallocZone();
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
obj = [[rootClass allocWithZone: myZone] init];
|
||||
[obj release];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSObject: 1 def all/init/rel\t\t");
|
||||
|
||||
obj = [rootClass new];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[obj retain];
|
||||
[obj release];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSObject: 10 retain/rel\t\t");
|
||||
[obj release];
|
||||
|
||||
obj = [rootClass new];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[obj autorelease];
|
||||
[obj retain];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSObject: 10 autorel/ret\t\t");
|
||||
[obj release];
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[rootClass instancesRespondToSelector: @selector(hash)];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("ObjC: 10 inst responds to sel\t\t");
|
||||
|
||||
mutex = objc_mutex_allocate();
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
objc_mutex_lock(mutex);
|
||||
objc_mutex_unlock(mutex);
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("ObjC: 10 objc_mutex_lock/unl\t\t");
|
||||
objc_mutex_deallocate(mutex);
|
||||
|
||||
obj = [NSLock new];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[obj lock];
|
||||
[obj unlock];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSLock: 10 lock/unlock\t\t");
|
||||
[obj release];
|
||||
|
||||
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_array()
|
||||
{
|
||||
int i;
|
||||
id array;
|
||||
NSString *strings[MAX_COUNT];
|
||||
|
||||
AUTO_START;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
char buf1[100];
|
||||
sprintf(buf1, "str%0d", i);
|
||||
strings[i] = [stringClass stringWithUTF8String: buf1];
|
||||
}
|
||||
printf("NSArray\n");
|
||||
array = [NSMutableArray arrayWithCapacity: 16];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[array addObject: strings[i/10]];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSArray (10 addObject:)\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/100; i++)
|
||||
{
|
||||
[array indexOfObject: strings[i]];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSArray (1/100 indexOfObj)\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/100; i++)
|
||||
{
|
||||
[array indexOfObjectIdenticalTo: strings[i]];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSArray (1/100 indexIdent)\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < 1; i++)
|
||||
{
|
||||
[array makeObjectsPerformSelector: @selector(hash)];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSArray (once perform)\t\t");
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_dict()
|
||||
{
|
||||
int i;
|
||||
NSMutableDictionary *dict;
|
||||
id obj2;
|
||||
NSString *keys[MAX_COUNT/10];
|
||||
NSString *vals[MAX_COUNT/10];
|
||||
|
||||
AUTO_START;
|
||||
for (i = 0; i < MAX_COUNT/10; i++)
|
||||
{
|
||||
char buf1[100], buf2[100];
|
||||
sprintf(buf1, "key%0d", i);
|
||||
sprintf(buf2, "val%0d", i);
|
||||
keys[i] = [stringClass stringWithUTF8String: buf1];
|
||||
vals[i] = [stringClass stringWithUTF8String: buf2];
|
||||
}
|
||||
printf("NSDictionary\n");
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 16];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/10; i++)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
[dict setObject: vals[i] forKey: keys[i]];
|
||||
}
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSDict (1 setObject:) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
[dict objectForKey: keys[i/10]];
|
||||
}
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSDict (10 objectFor:) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[dict count];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSDictionary (10 count)\t\t");
|
||||
|
||||
obj2 = [dict copy];
|
||||
START_TIMER;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
[dict isEqual: obj2];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSDict (ten times isEqual:)\t\t");
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_number()
|
||||
{
|
||||
int i;
|
||||
NSMutableDictionary *dict;
|
||||
NSNumber *n[MAX_COUNT*10];
|
||||
|
||||
AUTO_START;
|
||||
|
||||
printf("NSNumber\n");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
n[i] = [NSNumber numberWithInt: i];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSNumber (creation) \t\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
[n[i] hash];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSNumber (hash) \t\t\t");
|
||||
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: MAX_COUNT];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[dict setObject: n[i] forKey: n[i]];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSNumber (dictionary setObject:)\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 1; i < MAX_COUNT; i++)
|
||||
{
|
||||
[n[i] isEqual: n[i-1]];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSNumber (isEqual:)\t\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
[n[i] copyWithZone: NSDefaultMallocZone()];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSNumber (copy)\t\t\t");
|
||||
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_str()
|
||||
{
|
||||
int i;
|
||||
NSString *str;
|
||||
NSMutableString *ms;
|
||||
id plist;
|
||||
NSString *plstr;
|
||||
Class arc = [NSArchiver class];
|
||||
Class una = [NSUnarchiver class];
|
||||
Class ser = [NSSerializer class];
|
||||
Class des = [NSDeserializer class];
|
||||
Class md = [NSMutableDictionary class];
|
||||
AUTO_START;
|
||||
|
||||
[[md new] release];
|
||||
|
||||
plist = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"Value1", @"Key1",
|
||||
@"", @"Key2",
|
||||
[NSArray array], @"Key3",
|
||||
[NSArray arrayWithObjects:
|
||||
@"Array1 entry1",
|
||||
@"Array1 entry2",
|
||||
[NSArray arrayWithObjects:
|
||||
@"Array2 entry1",
|
||||
@"Array2 entry2",
|
||||
nil],
|
||||
[NSDictionary dictionary],
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"Value", @"Key",
|
||||
nil],
|
||||
nil], @"Key4",
|
||||
[NSDictionary dictionary], @"Key5",
|
||||
[NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"Value", @"Key",
|
||||
nil], @"Key6",
|
||||
[NSData data], @"Key7",
|
||||
[NSData dataWithBytes: "hello" length: 5], @"Key8",
|
||||
nil];
|
||||
plstr = [plist description];
|
||||
|
||||
printf("NSString\n");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
str = [[stringClass alloc] initWithFormat: @"Hello %d", i];
|
||||
RELEASE(str);
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1 initWithFormat:) \t\t");
|
||||
|
||||
ms = [NSMutableString stringWithCapacity: 0];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
[ms appendFormat: @"%d", i];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1 appendFormat:) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
str = [stringClass stringWithUTF8String: "hello world"];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1 cstring:) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str length];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 length) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str copy];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 copy) <initWithCString:> ");
|
||||
|
||||
str = @"ConstantString";
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str copy];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 copy) <@'ConstantString'> ");
|
||||
|
||||
str = [[NSString alloc] initWithCStringNoCopy: (char *)[str cString]
|
||||
length: [str length]
|
||||
freeWhenDone: NO];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str copy];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 copy) <NoCopy:free:NO> ");
|
||||
|
||||
str = [[NSString alloc] initWithCStringNoCopy: (char *)[str cString]
|
||||
length: [str length]
|
||||
freeWhenDone: YES];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str copy];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 copy) <NoCopy:free:YES> ");
|
||||
|
||||
str = [stringClass stringWithCString: "hello world"];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str hash];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 hash) <initWithCString:> ");
|
||||
|
||||
str = @"ConstantString";
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
[str hash];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (10 hash) <@'ConstantString'> ");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/100; i++)
|
||||
{
|
||||
id arp = [NSAutoreleasePool new];
|
||||
[plist description];
|
||||
[arp release];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1/100 mkplist) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/1000; i++)
|
||||
{
|
||||
[plstr propertyList];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1/1000 plparse)\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/1000; i++)
|
||||
{
|
||||
id arp = [NSAutoreleasePool new];
|
||||
NSString *s = [plist description];
|
||||
id p = [s propertyList];
|
||||
if ([p isEqual: plist] == NO)
|
||||
printf("Argh 1\n");
|
||||
if ([s isEqual: plstr] == NO)
|
||||
printf("Argh 2\n");
|
||||
[arp release];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1/1000 plcomp)\t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/100; i++)
|
||||
{
|
||||
NSData *d = [ser serializePropertyList: plist];
|
||||
[des deserializePropertyListFromData: d mutableContainers: NO];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1/100 ser/des)\t\t");
|
||||
|
||||
[NSDeserializer uniquing: YES];
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/100; i++)
|
||||
{
|
||||
NSData *d = [ser serializePropertyList: plist];
|
||||
[des deserializePropertyListFromData: d mutableContainers: NO];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1/100 ser/des - uniquing)\t");
|
||||
[NSDeserializer uniquing: NO];
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/100; i++)
|
||||
{
|
||||
NSData *d = [arc archivedDataWithRootObject: plist];
|
||||
[una unarchiveObjectWithData: d];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSString (1/100 arc/una)\t\t");
|
||||
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_date()
|
||||
{
|
||||
int i;
|
||||
id d;
|
||||
AUTO_START;
|
||||
Class dateClass = [NSCalendarDate class];
|
||||
|
||||
printf("NSCalendarDate\n");
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/10; i++)
|
||||
{
|
||||
d = [[dateClass alloc] init];
|
||||
[d description];
|
||||
[d dayOfYear];
|
||||
[d minuteOfHour];
|
||||
[d release];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSCalendarDate (various)\t\t");
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_data()
|
||||
{
|
||||
int i;
|
||||
id d, o;
|
||||
AUTO_START;
|
||||
Class dataClass = [NSData class];
|
||||
|
||||
printf("NSData\n");
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/10; i++)
|
||||
{
|
||||
d = [[dataClass alloc] initWithContentsOfFile:@"benchmark.m"];
|
||||
[d length];
|
||||
o = [d copy];
|
||||
[o release];
|
||||
o = [d mutableCopy];
|
||||
[o release];
|
||||
[d release];
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSData (various)\t\t\t");
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
void
|
||||
bench_maptable()
|
||||
{
|
||||
int i;
|
||||
NSMapTable *table;
|
||||
NSMapTable *table2;
|
||||
NSString *keys[MAX_COUNT/10];
|
||||
NSString *vals[MAX_COUNT/10];
|
||||
|
||||
AUTO_START;
|
||||
for (i = 0; i < MAX_COUNT/10; i++)
|
||||
{
|
||||
char buf1[100], buf2[100];
|
||||
sprintf(buf1, "key%0d", i);
|
||||
sprintf(buf2, "val%0d", i);
|
||||
keys[i] = [stringClass stringWithCString: buf1];
|
||||
vals[i] = [stringClass stringWithCString: buf2];
|
||||
}
|
||||
printf("NSMapTable\n");
|
||||
table = NSCreateMapTable(NSObjectMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 16);
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT/10; i++)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
NSMapInsert(table, keys[i], vals[i]);
|
||||
}
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSMapTable (1 NSMapInsert) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT; i++)
|
||||
{
|
||||
int j;
|
||||
|
||||
for (j = 0; j < 10; j++)
|
||||
{
|
||||
NSMapGet(table, keys[i/10]);
|
||||
}
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSMapTable (10 NSMapGet) \t\t");
|
||||
|
||||
START_TIMER;
|
||||
for (i = 0; i < MAX_COUNT*10; i++)
|
||||
{
|
||||
NSCountMapTable(table);
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSMapTable (10 NSCountMapTable)\t");
|
||||
|
||||
table2 = NSCopyMapTableWithZone(table, NSDefaultMallocZone());
|
||||
START_TIMER;
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
NSCompareMapTables(table, table2);
|
||||
}
|
||||
END_TIMER;
|
||||
PRINT_TIMER("NSMapTable (ten times NSCompareMapTables)");
|
||||
AUTO_END;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[], char **env)
|
||||
{
|
||||
id pool;
|
||||
|
||||
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
|
||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Cache classes to remove overhead of objc runtime class lookup from
|
||||
* the benchmark.
|
||||
*/
|
||||
rootClass = [NSObject class];
|
||||
stringClass = [NSString class];
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
printf(" Test \t\t\t\t time (sec) \t index\n");
|
||||
bench_object();
|
||||
bench_number();
|
||||
bench_str();
|
||||
bench_array();
|
||||
bench_dict();
|
||||
bench_maptable();
|
||||
bench_date();
|
||||
bench_data();
|
||||
AUTO_END;
|
||||
return 0;
|
||||
}
|
||||
|
204
Testing/call.m
204
Testing/call.m
|
@ -1,204 +0,0 @@
|
|||
|
||||
/* call - Program to test NSFileHandle TCP/IP connection.
|
||||
|
||||
Copyright (C) 2002 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Richard Frith-Macdonald <rfm@gnu.org>
|
||||
Date: Jun 2002
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
GS_EXPORT NSString * const GSTelnetNotification;
|
||||
GS_EXPORT NSString * const GSTelnetErrorKey;
|
||||
GS_EXPORT NSString * const GSTelnetTextKey;
|
||||
@class GSTelnetHandle;
|
||||
|
||||
@interface Call : NSObject
|
||||
{
|
||||
NSFileHandle *ichan;
|
||||
NSFileHandle *ochan;
|
||||
id remote;
|
||||
NSMutableData *buf;
|
||||
}
|
||||
- (void) didRead: (NSNotification*)notification;
|
||||
- (void) didWrite: (NSNotification*)notification;
|
||||
- (void) gotTelnet: (NSNotification*)notification;
|
||||
@end
|
||||
|
||||
|
||||
@implementation Call
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(ichan);
|
||||
RELEASE(ochan);
|
||||
RELEASE(remote);
|
||||
RELEASE(buf);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) didRead: (NSNotification*)notification
|
||||
{
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
NSData *d;
|
||||
|
||||
d = [userInfo objectForKey: NSFileHandleNotificationDataItem];
|
||||
if (d == nil || [d length] == 0)
|
||||
{
|
||||
NSLog(@"Read EOF");
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *ptr;
|
||||
unsigned len;
|
||||
int i;
|
||||
|
||||
[buf appendData: d];
|
||||
ptr = [buf mutableBytes];
|
||||
len = [buf length];
|
||||
for (i = 0; i < len; i++)
|
||||
{
|
||||
if (ptr[i] == '\n')
|
||||
{
|
||||
NSString *s;
|
||||
|
||||
if (i > 0 && ptr[i-1] == '\r')
|
||||
{
|
||||
s = [[NSString alloc] initWithBytes: ptr
|
||||
length: i-1
|
||||
encoding: NSUTF8StringEncoding];
|
||||
}
|
||||
else
|
||||
{
|
||||
s = [[NSString alloc] initWithBytes: ptr
|
||||
length: i
|
||||
encoding: NSUTF8StringEncoding];
|
||||
}
|
||||
len -= (i + 1);
|
||||
if (len > 0)
|
||||
{
|
||||
memcpy(ptr, &ptr[i+1], len);
|
||||
}
|
||||
[buf setLength: len];
|
||||
ptr = [buf mutableBytes];
|
||||
i = -1;
|
||||
[remote putTelnetLine: s];
|
||||
[s release];
|
||||
}
|
||||
}
|
||||
[ichan readInBackgroundAndNotify];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) didWrite: (NSNotification*)notification
|
||||
{
|
||||
NSDictionary *userInfo = [notification userInfo];
|
||||
NSString *e;
|
||||
|
||||
e = [userInfo objectForKey: GSFileHandleNotificationError];
|
||||
if (e)
|
||||
{
|
||||
NSLog(@"%@", e);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
- (void) gotTelnet: (NSNotification*)notification
|
||||
{
|
||||
NSDictionary *info = [notification userInfo];
|
||||
NSArray *text;
|
||||
|
||||
text = [info objectForKey: GSTelnetTextKey];
|
||||
if (text == nil)
|
||||
{
|
||||
NSLog(@"Lost telnet - %@", [info objectForKey: GSTelnetErrorKey]);
|
||||
exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < [text count]; i++)
|
||||
{
|
||||
[ochan writeInBackgroundAndNotify:
|
||||
[[text objectAtIndex: i] dataUsingEncoding: NSUTF8StringEncoding]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
NSArray *args = [[NSProcessInfo processInfo] arguments];
|
||||
NSString *host = @"localhost";
|
||||
NSString *service = @"telnet";
|
||||
NSString *protocol = @"tcp";
|
||||
|
||||
if ([args count] > 1)
|
||||
{
|
||||
host = [args objectAtIndex: 1];
|
||||
if ([args count] > 2)
|
||||
{
|
||||
service = [args objectAtIndex: 2];
|
||||
if ([args count] > 3)
|
||||
{
|
||||
protocol = [args objectAtIndex: 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
buf = [NSMutableData new];
|
||||
ichan = RETAIN([NSFileHandle fileHandleWithStandardInput]);
|
||||
ochan = RETAIN([NSFileHandle fileHandleWithStandardOutput]);
|
||||
remote = [[GSTelnetHandle alloc] initWithHandle:
|
||||
[NSFileHandle fileHandleAsClientAtAddress:
|
||||
host service: service protocol: protocol] isConnected: YES];
|
||||
if (remote == nil)
|
||||
{
|
||||
NSLog(@"Failed to create connection");
|
||||
DESTROY(self);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[nc addObserver: self
|
||||
selector: @selector(didRead:)
|
||||
name: NSFileHandleReadCompletionNotification
|
||||
object: ichan];
|
||||
[nc addObserver: self
|
||||
selector: @selector(didWrite:)
|
||||
name: GSFileHandleWriteCompletionNotification
|
||||
object: ochan];
|
||||
[nc addObserver: self
|
||||
selector: @selector(gotTelnet:)
|
||||
name: GSTelnetNotification
|
||||
object: remote];
|
||||
[ichan readInBackgroundAndNotify];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
Call *console;
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
|
||||
console = [Call new];
|
||||
RELEASE(arp);
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
RELEASE(console);
|
||||
return 0;
|
||||
}
|
||||
|
110
Testing/coder.m
110
Testing/coder.m
|
@ -1,110 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* A demonstration of writing and reading GNU Objective C objects to a file. */
|
||||
// Fri Oct 23 03:01:09 MET DST 1998 dave@turbocat.de
|
||||
|
||||
#include <GNUstepBase/Archiver.h>
|
||||
#include <GNUstepBase/BinaryCStream.h>
|
||||
#include <GNUstepBase/Array.h>
|
||||
#include <GNUstepBase/Dictionary.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
id array, dictionary;
|
||||
id archiver;
|
||||
id name;
|
||||
id arp;
|
||||
int i;
|
||||
Class cstream_class;
|
||||
|
||||
if (argc > 1)
|
||||
cstream_class = objc_get_class (argv[1]);
|
||||
else
|
||||
cstream_class = [BinaryCStream class];
|
||||
|
||||
[NSObject enableDoubleReleaseCheck: YES];
|
||||
arp = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* Create an Array and Dictionary */
|
||||
array = [Array new];
|
||||
dictionary = [Dictionary new];
|
||||
|
||||
for (i = 0; i < 6; i++)
|
||||
{
|
||||
[array addObject: [NSNumber numberWithInt: i]];
|
||||
[dictionary putObject: [NSNumber numberWithInt: i]
|
||||
atKey: [NSNumber numberWithInt: i*i]];
|
||||
}
|
||||
[array printForDebugger];
|
||||
[dictionary printForDebugger];
|
||||
|
||||
/* Write them to a file */
|
||||
|
||||
/* Create an instances of the Archiver class, specify that we
|
||||
want human-readable "Text"-style, instead of "Binary"-style
|
||||
coding. */
|
||||
archiver = [[Archiver alloc] initForWritingToFile: @"./coder.dat"
|
||||
withCStreamClass: cstream_class];
|
||||
[archiver encodeObject: array
|
||||
withName: @"Test Array"];
|
||||
[archiver encodeObject: dictionary
|
||||
withName: @"Test Dictionary"];
|
||||
|
||||
/* Release the objects that were coded */
|
||||
[array release];
|
||||
[dictionary release];
|
||||
|
||||
/* Close the archiver, (and thus flush the stream); then release it.
|
||||
We must separate the idea of "closing" a stream and
|
||||
"deallocating" a stream because of delays in deallocation due to
|
||||
-autorelease. */
|
||||
[archiver close];
|
||||
[archiver release];
|
||||
|
||||
|
||||
/* Read them back in from the file */
|
||||
|
||||
/* First create the unarchiver */
|
||||
archiver = [Unarchiver newReadingFromFile: @"./coder.dat"];
|
||||
|
||||
/* Read in the Array */
|
||||
[archiver decodeObjectAt: &array withName: &name];
|
||||
if (name)
|
||||
printf ("got object named %s\n", [name cString]);
|
||||
else
|
||||
printf ("got object named (unnamed)\n");
|
||||
|
||||
/* Read in the Dictionary */
|
||||
[archiver decodeObjectAt: &dictionary withName: &name];
|
||||
if (name)
|
||||
printf ("got object named %s\n", [name cString]);
|
||||
else
|
||||
printf ("got object named (unnamed)\n");
|
||||
|
||||
/* Display what we read, to make sure it matches what we wrote */
|
||||
[array printForDebugger];
|
||||
[dictionary printForDebugger];
|
||||
|
||||
/* Relase the objects we read */
|
||||
[array release];
|
||||
[dictionary release];
|
||||
|
||||
/* Release the unarchiver. */
|
||||
[archiver release];
|
||||
|
||||
/* Do the autorelease. */
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,247 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <objc/Protocol.h>
|
||||
|
||||
@interface Foo: NSObject
|
||||
{
|
||||
}
|
||||
|
||||
+ foo;
|
||||
- (BOOL) conformsToProtocol: (Protocol *) aProtocol;
|
||||
- (BOOL) respondsToSelector: (SEL) aSelector;
|
||||
- copyWithZone: (NSZone *) zone;
|
||||
- mutableCopyWithZone: (NSZone *) zone;
|
||||
@end
|
||||
|
||||
|
||||
@implementation Foo
|
||||
|
||||
+ foo
|
||||
{
|
||||
return [[[Foo alloc] init] autorelease];
|
||||
}
|
||||
|
||||
- (BOOL) conformsToProtocol: (Protocol *) aProtocol
|
||||
{
|
||||
BOOL ret = [super conformsToProtocol: aProtocol];
|
||||
|
||||
NSLog(@"-[<%@:0x%x> %@<%s>] -> %@",
|
||||
NSStringFromClass([self class]), self, NSStringFromSelector(_cmd),
|
||||
[aProtocol name], ret ? @"YES" : @"NO");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) respondsToSelector: (SEL) aSelector
|
||||
{
|
||||
BOOL ret = [super respondsToSelector: aSelector];
|
||||
|
||||
if (![NSStringFromSelector(aSelector) hasPrefix:@"description"])
|
||||
NSLog(@"-[<%@:0x%x> %@%@] -> %@",
|
||||
NSStringFromClass([self class]), self, NSStringFromSelector(_cmd),
|
||||
NSStringFromSelector(aSelector), ret ? @"YES" : @"NO");
|
||||
return ret;
|
||||
}
|
||||
|
||||
- copyWithZone: (NSZone *) zone
|
||||
{
|
||||
id ret = [Foo foo];
|
||||
|
||||
NSLog(@"-[<%@:0x%x> %@0x%x] -> <%@:0x%x>",
|
||||
NSStringFromClass([self class]), self,
|
||||
NSStringFromSelector(_cmd), zone, NSStringFromClass([ret class]), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- mutableCopyWithZone: (NSZone *) zone
|
||||
{
|
||||
id ret = [Foo foo];
|
||||
|
||||
NSLog(@"-[<%@:0x%x> %@0x%x] -> <%@:0x%x>",
|
||||
NSStringFromClass([self class]), self,
|
||||
NSStringFromSelector(_cmd), zone, NSStringFromClass([ret class]), ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
- retain
|
||||
{
|
||||
id ret = [super retain];
|
||||
|
||||
NSLog(@"-[<%@:0x%x> %@] -> retainCount = %d",
|
||||
NSStringFromClass([self class]), self,
|
||||
NSStringFromSelector(_cmd), [ret retainCount]);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void
|
||||
isDeepArrayCopy(NSArray *obj1, NSArray *obj2)
|
||||
{
|
||||
id obj1FirstObject = [obj1 objectAtIndex:0];
|
||||
id obj2FirstObject = [obj2 objectAtIndex:0];
|
||||
|
||||
NSLog(@"<%@:0x%x> -> <%@:0x%x>, %@",
|
||||
NSStringFromClass([obj1 class]), obj1,
|
||||
NSStringFromClass([obj2 class]), obj2,
|
||||
(obj1FirstObject == obj2FirstObject) ? ((obj1 == obj2) ? @"retained" : @"shallow") : @"deep(ish)");
|
||||
}
|
||||
|
||||
void
|
||||
isDeepDictionaryCopy(NSDictionary *obj1, NSDictionary *obj2)
|
||||
{
|
||||
id obj1FirstObject = [obj1 objectForKey: @"Key"];
|
||||
id obj2FirstObject = [obj2 objectForKey: @"Key"];
|
||||
|
||||
NSLog(@"<%@:0x%x> -> <%@:0x%x>, %@",
|
||||
NSStringFromClass([obj1 class]), obj1,
|
||||
NSStringFromClass([obj2 class]), obj2,
|
||||
(obj1FirstObject == obj2FirstObject) ? ((obj1 == obj2) ? @"retained" : @"shallow") : @"deep(ish)");
|
||||
}
|
||||
|
||||
void
|
||||
isDeepSetCopy(NSSet *obj1, NSSet *obj2)
|
||||
{
|
||||
id obj1FirstObject = [obj1 anyObject];
|
||||
id obj2FirstObject = [obj2 anyObject];
|
||||
|
||||
NSLog(@"<%@:0x%x> -> <%@:0x%x>, %@",
|
||||
NSStringFromClass([obj1 class]), obj1,
|
||||
NSStringFromClass([obj2 class]), obj2,
|
||||
(obj1FirstObject == obj2FirstObject) ? ((obj1 == obj2) ? @"retained" : @"shallow") : @"deep(ish)");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NSAutoreleasePool *thePool = [[NSAutoreleasePool alloc] init];
|
||||
NSArray *anArrayCopy;
|
||||
NSArray *aMutableArrayCopy;
|
||||
NSArray *anArrayMutableCopy;
|
||||
NSArray *aMutableArrayMutableCopy;
|
||||
NSMutableArray *aMutableArray
|
||||
= [NSMutableArray arrayWithObject: [Foo foo]];
|
||||
NSArray *anArray = [NSArray arrayWithObject: [Foo foo]];
|
||||
NSDictionary *aDictionaryCopy;
|
||||
NSDictionary *aMutableDictionaryCopy;
|
||||
NSDictionary *aDictionaryMutableCopy;
|
||||
NSDictionary *aMutableDictionaryMutableCopy;
|
||||
NSMutableDictionary *aMutableDictionary
|
||||
= [NSMutableDictionary dictionaryWithObjectsAndKeys: [Foo foo], @"Key", nil];
|
||||
NSDictionary *aDictionary
|
||||
= [NSDictionary dictionaryWithObjectsAndKeys: [Foo foo], @"Key", nil];
|
||||
NSSet *aSetCopy;
|
||||
NSSet *aMutableSetCopy;
|
||||
NSSet *aSetMutableCopy;
|
||||
NSSet *aMutableSetMutableCopy;
|
||||
NSMutableSet *aMutableSet = [NSMutableSet setWithObject: [Foo foo]];
|
||||
NSSet *aSet = [NSSet setWithObject: [Foo foo]];
|
||||
NSZone *zone = NSDefaultMallocZone();
|
||||
|
||||
while (zone != 0)
|
||||
{
|
||||
NSLog(@"Copying from zone 0x%x -> 0x%x", NSDefaultMallocZone(), zone);
|
||||
|
||||
NSLog(@"MutableArray -copy");
|
||||
aMutableArrayCopy = [aMutableArray copyWithZone:zone];
|
||||
NSLog(@"MutableArray -mutableCopy");
|
||||
aMutableArrayMutableCopy = [aMutableArray mutableCopyWithZone:zone];
|
||||
NSLog(@"Array -copy");
|
||||
anArrayCopy = [anArray copyWithZone:zone];
|
||||
NSLog(@"Array -mutableCopy");
|
||||
anArrayMutableCopy = [anArray mutableCopyWithZone:zone];
|
||||
|
||||
NSLog(@"MutableArray: %@", aMutableArray);
|
||||
NSLog(@"MutableArrayCopy: %@", aMutableArrayCopy);
|
||||
NSLog(@"MutableArrayMutableCopy: %@", aMutableArrayMutableCopy);
|
||||
NSLog(@"anArray: %@", anArray);
|
||||
NSLog(@"anArrayCopy: %@", anArrayCopy);
|
||||
NSLog(@"anArrayCopy: %@", anArrayMutableCopy);
|
||||
|
||||
NSLog(@"Test MutableArray against Copy");
|
||||
isDeepArrayCopy(aMutableArray, aMutableArrayCopy);
|
||||
|
||||
NSLog(@"Test MutableArray against MutableCopy");
|
||||
isDeepArrayCopy(aMutableArray, aMutableArrayMutableCopy);
|
||||
|
||||
NSLog(@"Test Array against Copy");
|
||||
isDeepArrayCopy(anArray, anArrayCopy);
|
||||
|
||||
NSLog(@"Test Array against MutableCopy");
|
||||
isDeepArrayCopy(anArray, anArrayMutableCopy);
|
||||
|
||||
NSLog(@"MutableDictionary -copy");
|
||||
aMutableDictionaryCopy = [aMutableDictionary copyWithZone:zone];
|
||||
NSLog(@"MutableDictionary -mutableCopy");
|
||||
aMutableDictionaryMutableCopy = [aMutableDictionary mutableCopyWithZone:zone];
|
||||
NSLog(@"Dictionary -copy");
|
||||
aDictionaryCopy = [aDictionary copyWithZone:zone];
|
||||
NSLog(@"Dictionary -mutableCopy");
|
||||
aDictionaryMutableCopy = [aDictionary mutableCopyWithZone:zone];
|
||||
|
||||
NSLog(@"MutableDictionary: %@", aMutableDictionary);
|
||||
NSLog(@"MutableDictionaryCopy: %@", aMutableDictionaryCopy);
|
||||
NSLog(@"MutableDictionaryMutableCopy: %@", aMutableDictionaryMutableCopy);
|
||||
NSLog(@"aDictionary: %@", aDictionary);
|
||||
NSLog(@"aDictionaryCopy: %@", aDictionaryCopy);
|
||||
NSLog(@"aDictionaryCopy: %@", aDictionaryMutableCopy);
|
||||
|
||||
NSLog(@"Test MutableDictionary against Copy");
|
||||
isDeepDictionaryCopy(aMutableDictionary, aMutableDictionaryCopy);
|
||||
|
||||
NSLog(@"Test MutableDictionary against MutableCopy");
|
||||
isDeepDictionaryCopy(aMutableDictionary, aMutableDictionaryMutableCopy);
|
||||
|
||||
NSLog(@"Test Dictionary against Copy");
|
||||
isDeepDictionaryCopy(aDictionary, aDictionaryCopy);
|
||||
|
||||
NSLog(@"Test Dictionary against MutableCopy");
|
||||
isDeepDictionaryCopy(aDictionary, aDictionaryMutableCopy);
|
||||
|
||||
NSLog(@"MutableSet -copy");
|
||||
aMutableSetCopy = [aMutableSet copyWithZone:zone];
|
||||
NSLog(@"MutableSet -mutableCopy");
|
||||
aMutableSetMutableCopy = [aMutableSet mutableCopyWithZone:zone];
|
||||
NSLog(@"Set -copy");
|
||||
aSetCopy = [aSet copyWithZone:zone];
|
||||
NSLog(@"Set -mutableCopy");
|
||||
aSetMutableCopy = [aSet mutableCopyWithZone:zone];
|
||||
|
||||
NSLog(@"MutableSet: %@", aMutableSet);
|
||||
NSLog(@"MutableSetCopy: %@", aMutableSetCopy);
|
||||
NSLog(@"MutableSetMutableCopy: %@", aMutableSetMutableCopy);
|
||||
NSLog(@"aSet: %@", aSet);
|
||||
NSLog(@"aSetCopy: %@", aSetCopy);
|
||||
NSLog(@"aSetCopy: %@", aSetMutableCopy);
|
||||
|
||||
NSLog(@"Test MutableSet against Copy");
|
||||
isDeepSetCopy(aMutableSet, aMutableSetCopy);
|
||||
|
||||
NSLog(@"Test MutableSet against MutableCopy");
|
||||
isDeepSetCopy(aMutableSet, aMutableSetMutableCopy);
|
||||
|
||||
NSLog(@"Test Set against Copy");
|
||||
isDeepSetCopy(aSet, aSetCopy);
|
||||
|
||||
NSLog(@"Test Set against MutableCopy");
|
||||
isDeepSetCopy(aSet, aSetMutableCopy);
|
||||
|
||||
if (zone == NSDefaultMallocZone())
|
||||
zone = NSCreateZone(NSPageSize(), NSPageSize(), YES);
|
||||
else
|
||||
zone = 0;
|
||||
}
|
||||
[thePool release];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,170 +0,0 @@
|
|||
/** externs.m Program to test correct initialization of externs.
|
||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Ayers <d.ayers@inode.at>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This file 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.
|
||||
|
||||
This file 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 file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define MyAssert1(IDENT) do { \
|
||||
cache[i++] = IDENT; \
|
||||
assert (IDENT != 0); \
|
||||
} while (0)
|
||||
|
||||
#define MyAssert2(IDENT) do { \
|
||||
NSCAssert2([IDENT isEqual: \
|
||||
[NSString stringWithUTF8String: #IDENT]], \
|
||||
@"Invalid value: %@ for: %s", \
|
||||
IDENT, #IDENT); \
|
||||
NSCAssert2([cache[i++] isEqual: IDENT], \
|
||||
@"Initial values differ:%@ %@", \
|
||||
cache[i-1], IDENT); \
|
||||
} while (0)
|
||||
|
||||
#define CACHE_SIZE 256
|
||||
NSString *cache[CACHE_SIZE];
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
int i = 0;
|
||||
|
||||
/* Insure extern identifiers are initialized
|
||||
before ObjC code is executed. */
|
||||
MyAssert1(NSConnectionDidDieNotification);
|
||||
MyAssert1(NSConnectionDidInitializeNotification);
|
||||
MyAssert1(NSWillBecomeMultiThreadedNotification);
|
||||
MyAssert1(NSThreadDidStartNotification);
|
||||
MyAssert1(NSThreadWillExitNotification);
|
||||
MyAssert1(NSPortDidBecomeInvalidNotification);
|
||||
MyAssert1(NSConnectionReplyMode);
|
||||
MyAssert1(NSBundleDidLoadNotification);
|
||||
MyAssert1(NSShowNonLocalizedStrings);
|
||||
MyAssert1(NSLoadedClasses);
|
||||
// MyAssert1(StreamException);
|
||||
MyAssert1(NSArgumentDomain);
|
||||
MyAssert1(NSGlobalDomain);
|
||||
MyAssert1(NSRegistrationDomain);
|
||||
MyAssert1(NSUserDefaultsDidChangeNotification);
|
||||
MyAssert1(NSWeekDayNameArray);
|
||||
MyAssert1(NSShortWeekDayNameArray);
|
||||
MyAssert1(NSMonthNameArray);
|
||||
MyAssert1(NSShortMonthNameArray);
|
||||
MyAssert1(NSTimeFormatString);
|
||||
MyAssert1(NSDateFormatString);
|
||||
MyAssert1(NSShortDateFormatString);
|
||||
MyAssert1(NSTimeDateFormatString);
|
||||
MyAssert1(NSShortTimeDateFormatString);
|
||||
MyAssert1(NSCurrencySymbol);
|
||||
MyAssert1(NSDecimalSeparator);
|
||||
MyAssert1(NSThousandsSeparator);
|
||||
MyAssert1(NSInternationalCurrencyString);
|
||||
MyAssert1(NSCurrencyString);
|
||||
// MyAssert1(NSNegativeCurrencyFormatString);
|
||||
// MyAssert1(NSPositiveCurrencyFormatString);
|
||||
MyAssert1(NSDecimalDigits);
|
||||
MyAssert1(NSAMPMDesignation);
|
||||
MyAssert1(NSHourNameDesignations);
|
||||
MyAssert1(NSYearMonthWeekDesignations);
|
||||
MyAssert1(NSEarlierTimeDesignations);
|
||||
MyAssert1(NSLaterTimeDesignations);
|
||||
MyAssert1(NSThisDayDesignations);
|
||||
MyAssert1(NSNextDayDesignations);
|
||||
MyAssert1(NSNextNextDayDesignations);
|
||||
MyAssert1(NSPriorDayDesignations);
|
||||
MyAssert1(NSDateTimeOrdering);
|
||||
MyAssert1(NSLanguageCode);
|
||||
MyAssert1(NSLanguageName);
|
||||
MyAssert1(NSFormalName);
|
||||
// MyAssert1(NSLocale);
|
||||
MyAssert1(NSConnectionRepliesReceived);
|
||||
MyAssert1(NSConnectionRepliesSent);
|
||||
MyAssert1(NSConnectionRequestsReceived);
|
||||
MyAssert1(NSConnectionRequestsSent);
|
||||
MyAssert1(NSConnectionLocalCount);
|
||||
MyAssert1(NSConnectionProxyCount);
|
||||
MyAssert1(NSClassDescriptionNeededForClassNotification);
|
||||
|
||||
assert(i < CACHE_SIZE); /* incread the cache size. */
|
||||
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
i = 0;
|
||||
MyAssert2(NSConnectionDidDieNotification);
|
||||
MyAssert2(NSConnectionDidInitializeNotification);
|
||||
MyAssert2(NSWillBecomeMultiThreadedNotification);
|
||||
MyAssert2(NSThreadDidStartNotification);
|
||||
MyAssert2(NSThreadWillExitNotification);
|
||||
MyAssert2(NSPortDidBecomeInvalidNotification);
|
||||
MyAssert2(NSConnectionReplyMode);
|
||||
MyAssert2(NSBundleDidLoadNotification);
|
||||
MyAssert2(NSShowNonLocalizedStrings);
|
||||
MyAssert2(NSLoadedClasses);
|
||||
MyAssert2(NSArgumentDomain);
|
||||
MyAssert2(NSGlobalDomain);
|
||||
MyAssert2(NSRegistrationDomain);
|
||||
MyAssert2(NSUserDefaultsDidChangeNotification);
|
||||
MyAssert2(NSWeekDayNameArray);
|
||||
MyAssert2(NSShortWeekDayNameArray);
|
||||
MyAssert2(NSMonthNameArray);
|
||||
MyAssert2(NSShortMonthNameArray);
|
||||
MyAssert2(NSTimeFormatString);
|
||||
MyAssert2(NSDateFormatString);
|
||||
MyAssert2(NSShortDateFormatString);
|
||||
MyAssert2(NSTimeDateFormatString);
|
||||
MyAssert2(NSShortTimeDateFormatString);
|
||||
MyAssert2(NSCurrencySymbol);
|
||||
MyAssert2(NSDecimalSeparator);
|
||||
MyAssert2(NSThousandsSeparator);
|
||||
MyAssert2(NSInternationalCurrencyString);
|
||||
MyAssert2(NSCurrencyString);
|
||||
// MyAssert2(NSNegativeCurrencyFormatString);
|
||||
// MyAssert2(NSPositiveCurrencyFormatString);
|
||||
MyAssert2(NSDecimalDigits);
|
||||
MyAssert2(NSAMPMDesignation);
|
||||
MyAssert2(NSHourNameDesignations);
|
||||
MyAssert2(NSYearMonthWeekDesignations);
|
||||
MyAssert2(NSEarlierTimeDesignations);
|
||||
MyAssert2(NSLaterTimeDesignations);
|
||||
MyAssert2(NSThisDayDesignations);
|
||||
MyAssert2(NSNextDayDesignations);
|
||||
MyAssert2(NSNextNextDayDesignations);
|
||||
MyAssert2(NSPriorDayDesignations);
|
||||
MyAssert2(NSDateTimeOrdering);
|
||||
MyAssert2(NSLanguageCode);
|
||||
MyAssert2(NSLanguageName);
|
||||
MyAssert2(NSFormalName);
|
||||
// MyAssert2(NSLocale);
|
||||
MyAssert2(NSConnectionRepliesReceived);
|
||||
MyAssert2(NSConnectionRepliesSent);
|
||||
MyAssert2(NSConnectionRequestsReceived);
|
||||
MyAssert2(NSConnectionRequestsSent);
|
||||
MyAssert2(NSConnectionLocalCount);
|
||||
MyAssert2(NSConnectionProxyCount);
|
||||
MyAssert2(NSClassDescriptionNeededForClassNotification);
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
201
Testing/fref.m
201
Testing/fref.m
|
@ -1,201 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* Test NSArchiver on encoding of self-referential forward references. */
|
||||
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
/* This object encodes an -encodeConditionalObject: reference to a Foo. */
|
||||
@interface SubFoo : NSObject
|
||||
{
|
||||
id super_foo;
|
||||
int label;
|
||||
}
|
||||
@end
|
||||
|
||||
/* This object encodes an -encodeObject: reference to a SubFoo. */
|
||||
@interface Foo : NSObject
|
||||
{
|
||||
id sub_foo;
|
||||
int label;
|
||||
}
|
||||
- (int) label;
|
||||
@end
|
||||
|
||||
@implementation SubFoo
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(super_foo);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) initWithSuperFoo: (id)o label: (int)l
|
||||
{
|
||||
self = [super init];
|
||||
super_foo = RETAIN(o);
|
||||
label = l;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) superFoo
|
||||
{
|
||||
return super_foo;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)coder
|
||||
{
|
||||
printf ("In [SubFoo encodeWithCoder:]\n");
|
||||
[coder encodeConditionalObject: super_foo];
|
||||
[coder encodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)coder
|
||||
{
|
||||
[coder decodeValueOfObjCType: @encode(id)
|
||||
at: &super_foo];
|
||||
[coder decodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) print
|
||||
{
|
||||
printf ("label = %d, super label = %d\n",
|
||||
label, [super_foo label]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation Foo
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
RELEASE(sub_foo);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
sub_foo = nil;
|
||||
label = 0;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setSubFoo: o
|
||||
{
|
||||
ASSIGN(sub_foo, o);
|
||||
}
|
||||
|
||||
- (id) subFoo
|
||||
{
|
||||
return sub_foo;
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)coder
|
||||
{
|
||||
printf ("In [Foo encodeWithCoder:]\n");
|
||||
[coder encodeObject: sub_foo];
|
||||
[coder encodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)coder
|
||||
{
|
||||
[coder decodeValueOfObjCType: @encode(id)
|
||||
at: &sub_foo];
|
||||
[coder decodeValueOfObjCType: @encode(int)
|
||||
at: &label];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (int) label
|
||||
{
|
||||
return label;
|
||||
}
|
||||
|
||||
- (void) setLabel: (int)l
|
||||
{
|
||||
label = l;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/* Test the use of -encodeConditional to encode a forward reference
|
||||
to an object. */
|
||||
void
|
||||
test_fref ()
|
||||
{
|
||||
id array;
|
||||
id foo, sub_foo;
|
||||
printf ("\nTest encoding of forward references\n");
|
||||
|
||||
array = [[NSMutableArray alloc] init];
|
||||
foo = [[Foo alloc] init];
|
||||
[foo setLabel: 4];
|
||||
sub_foo = [[SubFoo alloc] initWithSuperFoo: foo label: 3];
|
||||
[foo setSubFoo: sub_foo];
|
||||
[array addObject: foo];
|
||||
[array insertObject: sub_foo atIndex: 0];
|
||||
|
||||
[NSArchiver archiveRootObject: array toFile: @"fref.dat"];
|
||||
printf ("Encoded: ");
|
||||
[sub_foo print];
|
||||
RELEASE(foo);
|
||||
RELEASE(sub_foo);
|
||||
RELEASE(array);
|
||||
|
||||
array = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"];
|
||||
foo = [array objectAtIndex: 1];
|
||||
sub_foo = [foo subFoo];
|
||||
printf ("Decoded: ");
|
||||
[sub_foo print];
|
||||
}
|
||||
|
||||
/* Test the encode of a self-referential forward reference. */
|
||||
void
|
||||
test_self_fref ()
|
||||
{
|
||||
id foo, sub_foo;
|
||||
printf ("\nTest encoding of self-referential forward references\n");
|
||||
|
||||
foo = [[Foo alloc] init];
|
||||
[foo setLabel: 4];
|
||||
sub_foo = [[SubFoo alloc] initWithSuperFoo: foo label: 3];
|
||||
[foo setSubFoo: sub_foo];
|
||||
|
||||
[NSArchiver archiveRootObject: foo toFile: @"fref.dat"];
|
||||
printf ("Encoded: ");
|
||||
[sub_foo print];
|
||||
RELEASE(foo);
|
||||
RELEASE(sub_foo);
|
||||
|
||||
foo = [NSUnarchiver unarchiveObjectWithFile: @"fref.dat"];
|
||||
sub_foo = [foo subFoo];
|
||||
printf ("Decoded: ");
|
||||
[sub_foo print];
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
|
||||
test_fref ();
|
||||
test_self_fref ();
|
||||
|
||||
RELEASE(arp);
|
||||
|
||||
exit (0);
|
||||
}
|
|
@ -1,378 +0,0 @@
|
|||
/** gsbehavior - Program to test GSObjCAddClassBehavior.
|
||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Ayers <d.ayers@inode.at>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This file 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.
|
||||
|
||||
This file 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 file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
#include <GNUstepBase/GSObjCRuntime.h>
|
||||
|
||||
/*------------------------------------*/
|
||||
@interface MyClass : NSObject
|
||||
-(const char *)text;
|
||||
-(const char *)textBase;
|
||||
@end
|
||||
@implementation MyClass
|
||||
-(void)myClassMain {};
|
||||
-(const char *)text
|
||||
{
|
||||
return "class_main";
|
||||
}
|
||||
-(const char *)textBase
|
||||
{
|
||||
return "class_main_base";
|
||||
}
|
||||
@end
|
||||
|
||||
@interface MyClass (Category1)
|
||||
-(void)myClassCategory1;
|
||||
@end
|
||||
@implementation MyClass (Category1)
|
||||
-(void)myClassCategory1 {};
|
||||
-(const char *)text
|
||||
{
|
||||
return "class_category_1";
|
||||
}
|
||||
@end
|
||||
|
||||
@interface MyClass (Category2)
|
||||
-(void)myClassCategory2;
|
||||
@end
|
||||
@implementation MyClass (Category2)
|
||||
-(void)myClassCategory2 {};
|
||||
-(const char *)text
|
||||
{
|
||||
return "class_category_2";
|
||||
}
|
||||
@end
|
||||
|
||||
/*------------------------------------*/
|
||||
|
||||
@interface MyTemplate1 : NSObject
|
||||
@end
|
||||
@implementation MyTemplate1
|
||||
@end
|
||||
|
||||
/*------------------------------------*/
|
||||
/*------------------------------------*/
|
||||
|
||||
@interface MyTemplate2 : NSObject
|
||||
-(const char *)text;
|
||||
@end
|
||||
@implementation MyTemplate2
|
||||
-(const char *)text
|
||||
{
|
||||
return "template_main";
|
||||
}
|
||||
@end
|
||||
|
||||
/*------------------------------------*/
|
||||
|
||||
@interface MyBehavior : NSObject
|
||||
-(const char *)text;
|
||||
-(const char *)textBase;
|
||||
@end
|
||||
@implementation MyBehavior
|
||||
-(void)myBehaviorMain {};
|
||||
-(const char *)text
|
||||
{
|
||||
return "behavior_main";
|
||||
}
|
||||
-(const char *)textBase
|
||||
{
|
||||
return "behavior_main_base";
|
||||
}
|
||||
@end
|
||||
@interface MyBehavior (Category1)
|
||||
-(void)myBehaviorCategory1;
|
||||
@end
|
||||
@implementation MyBehavior (Category1)
|
||||
-(void)myBehaviorCategory1 {};
|
||||
-(const char *)text
|
||||
{
|
||||
return "behavior_category_1";
|
||||
}
|
||||
@end
|
||||
|
||||
@interface MyBehavior (Category2)
|
||||
-(void)myBehaviorCategory2;
|
||||
@end
|
||||
@implementation MyBehavior (Category2)
|
||||
-(void)myBehaviorCategory2 {};
|
||||
-(const char *)text
|
||||
{
|
||||
return "behavior_category_2";
|
||||
}
|
||||
@end
|
||||
|
||||
/*------------------------------------*/
|
||||
|
||||
void
|
||||
test_basic(void)
|
||||
{
|
||||
id myClass;
|
||||
id myBehavior;
|
||||
|
||||
myClass = [MyClass new];
|
||||
myBehavior = [MyBehavior new];
|
||||
|
||||
NSCAssert(strncmp([myClass text], "class_category", 14) == 0,
|
||||
@"Default implementation isn't Category!");
|
||||
NSCAssert(strncmp([myBehavior text], "behavior_category", 17) == 0,
|
||||
@"Default implementation isn't Category!");
|
||||
|
||||
RELEASE(myClass);
|
||||
RELEASE(myBehavior);
|
||||
}
|
||||
|
||||
void
|
||||
test_create_list(void)
|
||||
{
|
||||
GSMethodList myList;
|
||||
GSMethod myMethod;
|
||||
Class myClass;
|
||||
void *it;
|
||||
IMP imp_main;
|
||||
IMP imp_1;
|
||||
IMP imp_2;
|
||||
const char *types;
|
||||
id myObj;
|
||||
|
||||
it = 0;
|
||||
myClass = [MyClass class];
|
||||
myObj = [myClass new];
|
||||
myList = GSMethodListForSelector(myClass, @selector(text), &it, YES);
|
||||
NSCAssert(myList,@"List is NULL!");
|
||||
myMethod = GSMethodFromList(myList, @selector(text), NO);
|
||||
NSCAssert(myMethod,@"Method is NULL!");
|
||||
imp_1 = myMethod->method_imp;
|
||||
|
||||
myList = GSMethodListForSelector(myClass, @selector(text), &it, YES);
|
||||
NSCAssert(myList,@"List is NULL!");
|
||||
myMethod = GSMethodFromList(myList, @selector(text), NO);
|
||||
NSCAssert(myMethod,@"Method is NULL!");
|
||||
imp_2 = myMethod->method_imp;
|
||||
|
||||
myList = GSMethodListForSelector(myClass, @selector(text), &it, YES);
|
||||
NSCAssert(myList,@"List is NULL!");
|
||||
myMethod = GSMethodFromList(myList, @selector(text), NO);
|
||||
NSCAssert(myMethod,@"Method is NULL!");
|
||||
imp_main = myMethod->method_imp;
|
||||
|
||||
types = myMethod->method_types;
|
||||
|
||||
myList = GSAllocMethodList(3);
|
||||
GSAppendMethodToList(myList, @selector(text_main), types, imp_main, YES);
|
||||
GSAppendMethodToList(myList, @selector(text_1), types, imp_1, YES);
|
||||
GSAppendMethodToList(myList, @selector(text_2), types, imp_2, YES);
|
||||
|
||||
GSAddMethodList(myClass, myList, YES);
|
||||
GSFlushMethodCacheForClass(myClass);
|
||||
NSCAssert([myObj respondsToSelector:@selector(text_main)] == YES,
|
||||
@"Add failed.");
|
||||
NSCAssert([myObj respondsToSelector:@selector(text_1)] == YES,
|
||||
@"Add failed.");
|
||||
NSCAssert([myObj respondsToSelector:@selector(text_2)] == YES,
|
||||
@"Add failed.");
|
||||
NSCAssert(strcmp([myObj text_main], "class_main") == 0,
|
||||
@"Add failed to add correct implementation!");
|
||||
NSCAssert(strncmp([myObj text_1], "class_category", 14) == 0,
|
||||
@"Add failed to add correct implementation!");
|
||||
NSCAssert(strncmp([myObj text_2], "class_category", 14) == 0,
|
||||
@"Add failed to add correct implementation!");
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
test_reorder_list(void)
|
||||
{
|
||||
Class myClass;
|
||||
id myObj;
|
||||
GSMethodList list;
|
||||
|
||||
myClass = [MyClass class];
|
||||
myObj = [MyClass new];
|
||||
|
||||
list = GSMethodListForSelector(myClass, @selector(myClassMain), 0, YES);
|
||||
|
||||
/* Remove */
|
||||
GSRemoveMethodList(myClass, list, YES);
|
||||
GSFlushMethodCacheForClass(myClass);
|
||||
NSCAssert([myObj respondsToSelector:@selector(myClassMain)] == NO,
|
||||
@"Remove failed.");
|
||||
|
||||
/* Add */
|
||||
GSAddMethodList(myClass, list, YES);
|
||||
GSFlushMethodCacheForClass(myClass);
|
||||
|
||||
NSCAssert([myObj respondsToSelector:@selector(myClassMain)] == YES,
|
||||
@"Add failed.");
|
||||
NSCAssert(strcmp([myObj text], "class_main") == 0,
|
||||
@"Add failed to add correct implementation!");
|
||||
|
||||
RELEASE(myClass);
|
||||
}
|
||||
|
||||
void
|
||||
test_exchange_method(void)
|
||||
{
|
||||
Class myClass;
|
||||
Class myBehavior;
|
||||
id myClsObj;
|
||||
id myBhvObj;
|
||||
GSMethodList myListC;
|
||||
GSMethodList myListB;
|
||||
GSMethod myMethodC;
|
||||
GSMethod myMethodB;
|
||||
struct objc_method myMethodStructC;
|
||||
struct objc_method myMethodStructB;
|
||||
|
||||
myClass = [MyClass class];
|
||||
myBehavior = [MyBehavior class];
|
||||
|
||||
myClsObj = [myClass new];
|
||||
myBhvObj = [myBehavior new];
|
||||
|
||||
NSCAssert(strcmp([myClsObj textBase], "class_main_base") == 0,
|
||||
@"Wrong precondition!");
|
||||
NSCAssert(strcmp([myBhvObj textBase], "behavior_main_base") == 0,
|
||||
@"Wrong precondition!");
|
||||
|
||||
myListC = GSMethodListForSelector(myClass, @selector(textBase), 0, YES);
|
||||
myListB = GSMethodListForSelector(myBehavior, @selector(textBase), 0, YES);
|
||||
|
||||
myMethodC = GSMethodFromList(myListC, @selector(textBase), NO);
|
||||
myMethodStructC = *myMethodC;
|
||||
myMethodC = &myMethodStructC;
|
||||
myMethodB = GSMethodFromList(myListB, @selector(textBase), NO);
|
||||
myMethodStructB = *myMethodB;
|
||||
myMethodB = &myMethodStructB;
|
||||
|
||||
GSRemoveMethodFromList(myListC, @selector(textBase), NO);
|
||||
GSRemoveMethodFromList(myListB, @selector(textBase), NO);
|
||||
|
||||
GSAppendMethodToList(myListC,
|
||||
myMethodB->method_name,
|
||||
myMethodB->method_types,
|
||||
myMethodB->method_imp,
|
||||
NO);
|
||||
GSAppendMethodToList(myListB,
|
||||
myMethodC->method_name,
|
||||
myMethodC->method_types,
|
||||
myMethodC->method_imp,
|
||||
NO);
|
||||
|
||||
GSFlushMethodCacheForClass(myClass);
|
||||
GSFlushMethodCacheForClass(myBehavior);
|
||||
|
||||
NSCAssert(strcmp([myClsObj textBase], "behavior_main_base") == 0,
|
||||
@"Couldn't replace implementation!");
|
||||
NSCAssert(strcmp([myBhvObj textBase], "class_main_base") == 0,
|
||||
@"Couldn't replace implementation!");
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
test_behavior1(void)
|
||||
{
|
||||
Class myTmplClass;
|
||||
id myTmplObj;
|
||||
|
||||
myTmplClass = [MyTemplate1 class];
|
||||
myTmplObj = [MyTemplate1 new];
|
||||
|
||||
NSCAssert([myTmplObj respondsToSelector:@selector(text)] == NO,
|
||||
@"Initial state invalid");
|
||||
GSObjCAddClassBehavior(myTmplClass, [MyClass class]);
|
||||
NSCAssert([myTmplObj respondsToSelector:@selector(text)] == YES,
|
||||
@"Behavior failed");
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
test_behavior2(void)
|
||||
{
|
||||
Class myTmplClass;
|
||||
id myTmplObj;
|
||||
|
||||
myTmplClass = [MyTemplate2 class];
|
||||
myTmplObj = [MyTemplate2 new];
|
||||
|
||||
NSCAssert([myTmplObj respondsToSelector:@selector(myClassCategory1)] == NO,
|
||||
@"Initial state invalid");
|
||||
GSObjCAddClassBehavior(myTmplClass, [MyClass class]);
|
||||
NSCAssert([myTmplObj respondsToSelector:@selector(myClassCategory1)] == YES,
|
||||
@"Behavior failed");
|
||||
|
||||
NSCAssert(strcmp([myTmplObj text], "template_main") == 0,
|
||||
@"Overwritten existing implementation!");
|
||||
}
|
||||
|
||||
void
|
||||
test_methodnames(void)
|
||||
{
|
||||
id obj = [NSNotificationCenter defaultCenter];
|
||||
NSArray *names;
|
||||
|
||||
names = GSObjCMethodNames(obj);
|
||||
NSDebugLog(@"obj:%@", names);
|
||||
names = GSObjCMethodNames([obj class]);
|
||||
NSDebugLog(@"class:%@", names);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
// [NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
test_methodnames();
|
||||
test_basic();
|
||||
test_create_list();
|
||||
test_reorder_list();
|
||||
test_exchange_method();
|
||||
|
||||
NSLog(@"Behavior Test Succeeded.");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"Behavior Test Failed:");
|
||||
NSLog(@"%@ %@ %@",
|
||||
[localException name],
|
||||
[localException reason],
|
||||
[localException userInfo]);
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
228
Testing/gslock.m
228
Testing/gslock.m
|
@ -1,228 +0,0 @@
|
|||
/** gslock - Program to test GSLazyLocks.
|
||||
Copyright (C) 2003 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Ayers <d.ayers@inode.at>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This file 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.
|
||||
|
||||
This file 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 file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSFileHandle.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
|
||||
#include <GNUstepBase/GSLock.h>
|
||||
|
||||
NSLock *lock = nil;
|
||||
|
||||
NSLock *gLock1 = nil;
|
||||
GSLazyRecursiveLock *gLock2 = nil;
|
||||
|
||||
NSConditionLock *cLock = nil;
|
||||
|
||||
volatile int counter = 0;
|
||||
volatile int threadExitCounter;
|
||||
|
||||
void
|
||||
wait_a_while ()
|
||||
{
|
||||
volatile int i;
|
||||
for (i = 0; i < 5; i++)
|
||||
i = ((i + 1) + (i - 1) / 2);
|
||||
}
|
||||
|
||||
#define NUM_ITERATIONS 10000
|
||||
|
||||
@interface Tester : NSObject
|
||||
- (void)runTest:(NSString *)ident;
|
||||
- (void)dummy:(id)none;
|
||||
- (void)createNewLockAt:(id)none;
|
||||
@end
|
||||
@implementation Tester
|
||||
- (void)dummy:(id)none
|
||||
{
|
||||
NSLog(@"Multithreaded:%@",[NSThread currentThread]);
|
||||
}
|
||||
- (void)runTest:(NSString *)ident
|
||||
{
|
||||
NSDate *start;
|
||||
NSDate *end;
|
||||
int i,j;
|
||||
NSTimeInterval time = 0;
|
||||
NSAutoreleasePool *pool;
|
||||
BOOL makeMulti;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
makeMulti = ([ident isEqualToString: @"Make Multithreaded GS"]);
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
start = [NSDate date];
|
||||
for (j = 0; j < NUM_ITERATIONS; j++)
|
||||
{
|
||||
volatile int temp;
|
||||
|
||||
[lock lock];
|
||||
|
||||
temp = counter;
|
||||
wait_a_while ();
|
||||
|
||||
if (makeMulti && i == 49 )
|
||||
{
|
||||
[NSThread detachNewThreadSelector: @selector(dummy:)
|
||||
toTarget: self
|
||||
withObject: nil];
|
||||
makeMulti = NO;
|
||||
}
|
||||
|
||||
|
||||
counter = temp + 1;
|
||||
wait_a_while ();
|
||||
|
||||
[lock unlock];
|
||||
}
|
||||
end = [NSDate date];
|
||||
time += [end timeIntervalSinceDate: start];
|
||||
}
|
||||
NSLog(@"End (%@/%@/%@):%f ",
|
||||
[NSThread currentThread], ident, lock, time / 100 );
|
||||
|
||||
threadExitCounter++;
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
-(void)createNewLockAt:(id)none
|
||||
{
|
||||
[cLock lock];
|
||||
|
||||
GS_INITIALIZED_LOCK(gLock1,NSLock);
|
||||
GS_INITIALIZED_LOCK(gLock2,GSLazyRecursiveLock);
|
||||
|
||||
NSLog(@"Created locks: %@ %@", gLock1, gLock2);
|
||||
|
||||
[cLock unlockWithCondition: YES];
|
||||
}
|
||||
@end
|
||||
|
||||
void
|
||||
test_lazyLocks()
|
||||
{
|
||||
Tester *tester;
|
||||
int i;
|
||||
|
||||
tester = [Tester new];
|
||||
|
||||
[tester runTest:@"empty"];
|
||||
|
||||
lock = [GSLazyLock new];
|
||||
[tester runTest:@"single GS"];
|
||||
|
||||
lock = [GSLazyRecursiveLock new];
|
||||
[tester runTest:@"single (r) GS"];
|
||||
|
||||
lock = [NSLock new];
|
||||
[tester runTest:@"single NS"];
|
||||
|
||||
lock = [NSRecursiveLock new];
|
||||
[tester runTest:@"single (r) NS"];
|
||||
|
||||
lock = [GSLazyLock new];
|
||||
[tester runTest:@"Make Multithreaded GS"];
|
||||
|
||||
/* We are now multithreaded. */
|
||||
NSCAssert1 ([lock class] == [NSLock class],
|
||||
@"Class didn't morph:%@", lock);
|
||||
|
||||
lock = [GSLazyLock new];
|
||||
NSCAssert1 ([lock class] == [NSLock class],
|
||||
@"Returned wrong lock:%@", lock);
|
||||
/* These tests actually only test NS*Lock locking, but... */
|
||||
[tester runTest:@"multi simple GS"];
|
||||
|
||||
lock = [GSLazyRecursiveLock new];
|
||||
NSCAssert1 ([lock class] == [NSRecursiveLock class],
|
||||
@"Returned wrong lock:%@", lock);
|
||||
[tester runTest:@"multi simple (r) GS"];
|
||||
|
||||
lock = [NSLock new];
|
||||
[tester runTest:@"multi simple NS"];
|
||||
|
||||
lock = [NSRecursiveLock new];
|
||||
[tester runTest:@"multi simple NS"];
|
||||
|
||||
/* Let's test locking anyway while we're at it. */
|
||||
for (threadExitCounter = 0, i = 0; i < 3; i++)
|
||||
{
|
||||
NSString *ident;
|
||||
ident = [NSString stringWithFormat: @"multi complex (%d)", i];
|
||||
[NSThread detachNewThreadSelector: @selector(runTest:)
|
||||
toTarget: tester
|
||||
withObject: ident];
|
||||
}
|
||||
|
||||
while (threadExitCounter < 3)
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 10.0]];
|
||||
|
||||
NSCAssert1 (counter == NUM_ITERATIONS * 1300,
|
||||
@"Locks broken! %d", counter );
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
test_newLockAt(void)
|
||||
{
|
||||
Tester *t = [Tester new];
|
||||
|
||||
cLock = [[NSConditionLock alloc] initWithCondition: NO];
|
||||
|
||||
[NSThread detachNewThreadSelector: @selector(createNewLockAt:)
|
||||
toTarget: t
|
||||
withObject: nil];
|
||||
|
||||
[cLock lockWhenCondition: YES
|
||||
beforeDate: [NSDate dateWithTimeIntervalSinceNow: 10.0]];
|
||||
[cLock unlock];
|
||||
|
||||
NSCAssert1([gLock1 isKindOfClass: [NSLock class]],
|
||||
@"-[NSLock newLockAt:] returned %@", gLock1);
|
||||
NSCAssert1([gLock2 isKindOfClass: [NSRecursiveLock class]],
|
||||
@"-[GSLazyRecursiveLock newLockAt:] returned %@", gLock1);
|
||||
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
test_lazyLocks();
|
||||
test_newLockAt();
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* Test Heap class. */
|
||||
|
||||
#include <GNUstepBase/all.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
#define N 20
|
||||
|
||||
#if defined(__svr4__) || defined(__hpux) || defined(_SEQUENT_)
|
||||
long lrand48();
|
||||
#define random lrand48
|
||||
#endif
|
||||
|
||||
int main()
|
||||
{
|
||||
int i, s;
|
||||
id s1, s2;
|
||||
id arp;
|
||||
|
||||
Heap* heap = [Heap new];
|
||||
Array* array = [Array new];
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
s = random () % 100;
|
||||
[heap addObject: [NSNumber numberWithInt: s]];
|
||||
[array addObject: [NSNumber numberWithInt: s]];
|
||||
}
|
||||
[array sortContents];
|
||||
|
||||
[heap printForDebugger];
|
||||
[array printForDebugger];
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
{
|
||||
s1 = [heap firstObject];
|
||||
s2 = [array firstObject];
|
||||
[heap removeFirstObject];
|
||||
[array removeFirstObject];
|
||||
printf("(%d,%d) ", [s1 intValue], [s2 intValue]);
|
||||
assert ([s1 intValue] == [s2 intValue]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
[heap release];
|
||||
[array release];
|
||||
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
#
|
||||
# GNUmakefile - Generated by ProjectCenter
|
||||
#
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
#
|
||||
# Tool
|
||||
#
|
||||
VERSION = 0.1
|
||||
PACKAGE_NAME = LockTest
|
||||
TOOL_NAME = LockTest
|
||||
LockTest_TOOL_ICON =
|
||||
|
||||
|
||||
#
|
||||
# Resource files
|
||||
#
|
||||
LockTest_RESOURCE_FILES = \
|
||||
Resources/Version \
|
||||
|
||||
|
||||
#
|
||||
# Other sources
|
||||
#
|
||||
LockTest_OBJC_FILES += \
|
||||
locktest.m
|
||||
|
||||
#
|
||||
# Makefiles
|
||||
#
|
||||
-include GNUmakefile.preamble
|
||||
include $(GNUSTEP_MAKEFILES)/aggregate.make
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
-include GNUmakefile.postamble
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# GNUmakefile.preamble - Generated by ProjectCenter
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS +=
|
||||
|
||||
# Additional flags to pass to Objective C compiler
|
||||
ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to C compiler
|
||||
ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional flags to pass to the linker
|
||||
ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS +=
|
||||
|
||||
# Additional TOOL libraries to link
|
||||
ADDITIONAL_TOOL_LIBS +=
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
Copyright = "Copyright (C) 200x";
|
||||
CopyrightDescription = "Released under ...";
|
||||
FullVersionID = 0.1;
|
||||
ToolDescription = "No description available!";
|
||||
ToolName = LockTest;
|
||||
ToolRelease = 0.1;
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
{
|
||||
CLASS_FILES = (
|
||||
);
|
||||
COMPILEROPTIONS = "";
|
||||
CPPOPTIONS = "";
|
||||
CREATION_DATE = "2009-01-28 18:16:19 -0500";
|
||||
DOCU_FILES = (
|
||||
);
|
||||
FRAMEWORKS = (
|
||||
);
|
||||
HEADER_FILES = (
|
||||
);
|
||||
IMAGES = (
|
||||
);
|
||||
INSTALLDIR = "$(HOME)/GNUstep/Tools";
|
||||
LANGUAGE = English;
|
||||
LAST_EDITING = "2009-01-28 21:44:35 -0500";
|
||||
LIBRARIES = (
|
||||
"gnustep-base"
|
||||
);
|
||||
LINKEROPTIONS = "";
|
||||
LOCALIZED_RESOURCES = (
|
||||
);
|
||||
MAKEFILEDIR = "$(GNUSTEP_MAKEFILES)";
|
||||
OBJC_COMPILEROPTIONS = "";
|
||||
OTHER_RESOURCES = (
|
||||
Version
|
||||
);
|
||||
OTHER_SOURCES = (
|
||||
locktest.m
|
||||
);
|
||||
PROJECT_AUTHORS = (
|
||||
);
|
||||
PROJECT_COPYRIGHT = "Copyright (C) 200x";
|
||||
PROJECT_COPYRIGHT_DESC = "Released under ...";
|
||||
PROJECT_CREATOR = "Gregory John Casamento,,,";
|
||||
PROJECT_DESCRIPTION = "No description available!";
|
||||
PROJECT_GROUP = "No group available!";
|
||||
PROJECT_MAINTAINER = "Gregory John Casamento,,,";
|
||||
PROJECT_NAME = LockTest;
|
||||
PROJECT_RELEASE = 0.1;
|
||||
PROJECT_SUMMARY = "No summary available!";
|
||||
PROJECT_TYPE = Tool;
|
||||
PROJECT_URL = "";
|
||||
SEARCH_HEADER_DIRS = (
|
||||
);
|
||||
SEARCH_LIB_DIRS = (
|
||||
);
|
||||
SUBPROJECTS = (
|
||||
);
|
||||
SUPPORTING_FILES = (
|
||||
GNUmakefile.preamble,
|
||||
GNUmakefile,
|
||||
GNUmakefile.postamble,
|
||||
LockTestInfo.plist
|
||||
);
|
||||
TOOLICON = "";
|
||||
USER_LANGUAGES = (
|
||||
AmericanEnglish,
|
||||
English
|
||||
);
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
|
||||
.\"See Also:
|
||||
.\"man mdoc.samples for a complete listing of options
|
||||
.\"man mdoc for the short list of editing options
|
||||
.\"/usr/share/misc/mdoc.template
|
||||
.Dd 1/28/09 \" DATE
|
||||
.Dt locktest 1 \" Program name and manual section number
|
||||
.Os Darwin
|
||||
.Sh NAME \" Section Header - required - don't modify
|
||||
.Nm locktest,
|
||||
.\" The following lines are read in generating the apropos(man -k) database. Use only key
|
||||
.\" words here as the database is built based on the words here and in the .ND line.
|
||||
.Nm Other_name_for_same_program(),
|
||||
.Nm Yet another name for the same program.
|
||||
.\" Use .Nm macro to designate other names for the documented program.
|
||||
.Nd This line parsed for whatis database.
|
||||
.Sh SYNOPSIS \" Section Header - required - don't modify
|
||||
.Nm
|
||||
.Op Fl abcd \" [-abcd]
|
||||
.Op Fl a Ar path \" [-a path]
|
||||
.Op Ar file \" [file]
|
||||
.Op Ar \" [file ...]
|
||||
.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
|
||||
arg2 ... \" Arguments
|
||||
.Sh DESCRIPTION \" Section Header - required - don't modify
|
||||
Use the .Nm macro to refer to your program throughout the man page like such:
|
||||
.Nm
|
||||
Underlining is accomplished with the .Ar macro like this:
|
||||
.Ar underlined text .
|
||||
.Pp \" Inserts a space
|
||||
A list of items with descriptions:
|
||||
.Bl -tag -width -indent \" Begins a tagged list
|
||||
.It item a \" Each item preceded by .It macro
|
||||
Description of item a
|
||||
.It item b
|
||||
Description of item b
|
||||
.El \" Ends the list
|
||||
.Pp
|
||||
A list of flags and their descriptions:
|
||||
.Bl -tag -width -indent \" Differs from above in tag removed
|
||||
.It Fl a \"-a flag as a list item
|
||||
Description of -a flag
|
||||
.It Fl b
|
||||
Description of -b flag
|
||||
.El \" Ends the list
|
||||
.Pp
|
||||
.\" .Sh ENVIRONMENT \" May not be needed
|
||||
.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
|
||||
.\" .It Ev ENV_VAR_1
|
||||
.\" Description of ENV_VAR_1
|
||||
.\" .It Ev ENV_VAR_2
|
||||
.\" Description of ENV_VAR_2
|
||||
.\" .El
|
||||
.Sh FILES \" File used or created by the topic of the man page
|
||||
.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
|
||||
.It Pa /usr/share/file_name
|
||||
FILE_1 description
|
||||
.It Pa /Users/joeuser/Library/really_long_file_name
|
||||
FILE_2 description
|
||||
.El \" Ends the list
|
||||
.\" .Sh DIAGNOSTICS \" May not be needed
|
||||
.\" .Bl -diag
|
||||
.\" .It Diagnostic Tag
|
||||
.\" Diagnostic informtion here.
|
||||
.\" .It Diagnostic Tag
|
||||
.\" Diagnostic informtion here.
|
||||
.\" .El
|
||||
.Sh SEE ALSO
|
||||
.\" List links in ascending order by section, alphabetically within a section.
|
||||
.\" Please do not reference files that do not exist without filing a bug report
|
||||
.Xr a 1 ,
|
||||
.Xr b 1 ,
|
||||
.Xr c 1 ,
|
||||
.Xr a 2 ,
|
||||
.Xr b 2 ,
|
||||
.Xr a 3 ,
|
||||
.Xr b 3
|
||||
.\" .Sh BUGS \" Document known, unremedied bugs
|
||||
.\" .Sh HISTORY \" Document history if command behaves in a unique manner
|
|
@ -1,170 +0,0 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
// BOOL pass;
|
||||
|
||||
void testNSLockLock()
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
// insert code here...
|
||||
NSLock *lock = [[NSLock alloc] init];
|
||||
[lock lock];
|
||||
#ifdef GNUSTEP
|
||||
[lock lock]; // On Mac OS X, this deadlocks. Should we do the same?
|
||||
// our behavior in this case is arguably better since we raise an exception
|
||||
#endif
|
||||
[lock unlock];
|
||||
[lock release];
|
||||
#ifndef GNUSTEP
|
||||
NSLog(@"[NSLock lock] test passed -- Mac OS X behavior is to deadlock in this case, we throw an exception.");
|
||||
#else
|
||||
NSLog(@"[NSLock lock] test failed");
|
||||
#endif
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"[NSLock lock] test passed");
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
|
||||
void testNSConditionLockLock()
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
// insert code here...
|
||||
NSConditionLock *lock = [[NSConditionLock alloc] init];
|
||||
[lock lock];
|
||||
#ifdef GNUSTEP
|
||||
[lock lock]; // On Mac OS X, this deadlocks. Should we do the same?
|
||||
// our behavior in this case is arguably better since we raise an exception
|
||||
#endif
|
||||
[lock unlock];
|
||||
[lock release];
|
||||
#ifndef GNUSTEP
|
||||
NSLog(@"[NSConditionLock lock] test passed -- Mac OS X behavior is to deadlock in this case, we throw an exception.");
|
||||
#else
|
||||
NSLog(@"[NSConditionLock lock] test failed");
|
||||
#endif
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"[NSConditionLock lock] test passed");
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
void testNSRecursiveLockLock()
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
// insert code here...
|
||||
NSRecursiveLock *lock = [[NSRecursiveLock alloc] init];
|
||||
[lock lock];
|
||||
[lock lock];
|
||||
[lock unlock];
|
||||
[lock unlock];
|
||||
[lock release];
|
||||
NSLog(@"[NSRecursiveLock lock] test passed");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"[NSRecursiveLock lock] test failed");
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
void testNSLockTryLock()
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
// insert code here...
|
||||
NSLock *lock = [[NSLock alloc] init];
|
||||
[lock tryLock];
|
||||
[lock tryLock];
|
||||
[lock unlock];
|
||||
[lock release];
|
||||
NSLog(@"[NSLock tryLock] test passed");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"[NSLock tryLock] test failed");
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
|
||||
void testNSConditionLockTryLock()
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
// insert code here...
|
||||
NSConditionLock *lock = [[NSConditionLock alloc] init];
|
||||
[lock tryLock];
|
||||
[lock tryLock];
|
||||
[lock unlock];
|
||||
[lock release];
|
||||
NSLog(@"[NSConditionLock tryLock] test passed");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"[NSConditionLock tryLock] test failed");
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
void testNSRecursiveLockTryLock()
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
// insert code here...
|
||||
NSRecursiveLock *lock = [[NSRecursiveLock alloc] init];
|
||||
[lock tryLock];
|
||||
[lock tryLock];
|
||||
[lock unlock];
|
||||
[lock unlock];
|
||||
[lock release];
|
||||
NSLog(@"[NSRecursiveLock tryLock] test passed");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"[NSRecursiveLock tryLock] test failed");
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
}
|
||||
|
||||
void singleThreadedTests()
|
||||
{
|
||||
// single threaded tests...
|
||||
NSLog(@"======== SINGLE THREADED TESTS");
|
||||
|
||||
// lock
|
||||
testNSLockLock();
|
||||
testNSConditionLockLock();
|
||||
testNSRecursiveLockLock();
|
||||
|
||||
// tryLock
|
||||
testNSLockTryLock();
|
||||
testNSConditionLockTryLock();
|
||||
testNSRecursiveLockTryLock();
|
||||
}
|
||||
|
||||
|
||||
void multiThreadedTests()
|
||||
{
|
||||
NSLog(@"======== MULTI THREADED TESTS");
|
||||
}
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// pass = YES;
|
||||
// single threaded tests...
|
||||
singleThreadedTests();
|
||||
// multi threaded tests...
|
||||
multiThreadedTests();
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
|
@ -1,218 +0,0 @@
|
|||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 44;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
8DD76F9A0486AA7600D96B5E /* locktest.m in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* locktest.m */; settings = {ATTRIBUTES = (); }; };
|
||||
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
|
||||
8DD76F9F0486AA7600D96B5E /* locktest.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859EA3029092ED04C91782 /* locktest.1 */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
8DD76F9E0486AA7600D96B5E /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 8;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
8DD76F9F0486AA7600D96B5E /* locktest.1 in CopyFiles */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
08FB7796FE84155DC02AAC07 /* locktest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = locktest.m; sourceTree = "<group>"; };
|
||||
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
|
||||
32A70AAB03705E1F00C91783 /* locktest_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = locktest_Prefix.pch; sourceTree = "<group>"; };
|
||||
8DD76FA10486AA7600D96B5E /* locktest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = locktest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
C6859EA3029092ED04C91782 /* locktest.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = locktest.1; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
8DD76F9B0486AA7600D96B5E /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
08FB7794FE84155DC02AAC07 /* locktest */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
08FB7795FE84155DC02AAC07 /* Source */,
|
||||
C6859EA2029092E104C91782 /* Documentation */,
|
||||
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
|
||||
1AB674ADFE9D54B511CA2CBB /* Products */,
|
||||
);
|
||||
name = locktest;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
08FB7795FE84155DC02AAC07 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
32A70AAB03705E1F00C91783 /* locktest_Prefix.pch */,
|
||||
08FB7796FE84155DC02AAC07 /* locktest.m */,
|
||||
);
|
||||
name = Source;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
08FB779EFE84155DC02AAC07 /* Foundation.framework */,
|
||||
);
|
||||
name = "External Frameworks and Libraries";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
1AB674ADFE9D54B511CA2CBB /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
8DD76FA10486AA7600D96B5E /* locktest */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
C6859EA2029092E104C91782 /* Documentation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
C6859EA3029092ED04C91782 /* locktest.1 */,
|
||||
);
|
||||
name = Documentation;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
8DD76F960486AA7600D96B5E /* locktest */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "locktest" */;
|
||||
buildPhases = (
|
||||
8DD76F990486AA7600D96B5E /* Sources */,
|
||||
8DD76F9B0486AA7600D96B5E /* Frameworks */,
|
||||
8DD76F9E0486AA7600D96B5E /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = locktest;
|
||||
productInstallPath = "$(HOME)/bin";
|
||||
productName = locktest;
|
||||
productReference = 8DD76FA10486AA7600D96B5E /* locktest */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
08FB7793FE84155DC02AAC07 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "locktest" */;
|
||||
compatibilityVersion = "Xcode 3.0";
|
||||
hasScannedForEncodings = 1;
|
||||
mainGroup = 08FB7794FE84155DC02AAC07 /* locktest */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
8DD76F960486AA7600D96B5E /* locktest */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
8DD76F990486AA7600D96B5E /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8DD76F9A0486AA7600D96B5E /* locktest.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
1DEB927508733DD40010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
COPY_PHASE_STRIP = NO;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_ENABLE_FIX_AND_CONTINUE = YES;
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = locktest_Prefix.pch;
|
||||
INSTALL_PATH = /usr/local/bin;
|
||||
PRODUCT_NAME = locktest;
|
||||
ZERO_LINK = YES;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
1DEB927608733DD40010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
GCC_MODEL_TUNING = G5;
|
||||
GCC_PRECOMPILE_PREFIX_HEADER = YES;
|
||||
GCC_PREFIX_HEADER = locktest_Prefix.pch;
|
||||
INSTALL_PATH = /usr/local/bin;
|
||||
PRODUCT_NAME = locktest;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
1DEB927908733DD40010E9CD /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
PREBINDING = NO;
|
||||
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
1DEB927A08733DD40010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ARCHS = (
|
||||
ppc,
|
||||
i386,
|
||||
);
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
PREBINDING = NO;
|
||||
SDKROOT = "$(DEVELOPER_SDK_DIR)/MacOSX10.5.sdk";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "locktest" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
1DEB927508733DD40010E9CD /* Debug */,
|
||||
1DEB927608733DD40010E9CD /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "locktest" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
1DEB927908733DD40010E9CD /* Debug */,
|
||||
1DEB927A08733DD40010E9CD /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
};
|
||||
rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
//
|
||||
// Prefix header for all source files of the 'locktest' target in the 'locktest' project.
|
||||
//
|
||||
|
||||
#ifdef __OBJC__
|
||||
#import <Foundation/Foundation.h>
|
||||
#endif
|
|
@ -1,305 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* A demonstration of writing and reading with NSArchiver */
|
||||
|
||||
#if 1
|
||||
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
|
||||
@interface ClassOne : NSObject
|
||||
@end
|
||||
@implementation ClassOne
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
}
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
@interface ClassTwo : NSObject
|
||||
@end
|
||||
@implementation ClassTwo
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
}
|
||||
- (id) initWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
typedef struct { char a; double b; char c;} tstruct;
|
||||
int main()
|
||||
{
|
||||
id obj;
|
||||
id set;
|
||||
id arp;
|
||||
id arc;
|
||||
id una;
|
||||
id xxx;
|
||||
id apl;
|
||||
tstruct ss;
|
||||
tstruct tt;
|
||||
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
|
||||
arp = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
/* Create a Set of int's */
|
||||
set = [[NSSet alloc] initWithObjects:
|
||||
@"apple", @"banana", @"carrot", @"dal", @"escarole", @"fava",
|
||||
[NSValue valueWithPoint: NSMakePoint(1,1)],
|
||||
[NSValue valueWithSize: NSMakeSize(11,11)],
|
||||
[NSValue valueWithRange: NSMakeRange(10,2)],
|
||||
[NSValue valueWithRect: NSMakeRect(11,11,22,22)],
|
||||
nil];
|
||||
|
||||
/* Display the set */
|
||||
printf("Writing:\n");
|
||||
{
|
||||
id o, e = [set objectEnumerator];
|
||||
while ((o = [e nextObject]))
|
||||
printf("%s\n", [[o description] cString]);
|
||||
}
|
||||
|
||||
apl = [[NSAutoreleasePool alloc] init];
|
||||
ss.a = 'A';
|
||||
ss.b = 1.234;
|
||||
ss.c = 'Z';
|
||||
arc = [[NSArchiver new] autorelease];
|
||||
[arc encodeValueOfObjCType: @encode(tstruct) at: &ss];
|
||||
una = [[[NSUnarchiver alloc] initForReadingWithData: [arc archiverData]] autorelease];
|
||||
[una decodeValueOfObjCType: @encode(tstruct) at: &tt];
|
||||
[apl release];
|
||||
if (ss.a != tt.a) printf("Encoded '%c' in 'a' but got '%c'\n", ss.a, tt.a);
|
||||
if (ss.b != tt.b) printf("Encoded '%f' in 'a' but got '%f'\n", ss.b, tt.b);
|
||||
if (ss.c != tt.c) printf("Encoded '%c' in 'a' but got '%c'\n", ss.c, tt.c);
|
||||
|
||||
apl = [[NSAutoreleasePool alloc] init];
|
||||
arc = [[NSArchiver new] autorelease];
|
||||
printf("%u\n", [arc retainCount]);
|
||||
[arc retain];
|
||||
printf("%u\n", [arc retainCount]);
|
||||
[arc release];
|
||||
printf("%u\n", [arc retainCount]);
|
||||
[arc encodeRootObject: set];
|
||||
una = [[[NSUnarchiver alloc] initForReadingWithData: [arc archiverData]] autorelease];
|
||||
xxx = [una decodeObject];
|
||||
if ([xxx isEqual: set] == NO)
|
||||
printf("Argh\n");
|
||||
printf("%s\n", [[xxx description] cString]);
|
||||
[apl release];
|
||||
|
||||
|
||||
/* Write it to a file */
|
||||
[NSArchiver archiveRootObject: set toFile: @"./nsarchiver.dat"];
|
||||
|
||||
/* Release the object that was coded */
|
||||
[set release];
|
||||
|
||||
/* Read it back in from the file */
|
||||
#if 1
|
||||
{
|
||||
id d = [[NSData alloc] initWithContentsOfFile:@"./nsarchiver.dat"];
|
||||
id a = [NSUnarchiver alloc];
|
||||
a = [a initForReadingWithData:d];
|
||||
set = [a decodeObject];
|
||||
}
|
||||
#else
|
||||
set = [NSUnarchiver unarchiveObjectWithFile: @"./nsarchiver.dat"];
|
||||
#endif
|
||||
|
||||
/* Display what we read, to make sure it matches what we wrote */
|
||||
printf("\nReading:\n");
|
||||
{
|
||||
id o, e = [set objectEnumerator];
|
||||
while ((o = [e nextObject]))
|
||||
printf("%s\n", [[o description] cString]);
|
||||
}
|
||||
|
||||
obj = [ClassOne new];
|
||||
[NSArchiver archiveRootObject: obj toFile: @"./nsarchiver.dat"];
|
||||
RELEASE(obj);
|
||||
[NSUnarchiver decodeClassName: @"ClassOne" asClassName: @"ClassTwo"];
|
||||
obj = [NSUnarchiver unarchiveObjectWithFile: @"./nsarchiver.dat"];
|
||||
if ([obj isKindOfClass: [ClassTwo class]] == NO)
|
||||
NSLog(@"ERROR: ClassOne decoded as %@", NSStringFromClass([obj class]));
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* Benchmark use of very lightwight archiving - a single
|
||||
* archiver/unarchiver pair using a single mutable data object to
|
||||
* archive and unarchive many times.
|
||||
*/
|
||||
{
|
||||
NSDate *start = [NSDate date];
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
int i;
|
||||
NSUnarchiver *u = nil;
|
||||
NSMutableData *d;
|
||||
NSArchiver *a;
|
||||
|
||||
d = [NSMutableData data];
|
||||
a = [[NSArchiver alloc] initForWritingWithMutableData: d];
|
||||
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:NO];
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
id o;
|
||||
|
||||
[a encodeRootObject: set];
|
||||
if (u == nil)
|
||||
{
|
||||
u = [[NSUnarchiver alloc] initForReadingWithData: d];
|
||||
}
|
||||
else
|
||||
{
|
||||
[u resetUnarchiverWithData: d atIndex: 0];
|
||||
}
|
||||
o = [u decodeObject];
|
||||
[d setLength: 0];
|
||||
[a resetArchiver];
|
||||
}
|
||||
[a release];
|
||||
[u release];
|
||||
[arp release];
|
||||
printf("Time: %f\n", -[start timeIntervalSinceNow]);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Do the autorelease. */
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
/* An old, unused test. */
|
||||
#else
|
||||
|
||||
#include <GNUstepBase/all.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
@interface TestClass : NSObject
|
||||
{
|
||||
id next_responder;
|
||||
}
|
||||
|
||||
- (void)setNextResponder: anObject;
|
||||
- nextResponder;
|
||||
@end
|
||||
|
||||
@implementation TestClass
|
||||
|
||||
- (void)setNextResponder: anObject
|
||||
{
|
||||
next_responder = anObject;
|
||||
}
|
||||
|
||||
- nextResponder
|
||||
{
|
||||
return next_responder;
|
||||
}
|
||||
|
||||
// NSCoding protocol
|
||||
- (void)encodeWithCoder:aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
[aCoder encodeObjectReference:next_responder withName:@"Next Responder"];
|
||||
}
|
||||
|
||||
- initWithCoder:aDecoder
|
||||
{
|
||||
id d;
|
||||
[super initWithCoder:aDecoder];
|
||||
[aDecoder decodeObjectAt:&next_responder withName:&d];
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
////////////////////////////////////////
|
||||
|
||||
int main()
|
||||
{
|
||||
id arp;
|
||||
id r1, r2;
|
||||
|
||||
arp = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
// Create a simple loop
|
||||
r1 = [[TestClass alloc] init];
|
||||
r2 = [[TestClass alloc] init];
|
||||
[r1 setNextResponder: r2];
|
||||
[r2 setNextResponder: r1];
|
||||
|
||||
printf("Writing\n");
|
||||
printf("%d\n", [r1 hash]);
|
||||
printf("%d\n", [r2 hash]);
|
||||
printf("%d\n", [[r1 nextResponder] hash]);
|
||||
printf("%d\n", [[r2 nextResponder] hash]);
|
||||
|
||||
/* Write it to a file */
|
||||
{
|
||||
id d = [[NSMutableData alloc] init];
|
||||
id a = [[Archiver alloc] initForWritingWithMutableData: d];
|
||||
|
||||
[a startEncodingInterconnectedObjects];
|
||||
[a encodeObject: r1 withName:@"one"];
|
||||
[a encodeObject: r2 withName:@"another"];
|
||||
[a finishEncodingInterconnectedObjects];
|
||||
|
||||
[d writeToFile: @"./nsarchiver.dat" atomically:NO];
|
||||
|
||||
[d release];
|
||||
[a release];
|
||||
}
|
||||
|
||||
/* Release the object that was coded */
|
||||
[r1 release];
|
||||
[r2 release];
|
||||
|
||||
/* Read it back in from the file */
|
||||
printf("\nReading:\n");
|
||||
{
|
||||
id d;
|
||||
id a = [Unarchiver newReadingFromFile:@"./nsarchiver.dat"];
|
||||
|
||||
[a startDecodingInterconnectedObjects];
|
||||
[a decodeObjectAt: &r1 withName:&d];
|
||||
[a decodeObjectAt: &r2 withName:&d];
|
||||
[a finishDecodingInterconnectedObjects];
|
||||
}
|
||||
|
||||
/* Display what we read, to make sure it matches what we wrote */
|
||||
{
|
||||
printf("%d\n", [r1 hash]);
|
||||
printf("%d\n", [r2 hash]);
|
||||
printf("%d\n", [[r1 nextResponder] hash]);
|
||||
printf("%d\n", [[r2 nextResponder] hash]);
|
||||
}
|
||||
|
||||
/* Do the autorelease. */
|
||||
[arp release];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,386 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
||||
int compare(id elem1, id elem2, void* context)
|
||||
{
|
||||
return (int)[elem1 performSelector:@selector(compare:) withObject:elem2];
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
id a, b, c, d, e, f, g, h; /* arrays */
|
||||
id enumerator;
|
||||
id i;
|
||||
id s = @"Hello World\n";
|
||||
id pool;
|
||||
id o1, o2, o3;
|
||||
unsigned int p;
|
||||
|
||||
//behavior_set_debug(0);
|
||||
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
o1 = [NSNumber numberWithInt:1];
|
||||
o2 = [NSNumber numberWithInt:2];
|
||||
o3 = [NSNumber numberWithInt:3];
|
||||
a = [[[NSArray arrayWithObject:o1] arrayByAddingObject:o2] arrayByAddingObject:o3];
|
||||
printf("%u,%u,%u\n", [o1 retainCount], [o2 retainCount], [o3 retainCount]);
|
||||
b = [[a copy] autorelease];
|
||||
printf("%u,%u,%u\n", [o1 retainCount], [o2 retainCount], [o3 retainCount]);
|
||||
c = [[b mutableCopy] autorelease];
|
||||
printf("%u,%u,%u\n", [o1 retainCount], [o2 retainCount], [o3 retainCount]);
|
||||
d = [[c copy] autorelease];
|
||||
printf("%u,%u,%u\n", [o1 retainCount], [o2 retainCount], [o3 retainCount]);
|
||||
|
||||
// NSArray tests
|
||||
{
|
||||
// Class methods for allocating and initializing an array
|
||||
printf("Method: +array\n");
|
||||
a = [NSArray array];
|
||||
if ([a count] == 0)
|
||||
printf("Empty array count is zero\n");
|
||||
else
|
||||
printf("Error: empty array count is not zero\n");
|
||||
|
||||
printf("Method: +arrayWithObject:\n");
|
||||
b = [NSArray arrayWithObject: s];
|
||||
printf("NSArray has count %d\n", [b count]);
|
||||
if ([b count] != 1)
|
||||
printf("Error: count != 1\n");
|
||||
|
||||
printf("Method: +arrayWithObjects:...\n");
|
||||
c = [NSArray arrayWithObjects:
|
||||
[NSObject class],
|
||||
[NSArray class],
|
||||
[NSMutableArray class],
|
||||
nil];
|
||||
printf("NSArray has count %d\n", [c count]);
|
||||
if ([c count] != 3)
|
||||
printf("Error: count != 3\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Instance methods for allocating and initializing an array
|
||||
printf("Method: -arrayByAddingObject:\n");
|
||||
d = [c arrayByAddingObject: s];
|
||||
printf("NSArray has count %d\n", [c count]);
|
||||
if ([d count] != 4)
|
||||
printf("Error: count != 4\n");
|
||||
|
||||
printf("Method: -arrayByAddingObjectsFromArray:\n");
|
||||
e = [c arrayByAddingObjectsFromArray: b];
|
||||
printf("NSArray has count %d\n", [c count]);
|
||||
if ([e count] != 4)
|
||||
printf("Error: count != 4\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Querying the arra
|
||||
NSCParameterAssert([c containsObject:[NSObject class]]);
|
||||
|
||||
p = [e indexOfObject:@"Hello World\n"];
|
||||
if (p == NSNotFound)
|
||||
printf("Error: index of object not found\n");
|
||||
else
|
||||
printf("Index of object is %d\n", p);
|
||||
|
||||
p = [e indexOfObjectIdenticalTo:s];
|
||||
if (p == NSNotFound)
|
||||
printf("Error: index of identical object not found\n");
|
||||
else
|
||||
printf("Index of identical object is %d\n", p);
|
||||
|
||||
NSCParameterAssert([c lastObject]);
|
||||
printf("Class at index 2 is %s\n", [[[c objectAtIndex:2] description] cString]);
|
||||
|
||||
printf("Forward enumeration\n");
|
||||
enumerator = [e objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Reverse enumeration\n");
|
||||
enumerator = [e reverseObjectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Sending messages to elements
|
||||
[c makeObjectsPerform:@selector(description)];
|
||||
|
||||
//[c makeObjectsPerform:@selector(isEqual:) withObject: @"NSArray"];
|
||||
}
|
||||
|
||||
{
|
||||
// Comparing arrays
|
||||
NSCParameterAssert([d firstObjectCommonWithArray:e]);
|
||||
|
||||
if ([d isEqualToArray: d])
|
||||
printf("NSArray is equal to itself\n");
|
||||
else
|
||||
printf("Error: NSArray is not equal to itself\n");
|
||||
|
||||
if ([d isEqualToArray: e])
|
||||
printf("NSArrays are equal\n");
|
||||
else
|
||||
printf("Error: NSArrays are not equal\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Deriving new arrays
|
||||
NSRange r = NSMakeRange(0, 3);
|
||||
|
||||
f = [NSMutableArray array];
|
||||
[f addObject: @"Lions"];
|
||||
[f addObject: @"Tigers"];
|
||||
[f addObject: @"Bears"];
|
||||
[f addObject: @"Penguins"];
|
||||
[f addObject: @"Giraffes"];
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [i cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method: -sortedArrayUsingSelector:\n");
|
||||
g = [f sortedArrayUsingSelector: @selector(compare:)];
|
||||
printf("Method: -sortedArrayUsingFunction:context:\n");
|
||||
h = [f sortedArrayUsingFunction: compare context: NULL];
|
||||
|
||||
enumerator = [g objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [i cString]);
|
||||
printf("\n");
|
||||
|
||||
if (([g isEqualToArray: h]) && (![g isEqualToArray: f]))
|
||||
printf("Sorted arrays are correct\n");
|
||||
else
|
||||
printf("Error: Sorted arrays are not correct\n");
|
||||
|
||||
printf("Method: -subarrayWithRange:\n");
|
||||
f = [e subarrayWithRange: r];
|
||||
|
||||
printf("NSArray has count %d\n", [f count]);
|
||||
if ([f count] != 3)
|
||||
printf("Error: count != 3\n");
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
if ([f isEqualToArray: c])
|
||||
printf("Subarray is correct\n");
|
||||
else
|
||||
printf("Error: Subarray does not have correct elements\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Joining string elements
|
||||
printf("Method: -componentsJoinedByString:\n");
|
||||
i = [c componentsJoinedByString: @"/"];
|
||||
if ([i isEqual: @"NSObject/NSArray/NSMutableArray"])
|
||||
printf("%s is correct\n", [i cString]);
|
||||
else
|
||||
{
|
||||
printf("Error: %s is not correct\n", [i cString]);
|
||||
printf("Should be NSObject/NSArray/NSMutableArray\n");
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
// Creating a string description of the array
|
||||
/* What do the -description methods do?
|
||||
[e description]
|
||||
[e descriptionWithLocale:]
|
||||
[e descriptionWithLocale: indent:]
|
||||
*/
|
||||
}
|
||||
|
||||
// NSMutableArray tests
|
||||
printf("*** Start of NSMutableArray tests\n");
|
||||
{
|
||||
// Creating and initializing an NSMutableArray
|
||||
f = [NSMutableArray arrayWithCapacity: 10];
|
||||
NSCParameterAssert(f);
|
||||
f = [[NSMutableArray alloc] initWithCapacity: 10];
|
||||
[f release];
|
||||
NSCParameterAssert(f);
|
||||
}
|
||||
|
||||
{
|
||||
// Adding objects
|
||||
f = [e mutableCopy];
|
||||
NSCParameterAssert([f count]);
|
||||
|
||||
printf("Method -addObject:[NSObject class]\n");
|
||||
[f addObject:[NSObject class]];
|
||||
printf("NSMutableArray has count %d\n", [f count]);
|
||||
if ([f count] != 5)
|
||||
printf("Error: count != 5\n");
|
||||
|
||||
printf("Method -addObjectsFromArray:\n");
|
||||
[f addObjectsFromArray: c];
|
||||
printf("NSMutableArray has count %d\n", [f count]);
|
||||
if ([f count] != 8)
|
||||
printf("Error: count != 8\n");
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method -insertObject: [NSMutableArray class] atIndex: 2\n");
|
||||
[f insertObject: [NSMutableArray class] atIndex: 2];
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
}
|
||||
|
||||
g = [f mutableCopy];
|
||||
h = [f mutableCopy];
|
||||
|
||||
{
|
||||
// Removing objects
|
||||
unsigned int ind[7] = {7, 4, 1, 3, 5, 0, 6};
|
||||
|
||||
printf("Method -removeAllObjects\n");
|
||||
printf("Array count is %d\n", [h count]);
|
||||
[h removeAllObjects];
|
||||
printf("Array count is %d\n", [h count]);
|
||||
if ([h count] != 0)
|
||||
printf("Error: count != 0\n");
|
||||
|
||||
h = [f mutableCopy];
|
||||
|
||||
printf("Method -removeLastObject\n");
|
||||
[f removeLastObject];
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method -removeObject: [NSObject class]\n");
|
||||
[f removeObject: [NSObject class]];
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method -removeObjectIdenticalTo: [NSArray class]\n");
|
||||
[f removeObjectIdenticalTo: [NSArray class]];
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method -removeObjectAtIndex: 2\n");
|
||||
[f removeObjectAtIndex: 2];
|
||||
|
||||
enumerator = [f objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method -removeObjectsFromIndices: {7,4,1,3,5,0,6} "
|
||||
"numIndices: 6\n");
|
||||
enumerator = [g objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
[g removeObjectsFromIndices: ind numIndices: 7];
|
||||
enumerator = [g objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
if ([f isEqualToArray: g])
|
||||
printf("Remove methods worked properly\n");
|
||||
else
|
||||
printf("Error: remove methods failed\n");
|
||||
|
||||
printf("Method -removeObjectsInArray:\n");
|
||||
printf("Receiver array\n");
|
||||
enumerator = [h objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
printf("Removing objects in this array\n");
|
||||
enumerator = [c objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
[h removeObjectsInArray: c];
|
||||
|
||||
printf("Array count is %d\n", [h count]);
|
||||
if ([h count] != 1)
|
||||
printf("Error: count != 1\n");
|
||||
|
||||
printf("%s", [[h objectAtIndex: 0] cString]);
|
||||
if ([[h objectAtIndex: 0] isEqual: s])
|
||||
printf("-removeObjectsInArray: worked correctly\n");
|
||||
else
|
||||
printf("Error: object in array is not correct\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Replacing objects
|
||||
c = [[c mutableCopy] autorelease];
|
||||
printf("Method -replaceObjectAtIndex: 2 withObject:[NSString class]\n");
|
||||
enumerator = [c objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
[c replaceObjectAtIndex: 2 withObject:[NSString class]];
|
||||
enumerator = [c objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
|
||||
printf("Method -setArray:\n");
|
||||
[h setArray: f];
|
||||
enumerator = [h objectEnumerator];
|
||||
while ((i = [enumerator nextObject]))
|
||||
printf("%s ", [[i description] cString]);
|
||||
printf("\n");
|
||||
if ([h isEqualToArray: h])
|
||||
printf("-setArray worked properly\n");
|
||||
else
|
||||
printf("Error: array is incorrect\n");
|
||||
}
|
||||
|
||||
{
|
||||
// Sorting Elements
|
||||
//[ sortUsingFunction: context:];
|
||||
//[ sortUsingSelector:];
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
test.m
|
||||
|
||||
Test NSAttributedString and NSMutableAttributedString classes
|
||||
|
||||
Copyright (C) 1997 Free Software Foundation, Inc.
|
||||
|
||||
Written by: ANOQ of the sun <anoq@vip.cybercity.dk>
|
||||
Date: June 1997
|
||||
|
||||
This file 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.
|
||||
|
||||
This file 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 file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSAttributedString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// These are normally defined in the AppKit
|
||||
NSString *NSFontAttributeName = @"NSFont";
|
||||
NSString *NSForegroundColorAttributeName = @"NSForegroundColor";
|
||||
NSString *NSBackgroundColorAttributeName = @"NSBackgroundColor";
|
||||
|
||||
void printAttrString(NSAttributedString *attrStr)
|
||||
{
|
||||
#if 0
|
||||
NSDictionary *tmpAttrDict;
|
||||
NSEnumerator *keyEnumerator;
|
||||
NSString *tmpStr;
|
||||
NSRange effectiveRange;
|
||||
unsigned int tmpLength;
|
||||
|
||||
effectiveRange = NSMakeRange(0,0);
|
||||
tmpLength = [attrStr length];
|
||||
puts("Attributed string looks like this:");
|
||||
while (NSMaxRange(effectiveRange) < tmpLength)
|
||||
{
|
||||
tmpAttrDict = [attrStr attributesAtIndex:NSMaxRange(effectiveRange)
|
||||
effectiveRange:&effectiveRange];
|
||||
printf("String: %s attributes: ",[[attrStr string] cString]);
|
||||
keyEnumerator = [tmpAttrDict keyEnumerator];
|
||||
while ((tmpStr = [keyEnumerator nextObject]))
|
||||
printf("%s ",[tmpStr cString]);
|
||||
printf("location: %ld length: %ld\n",
|
||||
(long)effectiveRange.location,
|
||||
(long)effectiveRange.length);
|
||||
}
|
||||
#else
|
||||
printf("%s\n", [[attrStr description] cString]);
|
||||
#endif
|
||||
}
|
||||
|
||||
void testAttributedString(void)
|
||||
{
|
||||
NSAttributedString *attrString;
|
||||
NSMutableAttributedString *muAttrString,*muAttrString2;
|
||||
NSMutableDictionary *attributes,*colorAttributes,*twoAttributes;
|
||||
NSMutableAttributedString *text;
|
||||
|
||||
text = [[NSMutableAttributedString alloc] initWithString: @"this is a bug"];
|
||||
[text addAttribute: @"foo" value: @"bar" range: NSMakeRange(0,4)];
|
||||
[text deleteCharactersInRange: NSMakeRange(0,1)];
|
||||
[text attribute: @"foo" atIndex: 0 effectiveRange: 0];
|
||||
|
||||
attributes = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
[attributes setObject:@"Helvetica 12-point"
|
||||
forKey:NSFontAttributeName];
|
||||
colorAttributes = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
[colorAttributes setObject:@"black NSColor"
|
||||
forKey:NSForegroundColorAttributeName];
|
||||
twoAttributes = [[[NSMutableDictionary alloc] init] autorelease];
|
||||
[twoAttributes addEntriesFromDictionary:attributes];
|
||||
[twoAttributes setObject:@"red NSColor"
|
||||
forKey:NSBackgroundColorAttributeName];
|
||||
|
||||
attrString = [[NSAttributedString alloc]
|
||||
initWithString:@"Attributed string test"
|
||||
attributes:twoAttributes];
|
||||
[attrString autorelease];
|
||||
printAttrString(attrString);
|
||||
|
||||
muAttrString = [[NSMutableAttributedString alloc]
|
||||
initWithString:@"Testing the Mutable version"
|
||||
attributes:colorAttributes];
|
||||
[muAttrString autorelease];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString addAttribute:NSFontAttributeName value: @"Helvetica 12-point"
|
||||
range:NSMakeRange(2,4)];
|
||||
printAttrString(muAttrString);
|
||||
/*
|
||||
[muAttrString setAttributes:attributes
|
||||
range:NSMakeRange(2,4)];
|
||||
printAttrString(muAttrString);
|
||||
*/
|
||||
|
||||
[muAttrString setAttributes:attributes
|
||||
range:NSMakeRange(8,16)];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString addAttributes:colorAttributes
|
||||
range:NSMakeRange(5,12)];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
muAttrString2 = [muAttrString mutableCopy];
|
||||
printAttrString(muAttrString2);
|
||||
|
||||
[muAttrString replaceCharactersInRange:NSMakeRange(5,15)
|
||||
withAttributedString:attrString];
|
||||
printAttrString(muAttrString);
|
||||
|
||||
[muAttrString2 replaceCharactersInRange:NSMakeRange(15,5)
|
||||
withAttributedString:attrString];
|
||||
printAttrString(muAttrString2);
|
||||
|
||||
printAttrString([muAttrString2 attributedSubstringFromRange:NSMakeRange(10,7)]);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
testAttributedString();
|
||||
[arp release];
|
||||
exit(0);
|
||||
}
|
|
@ -1,139 +0,0 @@
|
|||
/* nsbundle - Program to test out dynamic linking via NSBundle.
|
||||
Copyright (C) 1993,1994,1995, 1996 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
||||
Date: Jul 1995
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
*/
|
||||
#ifndef __MINGW32__
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#include "Foundation/NSArray.h"
|
||||
#include "Foundation/NSBundle.h"
|
||||
#include "Foundation/NSDictionary.h"
|
||||
#include "Foundation/NSException.h"
|
||||
#include "Foundation/NSString.h"
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include "LoadMe.h"
|
||||
#include "SecondClass.h"
|
||||
#include "MyCategory.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[], char **env)
|
||||
{
|
||||
NSBundle *bundle;
|
||||
NSString *path;
|
||||
id object;
|
||||
NSAutoreleasePool *arp;
|
||||
|
||||
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
|
||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||
#endif
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
setbuf(stdout, 0);
|
||||
/* Test bundle version and info files */
|
||||
bundle = [NSBundle bundleForLibrary: @"gnustep-base"];
|
||||
GSPrintf(stdout, @" GNUstep Base Resources: %@\n", [bundle bundlePath]);
|
||||
object = [bundle infoDictionary];
|
||||
GSPrintf(stdout, @" gnustep-base version string = %@\n",
|
||||
[object objectForKey: @"GSBundleShortVersionString"]);
|
||||
GSPrintf(stdout, @" gnustep-base version number = %g\n\n",
|
||||
[[object objectForKey: @"GSBundleVersion"] doubleValue]);
|
||||
|
||||
|
||||
path = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0];
|
||||
printf(" Executable is in %s\n", [path cString]);
|
||||
path = [NSBundle _absolutePathOfExecutable: path];
|
||||
if (!path) {
|
||||
fprintf(stdout, "* ERROR: Can't find executable\n");
|
||||
exit(1);
|
||||
}
|
||||
printf(" Full directory is %s\n", [path cString]);
|
||||
|
||||
printf("Looking for LoadMe bundle...\n");
|
||||
path = [path stringByDeletingLastPathComponent];
|
||||
path = [path stringByDeletingLastPathComponent];
|
||||
if ([[path lastPathComponent] isEqualToString:@"Testing"] == NO)
|
||||
{
|
||||
/* Delete library combo */
|
||||
path = [path stringByDeletingLastPathComponent];
|
||||
path = [path stringByDeletingLastPathComponent];
|
||||
path = [path stringByDeletingLastPathComponent];
|
||||
}
|
||||
printf(" Bundle directory is %s\n", [path cString]);
|
||||
path = [NSBundle pathForResource:@"LoadMe" ofType:@"bundle"
|
||||
inDirectory: path];
|
||||
if (!path) {
|
||||
fprintf(stdout, "* ERROR: Can't find LoadMe bundle\n");
|
||||
exit(1);
|
||||
}
|
||||
printf(" Found LoadMe in: %s\n\n", [path cString]);
|
||||
|
||||
printf("Initializing LoadMe bundle...\n");
|
||||
bundle = [[NSBundle alloc] initWithPath:path];
|
||||
if (!bundle) {
|
||||
fprintf(stdout, "* ERROR: Can't init LoadMe bundle\n");
|
||||
exit(1);
|
||||
}
|
||||
path = [bundle pathForResource:@"NXStringTable" ofType:@"example"];
|
||||
if (!path) {
|
||||
fprintf(stdout, "* ERROR: Can't find example in LoadMe bundle\n");
|
||||
exit(1);
|
||||
}
|
||||
printf(" Found example file: %s\n\n", [path cString]);
|
||||
|
||||
printf("Retreiving principal class...\n");
|
||||
NS_DURING
|
||||
object = [bundle principalClass];
|
||||
NS_HANDLER
|
||||
object = nil;
|
||||
fprintf(stdout, " ERROR: %s\n", [[localException reason] cString]);
|
||||
fprintf(stdout, " Either there is a problem with dynamic loading,\n");
|
||||
fprintf(stdout, " or there is no dynamic loader on your system\n");
|
||||
exit(1);
|
||||
NS_ENDHANDLER
|
||||
if (!object)
|
||||
{
|
||||
printf("* ERROR: Can't find principal class\n");
|
||||
}
|
||||
else
|
||||
printf(" Principal class is: %s\n", GSClassNameFromObject(object));
|
||||
|
||||
printf("Testing LoadMe bundle classes...\n");
|
||||
printf(" This is LoadMe:\n");
|
||||
object = [[[bundle classNamed:@"LoadMe"] alloc] init];
|
||||
if (!object)
|
||||
{
|
||||
printf("* ERROR: Can't find LoadMe class\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
[object afterLoad];
|
||||
[object release];
|
||||
}
|
||||
|
||||
printf("\n This is SecondClass:\n");
|
||||
object = [[[bundle classNamed:@"SecondClass"] alloc] init];
|
||||
if (!object)
|
||||
{
|
||||
printf("* ERROR: Can't find SecondClass class\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
[object printName];
|
||||
[object printMyName];
|
||||
[object release];
|
||||
}
|
||||
|
||||
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSCharacterSet *alpha = [NSCharacterSet alphanumericCharacterSet];
|
||||
|
||||
if (alpha)
|
||||
printf("obtained alphanumeric character set\n");
|
||||
else
|
||||
printf("unable to obtain alphanumeric character set\n");
|
||||
|
||||
[arp release];
|
||||
exit(0);
|
||||
}
|
486
Testing/nsdata.m
486
Testing/nsdata.m
|
@ -1,486 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSRange.h>
|
||||
#include <Foundation/NSSerialization.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
/******************************************************************************
|
||||
* Module : NSMutableData(NSData) --- Black Box test module for the
|
||||
* *Data classes to make sure that methods that raise exceptions
|
||||
* do so, and that the exceptions are raised properly.
|
||||
*
|
||||
* Author : John W. M. Stevens
|
||||
|
||||
...............................................................................
|
||||
15 April 1997
|
||||
|
||||
******************************************************************************/
|
||||
|
||||
/* Data for stuffing into *Data objects. I like printable data, as it
|
||||
* gives a quick visual check mechanism, but it has the disadvantage
|
||||
* of not checking for 8 bit cleanliness.
|
||||
*/
|
||||
char *testString = "Test string for mutable data and archiver classes.";
|
||||
char *subString = "Sub String";
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
| Routine : TestNSMutableData() --- Create an instance of an NSMutableData
|
||||
| class, initialize it with a C string (to have something
|
||||
| printable for tests) and invoke the two methods that
|
||||
| should raise NSRangeException exceptions using ranges that
|
||||
| cross both edges of the buffer boundary.
|
||||
|
|
||||
| Notes : Please see work logs for discussion.
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
TestNSMutableData(void)
|
||||
{
|
||||
auto NSMutableData *nsMutData;
|
||||
auto char *str;
|
||||
auto NSRange range;
|
||||
|
||||
/* Allocate and initialize an instance of an NSMutableData
|
||||
* class.
|
||||
*/
|
||||
nsMutData = [NSMutableData dataWithLength: strlen( testString ) + 1];
|
||||
str = (char *) [nsMutData mutableBytes];
|
||||
strcpy(str, testString);
|
||||
|
||||
/* Get contents, display. */
|
||||
str = NULL;
|
||||
str = (char *) [nsMutData mutableBytes];
|
||||
printf("NSMutableData Test ---------------------------------------------"
|
||||
"---------------\n"
|
||||
"1) String: (%s)\n", str);
|
||||
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
range = NSMakeRange(-2, strlen( subString ));
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about a length that is less than zero? */
|
||||
NS_DURING
|
||||
range = NSMakeRange(6, -3.0);
|
||||
[nsMutData replaceBytesInRange: range
|
||||
withBytes : subString ];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
range = NSMakeRange(-2, strlen( subString ));
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about a length less than zero? */
|
||||
NS_DURING
|
||||
range = NSMakeRange(6.0, -3.0);
|
||||
[nsMutData resetBytesInRange: range];
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Get contents, display. */
|
||||
str = NULL;
|
||||
str = (char *) [nsMutData mutableBytes];
|
||||
printf("2) String: (%s)\n", str);
|
||||
|
||||
/* Attempt to force an out of memory exception. */
|
||||
#if 0
|
||||
for ( ; ; )
|
||||
{
|
||||
/* Append. */
|
||||
[nsMutData appendBytes: testString
|
||||
length : strlen( testString ) + 1];
|
||||
|
||||
/* Show current value. */
|
||||
printf("%9u\r", [nsMutData length]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
| Routine : TestNSData() --- Create an instance of an NSData
|
||||
| class, initialize it with a C string (to have something
|
||||
| printable for tests) and invoke the two methods that
|
||||
| should raise NSRangeException exceptions using ranges that
|
||||
| cross both edges of the buffer boundary.
|
||||
|
|
||||
| Notes : Please see work logs for discussion.
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
TestNSData(void)
|
||||
{
|
||||
auto NSData *nsData;
|
||||
auto NSData *newNsData;
|
||||
auto char *str;
|
||||
auto char bfr[128];
|
||||
auto NSRange range;
|
||||
|
||||
/* Allocate and initialize an instance of an NSData
|
||||
* class.
|
||||
*/
|
||||
nsData = [NSData dataWithBytes: testString
|
||||
length : (unsigned int) strlen( testString ) + 1];
|
||||
|
||||
/* Get contents, display. */
|
||||
str = (char *) [nsData bytes];
|
||||
printf("NSData Test ----------------------------------------------------"
|
||||
"---------------\n"
|
||||
"1) String: (%s)\n", str);
|
||||
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(-2.0, 6.0);
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[6] = '\0';
|
||||
printf(" A) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
/* Get piece. */
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" B) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" C) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about less than zero length? */
|
||||
NS_DURING
|
||||
range = NSMakeRange(5.0, -4.0);
|
||||
[nsData getBytes: bfr
|
||||
range : range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" C) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/*=================== subDataWithRange ======================================*/
|
||||
/* Attempt to force Range exception by having range start before
|
||||
* zero.
|
||||
*/
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(-2.0, 6.0);
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[6] = '\0';
|
||||
printf(" D) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(41, strlen( subString ));
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" E) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Attempt to force another Range exception. */
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(42, strlen( subString ));
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" F) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* How about a length less than zero? */
|
||||
NS_DURING
|
||||
/* Get buffer piece. */
|
||||
range = NSMakeRange(9.0, -6.0);
|
||||
newNsData = [nsData subdataWithRange: range];
|
||||
|
||||
/* Print buffer piece. */
|
||||
[newNsData getBytes: bfr];
|
||||
bfr[strlen( subString )] = '\0';
|
||||
printf(" F) Buffer: (%s)\n", bfr);
|
||||
NS_HANDLER
|
||||
fprintf(stderr,
|
||||
"%s %d : Exception %s - %s\n",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
[[localException name] cString],
|
||||
[[localException reason] cString]);
|
||||
NS_ENDHANDLER
|
||||
|
||||
/* Get contents, display. */
|
||||
str = NULL;
|
||||
str = (char *) [nsData bytes];
|
||||
printf("2) String: (%s)\n", str);
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
id a;
|
||||
id d;
|
||||
id o;
|
||||
id pool;
|
||||
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
d = [NSData dataWithContentsOfMappedFile:@"nsdata.m"];
|
||||
if (d == nil)
|
||||
printf("Unable to map file");
|
||||
printf("Mapped %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
d = [NSData dataWithContentsOfFile:@"nsdata.m"];
|
||||
if (d == nil)
|
||||
printf("Unable to read file");
|
||||
printf("Read %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
d = [NSData dataWithSharedBytes: [d bytes] length: [d length]];
|
||||
if (d == nil)
|
||||
printf("Unable to make shared data");
|
||||
printf("Shared data of %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
d = [NSMutableData dataWithSharedBytes: [d bytes] length: [d length]];
|
||||
if (d == nil)
|
||||
printf("Unable to make mutable shared data");
|
||||
printf("Mutable shared data of %d bytes\n", [d length]);
|
||||
|
||||
o = [d copy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
o = [d mutableCopy];
|
||||
printf("Copied %d bytes\n", [o length]);
|
||||
[o release];
|
||||
|
||||
[d appendBytes: "Hello world" length: 11];
|
||||
printf("Extended by 11 bytes to %d bytes\n", [d length]);
|
||||
|
||||
d = [NSMutableData dataWithShmID: [d shmID] length: [d length]];
|
||||
if (d == nil)
|
||||
printf("Unable to make mutable data with old ID\n");
|
||||
printf("data with shmID gives data length %d\n", [d length]);
|
||||
|
||||
a = [[NSArchiver new] autorelease];
|
||||
[a encodeRootObject: d];
|
||||
printf("Encoded data into archive\n");
|
||||
a = [[NSUnarchiver alloc] initForReadingWithData: [a archiverData]];
|
||||
o = [a decodeObject];
|
||||
printf("Decoded data from archive - length %d\n", [o length]);
|
||||
[a release];
|
||||
|
||||
[d setCapacity: 2000000];
|
||||
printf("Set capacity of shared memory item to %d\n", [d capacity]);
|
||||
|
||||
/* Test NSMutableData. */
|
||||
TestNSMutableData();
|
||||
|
||||
/* Test NSData. */
|
||||
TestNSData();
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
347
Testing/nsdate.m
347
Testing/nsdate.m
|
@ -1,347 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSCalendarDate.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSTimeZone.h>
|
||||
|
||||
#ifdef __MS_WIN32__
|
||||
int _MB_init_runtime()
|
||||
{
|
||||
libobjc_init_runtime();
|
||||
gnustep_base_init_runtime();
|
||||
nsdate_init_runtime();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DESCRIP(obj) [obj description]
|
||||
#define DESCRIP_FORMAT(obj) [obj descriptionWithCalendarFormat: nil]
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
id a, b, c, e; /* dates */
|
||||
id pool;
|
||||
|
||||
//behavior_set_debug(0);
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
NSLog(@"%@", [NSCalendarDate distantFuture]);
|
||||
NSLog(@"%@", [NSCalendarDate distantPast]);
|
||||
NSLog(@"%@", [NSCalendarDate dateWithNaturalLanguageString: @"01-08-2002 00:00:00"]);
|
||||
NSLog(@"%@", [NSCalendarDate dateWithNaturalLanguageString: @"31-08-2002 23:59:59"]);
|
||||
|
||||
if ([(NSDate*) [NSCalendarDate date] compare:
|
||||
[NSCalendarDate dateWithString:@"Feb 2 00:00:00 2001"
|
||||
calendarFormat:@"%b %d %H:%M:%S %Y"]] == NSOrderedDescending) {
|
||||
|
||||
NSLog(@"This version of the PostgreSQL Adaptor will expire soon.\nVisit ¬http://www.turbocat.de/ to learn how to get a new one.");
|
||||
}
|
||||
|
||||
// NSDate tests
|
||||
printf("NSDate tests\n");
|
||||
{
|
||||
// Create NSDate instances
|
||||
a = [NSDate date];
|
||||
printf("+[date] -- %s\n", [DESCRIP(a) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceNow: 0];
|
||||
printf("+[dateWithTimeIntervalSinceNow: 0] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceNow: 600];
|
||||
printf("+[dateWithTimeIntervalSinceNow: 600] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSince1970: 0];
|
||||
printf("+[dateWithTimeIntervalSince1970: 0] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSince1970: -600];
|
||||
printf("+[dateWithTimeIntervalSince1970: -600] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceReferenceDate: 0];
|
||||
printf("+[dateWithTimeIntervalSinceReferenceDate: 0] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceReferenceDate: 300];
|
||||
printf("+[dateWithTimeIntervalSinceReferenceDate: 300] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
b = [NSDate dateWithTimeIntervalSinceNow: 24*60*40];
|
||||
printf("+[dateWithTimeIntervalSinceNow: 0] -- %s\n",
|
||||
[DESCRIP(b) cString]);
|
||||
|
||||
// Comparisons
|
||||
|
||||
if ([a compare: [NSDate distantFuture]] == NSOrderedAscending)
|
||||
printf("Current date is before distantFuture\n");
|
||||
else
|
||||
printf("ERROR: Current date is *not* before distantFuture\n");
|
||||
|
||||
if ([a compare: [NSDate distantPast]] == NSOrderedDescending)
|
||||
printf("Current date is after distantPast\n");
|
||||
else
|
||||
printf("ERROR: Current date is *not* after distantPast\n");
|
||||
|
||||
c = [a earlierDate: b];
|
||||
if (c == a)
|
||||
printf("%s is earlier than %s\n", [DESCRIP(a) cString],
|
||||
[DESCRIP(b) cString]);
|
||||
else
|
||||
printf("ERROR: %s is not earlier than %s\n", [DESCRIP(a) cString],
|
||||
[DESCRIP(b) cString]);
|
||||
|
||||
c = [a laterDate: b];
|
||||
if (c == b)
|
||||
printf("%s is later than %s\n", [DESCRIP(b) cString],
|
||||
[DESCRIP(a) cString]);
|
||||
else
|
||||
printf("ERROR: %s is not later than %s\n", [DESCRIP(b) cString],
|
||||
[DESCRIP(a) cString]);
|
||||
}
|
||||
|
||||
// NSCalendarDate tests
|
||||
printf("NSCalendarDate tests\n");
|
||||
{
|
||||
NSCalendarDate *c1;
|
||||
NSTimeZone *gb = [NSTimeZone timeZoneWithName: @"GB"];
|
||||
int m, y, d, a;
|
||||
|
||||
// Create an NSCalendarDate with current date and time
|
||||
c = [NSCalendarDate calendarDate];
|
||||
printf("+[calendarDate] -- %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
printf("-[dayOfMonth] %d\n", [c dayOfMonth]);
|
||||
printf("-[dayOfWeek] %d\n", [c dayOfWeek]);
|
||||
printf("-[dayOfYear] %d\n", [c dayOfYear]);
|
||||
printf("-[hourOfDay] %d\n", [c hourOfDay]);
|
||||
printf("-[monthOfYear] %d\n", [c monthOfYear]);
|
||||
printf("-[yearOfCommonEra] %d\n", [c yearOfCommonEra]);
|
||||
|
||||
a = [c absoluteGregorianDay: 9 month: 10 year: 1996];
|
||||
printf("%d-%d-%d is Gregorian absolute %d\n", 9, 10, 1996, a);
|
||||
printf("-[dayOfCommonEra] %d\n", [c dayOfCommonEra]);
|
||||
printf("-[timeIntervalSinceReferenceDate] %f\n",
|
||||
[c timeIntervalSinceReferenceDate]);
|
||||
|
||||
a = [c absoluteGregorianDay: 1 month: 1 year: 2001];
|
||||
printf("%d-%d-%d is Gregorian absolute %d\n", 1, 1, 2001, a);
|
||||
[c gregorianDateFromAbsolute: a day: &d month: &m year: &y];
|
||||
printf("Gregorian absolute %d is %d-%d-%d\n", a, d, m, y);
|
||||
|
||||
c = [NSCalendarDate dateWithString: @"1996-10-09 0:00:01"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("calendar date %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
printf("-[dayOfCommonEra] %d\n", [c dayOfCommonEra]);
|
||||
printf("-[dayOfMonth] %d\n", [c dayOfMonth]);
|
||||
printf("-[dayOfWeek] %d\n", [c dayOfWeek]);
|
||||
printf("-[dayOfYear] %d\n", [c dayOfYear]);
|
||||
printf("-[hourOfDay] %d\n", [c hourOfDay]);
|
||||
printf("-[minuteOfHour] %d\n", [c minuteOfHour]);
|
||||
printf("-[monthOfYear] %d\n", [c monthOfYear]);
|
||||
printf("-[secondOfMinute] %d\n", [c secondOfMinute]);
|
||||
printf("-[yearOfCommonEra] %d\n", [c yearOfCommonEra]);
|
||||
printf("-[timeIntervalSinceReferenceDate] %f\n",
|
||||
[c timeIntervalSinceReferenceDate]);
|
||||
e = [NSCalendarDate dateWithString: @"1996-10-09 0:00:0"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("calendar date %s\n", [[e description] cString]);
|
||||
printf("-[timeIntervalSinceReferenceDate] %f\n",
|
||||
[e timeIntervalSinceReferenceDate]);
|
||||
printf("NSCalendrical time tests\n");
|
||||
{
|
||||
NSCalendarDate *momsBDay = [NSCalendarDate dateWithYear:1936
|
||||
month:1 day:8 hour:7 minute:30 second:0
|
||||
timeZone:[NSTimeZone timeZoneWithName:@"EST"]];
|
||||
NSCalendarDate *dob = [NSCalendarDate dateWithYear:1965
|
||||
month:12 day:7 hour:17 minute:25 second:0
|
||||
timeZone:[NSTimeZone timeZoneWithName:@"EST"]];
|
||||
int years, months, days;
|
||||
|
||||
[dob years:&years months:&months days:&days hours:0
|
||||
minutes:0 seconds:0 sinceDate:momsBDay];
|
||||
printf("%d, %d, %d\n", years, months, days);
|
||||
[dob years:0 months:&months days:&days hours:0
|
||||
minutes:0 seconds:0 sinceDate:momsBDay];
|
||||
printf("%d, %d\n", months, days);
|
||||
}
|
||||
|
||||
printf("\nY2K checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"1999-12-31 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
printf("YYYY-MM-DD %d-%d-%d\n", [c yearOfCommonEra], [c monthOfYear], [c dayOfMonth]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
printf("\nY2K is a leap year checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"2000-2-28 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:5 minute:0 second:0];
|
||||
printf("Add five hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:1 month:0 day:0 hour:0 minute:0 second:0];
|
||||
printf("Add one year - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:-1 hour:0 minute:0 second:0];
|
||||
printf("Subtract one day - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:1 month:0 day:1 hour:0 minute:0 second:0];
|
||||
printf("Add a year and a day - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
printf("\n2004 is a leap year checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"2004-2-28 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
printf("\n2100 is NOT a leap year checks\n");
|
||||
c = [NSCalendarDate dateWithString: @"2100-2-28 23:59:59"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add one second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:0 minute:0 second:1];
|
||||
printf("Add another second - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
c = [NSCalendarDate dateWithString: @"2002-03-31 00:30:00 GB"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
|
||||
printf("\nSavings time begins at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-1 minute:0 second:0];
|
||||
printf("Subtract an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:2 minute:0 second:0];
|
||||
printf("Add two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:3 minute:0 second:0];
|
||||
printf("Add three hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-4 minute:0 second:0];
|
||||
printf("Subtract four hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:3 minute:0 second:0];
|
||||
printf("Add three hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-4 minute:0 second:0];
|
||||
printf("Subtract four hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:4 minute:0 second:0];
|
||||
printf("Add four hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-24 minute:0 second:0];
|
||||
printf("Subtract twentyfour hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:24 minute:0 second:0];
|
||||
printf("Add twentyfour hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:-1 hour:0 minute:0 second:0];
|
||||
printf("Subtract a day - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
c = [NSCalendarDate dateWithString: @"2002-10-27 00:30:00 GB"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
|
||||
printf("\nSavings time ends at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:1 minute:0 second:0];
|
||||
printf("Add an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-1 minute:0 second:0];
|
||||
printf("Subtract an hour - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:2 minute:0 second:0];
|
||||
printf("Add two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-2 minute:0 second:0];
|
||||
printf("Subtract two hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:3 minute:0 second:0];
|
||||
printf("Add three hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-4 minute:0 second:0];
|
||||
printf("Subtract four hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:3 minute:0 second:0];
|
||||
printf("Add three hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-4 minute:0 second:0];
|
||||
printf("Subtract four hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:4 minute:0 second:0];
|
||||
printf("Add four hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c = [c addYear:0 month:0 day:0 hour:-24 minute:0 second:0];
|
||||
printf("Subtract twentyfour hours - %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
|
||||
c = [NSCalendarDate dateWithYear: 2002 month: 3 day: 31 hour: 1 minute: 30 second: 0 timeZone: gb];
|
||||
printf("Build at %s\n", [[c description] cString]);
|
||||
|
||||
c = [NSCalendarDate dateWithString: @"2002-09-27 01:59:00"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S"];
|
||||
printf("Start at %s\n", [DESCRIP_FORMAT(c) cString]);
|
||||
c1 = [c dateByAddingYears: 0
|
||||
months: 0
|
||||
days: -180
|
||||
hours: 0
|
||||
minutes: 0
|
||||
seconds: 0];
|
||||
printf("Subtract 180 %s\n", [DESCRIP_FORMAT(c1) cString]);
|
||||
|
||||
printf("Week of year tests ... ");
|
||||
if ([[NSCalendarDate dateWithYear: 2002 month: 12 day: 29 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 52)
|
||||
printf("Failed on 2002/12/29 is week 52\n");
|
||||
if ([[NSCalendarDate dateWithYear: 2002 month: 12 day: 30 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2002/12/30 is week 1\n");
|
||||
if ([[NSCalendarDate dateWithYear: 2002 month: 12 day: 31 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2002/12/31 is week 1\n");
|
||||
if ([[NSCalendarDate dateWithYear: 2003 month: 1 day: 1 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2003/01/01 is week 1\n");
|
||||
else if ([[NSCalendarDate dateWithYear: 2003 month: 1 day: 2 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2003/01/02 is week 1\n");
|
||||
else if ([[NSCalendarDate dateWithYear: 2003 month: 1 day: 3 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2003/01/03 is week 1\n");
|
||||
else if ([[NSCalendarDate dateWithYear: 2003 month: 1 day: 4 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2003/01/04 is week 1\n");
|
||||
else if ([[NSCalendarDate dateWithYear: 2003 month: 1 day: 5 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 1)
|
||||
printf("Failed on 2003/01/05 is week 1\n");
|
||||
else if ([[NSCalendarDate dateWithYear: 2003 month: 1 day: 6 hour: 0
|
||||
minute: 0 second: 0 timeZone: gb] weekOfYear] != 2)
|
||||
printf("Failed on 2003/01/06 is week 2\n");
|
||||
else
|
||||
printf("All passed\n");
|
||||
|
||||
|
||||
c = [NSCalendarDate dateWithString: @"2004-05-30 00:30:00 HPT"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
|
||||
c1 = [NSCalendarDate dateWithString: @"2004-05-30 00:30:00 HST"
|
||||
calendarFormat: @"%Y-%m-%d %H:%M:%S %Z"];
|
||||
printf("date with time zone abbr %s\n", [[c description] cString]);
|
||||
if ([c isEqual: c1])
|
||||
printf("Passed date with time zone abbreviation\n");
|
||||
else
|
||||
printf("Failed date with time zone abbreviation\n");
|
||||
|
||||
}
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,208 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <assert.h>
|
||||
|
||||
int
|
||||
main(int argc, char** argv, char** envp)
|
||||
{
|
||||
NSString *strs[100000];
|
||||
NSMutableDictionary *dict;
|
||||
NSDate *when;
|
||||
int i, j;
|
||||
NSAutoreleasePool *arp;
|
||||
id a, b; /* dictionaries */
|
||||
id enumerator;
|
||||
id objects, keys;
|
||||
id key;
|
||||
BOOL ok;
|
||||
id o1, o2, o3, o4, o5, o6;
|
||||
NSMutableDictionary *d1, *d2;
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
o1 = [[NSNumber numberWithInt:1] stringValue];
|
||||
o2 = [[NSNumber numberWithInt:2] stringValue];
|
||||
o3 = [[NSNumber numberWithInt:3] stringValue];
|
||||
o4 = [[NSNumber numberWithInt:4] stringValue];
|
||||
o5 = [[NSNumber numberWithInt:5] stringValue];
|
||||
o6 = [[NSNumber numberWithInt:6] stringValue];
|
||||
|
||||
d1 = [[NSMutableDictionary new] autorelease];
|
||||
[d1 setObject:o1 forKey:o1];
|
||||
[d1 setObject:o2 forKey:o2];
|
||||
[d1 setObject:o3 forKey:o3];
|
||||
|
||||
d2 = [[NSMutableDictionary new] autorelease];
|
||||
[d2 setObject:o4 forKey:o4];
|
||||
[d2 setObject:o5 forKey:o5];
|
||||
[d2 setObject:o6 forKey:o6];
|
||||
|
||||
[d1 addEntriesFromDictionary: d2];
|
||||
|
||||
enumerator = [d1 objectEnumerator];
|
||||
while ((b = [enumerator nextObject]))
|
||||
printf("%s ", [b cString]);
|
||||
printf("\n");
|
||||
|
||||
//behavior_set_debug(0);
|
||||
|
||||
objects = [NSArray arrayWithObjects:
|
||||
@"vache", @"poisson", @"cheval", @"poulet", nil];
|
||||
keys = [NSArray arrayWithObjects:
|
||||
@"cow", @"fish", @"horse", @"chicken", nil];
|
||||
a = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
|
||||
b = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"vache",
|
||||
@"cow",
|
||||
@"poisson",
|
||||
@"fish",
|
||||
@"cheval",
|
||||
@"horse",
|
||||
@"poulet",
|
||||
@"chicken", nil];
|
||||
|
||||
printf("Match is %d\n", [a isEqual: b]);
|
||||
|
||||
printf("NSDictionary has count %d\n", [a count]);
|
||||
key = @"fish";
|
||||
printf("Object at key %s is %s\n",
|
||||
[key cString],
|
||||
[[a objectForKey:key] cString]);
|
||||
|
||||
assert([a count] == [[a allValues] count]);
|
||||
|
||||
enumerator = [a objectEnumerator];
|
||||
while ((b = [enumerator nextObject]))
|
||||
printf("%s ", [b cString]);
|
||||
printf("\n");
|
||||
|
||||
enumerator = [a keyEnumerator];
|
||||
while ((b = [enumerator nextObject]))
|
||||
printf("%s ", [b cString]);
|
||||
printf("\n");
|
||||
|
||||
b = [a mutableCopy];
|
||||
assert([b count]);
|
||||
|
||||
ok = [b isEqual: a];
|
||||
assert(ok);
|
||||
|
||||
[b setObject:@"formi" forKey:@"ant"];
|
||||
[b removeObjectForKey:@"horse"];
|
||||
|
||||
|
||||
when = [NSDate date];
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 100];
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
||||
[dict setObject: strs[i] forKey: strs[i]];
|
||||
}
|
||||
printf(" 10 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
printf("%s\n", [[[dict allKeys] description] cString]);
|
||||
|
||||
when = [NSDate date];
|
||||
for (i = 0; i < 100000; i++) {
|
||||
for (j = 0; j < 10; j++) {
|
||||
NSString *val = [dict objectForKey: strs[j]];
|
||||
}
|
||||
}
|
||||
printf(" 10 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
[arp release];
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
when = [NSDate date];
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 100];
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
||||
[dict setObject: strs[i] forKey: strs[i]];
|
||||
}
|
||||
printf(" 100 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
|
||||
when = [NSDate date];
|
||||
for (i = 0; i < 10000; i++) {
|
||||
for (j = 0; j < 100; j++) {
|
||||
NSString *val = [dict objectForKey: strs[j]];
|
||||
}
|
||||
}
|
||||
printf(" 100 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
[arp release];
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
when = [NSDate date];
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 1000];
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
||||
[dict setObject: strs[i] forKey: strs[i]];
|
||||
}
|
||||
printf(" 1000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
|
||||
when = [NSDate date];
|
||||
for (i = 0; i < 1000; i++) {
|
||||
for (j = 0; j < 1000; j++) {
|
||||
NSString *val = [dict objectForKey: strs[j]];
|
||||
}
|
||||
}
|
||||
printf(" 1000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
[arp release];
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
when = [NSDate date];
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 10000];
|
||||
for (i = 0; i < 10000; i++)
|
||||
{
|
||||
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
||||
[dict setObject: strs[i] forKey: strs[i]];
|
||||
}
|
||||
printf(" 10000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
|
||||
when = [NSDate date];
|
||||
for (i = 0; i < 100; i++) {
|
||||
for (j = 0; j < 10000; j++) {
|
||||
NSString *val = [dict objectForKey: strs[j]];
|
||||
}
|
||||
}
|
||||
printf(" 10000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
[arp release];
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
when = [NSDate date];
|
||||
dict = [NSMutableDictionary dictionaryWithCapacity: 100000];
|
||||
for (i = 0; i < 100000; i++)
|
||||
{
|
||||
strs[i] = [NSString stringWithFormat: @"Dictkey-%d", i];
|
||||
[dict setObject: strs[i] forKey: strs[i]];
|
||||
}
|
||||
printf("100000 creation: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
|
||||
when = [NSDate date];
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (j = 0; j < 100000; j++) {
|
||||
NSString *val = [dict objectForKey: strs[j]];
|
||||
}
|
||||
}
|
||||
printf("100000 For: %f\n", [[NSDate date] timeIntervalSinceDate: when]);
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSFileHandle.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
#include <assert.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
id pool;
|
||||
id src;
|
||||
id dst;
|
||||
id d0;
|
||||
id d1;
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
dst = [[NSFileHandle fileHandleForWritingAtPath:@"nsfilehandle.dat"] retain];
|
||||
if (dst == nil)
|
||||
{
|
||||
creat("nsfilehandle.dat", 0644);
|
||||
dst = [[NSFileHandle fileHandleForWritingAtPath:@"nsfilehandle.dat"] retain];
|
||||
src = [NSFileHandle fileHandleForReadingAtPath:@"nsfilehandle.dat"];
|
||||
NSLog(@"%@", [src readDataToEndOfFile]);
|
||||
}
|
||||
assert(dst != nil);
|
||||
|
||||
src = [[NSFileHandle fileHandleForReadingAtPath:@"nsfilehandle.m"] retain];
|
||||
assert(src != nil);
|
||||
|
||||
assert(src != nil);
|
||||
d0 = [[src readDataToEndOfFile] retain];
|
||||
[(NSFileHandle*)dst writeData: d0];
|
||||
[src release];
|
||||
[dst release];
|
||||
[pool release];
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
src = [[NSFileHandle fileHandleForReadingAtPath:@"nsfilehandle.dat"] retain];
|
||||
d1 = [[src readDataToEndOfFile] retain];
|
||||
[src release];
|
||||
[pool release];
|
||||
|
||||
unlink("nsfilehandle.dat");
|
||||
|
||||
if ([d0 isEqual:d1])
|
||||
printf("Test passed (length:%d)\n", [d1 length]);
|
||||
else
|
||||
printf("Test failed\n");
|
||||
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
src = [NSURL URLWithString: @"http://www.w3.org/index.html"];
|
||||
d0 = [src resourceDataUsingCache: NO];
|
||||
NSLog(@"Data is %@", d0);
|
||||
[pool release];
|
||||
|
||||
exit (0);
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
static int errors = 0;
|
||||
|
||||
@interface Handler : NSObject
|
||||
- (BOOL) fileManager: (NSFileManager*)manager
|
||||
shouldProceedAfterError: (NSString*)error;
|
||||
- (BOOL) fileManager: (NSFileManager*)manager
|
||||
willProcessPath: (NSString*)path;
|
||||
@end
|
||||
|
||||
@implementation Handler
|
||||
- (BOOL) fileManager: (NSFileManager*)manager
|
||||
shouldProceedAfterError: (NSString*)error
|
||||
{
|
||||
NSLog(@"Error - %@", error);
|
||||
errors++;
|
||||
return NO;
|
||||
}
|
||||
- (BOOL) fileManager: (NSFileManager*)manager
|
||||
willProcessPath: (NSString*)path
|
||||
{
|
||||
NSLog(@"Processing %@", path);
|
||||
errors++;
|
||||
return NO;
|
||||
}
|
||||
@end
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSString *src;
|
||||
NSString *dst;
|
||||
Handler *handler = AUTORELEASE([Handler new]);
|
||||
|
||||
src = [defs stringForKey: @"CopySrc"];
|
||||
dst = [defs objectForKey: @"CopyDst"];
|
||||
if (src != nil && dst != nil)
|
||||
{
|
||||
if ([mgr copyPath: src toPath: dst handler: handler] == NO)
|
||||
{
|
||||
NSLog(@"Copy %@ to %@ failed", src, dst);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
src = [defs stringForKey: @"LinkSrc"];
|
||||
dst = [defs objectForKey: @"LinkDst"];
|
||||
if (src != nil && dst != nil)
|
||||
{
|
||||
if ([mgr linkPath: src toPath: dst handler: handler] == NO)
|
||||
{
|
||||
NSLog(@"Link %@ to %@ failed", src, dst);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
src = [defs stringForKey: @"Remove"];
|
||||
if (src != nil)
|
||||
{
|
||||
if ([mgr removeFileAtPath: src handler: handler] == NO)
|
||||
{
|
||||
NSLog(@"Remove %@ failed", src);
|
||||
errors++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
NSDictionary *attributes = [mgr fileSystemAttributesAtPath: @"/"];
|
||||
NSNumber *freefs = [attributes objectForKey: NSFileSystemFreeSize];
|
||||
unsigned long long s = [freefs unsignedLongLongValue];
|
||||
|
||||
NSLog(@"Filesystem free size is %llu", s);
|
||||
}
|
||||
|
||||
NSLog(@"Home directory is %@", NSHomeDirectory());
|
||||
|
||||
RELEASE(arp);
|
||||
if (errors == 0)
|
||||
printf("Tests passed\n");
|
||||
exit (0);
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSHashTable.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
NSHashTable *ht;
|
||||
NSHashEnumerator he;
|
||||
int i;
|
||||
void *v;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
/* Test with ints */
|
||||
|
||||
ht = NSCreateHashTable (NSIntHashCallBacks, 0);
|
||||
|
||||
for (i = 1; i < 16; i++)
|
||||
NSHashInsert (ht, (void*)i);
|
||||
|
||||
NSHashRemove (ht, (void*)3);
|
||||
|
||||
he = NSEnumerateHashTable (ht);
|
||||
while ((v = NSNextHashEnumeratorItem (&he)))
|
||||
printf ("(%d) ", (int)v);
|
||||
printf ("\n");
|
||||
|
||||
NSFreeHashTable (ht);
|
||||
|
||||
|
||||
#if 0
|
||||
/* Test with NSNumber objects */
|
||||
|
||||
mt = NSCreateHashTable (NSObjectHashKeyCallBacks,
|
||||
NSObjectHashValueCallBacks,
|
||||
0);
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
NSHashInsert (mt,
|
||||
[NSNumber numberWithInt: i],
|
||||
[NSNumber numberWithInt: i*i]);
|
||||
|
||||
o = [NSNumber numberWithInt: 3];
|
||||
printf ("value for key %s is %s\n",
|
||||
[[o description] cString],
|
||||
[[(id)NSHashGet (mt, o) description] cString]);
|
||||
NSHashRemove (mt, o);
|
||||
printf ("after removing: value for key %s is %s\n",
|
||||
[[o description] cString],
|
||||
[[(id)NSHashGet (mt, o) description] cString]);
|
||||
|
||||
me = NSEnumerateHashTable (mt);
|
||||
while (NSNextHashEnumeratorPair (&me, &k, &v))
|
||||
printf ("(%d,%d) ", [(id)k intValue], [(id)v intValue]);
|
||||
printf ("\n");
|
||||
|
||||
NSFreeHashTable (mt);
|
||||
#endif
|
||||
|
||||
[arp release];
|
||||
exit (0);
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
// Fri Oct 23 03:02:52 MET DST 1998 dave@turbocat.de
|
||||
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSHost.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
void
|
||||
displayHost(NSHost* h)
|
||||
{
|
||||
NSArray* a;
|
||||
int i;
|
||||
|
||||
printf("\n");
|
||||
a = [h names];
|
||||
for (i = 0; i < [a count]; i++)
|
||||
printf("%s\n", [[a objectAtIndex:i] cString]);
|
||||
a = [h addresses];
|
||||
for (i = 0; i < [a count]; i++)
|
||||
printf("%s\n", [[a objectAtIndex:i] cString]);
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
NSHost* a;
|
||||
NSHost* c;
|
||||
NSHost* n;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
[NSAutoreleasePool enableDoubleReleaseCheck:YES];
|
||||
c = [NSHost currentHost];
|
||||
displayHost(c);
|
||||
n = [NSHost hostWithName:[c name]];
|
||||
displayHost(n);
|
||||
a = [NSHost hostWithAddress:[c address]];
|
||||
displayHost(a);
|
||||
|
||||
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
||||
printf("c isEqual: n ... %d\n", [c isEqual: n]);
|
||||
printf("n isEqual: c ... %d\n", [n isEqual: c]);
|
||||
printf("c isEqual: a ... %d\n", [c isEqual: a]);
|
||||
printf("a isEqual: c ... %d\n", [a isEqual: c]);
|
||||
printf("n isEqual: a ... %d\n", [n isEqual: a]);
|
||||
printf("a isEqual: n ... %d\n", [a isEqual: n]);
|
||||
|
||||
[NSHost setHostCacheEnabled:NO];
|
||||
|
||||
n = [NSHost hostWithName:[c name]];
|
||||
displayHost(n);
|
||||
printf("c:%lx, n:%lx, a:%lx\n", c, n, a);
|
||||
printf("c isEqual: n ... %d\n", [c isEqual: n]);
|
||||
printf("n isEqual: c ... %d\n", [n isEqual: c]);
|
||||
printf("c isEqual: a ... %d\n", [c isEqual: a]);
|
||||
printf("a isEqual: c ... %d\n", [a isEqual: c]);
|
||||
printf("n isEqual: a ... %d\n", [n isEqual: a]);
|
||||
printf("a isEqual: n ... %d\n", [a isEqual: n]);
|
||||
|
||||
[arp release];
|
||||
exit (0);
|
||||
}
|
|
@ -1,221 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSIndexSet *s;
|
||||
NSMutableIndexSet *m;
|
||||
NSMutableIndexSet *o;
|
||||
unsigned int buf[2];
|
||||
NSRange r;
|
||||
|
||||
printf("Can create empty set ...");
|
||||
s = [NSIndexSet indexSet];
|
||||
printf(" %s\n", s != nil ? "passed" : "failed");
|
||||
|
||||
printf("Empty set count is 0 ...");
|
||||
printf(" %s\n", [s count] == 0 ? "passed" : "failed");
|
||||
|
||||
printf("Empty set does not contain index 0 ...");
|
||||
printf(" %s\n", [s containsIndex: 0] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Empty set does not intersect indexes in range 0->NSNotFound-1 ...");
|
||||
printf(" %s\n", [s intersectsIndexesInRange: NSMakeRange(0,NSNotFound-1)] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Empty set first index is NSNotFound...");
|
||||
printf(" %s\n", [s firstIndex] == NSNotFound ? "passed" : "failed");
|
||||
|
||||
printf("Empty set last index is NSNotFound...");
|
||||
printf(" %s\n", [s lastIndex] == NSNotFound ? "passed" : "failed");
|
||||
|
||||
printf("Empty set index less than 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Empty set index less than or equal to 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanOrEqualToIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Empty set index greater than 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexGreaterThanIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Empty set index greater than or equal to 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexGreaterThanOrEqualToIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
|
||||
printf("Empty set getIndexes gives 0...");
|
||||
r = NSMakeRange(0, NSNotFound-1);
|
||||
printf(" %s\n", [s getIndexes: buf maxCount:3 inIndexRange: &r] == 0 ? "passed" : "failed");
|
||||
|
||||
|
||||
printf("Can create single index set with 2 ...");
|
||||
s = [NSIndexSet indexSetWithIndex: 2];
|
||||
printf(" %s\n", s != nil ? "passed" : "failed");
|
||||
|
||||
printf("Set count is 1 ...");
|
||||
printf(" %s\n", [s count] == 1 ? "passed" : "failed");
|
||||
|
||||
printf("Set does not contain index 0 ...");
|
||||
printf(" %s\n", [s containsIndex: 0] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Set contains index 2 ...");
|
||||
printf(" %s\n", [s containsIndex: 2] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Set intersects indexes in range 0->NSNotFound-1 ...");
|
||||
printf(" %s\n", [s intersectsIndexesInRange: NSMakeRange(0,NSNotFound-1)] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Set first index is 2...");
|
||||
printf(" %s\n", [s firstIndex] == 2 ? "passed" : "failed");
|
||||
|
||||
printf("Set last index is 2...");
|
||||
printf(" %s\n", [s lastIndex] == 2 ? "passed" : "failed");
|
||||
|
||||
printf("Set index less than 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index less than or equal to 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanOrEqualToIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index less than 2 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanIndex: 2] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index less than or equal to 2 is 2...");
|
||||
printf(" %s\n", [s indexLessThanOrEqualToIndex: 2] == 2 ? "passed" : "failed");
|
||||
printf("Set index greater than 1 is 2...");
|
||||
printf(" %s\n", [s indexGreaterThanIndex: 1] == 2 ? "passed" : "failed");
|
||||
printf("Set index greater than or equal to 1 is 2...");
|
||||
printf(" %s\n", [s indexGreaterThanOrEqualToIndex: 1] == 2 ? "passed" : "failed");
|
||||
printf("Set index greater than 2 is NSNotFound...");
|
||||
printf(" %s\n", [s indexGreaterThanIndex: 2] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index greater than or equal to 2 is 2...");
|
||||
printf(" %s\n", [s indexGreaterThanOrEqualToIndex: 2] == 2 ? "passed" : "failed");
|
||||
|
||||
printf("Set getIndexes gives 1...");
|
||||
r = NSMakeRange(0, NSNotFound-1);
|
||||
printf(" %s\n", [s getIndexes: buf maxCount:3 inIndexRange: &r] == 1 ? "passed" : "failed");
|
||||
|
||||
|
||||
printf("Can create multipe index set with range 2...5 ...");
|
||||
s = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(2,4)];
|
||||
printf(" %s\n", s != nil ? "passed" : "failed");
|
||||
|
||||
printf("Set count is 4 ...");
|
||||
printf(" %s\n", [s count] == 4 ? "passed" : "failed");
|
||||
|
||||
printf("Set does not contain index 0 ...");
|
||||
printf(" %s\n", [s containsIndex: 0] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Set contains index 2 ...");
|
||||
printf(" %s\n", [s containsIndex: 2] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Set contains index 5 ...");
|
||||
printf(" %s\n", [s containsIndex: 5] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Set intersects indexes in range 0->NSNotFound-1 ...");
|
||||
printf(" %s\n", [s intersectsIndexesInRange: NSMakeRange(0,NSNotFound-1)] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Set first index is 2...");
|
||||
printf(" %s\n", [s firstIndex] == 2 ? "passed" : "failed");
|
||||
|
||||
printf("Set last index is 5...");
|
||||
printf(" %s\n", [s lastIndex] == 5 ? "passed" : "failed");
|
||||
|
||||
printf("Set index less than 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index less than or equal to 1 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanOrEqualToIndex: 1] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index less than 2 is NSNotFound...");
|
||||
printf(" %s\n", [s indexLessThanIndex: 2] == NSNotFound ? "passed" : "failed");
|
||||
printf("Set index less than or equal to 2 is 2...");
|
||||
printf(" %s\n", [s indexLessThanOrEqualToIndex: 2] == 2 ? "passed" : "failed");
|
||||
printf("Set index greater than 1 is 2...");
|
||||
printf(" %s\n", [s indexGreaterThanIndex: 1] == 2 ? "passed" : "failed");
|
||||
printf("Set index greater than or equal to 1 is 2...");
|
||||
printf(" %s\n", [s indexGreaterThanOrEqualToIndex: 1] == 2 ? "passed" : "failed");
|
||||
printf("Set index greater than 2 is 3...");
|
||||
printf(" %s\n", [s indexGreaterThanIndex: 2] == 3 ? "passed" : "failed");
|
||||
printf("Set index greater than or equal to 2 is 2...");
|
||||
printf(" %s\n", [s indexGreaterThanOrEqualToIndex: 2] == 2 ? "passed" : "failed");
|
||||
|
||||
printf("Set getIndexes gives 3...");
|
||||
r = NSMakeRange(0, NSNotFound-1);
|
||||
printf(" %s\n", [s getIndexes: buf maxCount:3 inIndexRange: &r] == 3 ? "passed" : "failed");
|
||||
|
||||
printf("Set getIndexes gives 1...");
|
||||
printf(" %s\n", [s getIndexes: buf maxCount:3 inIndexRange: &r] == 1 ? "passed" : "failed");
|
||||
|
||||
|
||||
printf("Set mutableCopy works...");
|
||||
m = [[s mutableCopy] autorelease];
|
||||
printf(" %s\n", m != nil ? "passed" : "failed");
|
||||
|
||||
printf("Copy equals originals...");
|
||||
printf(" %s\n", [m isEqual: s] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Can add index 10 to mutable set...");
|
||||
[m addIndex: 10];
|
||||
printf(" %s\n", [m containsIndex: 10] == YES && [m containsIndex: 9] == NO && [m containsIndex: 11] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Can add index 7 to mutable set...");
|
||||
[m addIndex: 7];
|
||||
printf(" %s\n", [m containsIndex: 7] == YES && [m containsIndex: 6] == NO && [m containsIndex: 8] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Can add index 8 to mutable set...");
|
||||
[m addIndex: 8];
|
||||
printf(" %s\n", [m containsIndex: 7] == YES && [m containsIndex: 8] == YES && [m containsIndex: 9] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Can add index 9 to mutable set...");
|
||||
[m addIndex: 9];
|
||||
printf(" %s\n", [m containsIndex: 8] == YES && [m containsIndex: 9] == YES && [m containsIndex: 10] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Can remove index 9 from mutable set...");
|
||||
[m removeIndex: 9];
|
||||
printf(" %s\n", [m containsIndex: 8] == YES && [m containsIndex: 9] == NO && [m containsIndex: 10] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Can shift right by 5 from 7...");
|
||||
[m shiftIndexesStartingAtIndex: 7 by: 5];
|
||||
printf(" %s\n", [m containsIndex: 7] == NO && [m containsIndex: 12] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Can shift left by 5 from 12...");
|
||||
[m shiftIndexesStartingAtIndex: 12 by: -5];
|
||||
printf(" %s\n", [m containsIndex: 7] == YES && [m containsIndex: 12] == NO ? "passed" : "failed");
|
||||
|
||||
printf("Can remove range 5-7 from mutable set...");
|
||||
[m removeIndexesInRange: NSMakeRange(5, 3)];
|
||||
printf(" %s\n", [m containsIndex: 4] == YES && [m containsIndex: 5] == NO && [m containsIndex: 8] == YES ? "passed" : "failed");
|
||||
|
||||
printf("Can remove range 0-10 from mutable set...");
|
||||
[m removeIndexesInRange: NSMakeRange(0, 11)];
|
||||
printf(" %s\n", [m isEqual: [NSIndexSet indexSet]] == YES ? "passed" : "failed");
|
||||
|
||||
o = [NSMutableIndexSet indexSet];
|
||||
[m addIndex: 3];
|
||||
[m addIndex: 4];
|
||||
[m addIndex: 6];
|
||||
[m addIndex: 7];
|
||||
[o addIndex: 3];
|
||||
[o addIndex: 7];
|
||||
printf("Can remove range 4-6 from mutable set containing 3,4,6,7 ...");
|
||||
[m removeIndexesInRange: NSMakeRange(4, 3)];
|
||||
printf(" %s\n", [m isEqual: o] == YES ? "passed" : "failed");
|
||||
|
||||
[m addIndex: 3];
|
||||
[m addIndex: 4];
|
||||
[m addIndex: 6];
|
||||
[m addIndex: 7];
|
||||
[m addIndex: 8];
|
||||
[m addIndex: 9];
|
||||
[o addIndex: 3];
|
||||
[o removeIndex: 7];
|
||||
[o addIndex: 9];
|
||||
printf("Can remove range 4-8 from mutable set containing 3,4,6,7,8,9 ...");
|
||||
[m removeIndexesInRange: NSMakeRange(4, 5)];
|
||||
printf(" %s\n", [m isEqual: o] == YES ? "passed" : "failed");
|
||||
|
||||
// NSLog(@"%@", m);
|
||||
[arp release];
|
||||
exit (0);
|
||||
}
|
||||
|
|
@ -1,530 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSMethodSignature.h>
|
||||
#include <Foundation/NSInvocation.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
|
||||
static int loop_int_result;
|
||||
|
||||
typedef struct {
|
||||
char c;
|
||||
int i;
|
||||
} small;
|
||||
|
||||
typedef struct {
|
||||
int i;
|
||||
char *s;
|
||||
float f;
|
||||
} large;
|
||||
|
||||
@interface Target: NSObject
|
||||
- (char) loopChar: (char)v;
|
||||
- (double) loopDouble: (double)v;
|
||||
- (float) loopFloat: (float)v;
|
||||
- (int) loopInt: (int)v;
|
||||
- (large) loopLarge: (large)v;
|
||||
- (long) loopLong: (long)v;
|
||||
- (long long) loopLongLong: (long long)v;
|
||||
- (large) loopLargePtr: (large*)v;
|
||||
- (id) loopObject: (id)v;
|
||||
- (short) loopShort: (short)v;
|
||||
- (small) loopSmall: (small)v;
|
||||
- (small) loopSmallPtr: (small*)v;
|
||||
- (char*) loopString: (char*)v;
|
||||
|
||||
- (double) loopMulti: (float)f int: (float)v ch: (char)c;
|
||||
|
||||
- (char) retChar;
|
||||
- (double) retDouble;
|
||||
- (float) retFloat;
|
||||
- (int) retInt;
|
||||
- (large) retLarge;
|
||||
- (long) retLong;
|
||||
- (long long) retLongLong;
|
||||
- (id) retObject;
|
||||
- (short) retShort;
|
||||
- (small) retSmall;
|
||||
- (char*) retString;
|
||||
|
||||
- (void) addObserver: (unsigned long)anObserver
|
||||
selector: (NSString*)aSelector
|
||||
name: (NSString*)notificationName
|
||||
object: (NSString*)anObject
|
||||
suspensionBehavior: (int)suspensionBehavior
|
||||
for: (id)client;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Target
|
||||
- (char) loopChar: (char)v
|
||||
{
|
||||
return v+1;
|
||||
}
|
||||
- (double) loopDouble: (double)v
|
||||
{
|
||||
return v+1.0;
|
||||
}
|
||||
- (float) loopFloat: (float)v
|
||||
{
|
||||
return v+1.0;
|
||||
}
|
||||
- (int) loopInt: (int)v
|
||||
{
|
||||
loop_int_result = v+1;
|
||||
return v+1;
|
||||
}
|
||||
- (large) loopLarge: (large)v
|
||||
{
|
||||
return v;
|
||||
}
|
||||
- (long) loopLong: (long)v
|
||||
{
|
||||
return v+1;
|
||||
}
|
||||
- (long long) loopLongLong: (long long)v
|
||||
{
|
||||
return v+1;
|
||||
}
|
||||
- (large) loopLargePtr: (large*)v
|
||||
{
|
||||
return *v;
|
||||
}
|
||||
- (id) loopObject: (id)v
|
||||
{
|
||||
return v;
|
||||
}
|
||||
- (short) loopShort: (short)v
|
||||
{
|
||||
return v+1;
|
||||
}
|
||||
- (small) loopSmall: (small)v
|
||||
{
|
||||
return v;
|
||||
}
|
||||
- (small) loopSmallPtr: (small*)v
|
||||
{
|
||||
return *v;
|
||||
}
|
||||
- (char*) loopString: (char*)v
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
- (double) loopMulti: (float)f int: (float)v ch: (char)c
|
||||
{
|
||||
return v+1.0;
|
||||
}
|
||||
|
||||
- (char) retChar
|
||||
{
|
||||
return (char)99;
|
||||
}
|
||||
- (double) retDouble
|
||||
{
|
||||
return 123.456;
|
||||
}
|
||||
- (float) retFloat
|
||||
{
|
||||
return 123.456;
|
||||
}
|
||||
- (int) retInt
|
||||
{
|
||||
return 123456;
|
||||
}
|
||||
- (large) retLarge
|
||||
{
|
||||
static large l = {
|
||||
99, "large", 99.99
|
||||
};
|
||||
return l;
|
||||
}
|
||||
- (long) retLong
|
||||
{
|
||||
return 123456;
|
||||
}
|
||||
- (long long) retLongLong
|
||||
{
|
||||
return 123456;
|
||||
}
|
||||
- (id) retObject
|
||||
{
|
||||
return self;
|
||||
}
|
||||
- (short) retShort
|
||||
{
|
||||
return 12345;
|
||||
}
|
||||
- (small) retSmall
|
||||
{
|
||||
static small s = {
|
||||
11, 22
|
||||
};
|
||||
return s;
|
||||
}
|
||||
- (char*) retString
|
||||
{
|
||||
return "string";
|
||||
}
|
||||
|
||||
- (void) addObserver: (unsigned long)anObserver
|
||||
selector: (NSString*)aSelector
|
||||
name: (NSString*)notificationName
|
||||
object: (NSString*)anObject
|
||||
suspensionBehavior: (int)suspensionBehavior
|
||||
for: (id)client
|
||||
{
|
||||
printf("called multi argument method\n");
|
||||
}
|
||||
@end
|
||||
|
||||
@interface MyProxy : NSObject
|
||||
{
|
||||
id obj;
|
||||
}
|
||||
- (void) forwardInvocation: (NSInvocation*)inv;
|
||||
- (id) initWithTarget: (id)target;
|
||||
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector;
|
||||
@end
|
||||
|
||||
@implementation MyProxy
|
||||
- (id) initWithTarget: (id)target
|
||||
{
|
||||
obj = target;
|
||||
return self;
|
||||
}
|
||||
- (void) forwardInvocation: (NSInvocation*)inv
|
||||
{
|
||||
NSData *d = [NSArchiver archivedDataWithRootObject: inv];
|
||||
NSInvocation *i = [NSUnarchiver unarchiveObjectWithData: d];
|
||||
unsigned l;
|
||||
void *b;
|
||||
|
||||
[i invokeWithTarget: obj];
|
||||
d = [NSArchiver archivedDataWithRootObject: i];
|
||||
i = [NSUnarchiver unarchiveObjectWithData: d];
|
||||
l = [[i methodSignature] methodReturnLength];
|
||||
if (l < sizeof(void *))
|
||||
l = sizeof(void *);
|
||||
b = (void *)objc_malloc(l);
|
||||
[i getReturnValue: b];
|
||||
[inv setReturnValue: b];
|
||||
objc_free(b);
|
||||
}
|
||||
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
|
||||
{
|
||||
return [obj methodSignatureForSelector: aSelector];
|
||||
}
|
||||
@end
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
large la;
|
||||
small sm;
|
||||
large tmpla;
|
||||
large *laptr = &tmpla;
|
||||
small tmpsm;
|
||||
small *smptr = &tmpsm;
|
||||
int i;
|
||||
char c;
|
||||
short s;
|
||||
long l;
|
||||
long long q;
|
||||
float f;
|
||||
double d;
|
||||
id o;
|
||||
char *str;
|
||||
NSInvocation *inv;
|
||||
NSMethodSignature *sig;
|
||||
Target *t;
|
||||
id p;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
printf("Starting\n");
|
||||
t = [Target new];
|
||||
p = [[MyProxy alloc] initWithTarget: t];
|
||||
printf("Calling proxy\n");
|
||||
[p loopInt: 1];
|
||||
|
||||
printf("Testing NS_MESSAGE ... ");
|
||||
inv = NS_MESSAGE(t, loopInt: 5);
|
||||
loop_int_result = 0;
|
||||
[inv invoke];
|
||||
[inv getReturnValue: &i];
|
||||
if (i == 6 && loop_int_result == 6)
|
||||
printf("OK\n");
|
||||
else
|
||||
printf("ERROR ... expecting 6,6 and got %d,%d\n", i, loop_int_result);
|
||||
|
||||
printf("Testing NS_INVOCATION ... ");
|
||||
inv = NS_INVOCATION([Target class], loopInt: 7);
|
||||
[inv setTarget: t];
|
||||
loop_int_result = 0;
|
||||
[inv invoke];
|
||||
[inv getReturnValue: &i];
|
||||
if (i == 8 && loop_int_result == 8)
|
||||
printf("OK\n");
|
||||
else
|
||||
printf("ERROR ... expecting 8,8 and got %d,%d\n", i, loop_int_result);
|
||||
|
||||
#define SETUP(X) \
|
||||
sig = [t methodSignatureForSelector: @selector(X)]; \
|
||||
inv = [NSInvocation invocationWithMethodSignature: sig]; \
|
||||
[inv setSelector: @selector(X)];
|
||||
|
||||
tmpsm.c = 8;
|
||||
tmpsm.i = 9;
|
||||
|
||||
tmpla.i = 1;
|
||||
tmpla.s = "hello";
|
||||
tmpla.f = 1.23;
|
||||
|
||||
SETUP(retChar);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 99, ");
|
||||
[inv getReturnValue: &c];
|
||||
printf("invoke: %d ", c);
|
||||
c = [p retChar];
|
||||
printf("forward: %d\n", c);
|
||||
|
||||
SETUP(retShort);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 12345, ");
|
||||
[inv getReturnValue: &s];
|
||||
printf("invoke: %d ", s);
|
||||
s = [p retShort];
|
||||
printf("forward: %d\n", s);
|
||||
|
||||
SETUP(retInt);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 123456, ");
|
||||
[inv getReturnValue: &i];
|
||||
printf("invoke: %d ", i);
|
||||
i = [p retInt];
|
||||
printf("forward: %d\n", i);
|
||||
|
||||
SETUP(retLong);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 123456, ");
|
||||
[inv getReturnValue: &l];
|
||||
printf("invoke: %ld ", l);
|
||||
l = [p retLong];
|
||||
printf("forward: %ld\n", l);
|
||||
|
||||
SETUP(retLongLong);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 123456, ");
|
||||
[inv getReturnValue: &q];
|
||||
printf("invoke: %lld ", q);
|
||||
q = [p retLong];
|
||||
printf("forward: %lld\n", q);
|
||||
|
||||
SETUP(retFloat);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 123.456, ");
|
||||
[inv getReturnValue: &f];
|
||||
printf("invoke: %.3f ", f);
|
||||
f = [p retFloat];
|
||||
printf("forward: %.3f\n", f);
|
||||
|
||||
SETUP(retDouble);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 123.456, ");
|
||||
[inv getReturnValue: &d];
|
||||
printf("invoke: %.3f ", d);
|
||||
d = [p retDouble];
|
||||
printf("forward: %.3f\n", d);
|
||||
|
||||
SETUP(retObject);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: %p, ", t);
|
||||
[inv getReturnValue: &o];
|
||||
printf("invoke: %p ", o);
|
||||
o = [p retObject];
|
||||
printf("forward: %p\n", o);
|
||||
|
||||
SETUP(retString);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 'string', ");
|
||||
[inv getReturnValue: &str];
|
||||
printf("invoke: '%s' ", str);
|
||||
str = [p retString];
|
||||
printf("forward: '%s'\n", str);
|
||||
|
||||
|
||||
|
||||
|
||||
SETUP(loopChar:);
|
||||
c = 0;
|
||||
[inv setArgument: &c atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 1, ");
|
||||
[inv getReturnValue: &c];
|
||||
printf("invoke: %d ", c);
|
||||
c = [p loopChar: 0];
|
||||
printf("forward: %d\n", c);
|
||||
|
||||
SETUP(loopShort:);
|
||||
s = 1;
|
||||
[inv setArgument: &s atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 2, ");
|
||||
[inv getReturnValue: &s];
|
||||
printf("invoke: %d ", s);
|
||||
s = [p loopShort: 1];
|
||||
printf("forward: %d\n", s);
|
||||
|
||||
SETUP(loopInt:);
|
||||
i = 2;
|
||||
[inv setArgument: &i atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 3, ");
|
||||
[inv getReturnValue: &i];
|
||||
printf("invoke: %d ", i);
|
||||
i = [p loopInt: 2];
|
||||
printf("forward: %d\n", i);
|
||||
|
||||
SETUP(loopLong:);
|
||||
l = 3;
|
||||
[inv setArgument: &l atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 4, ");
|
||||
[inv getReturnValue: &l];
|
||||
printf("invoke: %ld ", l);
|
||||
l = [p loopLong: 3];
|
||||
printf("forward: %ld\n", l);
|
||||
|
||||
SETUP(loopLongLong:);
|
||||
q = 3;
|
||||
[inv setArgument: &q atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 4, ");
|
||||
[inv getReturnValue: &q];
|
||||
printf("invoke: %lld ", q);
|
||||
q = [p loopLong: 3];
|
||||
printf("forward: %lld\n", q);
|
||||
|
||||
SETUP(loopFloat:);
|
||||
f = 4.0;
|
||||
[inv setArgument: &f atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 5.0, ");
|
||||
[inv getReturnValue: &f];
|
||||
printf("invoke: %.1f ", f);
|
||||
f = [p loopFloat: 4.0];
|
||||
printf("forward: %.1f\n", f);
|
||||
|
||||
SETUP(loopDouble:);
|
||||
d = 5.0;
|
||||
[inv setArgument: &d atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 6.0, ");
|
||||
[inv getReturnValue: &d];
|
||||
printf("invoke: %.1f ", d);
|
||||
d = [p loopDouble: 5.0];
|
||||
printf("forward: %.1f\n", d);
|
||||
|
||||
SETUP(loopMulti:int:ch:);
|
||||
printf("Expect: 6.0, ");
|
||||
f = [p loopMulti: 3.0 int: 5.0 ch: 'a'];
|
||||
printf("forward: %.1f\n", f);
|
||||
|
||||
SETUP(loopObject:);
|
||||
[inv setArgument: &p atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: %p, ", p);
|
||||
[inv getReturnValue: &o];
|
||||
printf("invoke: %p ", o);
|
||||
o = [p loopObject: p];
|
||||
printf("forward: %p\n", o);
|
||||
|
||||
SETUP(loopString:);
|
||||
str = "Hello";
|
||||
[inv setArgument: &str atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: 'Hello', ");
|
||||
[inv getReturnValue: &str];
|
||||
printf("invoke: '%s' ", str);
|
||||
str = [p loopString: str];
|
||||
printf("forward: '%s'\n", str);
|
||||
|
||||
|
||||
|
||||
SETUP(addObserver:selector:name:object:suspensionBehavior:for:);
|
||||
q = 1;
|
||||
str = @"a";
|
||||
i = 2;
|
||||
[inv setArgument: &q atIndex: 2];
|
||||
[inv setArgument: &str atIndex: 3];
|
||||
[inv setArgument: &str atIndex: 4];
|
||||
[inv setArgument: &str atIndex: 5];
|
||||
[inv setArgument: &i atIndex: 6];
|
||||
[inv setArgument: &str atIndex: 7];
|
||||
[inv invokeWithTarget: t];
|
||||
|
||||
SETUP(retSmall);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: {11,22}, ");
|
||||
[inv getReturnValue: &sm];
|
||||
printf("invoke: {%d,%d} ", sm.c, sm.i);
|
||||
sm = [p retSmall];
|
||||
printf("forward: {%d,%d}\n", sm.c, sm.i);
|
||||
|
||||
SETUP(retLarge);
|
||||
[inv invokeWithTarget: t];
|
||||
printf("Expect: {99,large,99.99}, ");
|
||||
[inv getReturnValue: &la];
|
||||
printf("invoke: {%d,%s,%.2f} ", la.i, la.s, la.f);
|
||||
la = [p retLarge];
|
||||
printf("forward: {%d,%s,%.2f}\n", la.i, la.s, la.f);
|
||||
|
||||
SETUP(loopSmall:);
|
||||
printf("Expect: {8,9}, ");
|
||||
[inv setArgument: &tmpsm atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
[inv getReturnValue: &sm];
|
||||
printf("invoke: {%d,%d} ", sm.c, sm.i);
|
||||
sm = [p loopSmall: tmpsm];
|
||||
printf("forward: {%d,%d}\n", sm.c, sm.i);
|
||||
|
||||
SETUP(loopLarge:);
|
||||
printf("Expect: {1,hello,1.23}, ");
|
||||
[inv setArgument: &tmpla atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
[inv getReturnValue: &la];
|
||||
printf("invoke: {%d,%s,%.2f} ", la.i, la.s, la.f);
|
||||
la = [p loopLarge: tmpla];
|
||||
printf("forward: {%d,%s,%.2f}\n", la.i, la.s, la.f);
|
||||
|
||||
SETUP(loopSmallPtr:);
|
||||
printf("Expect: {8,9}, ");
|
||||
[inv setArgument: &smptr atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
[inv getReturnValue: &sm];
|
||||
printf("invoke: {%d,%d} ", sm.c, sm.i);
|
||||
sm = [p loopSmallPtr: smptr];
|
||||
printf("forward: {%d,%d}\n", sm.c, sm.i);
|
||||
|
||||
SETUP(loopLargePtr:);
|
||||
printf("Expect: {1,hello,1.23}, ");
|
||||
[inv setArgument: &laptr atIndex: 2];
|
||||
[inv invokeWithTarget: t];
|
||||
[inv getReturnValue: &la];
|
||||
printf("invoke: {%d,%s,%.2f} ", la.i, la.s, la.f);
|
||||
la = [p loopLargePtr: laptr];
|
||||
printf("forward: {%d,%s,%.2f}\n", la.i, la.s, la.f);
|
||||
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
NSMapTable *mt;
|
||||
NSMapEnumerator me;
|
||||
int i;
|
||||
void *k;
|
||||
void *v;
|
||||
id o;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
/* Test with ints */
|
||||
|
||||
mt = NSCreateMapTable (NSIntMapKeyCallBacks,
|
||||
NSIntMapValueCallBacks,
|
||||
0);
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
NSMapInsert (mt, (void*)i, (void*)(i*2));
|
||||
|
||||
printf ("value for key %d is %d\n",
|
||||
3, (int)NSMapGet (mt, (void*)3));
|
||||
NSMapRemove (mt, (void*)3);
|
||||
printf ("after removing: value for key %d is %d\n",
|
||||
3, (int)NSMapGet (mt, (void*)3));
|
||||
|
||||
me = NSEnumerateMapTable (mt);
|
||||
while (NSNextMapEnumeratorPair (&me, &k, &v))
|
||||
printf ("(%d,%d) ", (int)k, (int)v);
|
||||
printf ("\n");
|
||||
|
||||
NSFreeMapTable (mt);
|
||||
|
||||
|
||||
/* Test with NSNumber objects */
|
||||
|
||||
mt = NSCreateMapTable (NSObjectMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks,
|
||||
0);
|
||||
|
||||
for (i = 0; i < 16; i++)
|
||||
NSMapInsert (mt,
|
||||
[NSNumber numberWithInt: i],
|
||||
[NSNumber numberWithInt: i*i]);
|
||||
|
||||
o = [NSNumber numberWithInt: 3];
|
||||
printf ("value for key %s is %s\n",
|
||||
[[o description] cString],
|
||||
[[(id)NSMapGet (mt, o) description] cString]);
|
||||
NSMapRemove (mt, o);
|
||||
if (NSMapGet (mt, o))
|
||||
printf ("after removing: value for key %s is %s\n",
|
||||
[[o description] cString],
|
||||
[[(id)NSMapGet (mt, o) description] cString]);
|
||||
else
|
||||
printf ("after removing: no value for key %s\n",
|
||||
[[o description] cString]);
|
||||
|
||||
me = NSEnumerateMapTable (mt);
|
||||
while (NSNextMapEnumeratorPair (&me, &k, &v))
|
||||
printf ("(%d,%d) ", [(id)k intValue], [(id)v intValue]);
|
||||
printf ("\n");
|
||||
|
||||
NSFreeMapTable (mt);
|
||||
|
||||
[arp release];
|
||||
exit (0);
|
||||
}
|
|
@ -1,431 +0,0 @@
|
|||
/** nsmethodsignature - Program to test NSMethodSignature.
|
||||
Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
|
||||
Written by: David Ayers <d.ayers@inode.at>
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This file 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.
|
||||
|
||||
This file 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 file; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSMethodSignature.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
|
||||
#include <GNUstepBase/GSObjCRuntime.h>
|
||||
|
||||
|
||||
#define SRV_NAME @"nsmethodsignaturetest"
|
||||
|
||||
struct _MyLargeStruct
|
||||
{
|
||||
double first;
|
||||
double second;
|
||||
};
|
||||
typedef struct _MyLargeStruct MyLargeStruct;
|
||||
|
||||
struct _MySmallStruct
|
||||
{
|
||||
char first;
|
||||
};
|
||||
typedef struct _MySmallStruct MySmallStruct;
|
||||
|
||||
/*------------------------------------*/
|
||||
@interface MyClass : NSObject
|
||||
-(void)void_void;
|
||||
-(id)id_void;
|
||||
|
||||
-(char)char_void;
|
||||
-(unsigned char)uchar_void;
|
||||
-(signed char)schar_void;
|
||||
|
||||
-(short)short_void;
|
||||
-(unsigned short)ushort_void;
|
||||
-(signed short)sshort_void;
|
||||
|
||||
-(int)int_void;
|
||||
-(unsigned int)uint_void;
|
||||
-(signed int)sint_void;
|
||||
|
||||
-(long)long_void;
|
||||
-(unsigned long)ulong_void;
|
||||
-(signed long)slong_void;
|
||||
|
||||
-(float)float_void;
|
||||
-(double)double_void;
|
||||
|
||||
-(MyLargeStruct)largeStruct_void;
|
||||
-(MySmallStruct)smallStruct_void;
|
||||
|
||||
|
||||
|
||||
-(void)void_id:(id)_id;
|
||||
|
||||
-(void)void_char:(char)_char;
|
||||
-(void)void_uchar:(unsigned char)_char;
|
||||
-(void)void_schar:(signed char)_char;
|
||||
|
||||
-(void)void_short:(short)_short;
|
||||
-(void)void_ushort:(unsigned short)_short;
|
||||
-(void)void_sshort:(signed short)_short;
|
||||
|
||||
-(void)void_int:(int)_int;
|
||||
-(void)void_uint:(unsigned int)_int;
|
||||
-(void)void_sint:(signed int)_int;
|
||||
|
||||
-(void)void_long:(long)_long;
|
||||
-(void)void_ulong:(unsigned long)_long;
|
||||
-(void)void_slong:(signed long)_long;
|
||||
|
||||
-(void)void_float:(float)_float;
|
||||
-(void)void_double:(double)_double;
|
||||
|
||||
-(void)void_largeStruct:(MyLargeStruct)_str;
|
||||
-(void)void_smallStruct:(MySmallStruct)_str;
|
||||
|
||||
-(void)void_float:(float)_float double:(double)_double;
|
||||
-(void)void_double:(double)_double float:(float)_float;
|
||||
|
||||
-(MyLargeStruct)largeStruct_id:(id)_id
|
||||
char:(char)_char
|
||||
short:(short)_short
|
||||
int:(int)_int
|
||||
long:(long)_long
|
||||
float:(float)_float
|
||||
double:(double)_double
|
||||
largeStruct:(MyLargeStruct)_lstr
|
||||
smallStruct:(MySmallStruct)_sstr;
|
||||
-(MySmallStruct)smallStruct_id:(id)_id
|
||||
uchar:(unsigned char)_uchar
|
||||
ushort:(unsigned short)_ushort
|
||||
uint:(unsigned int)_uint
|
||||
ulong:(unsigned long)_ulong
|
||||
float:(float)_float
|
||||
double:(double)_double
|
||||
largeStruct:(MyLargeStruct)_lstr
|
||||
smallStruct:(MySmallStruct)_sstr;
|
||||
|
||||
-(const char *)runtimeSignatureForSelector:(SEL)selector;
|
||||
-(const char *)mframeSignatureForSelector:(SEL)selector;
|
||||
@end
|
||||
|
||||
@implementation MyClass
|
||||
-(void)void_void {}
|
||||
-(id)id_void { return 0; }
|
||||
|
||||
-(char)char_void { return 0; }
|
||||
-(unsigned char)uchar_void { return 0; }
|
||||
-(signed char)schar_void { return 0; }
|
||||
|
||||
-(short)short_void { return 0; }
|
||||
-(unsigned short)ushort_void { return 0; }
|
||||
-(signed short)sshort_void { return 0; }
|
||||
|
||||
-(int)int_void { return 0; }
|
||||
-(unsigned int)uint_void { return 0; }
|
||||
-(signed int)sint_void { return 0; }
|
||||
|
||||
-(long)long_void { return 0; }
|
||||
-(unsigned long)ulong_void { return 0; }
|
||||
-(signed long)slong_void { return 0; }
|
||||
|
||||
-(float)float_void { return 0; }
|
||||
-(double)double_void { return 0; }
|
||||
|
||||
-(MyLargeStruct)largeStruct_void { MyLargeStruct str; return str; }
|
||||
-(MySmallStruct)smallStruct_void { MySmallStruct str; return str; }
|
||||
|
||||
|
||||
|
||||
-(void)void_id:(id)_id {}
|
||||
|
||||
-(void)void_char:(char)_char {}
|
||||
-(void)void_uchar:(unsigned char)_char {}
|
||||
-(void)void_schar:(signed char)_char {}
|
||||
|
||||
-(void)void_short:(short)_short {}
|
||||
-(void)void_ushort:(unsigned short)_short {}
|
||||
-(void)void_sshort:(signed short)_short {}
|
||||
|
||||
-(void)void_int:(int)_int {}
|
||||
-(void)void_uint:(unsigned int)_int {}
|
||||
-(void)void_sint:(signed int)_int {}
|
||||
|
||||
-(void)void_long:(long)_long {}
|
||||
-(void)void_ulong:(unsigned long)_long {}
|
||||
-(void)void_slong:(signed long)_long {}
|
||||
|
||||
-(void)void_float:(float)_float {}
|
||||
-(void)void_double:(double)_double {}
|
||||
|
||||
-(void)void_largeStruct:(MyLargeStruct)_str {}
|
||||
-(void)void_smallStruct:(MySmallStruct)_str {}
|
||||
|
||||
-(void)void_float:(float)_float double:(double)_double {}
|
||||
-(void)void_double:(double)_double float:(float)_float {}
|
||||
|
||||
|
||||
-(MyLargeStruct)largeStruct_id:(id)_id
|
||||
char:(char)_char
|
||||
short:(short)_short
|
||||
int:(int)_int
|
||||
long:(long)_long
|
||||
float:(float)_float
|
||||
double:(double)_double
|
||||
largeStruct:(MyLargeStruct)_lstr
|
||||
smallStruct:(MySmallStruct)_sstr { return _lstr; }
|
||||
|
||||
-(MySmallStruct)smallStruct_id:(id)_id
|
||||
uchar:(unsigned char)_uchar
|
||||
ushort:(unsigned short)_ushort
|
||||
uint:(unsigned int)_uint
|
||||
ulong:(unsigned long)_ulong
|
||||
float:(float)_float
|
||||
double:(double)_double
|
||||
largeStruct:(MyLargeStruct)_lstr
|
||||
smallStruct:(MySmallStruct)_sstr { return _sstr; }
|
||||
|
||||
-(const char *)runtimeSignatureForSelector:(SEL)selector
|
||||
{
|
||||
GSMethod meth = GSGetMethod(isa, selector, YES, YES);
|
||||
return meth->method_types;
|
||||
}
|
||||
|
||||
-(const char *)mframeSignatureForSelector:(SEL)selector
|
||||
{
|
||||
const char *types = [self runtimeSignatureForSelector: selector];
|
||||
NSMethodSignature *sig = [NSMethodSignature signatureWithObjCTypes: types];
|
||||
return [sig methodType];
|
||||
}
|
||||
@end
|
||||
|
||||
/*------------------------------------*/
|
||||
|
||||
int failed = 0;
|
||||
|
||||
void
|
||||
test_mframe_build_signature(void)
|
||||
{
|
||||
const char *mf_types;
|
||||
void *it = 0;
|
||||
GSMethod meth;
|
||||
GSMethodList list;
|
||||
Class cls = [MyClass class];
|
||||
NSMethodSignature *sig;
|
||||
unsigned int i;
|
||||
|
||||
for (it = 0, list = class_nextMethodList(cls, &it);
|
||||
list != 0;
|
||||
list = class_nextMethodList(cls, &it))
|
||||
{
|
||||
id pool = [NSAutoreleasePool new];
|
||||
|
||||
for (i = 0; i < list->method_count; i++)
|
||||
{
|
||||
meth = &list->method_list[i];
|
||||
sig = [NSMethodSignature signatureWithObjCTypes: meth->method_types];
|
||||
mf_types = [sig methodType];
|
||||
if (strcmp(meth->method_types, mf_types))
|
||||
{
|
||||
NSLog(@"sel: %s\nrts:%s\nmfs:%s",
|
||||
GSNameFromSelector(meth->method_name),
|
||||
meth->method_types, mf_types);
|
||||
failed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
This test is useful if the nsmethodsignatureserver is running which
|
||||
was compiled with either a different GNUstep-base version or a different
|
||||
version of gcc. It the server isn't found the test is skipped.
|
||||
*/
|
||||
void
|
||||
test_compare_server_signature(void)
|
||||
{
|
||||
id objct = [MyClass new];
|
||||
id proxy = [NSConnection rootProxyForConnectionWithRegisteredName: SRV_NAME
|
||||
host: nil];
|
||||
if (proxy)
|
||||
{
|
||||
const char *rmtSig;
|
||||
const char *lclSig;
|
||||
|
||||
#define TEST_SEL(SELNAME) { \
|
||||
lclSig = [objct runtimeSignatureForSelector: @selector(SELNAME)]; \
|
||||
rmtSig = [proxy runtimeSignatureForSelector: @selector(SELNAME)]; \
|
||||
if (!GSSelectorTypesMatch(lclSig, rmtSig)) \
|
||||
NSLog(@"runtime: sel:%s\nlcl:%s\nrmt:%s", \
|
||||
GSNameFromSelector(@selector(SELNAME)), \
|
||||
lclSig, rmtSig); \
|
||||
lclSig = [objct mframeSignatureForSelector: @selector(SELNAME)]; \
|
||||
rmtSig = [proxy mframeSignatureForSelector: @selector(SELNAME)]; \
|
||||
if (!GSSelectorTypesMatch(lclSig, rmtSig)) \
|
||||
NSLog(@"mframe : sel:%s\nlcl:%s\nrmt:%s", \
|
||||
GSNameFromSelector(@selector(SELNAME)), \
|
||||
lclSig, rmtSig); \
|
||||
}
|
||||
|
||||
TEST_SEL(void_void);
|
||||
TEST_SEL(id_void);
|
||||
TEST_SEL(char_void);
|
||||
TEST_SEL(uchar_void);
|
||||
TEST_SEL(schar_void);
|
||||
TEST_SEL(short_void);
|
||||
TEST_SEL(ushort_void);
|
||||
TEST_SEL(sshort_void);
|
||||
TEST_SEL(int_void);
|
||||
TEST_SEL(uint_void);
|
||||
TEST_SEL(sint_void);
|
||||
TEST_SEL(long_void);
|
||||
TEST_SEL(ulong_void);
|
||||
TEST_SEL(slong_void);
|
||||
TEST_SEL(float_void);
|
||||
TEST_SEL(double_void);
|
||||
TEST_SEL(largeStruct_void);
|
||||
TEST_SEL(smallStruct_void);
|
||||
|
||||
TEST_SEL(void_id:);
|
||||
TEST_SEL(void_char:);
|
||||
TEST_SEL(void_uchar:);
|
||||
TEST_SEL(void_schar:);
|
||||
TEST_SEL(void_short:);
|
||||
TEST_SEL(void_ushort:);
|
||||
TEST_SEL(void_sshort:);
|
||||
TEST_SEL(void_int:);
|
||||
TEST_SEL(void_uint:);
|
||||
TEST_SEL(void_sint:);
|
||||
TEST_SEL(void_long:);
|
||||
TEST_SEL(void_ulong:);
|
||||
TEST_SEL(void_slong:);
|
||||
TEST_SEL(void_float:);
|
||||
TEST_SEL(void_double:);
|
||||
TEST_SEL(void_largeStruct:);
|
||||
TEST_SEL(void_smallStruct:);
|
||||
TEST_SEL(void_float:double:);
|
||||
TEST_SEL(void_double:float:);
|
||||
TEST_SEL(largeStruct_id:char:short:int:long:float:double:largeStruct:smallStruct:);
|
||||
TEST_SEL(smallStruct_id:uchar:ushort:uint:ulong:float:double:largeStruct:smallStruct:);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Skipping test_compare_server_signature: proxy not found.");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_GSSelectorTypesMatch(void)
|
||||
{
|
||||
const char *pairs[][2] = { {"@@::", "@12@0:4:8"},
|
||||
{"@@::", "@12@+0:+4:+8"},
|
||||
{"@@::", "@12@-0:-4:-8"},
|
||||
{"@12@0:4:8", "@@::"},
|
||||
{"@12@+0:+4:+8", "@@::"},
|
||||
{"@12@-0:-4:-8", "@@::"},
|
||||
|
||||
{"@12@0:4:8", "@12@+0:+4:+8"},
|
||||
{"@12@0:4:8", "@12@-0:-4:-8"},
|
||||
{"@12@+0:+4:+8", "@12@0:4:8"},
|
||||
{"@12@-0:-4:-8", "@12@0:4:8"},
|
||||
|
||||
{"@12@0:4:8", "@16@+4:+8:+12"},
|
||||
{"@12@0:4:8", "@16@-4:-8:-12"},
|
||||
{"@12@+0:+4:+8", "@16@4:8:12"},
|
||||
{"@12@-0:-4:-8", "@16@4:8:12"},
|
||||
|
||||
{"{_MyLargeStruct2={_MyLargeStruct=dd}dd}@:",
|
||||
"{??={??=dd}dd}16@0:4"},
|
||||
|
||||
{"{_MyLargeStruct=dd}56@+8:+12@+16c+23s+26i+28l24f28d32{_MyLargeStruct=dd}40{_MySmallStruct=c}44",
|
||||
"{_MyLargeStruct=dd}46@+8:+12@+16c+17s+16i+20l+24f+28d24{_MyLargeStruct=dd}32{_MySmallStruct=c}45"},
|
||||
{"{_MyLargeStruct=dd}56@+8:+12@+16c+23s+26i+28l24f28d32{_MyLargeStruct=dd}40{_MySmallStruct=c}44",
|
||||
"{??=dd}46@+8:+12@+16c+17s+16i+20l+24f+28d24{??=dd}32{??=c}45"},
|
||||
{0, 0} };
|
||||
unsigned int i = 0;
|
||||
|
||||
while (pairs[i][0])
|
||||
{
|
||||
if (GSSelectorTypesMatch(pairs[i][0], pairs[i][1]) == NO)
|
||||
{
|
||||
NSLog(@"pair %d does not match:\n%s\n%s",
|
||||
i, pairs[i][0], pairs[i][1]);
|
||||
failed = 1;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
run_server(void)
|
||||
{
|
||||
id obj = [MyClass new];
|
||||
NSConnection *conn = [NSConnection defaultConnection];
|
||||
|
||||
[conn setRootObject: obj];
|
||||
if ([conn registerName: SRV_NAME] == NO)
|
||||
{
|
||||
NSLog(@"Failed to register name: " SRV_NAME );
|
||||
abort();
|
||||
}
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
if ([[[[NSProcessInfo processInfo] arguments] lastObject] isEqual: @"srv"])
|
||||
{
|
||||
run_server();
|
||||
abort();
|
||||
}
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
test_mframe_build_signature();
|
||||
test_compare_server_signature();
|
||||
test_GSSelectorTypesMatch();
|
||||
if (failed)
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"discrepancies between gcc/mframe signatures"];
|
||||
|
||||
NSLog(@"MethodSignature Test Succeeded.");
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"MethodSignature Test Failed:");
|
||||
NSLog(@"%@ %@ %@",
|
||||
[localException name],
|
||||
[localException reason],
|
||||
[localException userInfo]);
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
|
||||
[pool release];
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* The simplest of tests for the NSNotification and NSNotificationCenter
|
||||
classes. These tests should be expanded.
|
||||
|
||||
(The Tcp*Port classes, however, do test the notification mechanism
|
||||
further.) */
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
@interface Observer : NSObject
|
||||
- (void) gotNotificationFoo: not;
|
||||
@end
|
||||
|
||||
@implementation Observer
|
||||
|
||||
- (void) gotNotificationFoo: (NSNotification*)not
|
||||
{
|
||||
printf ("Got %s\n", [[not name] cString]);
|
||||
}
|
||||
|
||||
- (void) gotNotificationFooNoObject: (NSNotification*)not
|
||||
{
|
||||
printf ("Got %s without object\n", [[not name] cString]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
id foo = @"NotificationTestFoo";
|
||||
|
||||
int main ()
|
||||
{
|
||||
id o1;
|
||||
id observer1;
|
||||
id arp;
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
NSLog(@"Make string object");
|
||||
o1 = [NSString new];
|
||||
NSLog(@"Make Observer object");
|
||||
observer1 = [Observer new];
|
||||
|
||||
NSLog(@"Add observer to process centre");
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: observer1
|
||||
selector: @selector(gotNotificationFoo:)
|
||||
name: foo
|
||||
object: o1];
|
||||
|
||||
NSLog(@"Add observer to distributed centre");
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
addObserver: observer1
|
||||
selector: @selector(gotNotificationFoo:)
|
||||
name: foo
|
||||
object: o1];
|
||||
|
||||
NSLog(@"Add observer to process centre");
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: observer1
|
||||
selector: @selector(gotNotificationFooNoObject:)
|
||||
name: foo
|
||||
object: nil];
|
||||
|
||||
NSLog(@"Add observer to distributed centre");
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
addObserver: observer1
|
||||
selector: @selector(gotNotificationFooNoObject:)
|
||||
name: foo
|
||||
object: nil];
|
||||
|
||||
|
||||
NSLog(@"Post to process centre");
|
||||
/* This will cause two messages to be printed, one for each request above. */
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: o1];
|
||||
|
||||
NSLog(@"Post to distributed centre");
|
||||
/* This will cause two messages to be printed, one for each request above. */
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: o1];
|
||||
|
||||
NSLog(@"Post to process centre");
|
||||
/* This will cause one message to be printed. */
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: nil];
|
||||
|
||||
NSLog(@"Post to distributed centre");
|
||||
/* This will cause one message to be printed. */
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: nil];
|
||||
|
||||
|
||||
NSLog(@"Remove observer from process centre");
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: observer1
|
||||
name: nil
|
||||
object: o1];
|
||||
|
||||
/* This will cause message to be printed. */
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: o1];
|
||||
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
removeObserver: observer1];
|
||||
|
||||
/* This will cause no messages to be printed. */
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: o1];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
addObserver: observer1
|
||||
selector: @selector(gotNotificationFooNoObject:)
|
||||
name: foo
|
||||
object: nil];
|
||||
|
||||
[[NSDistributedNotificationCenter defaultCenter]
|
||||
postNotificationName: foo
|
||||
object: @"hello"];
|
||||
|
||||
[arp release];
|
||||
|
||||
exit (0);
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* TESTING: NSPathUtilities.h ************************************************
|
||||
* *
|
||||
* Author: Sheldon Gill *
|
||||
* Date: 20-Dec-2003 *
|
||||
* *
|
||||
* Lists all search paths *
|
||||
* *
|
||||
**************************************************************************** */
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSPathUtilities.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
||||
/* Define any unknown directory keys */
|
||||
#ifndef NSDocumentDirectory
|
||||
#define NSDocumentDirectory 155
|
||||
#endif
|
||||
#ifndef GSFrameworksDirectory
|
||||
#define GSFrameworksDirectory 153
|
||||
#endif
|
||||
#ifndef GSFontsDirectory
|
||||
#define GSFontsDirectory 154
|
||||
#endif
|
||||
|
||||
void print_paths(NSArray *paths)
|
||||
{
|
||||
int i, count;
|
||||
|
||||
count = [paths count];
|
||||
if (count==1)
|
||||
{
|
||||
printf("%s\n", [[paths objectAtIndex:0] cString]);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("<list>\n");
|
||||
for ( i = 0; i < count; i++ )
|
||||
{
|
||||
printf(" %s\n", [[paths objectAtIndex:i] cString]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
NSAutoreleasePool *arp;
|
||||
|
||||
NSArray *domain_names;
|
||||
NSArray *directory_key_names;
|
||||
NSArray *paths;
|
||||
int i, j, k;
|
||||
|
||||
BOOL tilde_expansion = YES;
|
||||
|
||||
#define DIR_KEYS 16
|
||||
#define DOMAIN_MASKS 5
|
||||
|
||||
NSSearchPathDomainMask domain_masks[DOMAIN_MASKS] = {
|
||||
NSUserDomainMask,
|
||||
NSLocalDomainMask,
|
||||
NSNetworkDomainMask,
|
||||
NSSystemDomainMask,
|
||||
NSAllDomainsMask
|
||||
};
|
||||
|
||||
NSSearchPathDirectory directory_keys[DIR_KEYS] = {
|
||||
NSApplicationDirectory,
|
||||
NSDemoApplicationDirectory,
|
||||
NSDeveloperApplicationDirectory,
|
||||
NSAdminApplicationDirectory,
|
||||
NSLibraryDirectory,
|
||||
NSDeveloperDirectory,
|
||||
NSUserDirectory,
|
||||
NSDocumentationDirectory,
|
||||
NSDocumentDirectory,
|
||||
NSAllApplicationsDirectory,
|
||||
NSAllLibrariesDirectory,
|
||||
GSLibrariesDirectory,
|
||||
GSToolsDirectory,
|
||||
GSApplicationSupportDirectory,
|
||||
GSFrameworksDirectory,
|
||||
GSFontsDirectory
|
||||
};
|
||||
|
||||
NSSearchPathDirectory key;
|
||||
NSSearchPathDomainMask domain;
|
||||
|
||||
printf("TESTING: NSPathUtilities.h\n");
|
||||
|
||||
arp = [NSAutoreleasePool new];
|
||||
|
||||
if (argc > 1)
|
||||
tilde_expansion = NO;
|
||||
|
||||
printf("Begin...\n");
|
||||
|
||||
domain_names = [NSArray arrayWithObjects:
|
||||
@"NSUserDomainMask",
|
||||
@"NSLocalDomainMask",
|
||||
@"NSNetworkDomainMask",
|
||||
@"NSSystemDomainMask",
|
||||
@"NSAllDomainsMask",
|
||||
nil
|
||||
];
|
||||
|
||||
directory_key_names = [NSArray arrayWithObjects:
|
||||
@"NSApplicationDirectory",
|
||||
@"NSDemoApplicationDirectory",
|
||||
@"NSDeveloperApplicationDirectory",
|
||||
@"NSAdminApplicationDirectory",
|
||||
@"NSLibraryDirectory",
|
||||
@"NSDeveloperDirectory",
|
||||
@"NSUserDirectory",
|
||||
@"NSDocumentationDirectory",
|
||||
@"NSDocumentDirectory",
|
||||
@"NSAllApplicationsDirectory",
|
||||
@"NSAllLibrariesDirectory",
|
||||
@"GSLibrariesDirectory",
|
||||
@"GSToolsDirectory",
|
||||
@"GSApplicationSupportDirectory",
|
||||
@"GSFrameworksDirectory",
|
||||
@"GSFontsDirectory",
|
||||
nil
|
||||
];
|
||||
|
||||
printf("NSSearchPathForDirectoriesInDomains()\n");
|
||||
for ( i = 0 ; i < DOMAIN_MASKS ; i++ )
|
||||
{
|
||||
printf("Domain: %s\n",[[domain_names objectAtIndex: i] cString]);
|
||||
domain = domain_masks[i];
|
||||
|
||||
for ( j = 0 ; j < DIR_KEYS ; j++ )
|
||||
{
|
||||
printf(" %s = ",[[directory_key_names objectAtIndex: j] cString]);
|
||||
key = directory_keys[j];
|
||||
|
||||
paths = NSSearchPathForDirectoriesInDomains( key, domain, tilde_expansion );
|
||||
if ([paths count] == 0)
|
||||
{
|
||||
printf("<Empty>\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
print_paths(paths);
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("End NSSearchPathForDirectoriesInDomains\n\n");
|
||||
|
||||
printf("Begin NSUser functions...\n");
|
||||
GSPrintf(stdout,@"User name is '%@'\n",NSUserName());
|
||||
GSPrintf(stdout,@"Home directory is '%@'\n",NSHomeDirectory());
|
||||
GSPrintf(stdout,@"GSDefaultsRoot for user is '%@'\n",GSDefaultsRootForUser(NSUserName()));
|
||||
GSPrintf(stdout,@"Temp for user is '%@'\n",NSTemporaryDirectory());
|
||||
printf("End NSUser functions\n\n");
|
||||
|
||||
[arp release];
|
||||
|
||||
printf("End Testing!\n");
|
||||
return 0;
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSProcessInfo *pi = [NSProcessInfo processInfo];
|
||||
NSString* aString;
|
||||
NSString* aKey;
|
||||
NSEnumerator* enumerator;
|
||||
|
||||
printf("Host name: %s\n",[[pi hostName] UTF8String]);
|
||||
printf("Operating system: %d\n",[pi operatingSystem]);
|
||||
printf("Operating system name: %s\n",[[pi operatingSystemName] UTF8String]);
|
||||
printf("Operating system version: %s\n",[[pi operatingSystemVersionString] UTF8String]);
|
||||
printf("Process Name: %s\n",[[pi processName] UTF8String]);
|
||||
printf("Globally Unique String: %s\n",[[pi globallyUniqueString] UTF8String]);
|
||||
|
||||
printf("\nProcess arguments\n");
|
||||
printf("%d argument(s)\n", [[pi arguments] count]);
|
||||
enumerator = [[pi arguments] objectEnumerator];
|
||||
while ((aString = [enumerator nextObject]))
|
||||
printf("-->%s\n",[aString UTF8String]);
|
||||
|
||||
printf("\nProcess environment\n");
|
||||
printf("%d environment variables(s)\n", [[pi environment] count]);
|
||||
enumerator = [[pi environment] keyEnumerator];
|
||||
while ((aKey = [enumerator nextObject]))
|
||||
printf("++>%s=%s\n",[aKey UTF8String],[[[pi environment]
|
||||
objectForKey:aKey] UTF8String]);
|
||||
|
||||
[arp release];
|
||||
exit(0);
|
||||
}
|
|
@ -1,968 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/*
|
||||
* Test the operation of the NSScanner class.
|
||||
* All is well if this program produces no output.
|
||||
*
|
||||
* By default, double values differing by one least-significant-bit or
|
||||
* less are assumed to be equal. This behaviour can be changed with
|
||||
* the `-e' flag. For example, if you want only doubles that are exactly
|
||||
* equal to be treated as equal, use `-e0'.
|
||||
*
|
||||
* Eric Norum <eric@skatter.usask.ca>
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSScanner.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <limits.h>
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "wgetopt.h"
|
||||
|
||||
/*
|
||||
* Doubles differing by this many least-significant-bits
|
||||
* or less are assumed to be `equal'.
|
||||
*/
|
||||
int DoubleCompareEqual = 1;
|
||||
|
||||
/*
|
||||
* Check that scan completely consumed string
|
||||
*/
|
||||
void
|
||||
testFullScan (const char *message, NSString *string, NSScanner *scanner)
|
||||
{
|
||||
unsigned int scanLocation;
|
||||
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != [string length])
|
||||
printf ("%s of `%s' moves scan location to %u.\n", message,
|
||||
[string cString], scanLocation);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanInt: *
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test a valid scanInt operation
|
||||
*/
|
||||
void
|
||||
testScanIntGood (int i)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
int value;
|
||||
|
||||
string = [NSString stringWithFormat:@"%d", i];
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanInt:&value])
|
||||
printf ("scanInt of `%s' failed.\n", [string cString]);
|
||||
else if (value != i)
|
||||
printf ("scanInt of `%s' returned value %d.\n", [string cString], value);
|
||||
testFullScan ("scanInt", string, scanner);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that scanInt handles overflow
|
||||
*/
|
||||
void
|
||||
testScanIntOverflow (double d)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
int value;
|
||||
|
||||
string = [NSString stringWithFormat:@"%.0f", d];
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanInt:&value])
|
||||
printf ("scanInt of `%s' failed.\n", [string cString]);
|
||||
else if (value != ((d < 0) ? INT_MIN : INT_MAX))
|
||||
printf ("scanInt of `%s' didn't overflow, returned %d.\n", [string cString], value);
|
||||
testFullScan ("scanInt", string, scanner);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test scanInt operation
|
||||
*/
|
||||
void
|
||||
testScanInt (void)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
int i;
|
||||
int value;
|
||||
unsigned int scanLocation;
|
||||
|
||||
/*
|
||||
* Check values within range
|
||||
*/
|
||||
i = INT_MAX-20;
|
||||
for (;;) {
|
||||
testScanIntGood (i);
|
||||
if (i == INT_MAX)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
i = INT_MIN+20;
|
||||
for (;;) {
|
||||
testScanIntGood (i);
|
||||
if (i == INT_MIN)
|
||||
break;
|
||||
i--;
|
||||
}
|
||||
for (i = -20 ; i <= 20 ; i++)
|
||||
testScanIntGood (i);
|
||||
|
||||
|
||||
/*
|
||||
* Check overflow values
|
||||
*/
|
||||
for (i = 1 ; i <= 20 ; i++) {
|
||||
testScanIntOverflow ((double)INT_MAX + i);
|
||||
testScanIntOverflow ((double)INT_MIN - i);
|
||||
testScanIntOverflow ((2.0 * (double)INT_MAX) + i);
|
||||
testScanIntOverflow ((2.0 * (double)INT_MIN) - i);
|
||||
testScanIntOverflow ((10.0 * (double)INT_MAX) + i);
|
||||
testScanIntOverflow ((10.0 * (double)INT_MIN) - i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that non-digits terminate the scan
|
||||
*/
|
||||
string = @"1234FOO";
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanInt:&value])
|
||||
printf ("scanInt of `%s' failed.\n", [string cString]);
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != 4)
|
||||
printf ("scanInt of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
|
||||
/*
|
||||
* Check that non-digits don't move the scan location
|
||||
*/
|
||||
string = @"junk";
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if ([scanner scanInt:&value])
|
||||
printf ("scanInt of `%s' succeeded with value %d.\n", [string cString], value);
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != 0)
|
||||
printf ("scanInt of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
|
||||
/*
|
||||
* Check that non-digits don't consume characters to be skipped
|
||||
*/
|
||||
string = @" junk";
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if ([scanner scanInt:&value])
|
||||
printf ("scanInt of `%s' succeeded with value %d.\n", [string cString], value);
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != 0)
|
||||
printf ("scanInt of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanRadixUnsignedInt: *
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test a valid scanRadixUnsignedInt operation
|
||||
*/
|
||||
void
|
||||
testScanRadixUnsignedIntFinish (NSString *string, BOOL expectValue, unsigned int expectedValue, unsigned int expectedScanLocation)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
unsigned int value;
|
||||
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if ([scanner scanRadixUnsignedInt:&value]) {
|
||||
if (!expectValue)
|
||||
printf ("scanRadixUnsignedInt of `%s' succeeded.\n", [string cString]);
|
||||
else if (value != expectedValue)
|
||||
printf ("scanRadixUnsignedInt of `%s' returned value %u (%#x).\n", [string cString], value, value);
|
||||
}
|
||||
else {
|
||||
if (expectValue)
|
||||
printf ("scanRadixUnsignedInt of `%s' failed.\n", [string cString]);
|
||||
}
|
||||
if (expectedScanLocation != [scanner scanLocation])
|
||||
printf ("scanRadixUnsignedInt of `%s' moved scan location to %u (expected %u)\n", [string cString], [scanner scanLocation], expectedScanLocation);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test a valid scanRadixUnsignedInt operation
|
||||
*/
|
||||
void
|
||||
testScanRadixUnsignedIntGood (NSString *format, unsigned int i)
|
||||
{
|
||||
NSString *string;
|
||||
|
||||
if (format == nil) {
|
||||
testScanRadixUnsignedIntGood (@"%u", i);
|
||||
testScanRadixUnsignedIntGood (@"0%o", i);
|
||||
testScanRadixUnsignedIntGood (@"0x%x", i);
|
||||
testScanRadixUnsignedIntGood (@"0X%X", i);
|
||||
return;
|
||||
}
|
||||
string = [NSString stringWithFormat:format, i];
|
||||
testScanRadixUnsignedIntFinish (string, YES, i, [string length]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that scanRadixUnsignedInt handles overflow
|
||||
*/
|
||||
void
|
||||
testScanRadixUnsignedIntOverflow (double d)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
unsigned int value;
|
||||
|
||||
string = [NSString stringWithFormat:@"%.0f", d];
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanRadixUnsignedInt:&value])
|
||||
printf ("scanRadixUnsignedInt of `%s' failed.\n", [string cString]);
|
||||
else if (value != UINT_MAX)
|
||||
printf ("scanRadixUnsignedInt of `%s' didn't overflow, returned %u (%#x).\n", [string cString], value, value);
|
||||
testFullScan ("scanRadixUnsignedInt", string, scanner);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test scanRadixUnsignedInt operation
|
||||
*/
|
||||
void
|
||||
testScanRadixUnsignedInt (void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/*
|
||||
* I added this check so I can use the same test program on
|
||||
* NEXTSTEP/OPENSTEP which doesn't have the scanRadixUnsignedInt:
|
||||
* method.
|
||||
*/
|
||||
if (![NSScanner instancesRespondTo:@selector(scanRadixUnsignedInt:)]) {
|
||||
printf ("NSScanner objects do not respond to scanRadixUnsignedInt:\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check values within range
|
||||
*/
|
||||
i = UINT_MAX-32;
|
||||
for (;;) {
|
||||
testScanRadixUnsignedIntGood (nil, i);
|
||||
if (i == UINT_MAX)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
for (i = 0 ; i <= 32 ; i++)
|
||||
testScanRadixUnsignedIntGood (nil, i);
|
||||
|
||||
/*
|
||||
* Check overflow values
|
||||
*/
|
||||
for (i = 1 ; i <= 32 ; i++) {
|
||||
testScanRadixUnsignedIntOverflow ((double)UINT_MAX + i);
|
||||
testScanRadixUnsignedIntOverflow ((2.0 * (double)UINT_MAX) + i);
|
||||
testScanRadixUnsignedIntOverflow ((2.0 * (double)UINT_MAX) - i);
|
||||
testScanRadixUnsignedIntOverflow ((10.0 * (double)UINT_MAX) + i);
|
||||
testScanRadixUnsignedIntOverflow ((10.0 * (double)UINT_MAX) - i);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that non-digits terminate the scan
|
||||
*/
|
||||
testScanRadixUnsignedIntFinish (@"1234FOO", YES, 1234, 4);
|
||||
testScanRadixUnsignedIntFinish (@"01234FOO", YES, 01234, 5);
|
||||
testScanRadixUnsignedIntFinish (@"0x1234FOO", YES, 0x1234F, 7);
|
||||
testScanRadixUnsignedIntFinish (@"0X1234FOO", YES, 0x1234F, 7);
|
||||
testScanRadixUnsignedIntFinish (@"012348FOO", YES, 01234, 5);
|
||||
testScanRadixUnsignedIntFinish (@"012349FOO", YES, 01234, 5);
|
||||
|
||||
/*
|
||||
* Check that non-digits don't move the scan location
|
||||
*/
|
||||
testScanRadixUnsignedIntFinish (@"FOO", NO, 0, 0);
|
||||
testScanRadixUnsignedIntFinish (@" FOO", NO, 0, 0);
|
||||
testScanRadixUnsignedIntFinish (@" 0x ", NO, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanHexInt: *
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* Test a valid scanHexInt operation
|
||||
*/
|
||||
void
|
||||
testScanHexIntFinish (NSString *string, BOOL expectValue, unsigned int expectedValue, unsigned int expectedScanLocation)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
unsigned int value;
|
||||
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if ([scanner scanHexInt:&value]) {
|
||||
if (!expectValue)
|
||||
printf ("scanHexInt of `%s' succeeded.\n", [string cString]);
|
||||
else if (value != expectedValue)
|
||||
printf ("scanHexInt of `%s' returned value %u (%#x).\n", [string cString], value, value);
|
||||
}
|
||||
else {
|
||||
if (expectValue)
|
||||
printf ("scanHexInt of `%s' failed.\n", [string cString]);
|
||||
}
|
||||
if (expectedScanLocation != [scanner scanLocation])
|
||||
printf ("scanHexInt of `%s' moved scan location to %u (expected %u)\n", [string cString], [scanner scanLocation], expectedScanLocation);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test a valid scanHexInt operation
|
||||
*/
|
||||
void
|
||||
testScanHexIntGood (NSString *format, unsigned int i)
|
||||
{
|
||||
NSString *string;
|
||||
|
||||
if (format == nil) {
|
||||
testScanHexIntGood (@"%x", i);
|
||||
testScanHexIntGood (@"%X", i);
|
||||
return;
|
||||
}
|
||||
string = [NSString stringWithFormat:format, i];
|
||||
testScanHexIntFinish (string, YES, i, [string length]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test scanHexInt operation
|
||||
*/
|
||||
void
|
||||
testScanHexInt (void)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/*
|
||||
* Check values within range
|
||||
*/
|
||||
i = UINT_MAX-32;
|
||||
for (;;) {
|
||||
testScanHexIntGood (nil, i);
|
||||
if (i == UINT_MAX)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
for (i = 0 ; i <= 32 ; i++)
|
||||
testScanHexIntGood (nil, i);
|
||||
|
||||
/*
|
||||
* Check that non-digits terminate the scan
|
||||
*/
|
||||
testScanHexIntFinish (@"1234FOO", YES, 0x1234F, 5);
|
||||
testScanHexIntFinish (@"01234FOO", YES, 0x1234F, 6);
|
||||
|
||||
/*
|
||||
* Check that non-digits don't move the scan location
|
||||
*/
|
||||
testScanHexIntFinish (@"GOO", NO, 0, 0);
|
||||
testScanHexIntFinish (@" GOO", NO, 0, 0);
|
||||
testScanHexIntFinish (@" x ", NO, 0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanLongLong: *
|
||||
************************************************************************
|
||||
*/
|
||||
#if defined (LONG_LONG_MAX)
|
||||
/*
|
||||
* Quick hacks to convert a long long types.
|
||||
*/
|
||||
static char *
|
||||
unsignedlonglongToString (unsigned long long n)
|
||||
{
|
||||
static char cbuf[400]; /* Should be big enough! */
|
||||
char *cp = &cbuf[400];
|
||||
|
||||
*--cp = '\0';
|
||||
do {
|
||||
*--cp = (n % 10) + '0';
|
||||
n /= 10;
|
||||
} while (n);
|
||||
return cp;
|
||||
}
|
||||
|
||||
static char *
|
||||
longlongToString (long long i)
|
||||
{
|
||||
unsigned long long n;
|
||||
char *cp;
|
||||
|
||||
if (i < 0)
|
||||
n = -i;
|
||||
else
|
||||
n = i;
|
||||
cp = unsignedlonglongToString (n);
|
||||
if (i < 0)
|
||||
*--cp = '-';
|
||||
return cp;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test a valid scanLongLong operation
|
||||
*/
|
||||
void
|
||||
testScanLongLongGood (long long i)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
long long value;
|
||||
|
||||
string = [NSString stringWithFormat:@"%s", longlongToString (i)];
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanLongLong:&value])
|
||||
printf ("scanLongLong of `%s' failed.\n", [string cString]);
|
||||
else if (value != i)
|
||||
printf ("scanLongLong of `%s' returned value %s.\n", [string cString],
|
||||
longlongToString (value));
|
||||
testFullScan ("scanLongLong", string, scanner);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that scanLongLong handles overflow
|
||||
*/
|
||||
void
|
||||
testScanLongLongOverflow (const char *sign, unsigned long long check, long long expect)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
long long value;
|
||||
|
||||
string = [NSString stringWithFormat:@"%s%s", sign, unsignedlonglongToString (check)];
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanLongLong:&value])
|
||||
printf ("scanLongLong of `%s' failed.\n", [string cString]);
|
||||
else if (value != expect)
|
||||
printf ("scanLongLong of `%s' didn't overflow, returned %s.\n", [string cString],
|
||||
longlongToString (value));
|
||||
testFullScan ("scanLongLong", string, scanner);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test scanLongLong operation
|
||||
*/
|
||||
void
|
||||
testScanLongLong (void)
|
||||
{
|
||||
NSString *string;
|
||||
NSScanner *scanner;
|
||||
long long i;
|
||||
long long value;
|
||||
unsigned int scanLocation;
|
||||
|
||||
/*
|
||||
* Check values within range
|
||||
*/
|
||||
i = LONG_LONG_MAX-20;
|
||||
for (;;) {
|
||||
testScanLongLongGood (i);
|
||||
if (i == LONG_LONG_MAX)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
i = LONG_LONG_MIN+20;
|
||||
for (;;) {
|
||||
testScanLongLongGood (i);
|
||||
if (i == LONG_LONG_MIN)
|
||||
break;
|
||||
i--;
|
||||
}
|
||||
for (i = -20 ; i <= 20 ; i++)
|
||||
testScanLongLongGood (i);
|
||||
|
||||
|
||||
/*
|
||||
* Check overflow values
|
||||
*/
|
||||
for (i = 1 ; i <= 20 ; i++) {
|
||||
testScanLongLongOverflow ("", LONG_LONG_MAX + i, LONG_LONG_MAX);
|
||||
testScanLongLongOverflow ("", ULONG_LONG_MAX - i + 1, LONG_LONG_MAX);
|
||||
if (i > 1)
|
||||
testScanLongLongOverflow ("-", LONG_LONG_MAX + i, LONG_LONG_MIN);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that non-digits terminate the scan
|
||||
*/
|
||||
string = @"1234FOO";
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanLongLong:&value])
|
||||
printf ("scanLongLong of `%s' failed.\n", [string cString]);
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != 4)
|
||||
printf ("scanLongLong of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
|
||||
/*
|
||||
* Check that non-digits don't move the scan location
|
||||
*/
|
||||
string = @"junk";
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if ([scanner scanLongLong:&value])
|
||||
printf ("scanLongLong of `%s' succeeded with value %s\n", [string cString],
|
||||
longlongToString (value));
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != 0)
|
||||
printf ("scanLongLong of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
}
|
||||
#endif /* defined (LONG_LONG_MAX) */
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanDouble: *
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
/*
|
||||
* Compare two doubles for `almost' equality
|
||||
*/
|
||||
static double
|
||||
areDoublesEqual (double d1, double d2)
|
||||
{
|
||||
if (d1 == d2)
|
||||
return 0;
|
||||
if (d1 == 0)
|
||||
return (fabs (d2) /DBL_EPSILON);
|
||||
if (d2 == 0)
|
||||
return (fabs (d1) /DBL_EPSILON);
|
||||
d1 = fabs(d1);
|
||||
d2 = fabs(d2);
|
||||
if (d1 > d2)
|
||||
return fabs (1.0 - (d1 / d2)) / DBL_EPSILON;
|
||||
else
|
||||
return fabs (1.0 - (d2 / d1)) / DBL_EPSILON;
|
||||
}
|
||||
|
||||
/*
|
||||
* Test a scanDouble operation
|
||||
*/
|
||||
void
|
||||
testScanDoubleGood (NSString *string, double expect)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
double value, error;
|
||||
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanDouble:&value])
|
||||
printf ("scanDouble of `%s' failed.\n", [string cString]);
|
||||
else if ((error = areDoublesEqual (value, expect)) > DoubleCompareEqual)
|
||||
printf ("scanDouble of `%s' returned value %.*e (%g LSB different).\n",
|
||||
[string cString], DBL_DIG + 2, value, error);
|
||||
testFullScan ("scanDouble", string, scanner);
|
||||
}
|
||||
|
||||
static void
|
||||
testScanDoubleOneDigit (NSString *format, int digit, double expect)
|
||||
{
|
||||
NSString *string = [NSString stringWithFormat:format, digit];
|
||||
testScanDoubleGood (string, expect);
|
||||
}
|
||||
|
||||
static void
|
||||
testScanDoubleShort (NSString *string, double expect, unsigned int length)
|
||||
{
|
||||
NSScanner *scanner;
|
||||
double value, error;
|
||||
unsigned int scanLocation;
|
||||
|
||||
scanner = [NSScanner scannerWithString:string];
|
||||
if (![scanner scanDouble:&value])
|
||||
printf ("scanDouble of `%s' failed.\n", [string cString]);
|
||||
else if ((error = areDoublesEqual (value, expect)) > DoubleCompareEqual)
|
||||
printf ("scanDouble of `%s' returned value %.*e (%g LSB different).\n",
|
||||
[string cString], DBL_DIG + 2, value, error);
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != length)
|
||||
printf ("scanDouble of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
}
|
||||
|
||||
void
|
||||
testScanDoubleBad (NSString *string)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
double value;
|
||||
unsigned int scanLocation;
|
||||
|
||||
if ([scanner scanDouble:&value])
|
||||
printf ("scanDouble of `%s' succeeded with value %g\n", [string cString], value);
|
||||
scanLocation = [scanner scanLocation];
|
||||
if (scanLocation != 0)
|
||||
printf ("scanDouble of `%s' moves scan location to %u.\n", [string cString], scanLocation);
|
||||
}
|
||||
|
||||
/*
|
||||
* Test scanDouble operations
|
||||
*/
|
||||
void
|
||||
testScanDouble (void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/*
|
||||
* Check all digits before and after decimal point
|
||||
*/
|
||||
for (i = 0 ; i < 10 ; i++) {
|
||||
testScanDoubleOneDigit (@"%d", i, i);
|
||||
testScanDoubleOneDigit (@"%d.", i, i);
|
||||
testScanDoubleOneDigit (@"%d.0", i, i);
|
||||
testScanDoubleOneDigit (@"0%d.0", i, i);
|
||||
testScanDoubleOneDigit (@".%d", i, i / 10.0);
|
||||
testScanDoubleOneDigit (@"0.%d", i, i / 10.0);
|
||||
|
||||
testScanDoubleOneDigit (@"-%d", i, -i);
|
||||
testScanDoubleOneDigit (@"-%d.", i, -i);
|
||||
testScanDoubleOneDigit (@"-%d.0", i, -i);
|
||||
testScanDoubleOneDigit (@"-0%d.0", i, -i);
|
||||
testScanDoubleOneDigit (@"-.%d", i, -i / 10.0);
|
||||
testScanDoubleOneDigit (@"-0.%d", i, -i / 10.0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check exponents
|
||||
*/
|
||||
testScanDoubleGood (@"1e0", 1);
|
||||
testScanDoubleGood (@"1e1", 10);
|
||||
testScanDoubleGood (@"1e+1", 10);
|
||||
testScanDoubleGood (@"1e10", 1e10);
|
||||
testScanDoubleGood (@"1e+10", 1e10);
|
||||
testScanDoubleGood (@"1e-0", 1);
|
||||
testScanDoubleGood (@"1e-1", 1e-1);
|
||||
testScanDoubleGood (@"1e-1", 1e-1);
|
||||
testScanDoubleGood (@"1e-10", 1e-10);
|
||||
testScanDoubleGood (@"1e-10", 1e-10);
|
||||
|
||||
/*
|
||||
* Check a few other values
|
||||
*/
|
||||
testScanDoubleGood (@"123.456", 123.456);
|
||||
testScanDoubleGood (@"123.4567890123456789012345678901234567890123456789",
|
||||
123.4567890123456789012345678901234567890123456789);
|
||||
testScanDoubleGood (@"1234567890123456789012345678.9",
|
||||
1234567890123456789012345678.9);
|
||||
testScanDoubleGood (@"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890e-99",
|
||||
1.234567890123456789012345678901234567890123456789);
|
||||
testScanDoubleGood (@"0.000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000123456789e+100",
|
||||
1.23456789);
|
||||
|
||||
/*
|
||||
* Check some overflow values (for IEEE double-precision)
|
||||
*/
|
||||
testScanDoubleGood (@"12345678901234567890123456789012345678901234567890e300", HUGE_VAL);
|
||||
testScanDoubleGood (@"-12345678901234567890123456789012345678901234567890e300", -HUGE_VAL);
|
||||
testScanDoubleGood (@"1e999", HUGE_VAL);
|
||||
testScanDoubleGood (@"-1e999", -HUGE_VAL);
|
||||
|
||||
/*
|
||||
* Check some underflow values
|
||||
*/
|
||||
testScanDoubleGood (@"0.00000000000000000000000000000123456789e-300", 0);
|
||||
testScanDoubleGood (@"-0.00000000000000000000000000000123456789e-300", 0);
|
||||
testScanDoubleGood (@"1e-999", 0);
|
||||
testScanDoubleGood (@"-1e-999", 0);
|
||||
|
||||
/*
|
||||
* Check that non-digits terminate the scan
|
||||
*/
|
||||
testScanDoubleShort (@"1234FOO", 1234, 4);
|
||||
testScanDoubleShort (@"1234.FOO", 1234, 5);
|
||||
testScanDoubleShort (@"1234.0FOO", 1234, 6);
|
||||
testScanDoubleShort (@"1234..FOO", 1234, 5);
|
||||
testScanDoubleShort (@"1234.5.FOO", 1234.5, 6);
|
||||
|
||||
/*
|
||||
* Check that non-digits don't move the scan location
|
||||
*/
|
||||
testScanDoubleBad (@".foo");
|
||||
testScanDoubleBad (@"efoo");
|
||||
testScanDoubleBad (@".efoo");
|
||||
testScanDoubleBad (@"1234.5e.FOO");
|
||||
testScanDoubleBad (@"1234.5e.FOO");
|
||||
testScanDoubleBad (@"1234.5e 1");
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanString: *
|
||||
************************************************************************
|
||||
*/
|
||||
void
|
||||
testScanStringGood (NSString *string, NSString *search, NSString *match,
|
||||
BOOL caseSensitive, unsigned int goodScanLocation)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
[scanner setCaseSensitive:caseSensitive];
|
||||
if ([scanner scanString:search intoString:&s]) {
|
||||
if (([scanner scanLocation] != goodScanLocation)
|
||||
|| ![s isEqualToString:match])
|
||||
printf ("Case-%ssensitive scanString `%s' of `%s' gives `%s', scanLocation %d.\n",
|
||||
caseSensitive ? "" : "in",
|
||||
[search cString],
|
||||
[string cString],
|
||||
[s cString],
|
||||
[scanner scanLocation]);
|
||||
}
|
||||
else {
|
||||
printf ("Case-%ssensitive scanString:`%s' of `%s' failed.\n",
|
||||
caseSensitive ? "" : "in",
|
||||
[search cString],
|
||||
[string cString]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanStringBad (NSString *string, NSString *search, BOOL caseSensitive)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
[scanner setCaseSensitive:caseSensitive];
|
||||
if ([scanner scanString:search intoString:&s]) {
|
||||
printf ("Case-%ssensitive scanString `%s' of `%s' gives `%s'.\n",
|
||||
caseSensitive ? "" : "in",
|
||||
[search cString],
|
||||
[string cString],
|
||||
[s cString]);
|
||||
}
|
||||
else {
|
||||
if ([scanner scanLocation] != 0)
|
||||
printf ("Case-%ssensitive scanString `%s' of `%s' moves scan location to `%d'.\n",
|
||||
caseSensitive ? "" : "in",
|
||||
[search cString],
|
||||
[string cString],
|
||||
[scanner scanLocation]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanString (void)
|
||||
{
|
||||
testScanStringGood (@"a", @"a", @"a", NO, 1);
|
||||
testScanStringGood (@"a", @"a", @"a", YES, 1);
|
||||
testScanStringGood (@"a", @"A", @"a", NO, 1);
|
||||
testScanStringGood (@" abcdefg", @"aBcD", @"abcd", NO, 7);
|
||||
testScanStringGood (@" ABCdEFG", @"aBcD", @"ABCd", NO, 7);
|
||||
testScanStringBad (@"a", @"A", YES);
|
||||
testScanStringBad (@" a", @"A", YES);
|
||||
testScanStringBad (@" aA", @"A", YES);
|
||||
testScanStringBad (@" aAb", @"b", NO);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanUpToString: *
|
||||
************************************************************************
|
||||
*/
|
||||
void
|
||||
testScanUpToStringGood (NSString *string, NSString *search, NSString *match, BOOL caseSensitive)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
[scanner setCaseSensitive:caseSensitive];
|
||||
if ([scanner scanUpToString:search intoString:&s]) {
|
||||
if (![s isEqualToString:match])
|
||||
printf ("Case-%ssensitive scanUpToString `%s' of `%s' gives `%s'.\n",
|
||||
caseSensitive ? "" : "in",
|
||||
[search cString],
|
||||
[string cString],
|
||||
[s cString]);
|
||||
}
|
||||
else {
|
||||
printf ("Case-%ssensitive scanUpToString:`%s' of `%s' failed.\n",
|
||||
caseSensitive ? "" : "in",
|
||||
[search cString],
|
||||
[string cString]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanUpToString (void)
|
||||
{
|
||||
testScanUpToStringGood (@"abcdefg", @"d", @"abc", NO);
|
||||
testScanUpToStringGood (@"abcdefg", @"de", @"abc", NO);
|
||||
testScanUpToStringGood (@"abcdefg", @"DeF", @"abcdefg", YES);
|
||||
testScanUpToStringGood (@"abcdefgDeFg", @"DeF", @"abc", NO);
|
||||
testScanUpToStringGood (@"abcdefgDeFg", @"DeF", @"abcdefg", YES);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanCharactersFromSet: *
|
||||
************************************************************************
|
||||
*/
|
||||
void
|
||||
testScanCharactersFromSetGood (NSString *string, NSCharacterSet *set,
|
||||
NSString *match, unsigned int goodScanLocation)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
if ([scanner scanCharactersFromSet:set intoString:&s]) {
|
||||
if (([scanner scanLocation] != goodScanLocation)
|
||||
|| ![s isEqualToString:match])
|
||||
printf ("scanCharactersFromSet of `%s' gives `%s', scanLocation %d.\n",
|
||||
[string cString],
|
||||
[s cString],
|
||||
[scanner scanLocation]);
|
||||
}
|
||||
else {
|
||||
printf ("scanCharactersFromSet of `%s' failed.\n", [string cString]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanCharactersFromSetBad (NSString *string, NSCharacterSet *set)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
if ([scanner scanCharactersFromSet:set intoString:&s]) {
|
||||
printf ("scanCharactersFromSet of `%s' gives `%s'.\n",
|
||||
[string cString],
|
||||
[s cString]);
|
||||
}
|
||||
else {
|
||||
if ([scanner scanLocation] != 0)
|
||||
printf ("scanCharactersFromSet of `%s' moves scan location to `%d'.\n",
|
||||
[string cString],
|
||||
[scanner scanLocation]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanCharactersFromSet (void)
|
||||
{
|
||||
NSCharacterSet *set = [NSCharacterSet uppercaseLetterCharacterSet];
|
||||
|
||||
testScanCharactersFromSetGood (@"A", set, @"A", 1);
|
||||
testScanCharactersFromSetGood (@"ABCde", set, @"ABC", 3);
|
||||
testScanCharactersFromSetGood (@"ABC", set, @"ABC", 3);
|
||||
testScanCharactersFromSetGood (@" AB12", set, @"AB", 4);
|
||||
testScanCharactersFromSetBad (@"a", set);
|
||||
testScanCharactersFromSetBad (@" abc", set);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* scanUpToCharactersFromSet: *
|
||||
************************************************************************
|
||||
*/
|
||||
void
|
||||
testScanUpToCharactersFromSetGood (NSString *string, NSCharacterSet *set,
|
||||
NSString *match, unsigned int goodScanLocation)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
if ([scanner scanUpToCharactersFromSet:set intoString:&s]) {
|
||||
if (([scanner scanLocation] != goodScanLocation)
|
||||
|| ![s isEqualToString:match])
|
||||
printf ("scanUpToCharactersFromSet of `%s' gives `%s', scanLocation %d.\n",
|
||||
[string cString],
|
||||
[s cString],
|
||||
[scanner scanLocation]);
|
||||
}
|
||||
else {
|
||||
printf ("scanUpToCharactersFromSet of `%s' failed.\n", [string cString]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanUpToCharactersFromSetBad (NSString *string, NSCharacterSet *set)
|
||||
{
|
||||
NSScanner *scanner = [NSScanner scannerWithString:string];
|
||||
NSString *s;
|
||||
|
||||
if ([scanner scanUpToCharactersFromSet:set intoString:&s]) {
|
||||
printf ("scanUpToCharactersFromSet of `%s' gives `%s'.\n",
|
||||
[string cString],
|
||||
[s cString]);
|
||||
}
|
||||
else {
|
||||
if ([scanner scanLocation] != 0)
|
||||
printf ("scanUpToCharactersFromSet of `%s' moves scan location to `%d'.\n",
|
||||
[string cString],
|
||||
[scanner scanLocation]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
testScanUpToCharactersFromSet (void)
|
||||
{
|
||||
NSCharacterSet *set = [NSCharacterSet uppercaseLetterCharacterSet];
|
||||
|
||||
testScanUpToCharactersFromSetGood (@"aA", set, @"a", 1);
|
||||
testScanUpToCharactersFromSetGood (@" aABCde", set, @"a", 3);
|
||||
testScanUpToCharactersFromSetGood (@"abc", set, @"abc", 3);
|
||||
testScanUpToCharactersFromSetGood (@" abAB12", set, @"ab", 4);
|
||||
testScanUpToCharactersFromSetBad (@"A", set);
|
||||
testScanUpToCharactersFromSetBad (@" Abc", set);
|
||||
}
|
||||
|
||||
/*
|
||||
************************************************************************
|
||||
* TEST DRIVER *
|
||||
************************************************************************
|
||||
*/
|
||||
void
|
||||
runtest (void (*test)(void))
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
(*test)();
|
||||
[arp release];
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
extern char *optarg;
|
||||
int c;
|
||||
|
||||
while ((c = getopt (argc, argv, "e:")) != EOF) {
|
||||
switch (c) {
|
||||
case 'e':
|
||||
DoubleCompareEqual = atoi (optarg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
runtest (testScanInt);
|
||||
runtest (testScanRadixUnsignedInt);
|
||||
runtest (testScanHexInt);
|
||||
#if defined (LONG_LONG_MAX)
|
||||
runtest (testScanLongLong);
|
||||
#endif
|
||||
runtest (testScanDouble);
|
||||
runtest (testScanString);
|
||||
runtest (testScanUpToString);
|
||||
runtest (testScanCharactersFromSet);
|
||||
runtest (testScanUpToCharactersFromSet);
|
||||
printf("Finished Tests\n");
|
||||
return 0;
|
||||
}
|
130
Testing/nsset.m
130
Testing/nsset.m
|
@ -1,130 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSEnumerator.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <assert.h>
|
||||
|
||||
void original_test ();
|
||||
void intersects_set_test();
|
||||
void is_subset_of_set_test ();
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
original_test ();
|
||||
intersects_set_test ();
|
||||
is_subset_of_set_test ();
|
||||
|
||||
printf("Test passed\n");
|
||||
[arp release];
|
||||
exit (0);
|
||||
}
|
||||
|
||||
void
|
||||
original_test ()
|
||||
{
|
||||
id a, s1, s2;
|
||||
id enumerator;
|
||||
|
||||
a = [NSArray arrayWithObjects:
|
||||
@"vache", @"poisson", @"cheval", @"poulet", nil];
|
||||
|
||||
s1 = [NSSet setWithArray:a];
|
||||
|
||||
assert ([s1 member:@"vache"]);
|
||||
assert ([s1 containsObject:@"cheval"]);
|
||||
assert ([s1 count] == 4);
|
||||
|
||||
enumerator = [s1 objectEnumerator];
|
||||
while ([[enumerator nextObject] description]);
|
||||
|
||||
s2 = [s1 mutableCopy];
|
||||
assert ([s1 isEqual:s2]);
|
||||
}
|
||||
|
||||
void
|
||||
intersects_set_test()
|
||||
{
|
||||
id a1 = [NSArray arrayWithObjects: @"abstract factory", @"builder",
|
||||
@"factory method", @"prototype", @"singleton", nil];
|
||||
id s1 = [NSSet setWithArray: a1];
|
||||
|
||||
id a2 = [NSArray arrayWithObjects: @"adapter", @"bridge", @"composite",
|
||||
@"decorator", @"facade", @"flyweight", @"Proxy", nil];
|
||||
id s2 = [NSSet setWithArray: a2];
|
||||
|
||||
id s3 = [NSSet setWithObjects: @"abstract factory", @"adapter", nil];
|
||||
id s4 = [NSSet setWithObject: @"chain of responsibility"];
|
||||
|
||||
id s5 = [NSSet set];
|
||||
assert (![s1 intersectsSet: s2]);
|
||||
assert (![s2 intersectsSet: s1]);
|
||||
|
||||
assert ([s1 intersectsSet: s3]);
|
||||
assert ([s2 intersectsSet: s3]);
|
||||
assert ([s3 intersectsSet: s1]);
|
||||
assert ([s3 intersectsSet: s2]);
|
||||
|
||||
assert (![s1 intersectsSet: s4]);
|
||||
assert (![s2 intersectsSet: s4]);
|
||||
assert (![s4 intersectsSet: s1]);
|
||||
assert (![s4 intersectsSet: s2]);
|
||||
|
||||
assert (![s1 intersectsSet: s5]);
|
||||
assert (![s2 intersectsSet: s5]);
|
||||
assert (![s3 intersectsSet: s5]);
|
||||
assert (![s4 intersectsSet: s5]);
|
||||
assert (![s5 intersectsSet: s5]);
|
||||
|
||||
assert (![s5 intersectsSet: s1]);
|
||||
assert (![s5 intersectsSet: s2]);
|
||||
assert (![s5 intersectsSet: s3]);
|
||||
assert (![s5 intersectsSet: s4]);
|
||||
assert (![s5 intersectsSet: s5]);
|
||||
}
|
||||
|
||||
void
|
||||
is_subset_of_set_test ()
|
||||
{
|
||||
id a1 = [NSArray arrayWithObjects: @"abstract factory", @"builder",
|
||||
@"factory method", @"prototype", @"singleton", nil];
|
||||
id s1 = [NSSet setWithArray: a1];
|
||||
|
||||
id a2 = [NSArray arrayWithObjects: @"adapter", @"bridge", @"composite",
|
||||
@"decorator", @"facade", @"flyweight", @"proxy", nil];
|
||||
id s2 = [NSSet setWithArray: a2];
|
||||
|
||||
id s3 = [NSSet setWithObjects: @"abstract factory", nil];
|
||||
id s4 = [NSSet setWithObjects: @"adapter", @"proxy", nil];
|
||||
id s5 = [NSSet setWithObject: @"chain of responsibility"];
|
||||
|
||||
id s6 = [NSSet set];
|
||||
|
||||
assert ([s3 isSubsetOfSet: s1]);
|
||||
assert ([s4 isSubsetOfSet: s2]);
|
||||
assert ([s6 isSubsetOfSet: s1]);
|
||||
assert ([s6 isSubsetOfSet: s2]);
|
||||
assert ([s6 isSubsetOfSet: s3]);
|
||||
assert ([s6 isSubsetOfSet: s4]);
|
||||
assert ([s6 isSubsetOfSet: s5]);
|
||||
assert ([s6 isSubsetOfSet: s6]);
|
||||
|
||||
assert (![s1 isSubsetOfSet: s6]);
|
||||
assert (![s1 isSubsetOfSet: s5]);
|
||||
assert (![s1 isSubsetOfSet: s4]);
|
||||
assert (![s1 isSubsetOfSet: s3]);
|
||||
assert (![s1 isSubsetOfSet: s2]);
|
||||
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
|
||||
@interface TaskObs : NSObject
|
||||
- (void) terminated: (NSNotification*)aNotification;
|
||||
@end
|
||||
@implementation TaskObs
|
||||
- (void) terminated: (NSNotification*)aNotification
|
||||
{
|
||||
NSLog(@"Task (%@) terminated", [aNotification object]);
|
||||
}
|
||||
@end
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSDictionary *env;
|
||||
NSTask *task;
|
||||
NSTask *t0, *t1;
|
||||
NSData *d;
|
||||
TaskObs *obs = [TaskObs new];
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
[[NSNotificationCenter defaultCenter]
|
||||
addObserver: obs
|
||||
selector: @selector(terminated:)
|
||||
name: NSTaskDidTerminateNotification
|
||||
object: nil];
|
||||
|
||||
#ifdef __MINGW32__
|
||||
task = [NSTask launchedTaskWithLaunchPath: @"C:\\windows\\system32\\mem.exe"
|
||||
arguments: nil];
|
||||
#else
|
||||
task = [NSTask launchedTaskWithLaunchPath: @"/bin/ls"
|
||||
arguments: nil];
|
||||
#endif
|
||||
[task waitUntilExit];
|
||||
printf("Exit status - %d\n", [task terminationStatus]); fflush(stdout);
|
||||
|
||||
RELEASE(pool);
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
task = [NSTask new];
|
||||
env = [[[[NSProcessInfo processInfo] environment] mutableCopy] autorelease];
|
||||
[task setEnvironment: env];
|
||||
[task setLaunchPath: @"/bin/sh"];
|
||||
[task setArguments: [NSArray arrayWithObjects: @"-c", @"echo $PATH", nil]];
|
||||
if ([task usePseudoTerminal] == NO)
|
||||
printf("Argh - unable to use pseudo terminal\n");
|
||||
[task launch];
|
||||
d = [[task standardOutput] availableData];
|
||||
NSLog(@"Got PATH of '%*s'", [d length], [d bytes]);
|
||||
|
||||
[task waitUntilExit];
|
||||
RELEASE(task);
|
||||
|
||||
NSLog(@"Testing two tasks at the same time");
|
||||
t0 = [NSTask launchedTaskWithLaunchPath: @"/bin/sh"
|
||||
arguments:
|
||||
[NSArray arrayWithObjects: @"-c", @"echo task0", nil]];
|
||||
NSLog(@"Launched task0 - %@", t0);
|
||||
|
||||
t1 = [NSTask launchedTaskWithLaunchPath: @"/bin/sh"
|
||||
arguments:
|
||||
[NSArray arrayWithObjects: @"-c", @"echo task1", nil]];
|
||||
NSLog(@"Launched task1 - %@", t1);
|
||||
|
||||
while ([t0 isRunning] == YES || [t1 isRunning] == YES)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate:
|
||||
[NSDate dateWithTimeIntervalSinceNow: 1]];
|
||||
RELEASE(arp);
|
||||
}
|
||||
RELEASE(pool);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <Foundation/NSTimer.h>
|
||||
#include <Foundation/NSInvocation.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
@interface TestDouble : NSObject
|
||||
+ (double) testDouble;
|
||||
- (double) testDoubleInstance;
|
||||
@end
|
||||
@implementation TestDouble
|
||||
+ (void) sayCount
|
||||
{
|
||||
static int count = 0;
|
||||
printf ("Timer fired %d times\n", ++count);
|
||||
if (count == 20)
|
||||
exit(0);
|
||||
}
|
||||
+ (double) testDouble
|
||||
{
|
||||
return 12345678912345.0;
|
||||
}
|
||||
- (double) testDoubleInstance
|
||||
{
|
||||
return 92345678912345.0;
|
||||
}
|
||||
@end
|
||||
|
||||
double test_double ()
|
||||
{
|
||||
return 92345678912345.0;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
volatile double foo, bar;
|
||||
id inv;
|
||||
id o;
|
||||
id d;
|
||||
|
||||
inv = [NSInvocation invocationWithMethodSignature:
|
||||
[TestDouble methodSignatureForSelector: @selector(sayCount)]];
|
||||
[inv setSelector: @selector(sayCount)];
|
||||
[inv setTarget: [TestDouble class]];
|
||||
|
||||
foo = [TestDouble testDouble];
|
||||
printf ("TestDouble is %f\n", foo);
|
||||
foo = [TestDouble testDouble];
|
||||
printf ("TestDouble 2 is %f\n", foo);
|
||||
o = [[TestDouble alloc] init];
|
||||
bar = [o testDoubleInstance];
|
||||
printf ("testDouble is %f\n", bar);
|
||||
|
||||
foo = test_double ();
|
||||
printf ("test_double is %f\n", foo);
|
||||
|
||||
d = [NSDate date];
|
||||
printf ("time interval since now %f\n", [d timeIntervalSinceNow]);
|
||||
|
||||
[NSTimer scheduledTimerWithTimeInterval: 3.0
|
||||
invocation: inv
|
||||
repeats: YES];
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
[arp release];
|
||||
exit (0);
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* Test time zone code. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSTimeZone.h>
|
||||
#include <Foundation/NSCalendarDate.h>
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
NSTimeZone *system;
|
||||
NSTimeZone *other;
|
||||
NSCalendarDate *date;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
|
||||
GSPrintf(stdout, @"GMT time zone %x\n",
|
||||
[NSTimeZone timeZoneWithAbbreviation:@"GMT"]);
|
||||
GSPrintf(stdout, @"System time zone\n");
|
||||
system = [NSTimeZone systemTimeZone];
|
||||
GSPrintf(stdout, @" %@\n\n", [system description]);
|
||||
|
||||
GSPrintf(stdout, @"Local time zone:\n %@\n\n",
|
||||
[[NSTimeZone localTimeZone] description]);
|
||||
|
||||
GSPrintf(stdout, @"Time zone for PST (from dict):\n %@\n",
|
||||
[[NSTimeZone abbreviationDictionary] objectForKey: @"PST"]);
|
||||
GSPrintf(stdout, @"Time zones for PST (from map):\n %@\n",
|
||||
[[[NSTimeZone abbreviationMap] objectForKey: @"PST"] description]);
|
||||
|
||||
other = [NSTimeZone timeZoneWithAbbreviation: @"CEST"];
|
||||
GSPrintf(stdout, @"Time zone for CEST:\n %@\n", other);
|
||||
|
||||
date = [[NSCalendarDate alloc] initWithString:@"09/04/2003 17:58:45 CEST"
|
||||
calendarFormat:@"%m/%d/%Y %H:%M:%S %Z"];
|
||||
GSPrintf(stdout, @"Date in CEST:\n %@\n", date);
|
||||
|
||||
|
||||
RELEASE(pool);
|
||||
return 0;
|
||||
}
|
|
@ -1,53 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
@interface UndoObject: NSObject
|
||||
{
|
||||
int state;
|
||||
}
|
||||
- (void) setState: (int)aState;
|
||||
- (int) state;
|
||||
@end
|
||||
@implementation UndoObject
|
||||
- (void) setState: (int)aState
|
||||
{
|
||||
state = aState;
|
||||
}
|
||||
- (int) state
|
||||
{
|
||||
return state;
|
||||
}
|
||||
@end
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
NSUndoManager *u = [NSUndoManager new];
|
||||
UndoObject *o = [UndoObject new];
|
||||
BOOL failed = NO;
|
||||
|
||||
[u registerUndoWithTarget: o selector: @selector(setState:) object: (id)1];
|
||||
[u undo];
|
||||
if ([o state] != 1)
|
||||
{
|
||||
NSLog(@"Failed undo");
|
||||
failed = YES;
|
||||
}
|
||||
RELEASE(arp);
|
||||
if (failed == NO)
|
||||
{
|
||||
NSLog(@"Test passed");
|
||||
}
|
||||
exit (0);
|
||||
}
|
|
@ -1,141 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
@interface MyDelegate : NSObject
|
||||
{
|
||||
BOOL problem;
|
||||
unsigned startDoc;
|
||||
unsigned endDoc;
|
||||
unsigned startElem;
|
||||
unsigned endElem;
|
||||
}
|
||||
- (BOOL) check;
|
||||
@end
|
||||
|
||||
@implementation MyDelegate
|
||||
- (BOOL) check
|
||||
{
|
||||
if (startDoc != 1)
|
||||
{
|
||||
problem = YES;
|
||||
NSLog(@"Missing start doc");
|
||||
}
|
||||
if (endDoc != 1)
|
||||
{
|
||||
problem = YES;
|
||||
NSLog(@"Missing end doc");
|
||||
}
|
||||
if (startElem != 1)
|
||||
{
|
||||
problem = YES;
|
||||
NSLog(@"Missing start element");
|
||||
}
|
||||
if (endElem != 1)
|
||||
{
|
||||
problem = YES;
|
||||
NSLog(@"Missing end element");
|
||||
}
|
||||
return problem;
|
||||
}
|
||||
|
||||
- (void) parserDidEndDocument: (NSXMLParser*)aParser
|
||||
{
|
||||
endDoc++;
|
||||
}
|
||||
- (void) parserDidStartDocument: (NSXMLParser*)aParser
|
||||
{
|
||||
startDoc++;
|
||||
}
|
||||
|
||||
- (void) parser: (NSXMLParser*)aParser
|
||||
didStartElement: (NSString*)anElementName
|
||||
namespaceURI: (NSString*)aNamespaceURI
|
||||
qualifiedName: (NSString*)aQualifierName
|
||||
attributes: (NSDictionary*)anAttributeDict
|
||||
{
|
||||
if (startElem == 0)
|
||||
{
|
||||
startElem++;
|
||||
if ([anElementName isEqual: @"example"] == NO) {
|
||||
problem = YES;
|
||||
NSLog(@"Bad start element '%@' in namespace '%@' '%@' attributes '%@'",
|
||||
anElementName, aNamespaceURI, aQualifierName, anAttributeDict);
|
||||
}
|
||||
if ([aQualifierName isEqual: @"foo:example"] == NO) {
|
||||
problem = YES;
|
||||
NSLog(@"Bad qualified name '%@'", aQualifierName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
problem = YES;
|
||||
NSLog(@"Extra start element '%@' in namespace '%@' '%@' attributes '%@'",
|
||||
anElementName, aNamespaceURI, aQualifierName, anAttributeDict);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
- (void) parser: (NSXMLParser*)aParser
|
||||
didEndElement: (NSString*)anElementName
|
||||
namespaceURI: (NSString*)aNamespaceURI
|
||||
qualifiedName: (NSString*)aQualifierName
|
||||
{
|
||||
if (endElem == 0)
|
||||
{
|
||||
endElem++;
|
||||
if ([anElementName isEqual: @"example"] == NO) {
|
||||
problem = YES;
|
||||
NSLog(@"Bad end element '%@' in namespace '%@' '%@'",
|
||||
anElementName, aNamespaceURI, aQualifierName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
problem = YES;
|
||||
NSLog(@"Extra end element '%@' in namespace '%@' '%@'",
|
||||
anElementName, aNamespaceURI, aQualifierName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
int main ()
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
NSData *document;
|
||||
MyDelegate *delegate;
|
||||
NSXMLParser *parser;
|
||||
const char *str =
|
||||
"<?xml version=\"1.0\"?>"
|
||||
"<foo:example>"
|
||||
"</foo:example>";
|
||||
|
||||
document = [NSData dataWithBytes: str length: strlen(str)];
|
||||
parser = [[NSXMLParser alloc] initWithData: document];
|
||||
delegate = [MyDelegate new];
|
||||
[parser setDelegate: delegate];
|
||||
[parser setShouldProcessNamespaces: YES];
|
||||
|
||||
if ([parser parse] == NO)
|
||||
{
|
||||
NSLog(@"Failed to parse example document");
|
||||
}
|
||||
else if ([delegate check] == NO)
|
||||
{
|
||||
NSLog(@"All correct.");
|
||||
}
|
||||
[parser release];
|
||||
[pool release];
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* Test NXStringTable class. */
|
||||
|
||||
#include <objc/NXStringTable.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
id table;
|
||||
int i, times;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: table_test filename repeat\n");
|
||||
fprintf(stderr, " filename is a stringtable format file.\n");
|
||||
fprintf(stderr, " repeat is a number of times to loop\n");
|
||||
exit(1);
|
||||
}
|
||||
if (argc == 3)
|
||||
times = atoi(argv[2]);
|
||||
else
|
||||
times = 1;
|
||||
|
||||
table = [[NXStringTable alloc] init];
|
||||
|
||||
for (i=0; i < times; i++) {
|
||||
[table readFromFile:argv[1]];
|
||||
printf("-----------------------------------------\n");
|
||||
[table writeToStream:stdout];
|
||||
}
|
||||
return 0;
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#ifndef _server_h
|
||||
#define _server_h
|
||||
|
||||
#include <GNUstepBase/preface.h>
|
||||
#include <GNUstepBase/Connection.h>
|
||||
#include <GNUstepBase/Array.h>
|
||||
|
||||
typedef struct _small_struct {
|
||||
unsigned char z;
|
||||
} small_struct;
|
||||
|
||||
typedef struct _foo {
|
||||
int i;
|
||||
char *s;
|
||||
unsigned long l;
|
||||
} foo;
|
||||
|
||||
struct myarray {
|
||||
int a[3];
|
||||
};
|
||||
|
||||
@protocol ServerProtocol
|
||||
- (void) addObject: o;
|
||||
- objectAt: (unsigned)i;
|
||||
- (unsigned) count;
|
||||
- print: (const char *)msg;
|
||||
- getLong: (out unsigned long*)i;
|
||||
- (oneway void) shout;
|
||||
- callbackNameOn: obj;
|
||||
- bounce: sender count: (int)c;
|
||||
- (BOOL) doBoolean: (BOOL)b;
|
||||
- getBoolean: (BOOL*)bp;
|
||||
- getUCharPtr: (unsigned char *)ucp;
|
||||
- (foo*) sendStructPtr: (foo*)f;
|
||||
- sendStruct: (foo)f;
|
||||
- sendSmallStruct: (small_struct)small;
|
||||
- (foo) returnStruct;
|
||||
- sendArray: (int[3])a;
|
||||
- sendStructArray: (struct myarray)ma;
|
||||
- sendDouble: (double)d andFloat: (float)f;
|
||||
- (double*) doDoublePointer: (double*)d;
|
||||
- sendCharPtrPtr: (char**)sp;
|
||||
- sendBycopy: (bycopy id)o;
|
||||
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
|
||||
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12;
|
||||
- (float) returnFloat;
|
||||
- (double) returnDouble;
|
||||
@end
|
||||
|
||||
#if NeXT_runtime
|
||||
@protocol AllProxies <ServerProtocol>
|
||||
- (const char *)name;
|
||||
- (unsigned) hash;
|
||||
- self;
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface Server : NSObject <ServerProtocol>
|
||||
{
|
||||
id the_array;
|
||||
}
|
||||
@end
|
||||
|
||||
#endif /* _server_h */
|
|
@ -1,59 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/*
|
||||
From: Matthias Klose <doko@cs.tu-berlin.de>
|
||||
Date: Mon, 1 Aug 1994 21:17:20 +0200
|
||||
To: mccallum@cs.rochester.edu
|
||||
Subject: bug in libcoll-940725
|
||||
Reply-to: doko@cs.tu-berlin.de
|
||||
|
||||
Hello, the following code core dumps on Solaris 2.3 (compiled with gcc
|
||||
2.5.8 -g -O and with -g) and on NeXTstep 3.2 (gcc 2.5.8).
|
||||
Any hints?
|
||||
*/
|
||||
|
||||
#include <GNUstepBase/Queue.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
int main ()
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
Array *a;
|
||||
CircularArray *c;
|
||||
Queue *q;
|
||||
|
||||
a = [Array new];
|
||||
|
||||
[a prependObject: [NSObject new]];
|
||||
[a prependObject: [NSObject new]];
|
||||
[a prependObject: [NSObject new]];
|
||||
printf("count: %d\n", [a count]);
|
||||
[a insertObject: [NSObject new] atIndex: 2]; // ok!
|
||||
printf("count: %d\n", [a count]);
|
||||
|
||||
c = [CircularArray new];
|
||||
[c prependObject: [NSNumber numberWithInt:3]];
|
||||
[c prependObject: [NSNumber numberWithInt:2]];
|
||||
[c prependObject: [NSNumber numberWithInt:1]];
|
||||
[c insertObject:[NSNumber numberWithInt:0] atIndex:2]; // core dump!
|
||||
|
||||
q = [Queue new];
|
||||
[q enqueueObject: [NSObject new]];
|
||||
[q enqueueObject: [NSObject new]];
|
||||
[q enqueueObject: [NSObject new]];
|
||||
printf("count: %d\n", [q count]);
|
||||
[q insertObject: [NSObject new] atIndex: 2]; // core dump!
|
||||
printf("count: %d\n", [q count]);
|
||||
|
||||
[pool release];
|
||||
exit (0);
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
|
||||
#include <GNUstepBase/Random.h>
|
||||
#include <GNUstepBase/RNGBerkeley.h>
|
||||
#include <GNUstepBase/RNGAdditiveCongruential.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
id r;
|
||||
id rng;
|
||||
int i;
|
||||
|
||||
r = [[Random alloc] init];
|
||||
printf("float\n");
|
||||
for (i = 0; i < 20; i++)
|
||||
printf("%f\n", [r randomFloat]);
|
||||
printf("doubles\n");
|
||||
for (i = 0; i < 20; i++)
|
||||
printf("%f\n", [r randomDouble]);
|
||||
|
||||
rng = [[RNGBerkeley alloc] init];
|
||||
printf("%s chi^2 = %f\n",
|
||||
[rng name], [Random chiSquareOfRandomGenerator:rng]);
|
||||
[r release];
|
||||
|
||||
rng = [[RNGAdditiveCongruential alloc] init];
|
||||
/*
|
||||
for (i = 0; i < 50; i++)
|
||||
printf("%ld\n", [r nextRandom]);
|
||||
*/
|
||||
printf("%s chi^2 = %f\n",
|
||||
[rng name], [Random chiSquareOfRandomGenerator:rng]);
|
||||
[rng release];
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,153 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
@interface ReleaseTester : NSObject
|
||||
{
|
||||
int label;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation ReleaseTester
|
||||
|
||||
- initWithLabel: (int)l
|
||||
{
|
||||
label = l;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
{
|
||||
// printf ("release'ing %d\n", label);
|
||||
[super release];
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
// printf ("dealloc'ing %d\n", label);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void
|
||||
autorelease_test (int depth)
|
||||
{
|
||||
int n = 2;
|
||||
id os[n];
|
||||
id a = [NSMutableArray new];
|
||||
int i;
|
||||
id arp;
|
||||
|
||||
if (depth < 0)
|
||||
return;
|
||||
|
||||
arp = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
id r = [[[ReleaseTester alloc] initWithLabel: i+depth*n] autorelease];
|
||||
os[i] = r;
|
||||
[a addObject: r];
|
||||
}
|
||||
|
||||
#if 0
|
||||
fprintf (stderr, "totalAutoreleasedObjects %d\n",
|
||||
[NSAutoreleasePool totalAutoreleasedObjects]);
|
||||
#endif
|
||||
autorelease_test (depth-1);
|
||||
|
||||
[a release];
|
||||
|
||||
[arp release];
|
||||
|
||||
fflush (stdin);
|
||||
}
|
||||
|
||||
void
|
||||
release_test (int depth)
|
||||
{
|
||||
int n = 1000;
|
||||
id os[n];
|
||||
int i;
|
||||
|
||||
if (depth < 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
os[i] = [[ReleaseTester alloc] initWithLabel: i];
|
||||
for (i = 0; i < n; i++)
|
||||
[os[i] retain];
|
||||
for (i = 0; i < n; i++)
|
||||
[os[i] release];
|
||||
for (i = 0; i < n; i++)
|
||||
[os[i] release];
|
||||
|
||||
release_test (depth-1);
|
||||
}
|
||||
|
||||
|
||||
#if GNU_LIBC
|
||||
static void *(*old_malloc_hook) (size_t);
|
||||
static void (*old_free_hook) (void *ptr);
|
||||
|
||||
static void *
|
||||
my_malloc_hook (size_t size)
|
||||
{
|
||||
void *result;
|
||||
__malloc_hook = old_malloc_hook;
|
||||
result = malloc (size);
|
||||
/* `printf' might call `malloc', so protect it too. */
|
||||
printf ("malloc (%u) returns %p\n", (unsigned int) size, result);
|
||||
__malloc_hook = my_malloc_hook;
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
my_free_hook (void *ptr)
|
||||
{
|
||||
__free_hook = old_free_hook;
|
||||
free (ptr);
|
||||
__free_hook = my_free_hook;
|
||||
}
|
||||
#endif /* GNU_LIBC */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
int i;
|
||||
|
||||
#if GNU_LIBC
|
||||
old_malloc_hook = __malloc_hook;
|
||||
old_free_hook = __free_hook;
|
||||
__malloc_hook = my_malloc_hook;
|
||||
__free_hook = my_free_hook;
|
||||
#endif /* GNU_LIBC */
|
||||
|
||||
#if 1
|
||||
for (i = 0; i < 10000; i++)
|
||||
autorelease_test (3);
|
||||
#else
|
||||
/* Checking for memory leak in objc_mutex_lock() */
|
||||
_objc_mutex_t gate;
|
||||
gate = objc_mutex_allocate ();
|
||||
for (i = 0; i < 1000000; i++)
|
||||
{
|
||||
objc_mutex_lock (gate);
|
||||
objc_mutex_unlock (gate);
|
||||
}
|
||||
#endif
|
||||
|
||||
printf("Tests finished\n");
|
||||
exit (0);
|
||||
}
|
120
Testing/server.h
120
Testing/server.h
|
@ -1,120 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#ifndef _server_h
|
||||
#define _server_h
|
||||
|
||||
#include <GNUstepBase/preface.h>
|
||||
#include <Foundation/NSConnection.h>
|
||||
|
||||
typedef struct _small_struct {
|
||||
unsigned char z;
|
||||
} small_struct;
|
||||
|
||||
typedef struct _foo {
|
||||
char c;
|
||||
double d;
|
||||
int i;
|
||||
char *s;
|
||||
unsigned long l;
|
||||
} foo;
|
||||
|
||||
struct myarray {
|
||||
int a[3];
|
||||
};
|
||||
|
||||
#define ADD_CONST 47
|
||||
|
||||
@protocol ClientProtocol
|
||||
- (BOOL) callback;
|
||||
@end
|
||||
|
||||
@protocol ServerProtocol
|
||||
- (void) addObject: (id)o;
|
||||
- (BOOL) sendBoolean: (BOOL)b;
|
||||
- (void) getBoolean: (BOOL*)bp;
|
||||
- (unsigned char) sendUChar: (unsigned char)uc;
|
||||
- (void) getUChar: (unsigned char *)ucp;
|
||||
- (char) sendChar: (char)uc;
|
||||
- (void) getChar: (char *)ucp;
|
||||
- (short) sendShort: (short)num;
|
||||
- (void) getShort: (short *)num;
|
||||
- (int) sendInt: (int)num;
|
||||
- (void) getInt: (int *)num;
|
||||
- (long) sendLong: (long)num;
|
||||
- (void) getLong: (long *)num;
|
||||
- (float) sendFloat: (float)num;
|
||||
- (void) getFloat: (float *)num;
|
||||
- (double) sendDouble: (double)num;
|
||||
- (void) getDouble: (double *)num;
|
||||
- sendDouble: (double)dbl andFloat: (float)flt;
|
||||
|
||||
- (small_struct) sendSmallStruct: (small_struct)str;
|
||||
- (void) getSmallStruct: (small_struct *)str;
|
||||
- (foo) sendStruct: (foo)str;
|
||||
- (void) getStruct: (foo *)str;
|
||||
- (id) sendObject: (id)str;
|
||||
- (void) getObject: (id *)str;
|
||||
- (char *) sendString: (char *)str;
|
||||
- (void) getString: (char **)str;
|
||||
|
||||
- print: (const char *)str;
|
||||
|
||||
- objectAt: (unsigned)i;
|
||||
- (unsigned) count;
|
||||
- echoObject: obj;
|
||||
|
||||
- (oneway void) shout;
|
||||
- bounce: sender count: (int)c;
|
||||
- (oneway void) outputStats:obj;
|
||||
|
||||
- sendArray: (int[3])a;
|
||||
- sendStructArray: (struct myarray)ma;
|
||||
|
||||
- sendBycopy: (bycopy id)o;
|
||||
#ifdef _F_BYREF
|
||||
- sendByref: (byref id)o;
|
||||
- modifyByref: (byref NSMutableString *)o;
|
||||
#endif
|
||||
- manyArgs: (int)i1 : (int)i2 : (int)i3 : (int)i4 : (int)i5 : (int)i6
|
||||
: (int)i7 : (int)i8 : (int)i9 : (int)i10 : (int)i11 : (int)i12;
|
||||
- (int) exceptionTest1;
|
||||
- (void) exceptionTest2;
|
||||
- (oneway void) exceptionTest3;
|
||||
|
||||
- (oneway void) registerClient: (id<ClientProtocol>)client;
|
||||
- (oneway void) unregisterClient: (id<ClientProtocol>)client;
|
||||
- (BOOL) tryClientCallback;
|
||||
@end
|
||||
|
||||
#ifdef IN_SERVER
|
||||
/*
|
||||
* We don't want the client to know about some methods, so we can
|
||||
* check that they work when it doesn't know them.
|
||||
*/
|
||||
@protocol privateServer
|
||||
- quietBycopy: (bycopy id)o;
|
||||
@end
|
||||
@interface Server : NSObject <ServerProtocol,privateServer>
|
||||
{
|
||||
id the_array;
|
||||
id<ClientProtocol> registered_client;
|
||||
}
|
||||
@end
|
||||
#else
|
||||
@interface Server : NSObject <ServerProtocol>
|
||||
{
|
||||
id the_array;
|
||||
id<ClientProtocol> registered_client;
|
||||
}
|
||||
@end
|
||||
#endif
|
||||
|
||||
#endif /* _server_h */
|
158
Testing/string.m
158
Testing/string.m
|
@ -1,158 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
// Fri Oct 23 02:58:47 MET DST 1998 dave@turbocat.de
|
||||
// cStringNoCopy -> cString
|
||||
|
||||
/* For demo of Strings as Collections of char's. */
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
void
|
||||
print_string(NSString* s)
|
||||
{
|
||||
printf("The string [%s], length %d\n", [s lossyCString], [s length]);
|
||||
}
|
||||
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
id s = @"This is a test string";
|
||||
id s2, s3;
|
||||
unichar u0[5] = { 0xFE66, 'a', 'b', 'c', 'd'};
|
||||
unichar u1[6] = { '1', '2', '.', '3', '4', 0xFE66};
|
||||
unichar u2[7] = { 'a', 'b', 0xFE66, 'a', 'b', 'c', 'd'};
|
||||
NSString *us0 = [NSString stringWithCharacters: u0 length: 5];
|
||||
NSString *us1 = [NSString stringWithCharacters: u1 length: 6];
|
||||
NSString *us2 = [NSString stringWithCharacters: u2 length: 7];
|
||||
NSMutableString *fo = [NSMutableString stringWithString: @"abcdef"];
|
||||
NSMutableString *f1 = [NSMutableString stringWithString: @"ab"];
|
||||
NSStringEncoding *encs;
|
||||
|
||||
{
|
||||
NSURL *currentURL;
|
||||
NSData *data;
|
||||
|
||||
currentURL = [NSURL URLWithString:
|
||||
@"http:/www.foobar.org/PageWithAValid.plist"];
|
||||
data = [currentURL resourceDataUsingCache: NO];
|
||||
|
||||
if ( data )
|
||||
printf(" YES \n");
|
||||
printf(" NO\n");
|
||||
}
|
||||
#if 0
|
||||
{ // GSM test
|
||||
unichar buf[] = { 163, '[', ']', '{', '}', '\\', '^', '|', '~', '_' };
|
||||
NSString *str = [NSString stringWithCharacters: buf
|
||||
length: sizeof(buf)/sizeof(unichar)];
|
||||
NSData *gsm = [str dataUsingEncoding: NSGSM0338StringEncoding];
|
||||
|
||||
NSLog(@"GSM: %*.*s", [gsm length], [gsm length], [gsm bytes]);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_DURING
|
||||
[fo replaceCharactersInRange: [fo rangeOfString: @"xx"] withString: us1];
|
||||
NS_HANDLER
|
||||
printf("Caught exception during string replacement (expected)\n");
|
||||
NS_ENDHANDLER
|
||||
|
||||
[f1 appendString: us0];
|
||||
print_string(f1);
|
||||
printf("%d\n", [f1 isEqual: us2]);
|
||||
|
||||
print_string(s);
|
||||
|
||||
s2 = NSStringFromPoint(NSMakePoint(1.374, 5.100));
|
||||
print_string(s2);
|
||||
|
||||
printf("%f", [[NSString stringWithCharacters: u1 length: 5] floatValue]);
|
||||
|
||||
s2 = [s copy];
|
||||
print_string(s2);
|
||||
s3 = [s2 mutableCopy];
|
||||
[s2 release];
|
||||
s2 = [s3 copy];
|
||||
[s3 release];
|
||||
[s2 release];
|
||||
|
||||
s2 = [s copyWithZone: NSDefaultMallocZone ()];
|
||||
print_string(s2);
|
||||
|
||||
s2 = [s stringByAppendingString:@" with something added"];
|
||||
print_string(s2);
|
||||
|
||||
s2 = [s mutableCopy];
|
||||
[s2 replaceCharactersInRange:((NSRange){10,4})
|
||||
withString:@"changed"];
|
||||
print_string(s2);
|
||||
[s2 replaceOccurrencesOfString: @"changed"
|
||||
withString: @"changed again"
|
||||
options: NSLiteralSearch
|
||||
range: NSMakeRange(0, [s2 length])];
|
||||
print_string(s2);
|
||||
|
||||
#if 0
|
||||
/* Test the use of the `%@' format directive. */
|
||||
s2 = [NSString stringWithFormat: @"foo %@ bar",
|
||||
@"test"];
|
||||
print_string(s2);
|
||||
|
||||
for (a = 0; a < 10; a++)
|
||||
NSLog(@"A string with precision %d is :%.*@:", a, a, @"String");
|
||||
#endif
|
||||
|
||||
{
|
||||
NSMutableString *base = [@"hello" mutableCopy];
|
||||
NSString *ext = [@"\"\\UFE66???\"" propertyList];
|
||||
NSString *want = [@"\"hello\\UFE66???\"" propertyList];
|
||||
int i;
|
||||
|
||||
[base appendString: ext];
|
||||
printf("%u\n", [base length]);
|
||||
printf("%u\n", [ext length]);
|
||||
printf("%u\n", [want length]);
|
||||
for (i = 0; i < 4; i++)
|
||||
printf("%x\n", [ext characterAtIndex: i]);
|
||||
for (i = 0; i < 9; i++)
|
||||
printf("%x,%x\n", [base characterAtIndex: i], [want characterAtIndex: i]);
|
||||
|
||||
printf("%u\n", [want isEqual: base]);
|
||||
for (i = 0; i < 1000; i++)
|
||||
[base appendString: want];
|
||||
print_string(base);
|
||||
|
||||
encs = [NSString availableStringEncodings];
|
||||
while (*encs != 0)
|
||||
printf("Encoding %x\n", *encs++);
|
||||
}
|
||||
|
||||
GSPrintf(stdout, @"\nStandardize Paths\n");
|
||||
s2 = @"../";
|
||||
GSPrintf(stdout, @"%@ becomes %@\n",
|
||||
s2, [s2 stringByStandardizingPath]);
|
||||
s2 = @"/usr/bin/../lib";
|
||||
GSPrintf(stdout, @"%@ becomes %@\n",
|
||||
s2, [s2 stringByStandardizingPath]);
|
||||
s2 = @"~/Public/../GNUstep";
|
||||
GSPrintf(stdout, @"%@ becomes %@\n",
|
||||
s2, [s2 stringByStandardizingPath]);
|
||||
|
||||
[arp release];
|
||||
exit(0);
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
PACKAGE_NAME = gnustep-base
|
||||
|
||||
#
|
||||
# GNUmakefile - Generated by ProjectCenter
|
||||
#
|
||||
|
||||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
#
|
||||
# Tool
|
||||
#
|
||||
VERSION = 0.1
|
||||
TOOL_NAME = SyncTest
|
||||
SyncTest_TOOL_ICON =
|
||||
|
||||
|
||||
#
|
||||
# Resource files
|
||||
#
|
||||
SyncTest_RESOURCE_FILES = \
|
||||
Resources/Version \
|
||||
|
||||
|
||||
#
|
||||
# Other sources
|
||||
#
|
||||
SyncTest_OBJC_FILES += \
|
||||
main.m
|
||||
|
||||
#
|
||||
# Makefiles
|
||||
#
|
||||
-include GNUmakefile.preamble
|
||||
include $(GNUSTEP_MAKEFILES)/aggregate.make
|
||||
include $(GNUSTEP_MAKEFILES)/tool.make
|
||||
-include GNUmakefile.postamble
|
|
@ -1,40 +0,0 @@
|
|||
#
|
||||
# GNUmakefile.postamble - Generated by ProjectCenter
|
||||
#
|
||||
|
||||
# Things to do before compiling
|
||||
# before-all::
|
||||
|
||||
# Things to do after compiling
|
||||
# after-all::
|
||||
|
||||
# Things to do before installing
|
||||
# before-install::
|
||||
|
||||
# Things to do after installing
|
||||
# after-install::
|
||||
|
||||
# Things to do before uninstalling
|
||||
# before-uninstall::
|
||||
|
||||
# Things to do after uninstalling
|
||||
# after-uninstall::
|
||||
|
||||
# Things to do before cleaning
|
||||
# before-clean::
|
||||
|
||||
# Things to do after cleaning
|
||||
# after-clean::
|
||||
|
||||
# Things to do before distcleaning
|
||||
# before-distclean::
|
||||
|
||||
# Things to do after distcleaning
|
||||
# after-distclean::
|
||||
|
||||
# Things to do before checking
|
||||
# before-check::
|
||||
|
||||
# Things to do after checking
|
||||
# after-check::
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#
|
||||
# GNUmakefile.preamble - Generated by ProjectCenter
|
||||
#
|
||||
|
||||
# Additional flags to pass to the preprocessor
|
||||
ADDITIONAL_CPPFLAGS +=
|
||||
|
||||
# Additional flags to pass to Objective C compiler
|
||||
ADDITIONAL_OBJCFLAGS +=
|
||||
|
||||
# Additional flags to pass to C compiler
|
||||
ADDITIONAL_CFLAGS +=
|
||||
|
||||
# Additional flags to pass to the linker
|
||||
ADDITIONAL_LDFLAGS +=
|
||||
|
||||
# Additional include directories the compiler should search
|
||||
ADDITIONAL_INCLUDE_DIRS +=
|
||||
|
||||
# Additional library directories the linker should search
|
||||
ADDITIONAL_LIB_DIRS +=
|
||||
|
||||
# Additional TOOL libraries to link
|
||||
ADDITIONAL_TOOL_LIBS +=
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
CLASS_FILES = (
|
||||
);
|
||||
COMPILEROPTIONS = "";
|
||||
CPPOPTIONS = "";
|
||||
CREATION_DATE = "2008-11-04 19:40:49 -0500";
|
||||
DOCU_FILES = (
|
||||
);
|
||||
FRAMEWORKS = (
|
||||
);
|
||||
HEADER_FILES = (
|
||||
);
|
||||
IMAGES = (
|
||||
);
|
||||
INSTALLDIR = "$(HOME)/GNUstep/Tools";
|
||||
LANGUAGE = English;
|
||||
LAST_EDITING = "2008-11-05 17:26:50 -0500";
|
||||
LIBRARIES = (
|
||||
"gnustep-base"
|
||||
);
|
||||
LINKEROPTIONS = "";
|
||||
LOCALIZED_RESOURCES = (
|
||||
);
|
||||
MAKEFILEDIR = "$(GNUSTEP_MAKEFILES)";
|
||||
OBJC_COMPILEROPTIONS = "";
|
||||
OTHER_RESOURCES = (
|
||||
Version
|
||||
);
|
||||
OTHER_SOURCES = (
|
||||
main.m
|
||||
);
|
||||
PROJECT_AUTHORS = (
|
||||
);
|
||||
PROJECT_COPYRIGHT = "Copyright (C) 200x";
|
||||
PROJECT_COPYRIGHT_DESC = "Released under ...";
|
||||
PROJECT_CREATOR = "Gregory John Casamento,,,";
|
||||
PROJECT_DESCRIPTION = "No description available!";
|
||||
PROJECT_GROUP = "No group available!";
|
||||
PROJECT_MAINTAINER = "Gregory John Casamento,,,";
|
||||
PROJECT_NAME = SyncTest;
|
||||
PROJECT_RELEASE = 0.1;
|
||||
PROJECT_SUMMARY = "No summary available!";
|
||||
PROJECT_TYPE = Tool;
|
||||
PROJECT_URL = "";
|
||||
SEARCH_HEADER_DIRS = (
|
||||
);
|
||||
SEARCH_LIB_DIRS = (
|
||||
);
|
||||
SUBPROJECTS = (
|
||||
);
|
||||
SUPPORTING_FILES = (
|
||||
GNUmakefile.preamble,
|
||||
GNUmakefile,
|
||||
GNUmakefile.postamble,
|
||||
SyncTestInfo.plist
|
||||
);
|
||||
TOOLICON = "";
|
||||
USER_LANGUAGES = (
|
||||
);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
CLASS_FILES = (
|
||||
);
|
||||
COMPILEROPTIONS = "";
|
||||
CPPOPTIONS = "";
|
||||
CREATION_DATE = "2008-11-04 19:40:49 -0500";
|
||||
DOCU_FILES = (
|
||||
);
|
||||
FRAMEWORKS = (
|
||||
);
|
||||
HEADER_FILES = (
|
||||
);
|
||||
IMAGES = (
|
||||
);
|
||||
INSTALLDIR = "$(HOME)/GNUstep/Tools";
|
||||
LANGUAGE = English;
|
||||
LAST_EDITING = "2008-11-05 17:24:50 -0500";
|
||||
LIBRARIES = (
|
||||
"gnustep-base"
|
||||
);
|
||||
LINKEROPTIONS = "";
|
||||
LOCALIZED_RESOURCES = (
|
||||
);
|
||||
MAKEFILEDIR = "$(GNUSTEP_MAKEFILES)";
|
||||
OBJC_COMPILEROPTIONS = "";
|
||||
OTHER_RESOURCES = (
|
||||
Version
|
||||
);
|
||||
OTHER_SOURCES = (
|
||||
main.m
|
||||
);
|
||||
PROJECT_AUTHORS = (
|
||||
);
|
||||
PROJECT_COPYRIGHT = "Copyright (C) 200x";
|
||||
PROJECT_COPYRIGHT_DESC = "Released under ...";
|
||||
PROJECT_CREATOR = "Gregory John Casamento,,,";
|
||||
PROJECT_DESCRIPTION = "No description available!";
|
||||
PROJECT_GROUP = "No group available!";
|
||||
PROJECT_MAINTAINER = "Gregory John Casamento,,,";
|
||||
PROJECT_NAME = SyncTest;
|
||||
PROJECT_RELEASE = 0.1;
|
||||
PROJECT_SUMMARY = "No summary available!";
|
||||
PROJECT_TYPE = Tool;
|
||||
PROJECT_URL = "";
|
||||
SEARCH_HEADER_DIRS = (
|
||||
);
|
||||
SEARCH_LIB_DIRS = (
|
||||
);
|
||||
SUBPROJECTS = (
|
||||
);
|
||||
SUPPORTING_FILES = (
|
||||
GNUmakefile.preamble,
|
||||
GNUmakefile,
|
||||
GNUmakefile.postamble,
|
||||
SyncTestInfo.plist
|
||||
);
|
||||
TOOLICON = "";
|
||||
USER_LANGUAGES = (
|
||||
);
|
||||
}
|
0
Testing/synctest/Resources/.gitignore
vendored
0
Testing/synctest/Resources/.gitignore
vendored
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"!" = "Generated by ProjectCenter, do not edit";
|
||||
Copyright = "Copyright (C) 200x";
|
||||
CopyrightDescription = "Released under ...";
|
||||
FullVersionID = 0.1;
|
||||
ToolDescription = "No description available!";
|
||||
ToolName = SyncTest;
|
||||
ToolRelease = 0.1;
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
|
||||
static NSArray *array;
|
||||
|
||||
@interface SyncTest : NSObject
|
||||
- (void) sayHello;
|
||||
@end
|
||||
|
||||
@implementation SyncTest
|
||||
- (void) sayHello
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
NSLog(@"Before the sync block %s\n",[[[NSThread currentThread] description] cString]);
|
||||
@synchronized(array) {
|
||||
NSLog(@"In the sync block %s:%d\n",[[[NSThread currentThread] description] cString], [NSThread isMainThread]);
|
||||
NSLog(@"Waiting five seconds...\n");
|
||||
[NSThread sleepForTimeInterval: 5.0];
|
||||
NSLog(@"Done waiting\n");
|
||||
}
|
||||
NSLog(@"After the sync block %s\n",[[[NSThread currentThread] description] cString]);
|
||||
[pool release];
|
||||
}
|
||||
@end
|
||||
|
||||
int main (int argc, const char * argv[])
|
||||
{
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
SyncTest *st = [[SyncTest alloc] init];
|
||||
array = [NSArray arrayWithObjects: @"Hello World",nil];
|
||||
|
||||
[NSThread detachNewThreadSelector: @selector(sayHello)
|
||||
toTarget: st
|
||||
withObject: nil];
|
||||
[st sayHello];
|
||||
|
||||
[pool drain];
|
||||
return 0;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <GNUstepBase/TcpPort.h>
|
||||
#include <Foundation/NSRunLoop.h>
|
||||
#include <GNUstepBase/Invocation.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
|
||||
id handle_incoming_packet (id packet)
|
||||
{
|
||||
fprintf (stdout, "received >");
|
||||
fwrite ([packet streamBuffer] + [packet streamBufferPrefix],
|
||||
[packet streamEofPosition], 1, stdout);
|
||||
fprintf (stdout, "<\n");
|
||||
[packet release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
id out_port;
|
||||
id in_port;
|
||||
id packet;
|
||||
int i;
|
||||
|
||||
if (argc > 1)
|
||||
out_port = [TcpOutPort newForSendingToRegisteredName:
|
||||
[NSString stringWithUTF8String: argv[1]]
|
||||
onHost: @"localhost"];
|
||||
else
|
||||
out_port = [TcpOutPort newForSendingToRegisteredName: @"tcpport-test"
|
||||
onHost: nil];
|
||||
|
||||
in_port = [TcpInPort newForReceiving];
|
||||
|
||||
[in_port setReceivedPacketInvocation:
|
||||
[[[ObjectFunctionInvocation alloc]
|
||||
initWithObjectFunction: handle_incoming_packet]
|
||||
autorelease]];
|
||||
|
||||
[[NSRunLoop currentRunLoop] addPort: in_port
|
||||
forMode: NSDefaultRunLoopMode];
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
packet = [[TcpOutPacket alloc] initForSendingWithCapacity: 100
|
||||
replyInPort: in_port];
|
||||
[packet writeFormat: @"Here is message number %d", i];
|
||||
[out_port sendPacket: packet timeout: 10.0];
|
||||
[packet release];
|
||||
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:
|
||||
[NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
||||
}
|
||||
|
||||
[out_port close];
|
||||
|
||||
exit (0);
|
||||
}
|
|
@ -1,105 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/* Test whether each thread has their own exception handlers. */
|
||||
|
||||
#ifndef _REENTRANT
|
||||
#define _REENTRANT
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSThread.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
#define N 10 /* Number of threads */
|
||||
#define MAX_ITER 10000.0 /* Max number of iterations. */
|
||||
|
||||
FILE *file;
|
||||
int counter;
|
||||
|
||||
@interface SingleThread : NSObject
|
||||
{
|
||||
int ident; // Identifier
|
||||
}
|
||||
|
||||
- initWithInt: (int)n;
|
||||
- (void)runWith: (id)thing;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SingleThread
|
||||
|
||||
- initWithInt: (int)n
|
||||
{
|
||||
ident = n;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)runWith: (id)thing
|
||||
{
|
||||
int i, n;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
|
||||
NS_DURING
|
||||
n = 1+(int)((MAX_ITER*rand())/(RAND_MAX+1.0));
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fprintf(file, "%d ", i);
|
||||
fflush(file);
|
||||
}
|
||||
[NSException raise: @"Some exception" format: @"thread %d", ident];
|
||||
NS_HANDLER
|
||||
NSLog(@"%@ for thread %d\n", localException, ident);
|
||||
NS_ENDHANDLER
|
||||
IF_NO_GC(DESTROY(pool));
|
||||
counter--;
|
||||
[NSThread exit];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
int i;
|
||||
SingleThread *threads[N];
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
|
||||
printf("We run %d threads.\n", N);
|
||||
printf("Some of them might not raise exceptions,\n");
|
||||
printf("but the exception associated with each thread must match.\n");
|
||||
file = fopen("/dev/null", "w");
|
||||
srand(10);
|
||||
|
||||
counter = N;
|
||||
|
||||
for (i = 0; i < N; i++)
|
||||
threads[i] = [[SingleThread alloc] initWithInt: i];
|
||||
NS_DURING
|
||||
for (i = 0; i < N; i++)
|
||||
[NSThread detachNewThreadSelector: @selector(runWith:)
|
||||
toTarget: threads[i] withObject: nil];
|
||||
|
||||
// Hopefully this will end after all the other threads end.
|
||||
for (i = 0; i < N*MAX_ITER && counter > 0; i++)
|
||||
{
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
||||
fprintf(file, "%d", i);
|
||||
fflush(file);
|
||||
}
|
||||
NS_HANDLER
|
||||
fprintf(stderr, "There's a runaway exception! Something is wrong!\n");
|
||||
NS_ENDHANDLER
|
||||
fclose(file);
|
||||
IF_NO_GC(DESTROY(pool));
|
||||
return 0;
|
||||
}
|
129
Testing/thread.m
129
Testing/thread.m
|
@ -1,129 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
NSLock *lock = nil;
|
||||
unsigned retainReleaseThreads = 0;
|
||||
unsigned fireCount = 0;
|
||||
|
||||
@interface XX : NSObject
|
||||
- (void) fire;
|
||||
- (void) retainRelease: (id)obj;
|
||||
- (void) setup;
|
||||
@end
|
||||
|
||||
@implementation XX
|
||||
- (void) fire
|
||||
{
|
||||
NSLog(@"Got here");
|
||||
fireCount++;
|
||||
}
|
||||
- (void) retainRelease: (id)obj
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
NSLog(@"Start retain/releases in thread %@", [NSThread currentThread]);
|
||||
for (i = 0; i < 1000000; i++)
|
||||
{
|
||||
[obj retain];
|
||||
[obj release];
|
||||
}
|
||||
NSLog(@"Done %d retain/releases in thread %@", i, [NSThread currentThread]);
|
||||
[lock lock];
|
||||
retainReleaseThreads++;
|
||||
[lock unlock];
|
||||
NSLog(@"Finished thread %@", [NSThread currentThread]);
|
||||
}
|
||||
- (void) setup
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
|
||||
NSLog(@"Attempting to obtain lock to proceed");
|
||||
if ([lock lockBeforeDate: [NSDate dateWithTimeIntervalSinceNow: 5.0]] == YES)
|
||||
{
|
||||
NSLog(@"Setup1");
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
||||
NSLog(@"Setup2");
|
||||
[self performSelectorOnMainThread: @selector(fire)
|
||||
withObject: nil
|
||||
waitUntilDone: NO];
|
||||
NSLog(@"Done perform no wait.");
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
||||
NSLog(@"Setup3");
|
||||
[self performSelectorOnMainThread: @selector(fire)
|
||||
withObject: nil
|
||||
waitUntilDone: YES];
|
||||
NSLog(@"Done perform with wait.");
|
||||
[lock unlock];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Failed to obtain lock");
|
||||
}
|
||||
RELEASE(arp);
|
||||
[NSThread exit];
|
||||
}
|
||||
@end
|
||||
|
||||
int main(int argc, char **argv, char **env)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(arp);
|
||||
NSObject *o = [NSObject new];
|
||||
XX *x = [XX new];
|
||||
|
||||
NSLog(@"Start in main");
|
||||
lock = [NSLock new];
|
||||
[lock lock];
|
||||
|
||||
[NSThread detachNewThreadSelector: @selector(retainRelease:)
|
||||
toTarget: x
|
||||
withObject: o];
|
||||
[NSThread detachNewThreadSelector: @selector(retainRelease:)
|
||||
toTarget: x
|
||||
withObject: o];
|
||||
[NSThread detachNewThreadSelector: @selector(retainRelease:)
|
||||
toTarget: x
|
||||
withObject: o];
|
||||
[NSThread detachNewThreadSelector: @selector(retainRelease:)
|
||||
toTarget: x
|
||||
withObject: o];
|
||||
[NSThread detachNewThreadSelector: @selector(retainRelease:)
|
||||
toTarget: x
|
||||
withObject: o];
|
||||
|
||||
[NSThread detachNewThreadSelector: @selector(setup)
|
||||
toTarget: x
|
||||
withObject: nil];
|
||||
NSLog(@"Waiting to give thread time to start");
|
||||
[NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
||||
NSLog(@"Releasing lock so thread may proceed");
|
||||
[lock unlock]; // Allow other thread to proceed.
|
||||
|
||||
[[NSRunLoop currentRunLoop] runUntilDate:
|
||||
[NSDate dateWithTimeIntervalSinceNow: 30.0]];
|
||||
|
||||
NSLog(@"Done main thread");
|
||||
|
||||
while (retainReleaseThreads < 5)
|
||||
{
|
||||
NSLog(@"Waiting for all 5 retainRelease threads to complete (%d)",
|
||||
retainReleaseThreads);
|
||||
[[NSRunLoop currentRunLoop] acceptInputForMode: NSDefaultRunLoopMode
|
||||
beforeDate: [NSDate dateWithTimeIntervalSinceNow: 1.0]];
|
||||
}
|
||||
if ([o retainCount] != 1)
|
||||
{
|
||||
NSLog(@"ERROR ... retain count is %d, expected 1", [o retainCount]);
|
||||
}
|
||||
IF_NO_GC(DESTROY(arp));
|
||||
return 0;
|
||||
}
|
||||
|
190
Testing/values.m
190
Testing/values.m
|
@ -1,190 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
/*
|
||||
Test NSValue, NSNumber, and related classes
|
||||
|
||||
*/
|
||||
|
||||
#include <Foundation/NSValue.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
NSPoint p;
|
||||
NSRange range;
|
||||
NSRect rect;
|
||||
NSValue *v1, *v2;
|
||||
NSNumber *nc, *ns, *n1, *n2, *n3, *n4, *n5, *n6, *n7;
|
||||
NSMutableArray *a1, *a2;
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
// Numbers
|
||||
nc = [NSNumber numberWithChar: -100];
|
||||
ns = [NSNumber numberWithShort: -100];
|
||||
printf("try %d, %d", [nc charValue], [ns shortValue]);
|
||||
printf("nc compare: ns is %d\n", [nc compare: ns]);
|
||||
n1 = [NSNumber numberWithUnsignedShort: 30];
|
||||
if (strcmp([[n1 description] cString], "30") != 0)
|
||||
printf("*** TEST FAILED **** description for unsigned short number\n");
|
||||
n2 = [NSNumber numberWithDouble: 2.7];
|
||||
if (strcmp([[n2 description] cString], "2.7") != 0)
|
||||
printf("*** TEST FAILED **** description for double number\n");
|
||||
n3 = [NSNumber numberWithDouble: 30];
|
||||
if (strcmp([[n3 description] cString], "30") != 0)
|
||||
printf("*** TEST FAILED **** description for double number\n");
|
||||
n4 = [NSNumber numberWithChar: 111];
|
||||
if (strcmp([[n4 description] cString], "111") != 0)
|
||||
printf("*** TEST FAILED **** description for char number\n");
|
||||
n5 = [NSNumber numberWithChar: 111];
|
||||
if (strcmp([[n5 description] cString], "111") != 0)
|
||||
printf("*** TEST FAILED **** description for unsigned char number\n");
|
||||
n6 = [NSNumber numberWithFloat: 1.5];
|
||||
if (strcmp([[n6 description] cString], "1.5") != 0)
|
||||
printf("*** TEST FAILED **** description for float number\n");
|
||||
n7 = [NSNumber numberWithShort: 25];
|
||||
if (strcmp([[n7 description] cString], "25") != 0)
|
||||
printf("*** TEST FAILED **** description for short number\n");
|
||||
|
||||
printf("Number(n1) as int %d, as float %f\n",
|
||||
[n1 intValue], [n1 floatValue]);
|
||||
printf("n1 times n2=%f as int to get %d\n",
|
||||
[n2 floatValue], [n1 intValue]*[n2 intValue]);
|
||||
printf("n2 as string: %s\n", [[n2 stringValue] cString]);
|
||||
printf("n2 compare: n1 is %d\n", [n2 compare: n1]);
|
||||
printf("n1 compare: n2 is %d\n", [n1 compare: n2]);
|
||||
printf("n1 isEqual: n3 is %d\n", [n1 isEqual: n3]);
|
||||
printf("n4 isEqual: n5 is %d\n", [n4 isEqual: n5]);
|
||||
|
||||
a1 = [NSMutableArray arrayWithObjects:
|
||||
[NSNumber numberWithChar: 111],
|
||||
[NSNumber numberWithUnsignedChar: 112],
|
||||
[NSNumber numberWithShort: 121],
|
||||
[NSNumber numberWithUnsignedShort: 122],
|
||||
[NSNumber numberWithInt: 131],
|
||||
[NSNumber numberWithUnsignedInt: 132],
|
||||
[NSNumber numberWithInt: 141],
|
||||
[NSNumber numberWithUnsignedInt: 142],
|
||||
[NSNumber numberWithFloat: 151],
|
||||
[NSNumber numberWithDouble: 152], nil];
|
||||
|
||||
a2 = [NSMutableArray arrayWithObjects:
|
||||
[NSNumber numberWithChar: 111],
|
||||
[NSNumber numberWithUnsignedChar: 112],
|
||||
[NSNumber numberWithShort: 121],
|
||||
[NSNumber numberWithUnsignedShort: 122],
|
||||
[NSNumber numberWithInt: 131],
|
||||
[NSNumber numberWithUnsignedInt: 132],
|
||||
[NSNumber numberWithInt: 141],
|
||||
[NSNumber numberWithUnsignedInt: 142],
|
||||
[NSNumber numberWithFloat: 151],
|
||||
[NSNumber numberWithDouble: 152], nil];
|
||||
|
||||
printf("a1 isEqual: a2 is %d\n", [a1 isEqual: a2]);
|
||||
|
||||
// Test values, Geometry
|
||||
{
|
||||
unsigned char v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(unsigned char)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
signed char v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(signed char)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
unsigned short v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(unsigned short)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
signed short v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(signed short)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
unsigned int v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(unsigned int)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
signed int v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(signed int)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
unsigned long v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(unsigned long)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
signed long v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(signed long)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
float v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(float)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
{
|
||||
double v = 99;
|
||||
v1 = [NSValue value: &v withObjCType: @encode(double)];
|
||||
[a1 addObject: v1];
|
||||
}
|
||||
v1 = [NSValue valueWithPoint: NSMakePoint(1, 1)];
|
||||
[a1 addObject: v1];
|
||||
v1 = [NSValue valueWithRange: NSMakeRange(1, 1)];
|
||||
[a1 addObject: v1];
|
||||
rect = NSMakeRect(1.0, 103.3, 40.0, 843.);
|
||||
rect = NSIntersectionRect(rect, NSMakeRect(20, 78., 89., 30));
|
||||
v1 = [NSValue valueWithRect: rect];
|
||||
[a1 addObject: v1];
|
||||
printf("Encoding for rect is %s\n", [v1 objCType]);
|
||||
rect = [v1 rectValue];
|
||||
printf("Rect is %f %f %f %f\n", NSMinX(rect), NSMinY(rect), NSMaxX(rect),
|
||||
NSMaxY(rect));
|
||||
v2 = [NSValue valueWithPoint: NSMakePoint(3,4)];
|
||||
[a1 addObject: v1];
|
||||
v1 = [NSValue valueWithNonretainedObject: v2];
|
||||
[[v1 nonretainedObjectValue] getValue: &p];
|
||||
printf("point is %f %f\n", p.x, p.y);
|
||||
range = NSMakeRange(1, 103);
|
||||
range = NSIntersectionRange(range, NSMakeRange(2, 73));
|
||||
v1 = [NSValue valueWithRange: range];
|
||||
[a1 addObject: v1];
|
||||
printf("Encoding for range is %s\n", [v1 objCType]);
|
||||
range = [v1 rangeValue];
|
||||
printf("Range is %u %u\n", range.location, range.length);
|
||||
|
||||
printf("Try getting a null NSValue, should get a NSLog error message: \n");
|
||||
v2 = [NSValue value: NULL withObjCType: @encode(int)];
|
||||
[a1 addObject: v1];
|
||||
|
||||
a2 = [NSUnarchiver unarchiveObjectWithData:
|
||||
[NSArchiver archivedDataWithRootObject: a1]];
|
||||
|
||||
printf("After archiving, a1 isEqual: a2 is %d\n", [a1 isEqual: a2]);
|
||||
if ([a1 isEqual: a2] == NO)
|
||||
{
|
||||
printf("a1 - %s\n", [[a1 description] cString]);
|
||||
printf("a2 - %s\n", [[a2 description] cString]);
|
||||
}
|
||||
|
||||
[arp release];
|
||||
return 0;
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
/* Test/example program for the base library
|
||||
|
||||
Copyright (C) 2005 Free Software Foundation, Inc.
|
||||
|
||||
Copying and distribution of this file, with or without modification,
|
||||
are permitted in any medium without royalty provided the copyright
|
||||
notice and this notice are preserved.
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
*/
|
||||
#if (defined __MINGW32__)
|
||||
/* A simple implementation of getopt() */
|
||||
static int
|
||||
indexof(char c, char *string)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < strlen(string); i++)
|
||||
{
|
||||
if (string[i] == c)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static char *optarg;
|
||||
static int optind;
|
||||
static char
|
||||
getopt(int argc, char **argv, char *options)
|
||||
{
|
||||
static char *arg;
|
||||
int index;
|
||||
char retval = '\0';
|
||||
|
||||
optarg = NULL;
|
||||
if (optind == 0)
|
||||
{
|
||||
optind = 1;
|
||||
}
|
||||
while (optind < argc)
|
||||
{
|
||||
arg = argv[optind];
|
||||
if (strlen(arg) == 2)
|
||||
{
|
||||
if (arg[0] == '-')
|
||||
{
|
||||
if ((index = indexof(arg[1], options)) != -1)
|
||||
{
|
||||
retval = arg[1];
|
||||
if (index < strlen(options))
|
||||
{
|
||||
if (options[index+1] == ':')
|
||||
{
|
||||
if (optind < argc-1)
|
||||
{
|
||||
optind++;
|
||||
optarg = argv[optind];
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1; /* ':' given, but argv exhausted */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
optind++;
|
||||
return retval;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue