mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-29 16:01:38 +00:00
iUUID for unix by leeg
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37480 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9944f1823f
commit
9b99122b0f
6 changed files with 506 additions and 0 deletions
0
Tests/base/NSUUID/TestInfo
Normal file
0
Tests/base/NSUUID/TestInfo
Normal file
56
Tests/base/NSUUID/basic.m
Normal file
56
Tests/base/NSUUID/basic.m
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSUUID.h>
|
||||
#include "Testing.h"
|
||||
#include "ObjectTesting.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSUUID *uuid1, *uuid2;
|
||||
NSString *uuidString = @"2139CD2E-15E6-4C37-84DA-1E18EEBFAB4A";
|
||||
|
||||
uuid_t uuidBytes = { 0x80, 0x1f, 0x3a, 0x01, 0x95, 0x7c, 0x45, 0x0f,
|
||||
0xaf, 0xf2, 0x1b, 0xe9, 0x59, 0xf5, 0x89, 0x54 };
|
||||
|
||||
TEST_FOR_CLASS(@"NSUUID", [NSUUID alloc],
|
||||
"+[NSUUID alloc] returns a NSUUID");
|
||||
TEST_FOR_CLASS(@"NSUUID", [NSUUID UUID],
|
||||
"+[NSUUID UUID] returns a UUID");
|
||||
|
||||
uuid1 = [[NSUUID alloc] initWithUUIDString:@"test"];
|
||||
PASS(uuid1 == nil, "Don't create a UUID from an invalid string");
|
||||
|
||||
uuid1 = [[NSUUID alloc] initWithUUIDString:uuidString];
|
||||
PASS(uuid1 != nil, "Create a UUID from a valid string");
|
||||
PASS_EQUAL([uuid1 UUIDString], uuidString,
|
||||
"Derive a stable UUID string value");
|
||||
|
||||
uuid2 = [[NSUUID alloc] initWithUUIDString:uuidString];
|
||||
PASS_EQUAL(uuid1, uuid2, "UUIDs representing the same value are considered equal");
|
||||
PASS([uuid1 hash] == [uuid2 hash], "Equal objects have equal hashes");
|
||||
|
||||
DESTROY(uuid2);
|
||||
uuid2 = [[NSUUID alloc] initWithUUIDBytes:uuidBytes];
|
||||
PASS(![uuid1 isEqual:uuid2], "UUIDs representing different values should not be considered equal");
|
||||
|
||||
uuid_t otherBytes = {0};
|
||||
[uuid2 getUUIDBytes:otherBytes];
|
||||
|
||||
int comparison = memcmp(uuidBytes, otherBytes, 16);
|
||||
PASS(comparison == 0, "Get a stable value for the UUID bytes");
|
||||
DESTROY(uuid2);
|
||||
|
||||
uuid2 = [uuid1 copy];
|
||||
PASS_EQUAL(uuid1, uuid2, "-[NSUUID copy] returns an identical object");
|
||||
DESTROY(uuid2);
|
||||
|
||||
NSData *coded = [NSKeyedArchiver archivedDataWithRootObject:uuid1];
|
||||
uuid2 = [NSKeyedUnarchiver unarchiveObjectWithData:coded];
|
||||
PASS_EQUAL(uuid1, uuid2, "UUID survives a round-trip through archiver");
|
||||
DESTROY(uuid1);
|
||||
|
||||
[arp release];
|
||||
arp = nil;
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue