Keep the EKEzvOutgoingFileTransfer.m around so long as it is sending, regardless...
[adiumx.git] / UnitTests / TestDataAdditions.m
blob989101781b5d8da8a1cb35c9d15e9fb4d66fec8a
1 #import "TestDataAdditions.h"
2 #import "AIUnitTestUtilities.h"
4 #import <AIUtilities/AIDataAdditions.h>
6 enum {
7         lengthForSubdataTests = 6U,
8         fromIndexForSubdataTests = 3U,
9         toIndexForSubdataTests = 3U,
10         subdataLengthForSubdataTests = 3U
12 #define lengthForSubdataTests 6U
13 #define fromIndexForSubdataTests 3U
14 #define toIndexForSubdataTests 3U
15 #define subdataLengthForSubdataTests 3U
16 static char bytesForSubdataTests[lengthForSubdataTests] = { 'f', 'o', 'o', 'b', 'a', 'r' };
18 @implementation TestDataAdditions
20 - (void)testSubdataFromIndex {
21         NSData *data = [NSData dataWithBytesNoCopy:bytesForSubdataTests length:lengthForSubdataTests freeWhenDone:NO];
23         NSData *subdata = [data subdataFromIndex:fromIndexForSubdataTests];
24         STAssertEquals([subdata length], subdataLengthForSubdataTests, @"Subdata was not of expected length");
26         const char *bytes = [subdata bytes];
27         //Cast explanation: Character literals are of type int. STAssertEquals also checks that the two sides are of the same type, and const char is not int, so the assertion fails unless we cast the literals to const char.
28         STAssertEquals(bytes[0], (const char)'b', @"Unexpected first byte of subdata: 0x%x %c", bytes[0], bytes[0]);
29         STAssertEquals(bytes[1], (const char)'a', @"Unexpected second byte of subdata: 0x%x %c", bytes[1], bytes[1]);
30         STAssertEquals(bytes[2], (const char)'r', @"Unexpected third byte of subdata: 0x%x %c", bytes[2], bytes[2]);
32 - (void)testSubdataToIndex {
33         NSData *data = [NSData dataWithBytesNoCopy:bytesForSubdataTests length:lengthForSubdataTests freeWhenDone:NO];
35         NSData *subdata = [data subdataToIndex:toIndexForSubdataTests];
36         STAssertEquals([subdata length], subdataLengthForSubdataTests, @"Subdata was not of expected length");
38         const char *bytes = [subdata bytes];
39         //Cast explanation: Character literals are of type int. STAssertEquals also checks that the two sides are of the same type, and const char is not int, so the assertion fails unless we cast the literals to const char.
40         STAssertEquals(bytes[0], (const char)'f', @"Unexpected first byte of subdata: 0x%x %c", bytes[0], bytes[0]);
41         STAssertEquals(bytes[1], (const char)'o', @"Unexpected second byte of subdata: 0x%x %c", bytes[1], bytes[1]);
42         STAssertEquals(bytes[2], (const char)'o', @"Unexpected third byte of subdata: 0x%x %c", bytes[2], bytes[2]);
45 @end