diff --git a/Classes/ASIFormDataRequest.m b/Classes/ASIFormDataRequest.m index bcf95ec7..0c40b58e 100644 --- a/Classes/ASIFormDataRequest.m +++ b/Classes/ASIFormDataRequest.m @@ -181,7 +181,7 @@ - (void)buildMultipartFormDataPostBody NSString *endItemBoundary = [NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary]; NSEnumerator *e = [[self postData] keyEnumerator]; NSString *key; - int i=0; + NSUInteger i=0; while (key = [e nextObject]) { [self appendPostString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key]]; [self appendPostString:[[self postData] objectForKey:key]]; diff --git a/Classes/ASIHTTPRequest.m b/Classes/ASIHTTPRequest.m index 0c55504a..3295ce77 100644 --- a/Classes/ASIHTTPRequest.m +++ b/Classes/ASIHTTPRequest.m @@ -2129,7 +2129,7 @@ - (void)handleBytesAvailable if ([self needsRedirect]) { return; } - int bufferSize = 2048; + long long bufferSize = 2048; if (contentLength > 262144) { bufferSize = 65536; } else if (contentLength > 65536) { @@ -2142,13 +2142,13 @@ - (void)handleBytesAvailable if ([[self class] isBandwidthThrottled]) { [bandwidthThrottlingLock lock]; if (maxBandwidthPerSecond > 0) { - long long maxSize = (long long)maxBandwidthPerSecond-(long long)bandwidthUsedInLastSecond; - if (maxSize < 0) { + long long maxiumumSize = (long long)maxBandwidthPerSecond-(long long)bandwidthUsedInLastSecond; + if (maxiumumSize < 0) { // We aren't supposed to read any more data right now, but we'll read a single byte anyway so the CFNetwork's buffer isn't full bufferSize = 1; - } else if (maxSize/4 < bufferSize) { + } else if (maxiumumSize/4 < bufferSize) { // We were going to fetch more data that we should be allowed, so we'll reduce the size of our read - bufferSize = maxSize/4; + bufferSize = maxiumumSize/4; } } if (bufferSize < 1) { @@ -2350,7 +2350,7 @@ + (void)removeProxyAuthenticationCredentialsFromSessionStore:(NSDictionary *)cre { [sessionCredentialsLock lock]; NSMutableArray *sessionCredentialsList = [[self class] sessionProxyCredentialsStore]; - int i; + NSUInteger i; for (i=0; i<[sessionCredentialsList count]; i++) { NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i]; if ([theCredentials objectForKey:@"Credentials"] == credentials) { @@ -2366,7 +2366,7 @@ + (void)removeAuthenticationCredentialsFromSessionStore:(NSDictionary *)credenti { [sessionCredentialsLock lock]; NSMutableArray *sessionCredentialsList = [[self class] sessionCredentialsStore]; - int i; + NSUInteger i; for (i=0; i<[sessionCredentialsList count]; i++) { NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i]; if ([theCredentials objectForKey:@"Credentials"] == credentials) { @@ -2966,8 +2966,8 @@ + (void)recordBandwidthUsage bandwidthMeasurementDate = [[NSDate dateWithTimeIntervalSinceNow:1] retain]; bandwidthUsedInLastSecond = 0; - int measurements = [bandwidthUsageTracker count]; - unsigned long long totalBytes = 0; + NSUInteger measurements = [bandwidthUsageTracker count]; + unsigned long totalBytes = 0; for (NSNumber *bytes in bandwidthUsageTracker) { totalBytes += [bytes unsignedLongValue]; } @@ -3054,7 +3054,7 @@ + (unsigned long)maxUploadReadLength [bandwidthThrottlingLock lock]; // We'll split our bandwidth allowance into 4 (which is the default for an ASINetworkQueue's max concurrent operations count) to give all running requests a fighting chance of reading data this cycle - long long toRead = maxBandwidthPerSecond/4; + unsigned long toRead = maxBandwidthPerSecond/4; if (maxBandwidthPerSecond > 0 && (bandwidthUsedInLastSecond + toRead > maxBandwidthPerSecond)) { toRead = maxBandwidthPerSecond-bandwidthUsedInLastSecond; if (toRead < 0) { @@ -3100,11 +3100,11 @@ + (NSString*)base64forData:(NSData*)theData { } } - NSInteger index = (i / 3) * 4; - output[index + 0] = table[(value >> 18) & 0x3F]; - output[index + 1] = table[(value >> 12) & 0x3F]; - output[index + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '='; - output[index + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '='; + NSInteger theIndex = (i / 3) * 4; + output[theIndex + 0] = table[(value >> 18) & 0x3F]; + output[theIndex + 1] = table[(value >> 12) & 0x3F]; + output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '='; + output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '='; } return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease]; diff --git a/Classes/Tests/ASIHTTPRequestTests.h b/Classes/Tests/ASIHTTPRequestTests.h index bccf36cc..7a54c92b 100644 --- a/Classes/Tests/ASIHTTPRequestTests.h +++ b/Classes/Tests/ASIHTTPRequestTests.h @@ -51,4 +51,11 @@ - (void)testMainThreadDelegateAuthenticationFailure; +- (void)requestStarted:(ASIHTTPRequest *)request; +- (void)requestFinished:(ASIHTTPRequest *)request; +- (void)requestFailed:(ASIHTTPRequest *)request; +- (void)delegateTestStarted:(ASIHTTPRequest *)request; +- (void)delegateTestFinished:(ASIHTTPRequest *)request; +- (void)delegateTestFailed:(ASIHTTPRequest *)request; + @end diff --git a/Classes/Tests/ASIHTTPRequestTests.m b/Classes/Tests/ASIHTTPRequestTests.m index 575d3d70..d8666e95 100644 --- a/Classes/Tests/ASIHTTPRequestTests.m +++ b/Classes/Tests/ASIHTTPRequestTests.m @@ -78,10 +78,16 @@ - (void)testDelegateMethods GHAssertTrue(started,@"Failed to call the delegate method when the request started"); GHAssertTrue(finished,@"Failed to call the delegate method when the request finished"); + // Hacky, but this test won't run on the main thread, we have to hope the delegate methods will be called in this time + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; + request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]]; [request setDelegate:self]; [request setTimeOutSeconds:0.01]; [request start]; + + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; + GHAssertTrue(failed,@"Failed to call the delegate method when the request failed"); started = NO; @@ -95,7 +101,6 @@ - (void)testDelegateMethods [request setDidFinishSelector:@selector(delegateTestFinished:)]; [request start]; - // Hacky, but this test won't run on the main thread, we have to hope the delegate methods will be called in this time [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; GHAssertTrue(started,@"Failed to call the delegate method when the request started"); @@ -107,7 +112,6 @@ - (void)testDelegateMethods [request setTimeOutSeconds:0.01]; [request start]; - // Hacky, but this test won't run on the main thread, we have to hope the delegate methods will be called in this time [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; GHAssertTrue(failed,@"Failed to call the delegate method when the request failed"); @@ -188,7 +192,7 @@ - (void)testCharacterEncoding NSArray *IANAEncodings = [NSArray arrayWithObjects:@"UTF-8",@"US-ASCII",@"ISO-8859-1",@"UTF-16",nil]; NSUInteger NSStringEncodings[] = {NSUTF8StringEncoding,NSASCIIStringEncoding,NSISOLatin1StringEncoding,NSUnicodeStringEncoding}; - int i; + NSUInteger i; for (i=0; i<[IANAEncodings count]; i++) { NSURL *url = [[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://allseeing-i.com/ASIHTTPRequest/tests/Character-Encoding/%@",[IANAEncodings objectAtIndex:i]]] autorelease]; ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease]; @@ -394,7 +398,7 @@ - (void)testDownloadProgress [request start]; // Wait for the progress to catch up - [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]]; + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; BOOL success = (progress > 0.95); GHAssertTrue(success,@"Failed to properly increment download progress %f != 1.0",progress); @@ -1197,6 +1201,14 @@ - (void)asyncSuccess:(ASIHTTPRequest *)request } + +// Will be called on Mac OS +- (void)setDoubleValue:(double)newProgress; +{ + progress = (float)newProgress; +} + +// Will be called on iPhone OS - (void)setProgress:(float)newProgress; { progress = newProgress; diff --git a/Classes/Tests/ASINetworkQueueTests.m b/Classes/Tests/ASINetworkQueueTests.m index 5e2f1bb5..608cff72 100755 --- a/Classes/Tests/ASINetworkQueueTests.m +++ b/Classes/Tests/ASINetworkQueueTests.m @@ -335,16 +335,19 @@ - (void)testUploadProgress } +// Will be called on Mac OS +- (void)setDoubleValue:(double)newProgress; +{ + progress = (float)newProgress; +} - - -- (void)setProgress:(float)newProgress +// Will be called on iPhone OS +- (void)setProgress:(float)newProgress; { progress = newProgress; } - - (void)testFailure { complete = NO; diff --git a/Classes/Tests/ASIS3RequestTests.m b/Classes/Tests/ASIS3RequestTests.m index 3275d93a..e1bc6f09 100644 --- a/Classes/Tests/ASIS3RequestTests.m +++ b/Classes/Tests/ASIS3RequestTests.m @@ -40,12 +40,12 @@ - (void)testAuthenticationHeaderGeneration { NSString *exampleSecretAccessKey = @"uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"; NSString *exampleAccessKey = @"0PN5J17HBGZHT7JJ3X82"; - NSString *bucket = @"johnsmith"; + NSString *exampleBucket = @"johnsmith"; // Test GET NSString *path = @"/photos/puppy.jpg"; NSString *dateString = @"Tue, 27 Mar 2007 19:36:42 +0000"; - ASIS3Request *request = [ASIS3Request requestWithBucket:bucket path:path]; + ASIS3Request *request = [ASIS3Request requestWithBucket:exampleBucket path:path]; [request setDateString:dateString]; [request setSecretAccessKey:exampleSecretAccessKey]; [request setAccessKey:exampleAccessKey]; @@ -56,7 +56,7 @@ - (void)testAuthenticationHeaderGeneration // Test PUT path = @"/photos/puppy.jpg"; dateString = @"Tue, 27 Mar 2007 21:15:45 +0000"; - request = [ASIS3Request requestWithBucket:bucket path:path]; + request = [ASIS3Request requestWithBucket:exampleBucket path:path]; [request setRequestMethod:@"PUT"]; [request setMimeType:@"image/jpeg"]; [request setDateString:dateString]; @@ -68,7 +68,7 @@ - (void)testAuthenticationHeaderGeneration // Test List dateString = @"Tue, 27 Mar 2007 19:42:41 +0000"; - ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:bucket]; + ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:exampleBucket]; [listRequest setPrefix:@"photos"]; [listRequest setMaxResultCount:50]; [listRequest setMarker:@"puppy"]; @@ -82,7 +82,7 @@ - (void)testAuthenticationHeaderGeneration // Test fetch ACL path = @"/?acl"; dateString = @"Tue, 27 Mar 2007 19:44:46 +0000"; - request = [ASIS3Request requestWithBucket:bucket path:path]; + request = [ASIS3Request requestWithBucket:exampleBucket path:path]; [request setDateString:dateString]; [request setSecretAccessKey:exampleSecretAccessKey]; [request setAccessKey:exampleAccessKey]; @@ -92,10 +92,10 @@ - (void)testAuthenticationHeaderGeneration // Test Unicode keys // (I think Amazon's name for this example is misleading since this test actually only uses URL encoded strings) - bucket = @"dictionary"; + exampleBucket = @"dictionary"; path = @"/fran%C3%A7ais/pr%c3%a9f%c3%a8re"; dateString = @"Wed, 28 Mar 2007 01:49:49 +0000"; - request = [ASIS3Request requestWithBucket:bucket path:path]; + request = [ASIS3Request requestWithBucket:exampleBucket path:path]; [request setDateString:dateString]; [request setSecretAccessKey:exampleSecretAccessKey]; [request setAccessKey:exampleAccessKey]; @@ -111,10 +111,10 @@ - (void)testFailure // We're actually going to try with the Amazon example details, but the request will fail because the date is old NSString *exampleSecretAccessKey = @"uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o"; NSString *exampleAccessKey = @"0PN5J17HBGZHT7JJ3X82"; - NSString *bucket = @"johnsmith"; + NSString *exampleBucket = @"johnsmith"; NSString *path = @"/photos/puppy.jpg"; NSString *dateString = @"Tue, 27 Mar 2007 19:36:42 +0000"; - ASIS3Request *request = [ASIS3Request requestWithBucket:bucket path:path]; + ASIS3Request *request = [ASIS3Request requestWithBucket:exampleBucket path:path]; [request setDateString:dateString]; [request setSecretAccessKey:exampleSecretAccessKey]; [request setAccessKey:exampleAccessKey]; diff --git a/Mac.xcodeproj/project.pbxproj b/Mac.xcodeproj/project.pbxproj index 50491201..d8fedbba 100644 --- a/Mac.xcodeproj/project.pbxproj +++ b/Mac.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ 8D1107320486CEB800E47090 /* Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mac.app; sourceTree = BUILT_PRODUCTS_DIR; }; B50244191025D36B002B13E1 /* ProxyTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyTests.h; sourceTree = ""; }; B502441A1025D36B002B13E1 /* ProxyTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyTests.m; sourceTree = ""; }; + B515507810BD56E800608267 /* strict.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = strict.xcconfig; sourceTree = ""; }; B51791281024BF0F00583567 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; B51E5F39100B829D004A300D /* ASIS3BucketObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIS3BucketObject.h; sourceTree = ""; }; B51E5F3A100B829D004A300D /* ASIS3BucketObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIS3BucketObject.m; sourceTree = ""; }; @@ -178,6 +179,7 @@ 29B97315FDCFA39411CA2CEA /* Other Sources */ = { isa = PBXGroup; children = ( + B515507810BD56E800608267 /* strict.xcconfig */, B55B5E6E0F7656A40064029C /* main.m */, B55B5E6F0F7656A40064029C /* Mac_Prefix.pch */, B55B5ED00F76588D0064029C /* AppDelegate.h */, @@ -400,6 +402,7 @@ /* Begin XCBuildConfiguration section */ B55B5EE20F7658C80064029C /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B515507810BD56E800608267 /* strict.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = NO; @@ -432,6 +435,7 @@ }; B55B5EE30F7658C80064029C /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = B515507810BD56E800608267 /* strict.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = YES; diff --git a/strict.xcconfig b/strict.xcconfig new file mode 100644 index 00000000..4da6b5eb --- /dev/null +++ b/strict.xcconfig @@ -0,0 +1,26 @@ +// +// strict.xcconfig +// Mac +// +// Created by Ben Copsey on 25/11/2009. +// Copyright 2009 All-Seeing Interactive. All rights reserved. +// + +GCC_WARN_CHECK_SWITCH_STATEMENTS = YES +GCC_WARN_SHADOW = YES +GCC_WARN_64_TO_32_BIT_CONVERSION = YES +GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES +GCC_WARN_ABOUT_RETURN_TYPE = YES +//GCC_WARN_MISSING_PARENTHESES = YES +GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES +//GCC_WARN_ABOUT_MISSING_NEWLINE = YES +GCC_WARN_SIGN_COMPARE = YES +GCC_WARN_STRICT_SELECTOR_MATCH = missing value +GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES +//GCC_WARN_UNDECLARED_SELECTOR = YES +GCC_WARN_UNUSED_FUNCTION = YES +GCC_WARN_UNUSED_LABEL = YES +GCC_WARN_UNUSED_VALUE = YES +GCC_WARN_UNUSED_VARIABLE = YES +GCC_TREAT_WARNINGS_AS_ERRORS = YES +//RUN_CLANG_STATIC_ANALYZER = YES \ No newline at end of file