This is StringTest.new.m in view mode; [Download] [Up]
//
// StringTest.m -- test out the String class
// Written by Don Yacktman Copyright (c) 1994 by Don Yacktman.
// Version 1.0. All rights reserved.
//
// This notice may not be removed from this source code.
//
// This program is included in the MiscKit by permission from the author
// and its use is governed by the MiscKit license, found in the file
// "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
// for a list of all applicable permissions and restrictions.
//
// *******************************************************************
// This program is incomplete. That's why it isn't compiled or run
// yet. When finished, it will replace "StringTest.m" completely.
// *******************************************************************
// To find the test for a method, search for a method name in the format
// "-numOfChar:caseSensitive:" and you'll go right to it.
// There is a separate, source file for testing each category, each of
// which is brought into this source via an include.
// Functions left to write:
// testMiscStringComparing()
// testMiscStringFields()
// testMiscStringInsertion()
// testMiscStringModification()
// testMiscStringPatterns()
// testMiscStringReplacing()
// testMiscStringSearching()
// testMiscStringUNIX() (incomplete)
#import <appkit/appkit.h>
#import <misckit/misckit.h>
#import <stdio.h>
#define MSTRINGS 12
void testMiscString()
{
id string[MSTRINGS]; int i;
char *charString[10];
printf("***** Testing MiscString class\n");
// Test MiscString.m methods:
// Various ways to create new strings:
// -new, -newWithString:, -alloc and -init, -initString:, -initFromFormat:
string[0] = [MiscString new];
string[1] = [string[0] new];
string[2] = [MiscString newWithString:NULL];
string[3] = [MiscString newWithString:""];
string[4] = [MiscString newWithString:"This is String #4."];
string[5] = [[MiscString alloc] init];
string[6] = [[MiscString alloc] initString:NULL];
string[7] = [[MiscString alloc] initString:""];
string[8] = [[MiscString alloc] initString:"This is String #8."];
string[9] = [[MiscString alloc]
initFromFormat:"A formatted string: %d %f %s.", 10, 200.3, "Yup"];
// -allocateBuffer and -allocateBuffer:fromZone: will be exercised
// throughout this test suite, so we won't worry about them specifically.
// The same goes for -stringValue and -stringValueAndFree. They both
// get used a lot, so we'll assume that they work OK.
// -copyFromZone:, -freeString
string[10] = [string[8] copy]; // actually hits -copyFromZone:
string[11] = [string[9] copy]; [string[11] freeString];
// -free will be used throughout, so we won't test that here explicitly
// -getCopyInto:
charString[0] = (char *)malloc(32);
[string[4] getCopyInto:charString[0]];
charString[1] = [string[8] getCopyInto:NULL];
for (i=0; i<12; i++)
printf("String #%d: \"%s\", length = %d\n", i,
[string[i] stringValue], [string[i] length]);
for (i=0; i<2; i++)
printf("CharString #%d: \"%s\".\n", i, charString[i]);
// -emptyString
printf("emptyString: #2: %d, #3: %d, #4: %d, #11: %d\n",
[string[2] emptyString], [string[3] emptyString],
[string[4] emptyString], [string[11] emptyString]);
// -charAt:
printf("String #4, character at -10: '%c' (0x%x)\n",
[string[4] charAt:-10], (unsigned)[string[4] charAt:-10]);
printf("String #4, character at -1: '%c' (0x%x)\n",
[string[4] charAt:-1], (unsigned)[string[4] charAt:-1]);
printf("String #4, character at 0: '%c' (0x%x)\n",
[string[4] charAt:0], (unsigned)[string[4] charAt:0]);
printf("String #4, character at 1: '%c' (0x%x)\n",
[string[4] charAt:1], (unsigned)[string[4] charAt:1]);
printf("String #4, character at 5: '%c' (0x%x)\n",
[string[4] charAt:5], (unsigned)[string[4] charAt:5]);
printf("String #4, character at 50: '%c' (0x%x)\n",
[string[4] charAt:50], (unsigned)[string[4] charAt:50]);
printf("String #5, character at -1: '%c' (0x%x)\n",
[string[5] charAt:-1], (unsigned)[string[5] charAt:-1]);
printf("String #5, character at 0: '%c' (0x%x)\n",
[string[5] charAt:0], (unsigned)[string[5] charAt:0]);
printf("String #5, character at 1: '%c' (0x%x)\n",
[string[5] charAt:1], (unsigned)[string[5] charAt:1]);
printf("String #7, character at -1: '%c' (0x%x)\n",
[string[7] charAt:-1], (unsigned)[string[7] charAt:-1]);
printf("String #7, character at 0: '%c' (0x%x)\n",
[string[7] charAt:0], (unsigned)[string[7] charAt:0]);
printf("String #7, character at 1: '%c' (0x%x)\n",
[string[7] charAt:1], (unsigned)[string[7] charAt:1]);
// -numOfChar:, -numOfChar:caseSensitive:
printf("String #4, num of character 's': %d\n",
[string[4] numOfChar:'s']);
printf("String #4, num of character 's' case sense on: %d\n",
[string[4] numOfChar:'s' caseSensitive:YES]);
printf("String #4, num of character 's' case sense off: %d\n",
[string[4] numOfChar:'s' caseSensitive:NO]);
printf("String #4, num of character 'q': %d\n",
[string[4] numOfChar:'q']);
printf("String #4, num of character 'q' case sense on: %d\n",
[string[4] numOfChar:'q' caseSensitive:YES]);
printf("String #4, num of character 'q' case sense off: %d\n",
[string[4] numOfChar:'q' caseSensitive:NO]);
printf("String #4, num of character '<0>': %d\n",
[string[4] numOfChar:0]);
printf("String #4, num of character '<0>' case sense on: %d\n",
[string[4] numOfChar:0 caseSensitive:YES]);
printf("String #4, num of character '<0>' case sense off: %d\n",
[string[4] numOfChar:0 caseSensitive:NO]);
printf("String #5, num of character 'q': %d\n",
[string[5] numOfChar:'q']);
printf("String #5, num of character 'q' case sense on: %d\n",
[string[5] numOfChar:'q' caseSensitive:YES]);
printf("String #5, num of character 'q' case sense off: %d\n",
[string[5] numOfChar:'q' caseSensitive:NO]);
printf("String #5, num of character '<0>': %d\n",
[string[5] numOfChar:0]);
printf("String #5, num of character '<0>' case sense on: %d\n",
[string[5] numOfChar:0 caseSensitive:YES]);
printf("String #5, num of character '<0>' case sense off: %d\n",
[string[5] numOfChar:0 caseSensitive:NO]);
printf("String #7, num of character 'q': %d\n",
[string[7] numOfChar:'q']);
printf("String #7, num of character 'q' case sense on: %d\n",
[string[7] numOfChar:'q' caseSensitive:YES]);
printf("String #7, num of character 'q' case sense off: %d\n",
[string[7] numOfChar:'q' caseSensitive:NO]);
printf("String #7, num of character '<0>': %d\n",
[string[7] numOfChar:0]);
printf("String #7, num of character '<0>' case sense on: %d\n",
[string[7] numOfChar:0 caseSensitive:YES]);
printf("String #7, num of character '<0>' case sense off: %d\n",
[string[7] numOfChar:0 caseSensitive:NO]);
// -numOfChars:, -numOfChars:caseSensitive:
printf("String #8, num of characters \"rSt\": %d\n",
[string[8] numOfChars:"rSt"]);
printf("String #8, num of characters \"rSt\" case sense off: %d\n",
[string[8] numOfChars:"rSt" caseSensitive:NO]);
printf("String #8, num of characters \"rSt\" case sense on: %d\n",
[string[8] numOfChars:"rSt" caseSensitive:YES]);
printf("String #8, num of characters \"I\": %d\n",
[string[8] numOfChars:"I"]);
printf("String #8, num of characters \"I\" case sense off: %d\n",
[string[8] numOfChars:"I" caseSensitive:NO]);
printf("String #8, num of characters \"I\" case sense on: %d\n",
[string[8] numOfChars:"I" caseSensitive:YES]);
printf("String #8, num of characters \"x\": %d\n",
[string[8] numOfChars:"x"]);
printf("String #8, num of characters \"x\" case sense off: %d\n",
[string[8] numOfChars:"x" caseSensitive:NO]);
printf("String #8, num of characters \"x\" case sense on: %d\n",
[string[8] numOfChars:"x" caseSensitive:YES]);
printf("String #8, num of characters \"\": %d\n",
[string[8] numOfChars:""]);
printf("String #8, num of characters \"\" case sense off: %d\n",
[string[8] numOfChars:"" caseSensitive:NO]);
printf("String #8, num of characters \"\" case sense on: %d\n",
[string[8] numOfChars:"" caseSensitive:YES]);
printf("String #8, num of characters \"(NULL)\": %d\n",
[string[8] numOfChars:NULL]);
printf("String #8, num of characters \"(NULL)\" case sense off: %d\n",
[string[8] numOfChars:NULL caseSensitive:NO]);
printf("String #8, num of characters \"(NULL)\" case sense on: %d\n",
[string[8] numOfChars:NULL caseSensitive:YES]);
printf("String #5, num of characters \"xy\": %d\n",
[string[5] numOfChars:"xy"]);
printf("String #5, num of characters \"xy\" case sense off: %d\n",
[string[5] numOfChars:"xy" caseSensitive:NO]);
printf("String #5, num of characters \"xy\" case sense on: %d\n",
[string[5] numOfChars:"xy" caseSensitive:YES]);
printf("String #5, num of characters \"x\": %d\n",
[string[5] numOfChars:"x"]);
printf("String #5, num of characters \"x\" case sense off: %d\n",
[string[5] numOfChars:"x" caseSensitive:NO]);
printf("String #5, num of characters \"x\" case sense on: %d\n",
[string[5] numOfChars:"x" caseSensitive:YES]);
printf("String #5, num of characters \"\": %d\n",
[string[5] numOfChars:""]);
printf("String #5, num of characters \"\" case sense off: %d\n",
[string[5] numOfChars:"" caseSensitive:NO]);
printf("String #5, num of characters \"\" case sense on: %d\n",
[string[5] numOfChars:"" caseSensitive:YES]);
printf("String #5, num of characters \"(NULL)\": %d\n",
[string[5] numOfChars:NULL]);
printf("String #5, num of characters \"(NULL)\" case sense off: %d\n",
[string[5] numOfChars:NULL caseSensitive:NO]);
printf("String #5, num of characters \"(NULL)\" case sense on: %d\n",
[string[5] numOfChars:NULL caseSensitive:YES]);
printf("String #7, num of characters \"xy\": %d\n",
[string[7] numOfChars:"xy"]);
printf("String #7, num of characters \"xy\" case sense off: %d\n",
[string[7] numOfChars:"xy" caseSensitive:NO]);
printf("String #7, num of characters \"xy\" case sense on: %d\n",
[string[7] numOfChars:"xy" caseSensitive:YES]);
printf("String #7, num of characters \"x\": %d\n",
[string[7] numOfChars:"x"]);
printf("String #7, num of characters \"x\" case sense off: %d\n",
[string[7] numOfChars:"x" caseSensitive:NO]);
printf("String #7, num of characters \"x\" case sense on: %d\n",
[string[7] numOfChars:"x" caseSensitive:YES]);
printf("String #7, num of characters \"\": %d\n",
[string[7] numOfChars:""]);
printf("String #7, num of characters \"\" case sense off: %d\n",
[string[7] numOfChars:"" caseSensitive:NO]);
printf("String #7, num of characters \"\" case sense on: %d\n",
[string[7] numOfChars:"" caseSensitive:YES]);
printf("String #7, num of characters \"(NULL)\": %d\n",
[string[7] numOfChars:NULL]);
printf("String #7, num of characters \"(NULL)\" case sense off: %d\n",
[string[7] numOfChars:NULL caseSensitive:NO]);
printf("String #7, num of characters \"(NULL)\" case sense on: %d\n",
[string[7] numOfChars:NULL caseSensitive:YES]);
// no test available for -stringOrderTable or -setStringOrderTable:
// -intValue, -floatValue, -doubleValue
[string[5] setStringValue:"100x300"];
[string[6] setStringValue:"100.5x300.102"];
[string[7] setStringValue:"100.x300.102"];
[string[8] setStringValue:".1x300.102"];
[string[9] setStringValue:"0.1x300.102"];
[string[10] setStringValue:".x300.102"];
for (i=2; i<11; i++) {
printf("stringValue: \"%s\"\n", [string[i] stringValue]);
printf("doubleValue: \"%f\"\n", [string[i] doubleValue]);
printf(" floatValue: \"%f\"\n", [string[i] floatValue]);
printf(" intValue: \"%i\"\n", [string[i] intValue]);
}
// -free
for (i=0; i<MSTRINGS; i++) [string[i] free];
}
// Grab the category testing subroutines.
#include "StringTestComparing.m"
#include "StringTestCompat.m"
#include "StringTestDebugging.m"
#include "StringTestFields.m"
#include "StringTestInsertion.m"
#include "StringTestModification.m"
#include "StringTestNEXTSTEP.m"
#include "StringTestPatterns.m"
#include "StringTestReplacing.m"
#include "StringTestSearching.m"
#include "StringTestSybase.m"
#include "StringTestUNIX.m"
void main()
{ // we step through each source file's methods here, by file.
// so there is one function per source file, to help keep us organized.
testMiscString();
testMiscStringComparing();
testMiscStringCompat();
testMiscStringDebugging();
testMiscStringFields();
testMiscStringInsertion();
testMiscStringModification();
testMiscStringNEXTSTEP();
testMiscStringPatterns();
testMiscStringReplacing();
testMiscStringSearching();
testMiscStringSybase();
testMiscStringUNIX();
exit(0);
}
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.