mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 09:31:07 +00:00
import testsuite
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32187 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
734c214892
commit
0e02133729
374 changed files with 20864 additions and 0 deletions
BIN
Tests/base/coding/NSArray.1.data
Normal file
BIN
Tests/base/coding/NSArray.1.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSAttributedString.0.data
Normal file
BIN
Tests/base/coding/NSAttributedString.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSCharacterSet.0.data
Normal file
BIN
Tests/base/coding/NSCharacterSet.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSData.0.data
Normal file
BIN
Tests/base/coding/NSData.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSDate.1.data
Normal file
BIN
Tests/base/coding/NSDate.1.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSDateFormatter.0.data
Normal file
BIN
Tests/base/coding/NSDateFormatter.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSDictionary.0.data
Normal file
BIN
Tests/base/coding/NSDictionary.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSException.0.data
Normal file
BIN
Tests/base/coding/NSException.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSMutableData.0.data
Normal file
BIN
Tests/base/coding/NSMutableData.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSNotification.0.data
Normal file
BIN
Tests/base/coding/NSNotification.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSNull.0.data
Normal file
BIN
Tests/base/coding/NSNull.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSNumber.0.data
Normal file
BIN
Tests/base/coding/NSNumber.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSObject.0.data
Normal file
BIN
Tests/base/coding/NSObject.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSSet.0.data
Normal file
BIN
Tests/base/coding/NSSet.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSString.1.data
Normal file
BIN
Tests/base/coding/NSString.1.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSTableView.3.data
Normal file
BIN
Tests/base/coding/NSTableView.3.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSURL.0.data
Normal file
BIN
Tests/base/coding/NSURL.0.data
Normal file
Binary file not shown.
BIN
Tests/base/coding/NSValue.3.data
Normal file
BIN
Tests/base/coding/NSValue.3.data
Normal file
Binary file not shown.
218
Tests/base/coding/basictypes.m
Normal file
218
Tests/base/coding/basictypes.m
Normal file
|
@ -0,0 +1,218 @@
|
|||
#include "Testing.h"
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <limits.h>
|
||||
|
||||
@interface Model : NSObject <NSCoding>
|
||||
{
|
||||
int cint;
|
||||
unsigned int cuint;
|
||||
NSInteger nsint;
|
||||
NSUInteger nsuint;
|
||||
}
|
||||
@end
|
||||
@implementation Model
|
||||
-(void)setValues
|
||||
{
|
||||
cint = -1234567890;
|
||||
cuint = 1234567890;
|
||||
nsint = -1234567890;
|
||||
nsuint = 1234567890;
|
||||
}
|
||||
- (BOOL)testCInt:(Model *)o
|
||||
{
|
||||
return (cint == o->cint);
|
||||
}
|
||||
- (BOOL)testCUInt:(Model *)o
|
||||
{
|
||||
return (cuint == o->cuint);
|
||||
}
|
||||
- (BOOL)testNSInteger:(Model *)o
|
||||
{
|
||||
return (nsint == o->nsint);
|
||||
}
|
||||
- (BOOL)testNSUInteger:(Model *)o
|
||||
{
|
||||
return (nsuint == o->nsuint);
|
||||
}
|
||||
|
||||
-(void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeValueOfObjCType:@encode(int) at:&cint];
|
||||
[coder encodeValueOfObjCType:@encode(unsigned int) at:&cuint];
|
||||
[coder encodeValueOfObjCType:@encode(NSInteger) at:&nsint];
|
||||
[coder encodeValueOfObjCType:@encode(NSUInteger) at:&nsuint];
|
||||
}
|
||||
-(id)initWithCoder:(NSCoder *)coder
|
||||
{
|
||||
/* encoded as int - decoded as NSInteger. */
|
||||
[coder decodeValueOfObjCType: @encode(NSInteger) at: &nsint];
|
||||
/* encoded as unsinged int - decoded as NSUInteger. */
|
||||
[coder decodeValueOfObjCType: @encode(NSUInteger) at: &nsuint];
|
||||
/* encoded as NSInteger - decoded as int. */
|
||||
[coder decodeValueOfObjCType: @encode(int) at: &cint];
|
||||
/* encoded as NSUInteger - decoded as unsigned int. */
|
||||
[coder decodeValueOfObjCType: @encode(unsigned int) at: &cuint];
|
||||
return self;
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
static NSFileManager *fm;
|
||||
NSString *str = @"Do not taunt happy fun ball";
|
||||
#define TEST_DECL(testType,testName) \
|
||||
void testWriteBasicType_##testName (char *typeName, testType *toEncode) \
|
||||
{ \
|
||||
NSData *data; \
|
||||
NSMutableData *mData; \
|
||||
NSString *fileName; \
|
||||
long typeSize = sizeof(testType); \
|
||||
fileName = [[NSString stringWithFormat:@"%s-%li.type",typeName,typeSize] retain]; \
|
||||
if (![fm isReadableFileAtPath:fileName]) \
|
||||
{ \
|
||||
NSArchiver *arch; \
|
||||
mData = [[NSMutableData alloc] init]; \
|
||||
arch = [[NSArchiver alloc] initForWritingWithMutableData: mData]; \
|
||||
[arch encodeValueOfObjCType:@encode(testType) at:toEncode]; \
|
||||
[arch encodeObject:str]; \
|
||||
[mData writeToFile:fileName atomically:YES]; \
|
||||
data = [NSData dataWithContentsOfFile:fileName]; \
|
||||
PASS([data isEqual:mData], \
|
||||
"can write %s of size %li", typeName, typeSize); \
|
||||
[fileName release]; \
|
||||
[mData release]; \
|
||||
[arch release]; \
|
||||
} \
|
||||
} \
|
||||
void testReadBasicType_##testName (char *pre, testType *expect, testType *toDecode) \
|
||||
{ \
|
||||
NSData *data; \
|
||||
NSUnarchiver *unArch; \
|
||||
NSString *str2; \
|
||||
NSArray *encodedFiles; \
|
||||
NSString *prefix = [[NSString stringWithCString:pre] retain]; \
|
||||
unsigned int i, c; \
|
||||
encodedFiles = [[NSBundle bundleWithPath: [fm currentDirectoryPath]] \
|
||||
pathsForResourcesOfType:@"type" inDirectory:nil]; \
|
||||
for (i = 0, c = [encodedFiles count]; i < c; i++) \
|
||||
{ \
|
||||
NSString *fileName = [encodedFiles objectAtIndex:i]; \
|
||||
if ([[fileName lastPathComponent] hasPrefix:prefix]) \
|
||||
{ \
|
||||
data = [NSData dataWithContentsOfFile:fileName]; \
|
||||
unArch = [[NSUnarchiver alloc] initForReadingWithData:data]; \
|
||||
NS_DURING \
|
||||
[unArch decodeValueOfObjCType:@encode(testType) at:toDecode]; \
|
||||
NS_HANDLER \
|
||||
NSLog(@"%@ %@", [localException name], [localException reason]); \
|
||||
PASS(0, "can unarchive %s from %s", pre, [fileName cString]); \
|
||||
NS_ENDHANDLER \
|
||||
str2 = [unArch decodeObject]; \
|
||||
PASS((VAL_TEST(*expect,*toDecode) && [str isEqual:str2]), \
|
||||
"can unarchive %s from %s", pre, [fileName cString]); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
#define VAL_TEST(testX,testY) testX == testY
|
||||
TEST_DECL(int, int);
|
||||
TEST_DECL(unsigned int, uint);
|
||||
TEST_DECL(long, long);
|
||||
TEST_DECL(unsigned long, ulong);
|
||||
TEST_DECL(long long, llong);
|
||||
TEST_DECL(unsigned long long, ullong);
|
||||
TEST_DECL(signed char, schar);
|
||||
TEST_DECL(unsigned char, uchar);
|
||||
TEST_DECL(short, short);
|
||||
TEST_DECL(unsigned short, ushort);
|
||||
#undef VAL_TEST
|
||||
#define VAL_TEST(testx, testy) EQ(testx,testy)
|
||||
TEST_DECL(float, float);
|
||||
TEST_DECL(double, double);
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||
id obj1, obj2;
|
||||
NSData *data;
|
||||
int i = 2147483647;
|
||||
int i2;
|
||||
unsigned int ui = 4294967295U;
|
||||
unsigned int ui2;
|
||||
long l = 2147483647L;
|
||||
long l2;
|
||||
long long ll = 9223372036854775807LL;
|
||||
long long ll2;
|
||||
unsigned long long ull = 18446744073709551615ULL;
|
||||
unsigned long long ull2;
|
||||
unsigned long ul = 4294967295UL;
|
||||
unsigned long ul2;
|
||||
signed char c = 127;
|
||||
signed char c2;
|
||||
unsigned char uc = 255;
|
||||
unsigned char uc2;
|
||||
short s = 32767;
|
||||
short s2;
|
||||
unsigned short us = 65535;
|
||||
unsigned short us2;
|
||||
float f = 3.40282347e+38F;
|
||||
float f2;
|
||||
double d = 1.7976931348623157e+308;
|
||||
double d2;
|
||||
|
||||
fm = [NSFileManager defaultManager];
|
||||
|
||||
testWriteBasicType_int("int", &i);
|
||||
testReadBasicType_int("int", &i, &i2);
|
||||
|
||||
testWriteBasicType_uint("uint", &ui);
|
||||
testReadBasicType_uint("uint", &ui, &ui2);
|
||||
|
||||
testWriteBasicType_long("long", &l);
|
||||
testReadBasicType_long("long", &l, &l2);
|
||||
|
||||
testWriteBasicType_ulong("ulong", &ul);
|
||||
testReadBasicType_ulong("ulong", &ul, &ul2);
|
||||
|
||||
testWriteBasicType_llong("llong", &ll);
|
||||
testReadBasicType_llong("llong", &ll, &ll2);
|
||||
|
||||
testWriteBasicType_ullong("ullong", &ull);
|
||||
testReadBasicType_ullong("ullong", &ull, &ull2);
|
||||
|
||||
testWriteBasicType_schar("schar", &c);
|
||||
testReadBasicType_schar("schar", &c, &c2);
|
||||
|
||||
testWriteBasicType_uchar("uchar", &uc);
|
||||
testReadBasicType_uchar("uchar", &uc, &uc2);
|
||||
|
||||
testWriteBasicType_short("short", &s);
|
||||
testReadBasicType_short("short", &s, &s2);
|
||||
|
||||
testWriteBasicType_float("float", &f);
|
||||
testReadBasicType_float("float", &f, &f2);
|
||||
|
||||
testWriteBasicType_double("double", &d);
|
||||
testReadBasicType_double("double", &d, &d2);
|
||||
|
||||
testWriteBasicType_ushort("ushort", &us);
|
||||
testReadBasicType_ushort("ushort", &us, &us2);
|
||||
|
||||
obj1 = [Model new];
|
||||
[obj1 setValues];
|
||||
data = [NSArchiver archivedDataWithRootObject: obj1];
|
||||
obj2 = [NSUnarchiver unarchiveObjectWithData: data];
|
||||
PASS([obj1 testCInt:obj2], "archiving as int - dearchiving as NSInteger");
|
||||
PASS([obj1 testCUInt:obj2], "archiving as unsigned int - dearchiving as NSUInteger");
|
||||
PASS([obj1 testNSInteger:obj2], "archiving as NSInteger - dearchiving as int");
|
||||
PASS([obj1 testNSUInteger:obj2], "archiving as NSUInteger - dearchiving as unsigned int");
|
||||
|
||||
[pool release]; pool = nil;
|
||||
return 0;
|
||||
}
|
237
Tests/base/coding/decoding.m
Normal file
237
Tests/base/coding/decoding.m
Normal file
|
@ -0,0 +1,237 @@
|
|||
/*
|
||||
copyright 2004 Alexander Malmberg <alexander@malmberg.org>
|
||||
*/
|
||||
|
||||
#include "Testing.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSAttributedString.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSCharacterSet.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDate.h>
|
||||
#include <Foundation/NSDateFormatter.h>
|
||||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSFormatter.h>
|
||||
#include <Foundation/NSGeometry.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSNull.h>
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSSet.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSURL.h>
|
||||
#include <Foundation/NSValue.h>
|
||||
|
||||
@interface NSObject (DecodingTests)
|
||||
+ (NSObject*) createTestInstance;
|
||||
+ (BOOL) verifyTestInstance: (NSObject *)instance
|
||||
ofVersion: (int)version;
|
||||
- (BOOL) testEquality;
|
||||
@end
|
||||
|
||||
@implementation NSObject (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
if (self == [NSException class])
|
||||
{
|
||||
return [[NSException alloc] initWithName: @"Test"
|
||||
reason: @"Testing"
|
||||
userInfo: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [[self alloc] init];
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL) verifyTestInstance: (NSObject *)instance
|
||||
ofVersion: (int)version
|
||||
{
|
||||
id o;
|
||||
|
||||
if (instance == nil) return NO;
|
||||
o = [self createTestInstance];
|
||||
if (YES == [o respondsToSelector: @selector(testEquality:)])
|
||||
return [o testEquality: instance];
|
||||
if (NO == [instance testEquality]) return YES;
|
||||
return [o isEqual: instance];
|
||||
}
|
||||
|
||||
- (BOOL) testEquality
|
||||
{
|
||||
static IMP impNSObject = 0;
|
||||
/* By default, assume that every class that overrides NSObject's
|
||||
isEqual: implementation can compare archived instances.
|
||||
subclasses for which this doesn't hold can simply override this
|
||||
method in a category and return a constant YES/NO. */
|
||||
|
||||
if (!impNSObject)
|
||||
{
|
||||
impNSObject = [NSObject instanceMethodForSelector:@selector(isEqual:)];
|
||||
}
|
||||
return [self methodForSelector:@selector(isEqual:)] == impNSObject
|
||||
? NO : YES;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSCharacterSet (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[self characterSetWithCharactersInString: @"qwertzuiop"] retain];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSValue (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[self valueWithSize: NSMakeSize(1.1, 1.2)] retain];
|
||||
}
|
||||
- (BOOL) testEquality: (id)other
|
||||
{
|
||||
if (strcmp([self objCType], @encode(NSSize)) == 0)
|
||||
{
|
||||
NSSize mSize = [self sizeValue];
|
||||
NSSize oSize = [other sizeValue];
|
||||
|
||||
if (EQ(mSize.height, oSize.height) && EQ(mSize.width, oSize.width))
|
||||
return YES;
|
||||
return NO;
|
||||
}
|
||||
return [self isEqual: other];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSNumber (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[self numberWithInt: 1] retain];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSData (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[@"We need constant data" dataUsingEncoding: NSUnicodeStringEncoding] retain];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSDate (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[NSDate dateWithTimeIntervalSince1970: 4294967296.0] retain];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSURL (DecodingTests)
|
||||
+ (NSObject *) createTestInstance
|
||||
{
|
||||
return [[self alloc] initWithString: @"http://www.gnustep.org/"];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
/*
|
||||
If set, we write out new .data files for the current versions for classes
|
||||
that don't have them.
|
||||
*/
|
||||
BOOL update;
|
||||
|
||||
void test(Class class)
|
||||
{
|
||||
NS_DURING
|
||||
{
|
||||
/*
|
||||
In order to catch decoders that don't consume all the data that they
|
||||
should, we decode/encode an array that includes the object and a string.
|
||||
We verify that the string was correctly decoded, although any errors will
|
||||
likely be caught by crashes in the unarchiver.
|
||||
*/
|
||||
NSString *sentinel = @"quux!";
|
||||
|
||||
int v = [class version];
|
||||
NSObject *instance;
|
||||
NSArray *decodedInstance;
|
||||
NSData *d;
|
||||
NSString *filename;
|
||||
|
||||
instance = [class createTestInstance];
|
||||
|
||||
d = [NSArchiver archivedDataWithRootObject:
|
||||
[NSArray arrayWithObjects: instance, sentinel, nil]];
|
||||
decodedInstance = [NSUnarchiver unarchiveObjectWithData: d];
|
||||
|
||||
NSCAssert([sentinel isEqual: [decodedInstance objectAtIndex: 1]],
|
||||
NSInternalInconsistencyException);
|
||||
|
||||
PASS([class verifyTestInstance: [decodedInstance objectAtIndex: 0]
|
||||
ofVersion: v], "decoding current version of class %s", POBJECT(class));
|
||||
|
||||
for (; v >= 0; v--)
|
||||
{
|
||||
filename = [NSString stringWithFormat: @"%@.%i.data", class, v];
|
||||
d = [NSData dataWithContentsOfFile: filename];
|
||||
if (!d)
|
||||
{
|
||||
if (v == [class version])
|
||||
{
|
||||
if (!update)
|
||||
PASS(0, "%s has reference data for the current version",
|
||||
POBJECT(class))
|
||||
else
|
||||
[NSArchiver archiveRootObject:
|
||||
[NSArray arrayWithObjects: instance, sentinel, nil]
|
||||
toFile: filename];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
decodedInstance = [NSUnarchiver unarchiveObjectWithData: d];
|
||||
NSCAssert([sentinel isEqual: [decodedInstance objectAtIndex: 1]],
|
||||
NSInternalInconsistencyException);
|
||||
PASS([class verifyTestInstance: [decodedInstance objectAtIndex: 0]
|
||||
ofVersion: v], "decoding version %i of class %s",
|
||||
v, POBJECT(class));
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
PASS(0, "decoding class %s: %s",
|
||||
POBJECT(class), POBJECT(localException));
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
update = argc == 2 && !strcmp(argv[1], "--update");
|
||||
|
||||
#define T(c) test([c class]);
|
||||
T(NSArray)
|
||||
T(NSAttributedString)
|
||||
T(NSCharacterSet)
|
||||
T(NSData)
|
||||
T(NSMutableData)
|
||||
T(NSDate)
|
||||
T(NSDateFormatter)
|
||||
T(NSDictionary)
|
||||
T(NSException)
|
||||
T(NSNotification)
|
||||
T(NSNull)
|
||||
T(NSObject)
|
||||
T(NSSet)
|
||||
T(NSString)
|
||||
T(NSURL)
|
||||
T(NSValue)
|
||||
T(NSNumber)
|
||||
|
||||
[arp release]; arp = nil;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
BIN
Tests/base/coding/double-8.type
Normal file
BIN
Tests/base/coding/double-8.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/float-4.type
Normal file
BIN
Tests/base/coding/float-4.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/int-4.type
Normal file
BIN
Tests/base/coding/int-4.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/llong-8.type
Normal file
BIN
Tests/base/coding/llong-8.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/long-4.type
Normal file
BIN
Tests/base/coding/long-4.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/schar-1.type
Normal file
BIN
Tests/base/coding/schar-1.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/short-2.type
Normal file
BIN
Tests/base/coding/short-2.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/uchar-1.type
Normal file
BIN
Tests/base/coding/uchar-1.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/uint-4.type
Normal file
BIN
Tests/base/coding/uint-4.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/ullong-8.type
Normal file
BIN
Tests/base/coding/ullong-8.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/ulong-4.type
Normal file
BIN
Tests/base/coding/ulong-4.type
Normal file
Binary file not shown.
BIN
Tests/base/coding/ushort-2.type
Normal file
BIN
Tests/base/coding/ushort-2.type
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue