Ben Copsey

Fix a potential crasher (wrap readStream access in main loop in the cancelledLock)

Tests now build on the device
Fix file paths in tests so they pass on the device
Removed some old cruft
... ... @@ -602,10 +602,14 @@ static NSError *ASITooMuchRedirectionError;
}
// Find out how much data we've uploaded so far
[[self cancelledLock] lock];
[self setTotalBytesSent:[[(NSNumber *)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPRequestBytesWrittenCount) autorelease] unsignedLongLongValue]];
[[self cancelledLock] unlock];
[self updateProgressIndicators];
// This thread should wait for 1/4 second for the stream to do something. We'll stop early if it does.
CFRunLoopRunInMode(ASIHTTPRequestRunMode,0.25,YES);
}
... ... @@ -1397,9 +1401,11 @@ static NSError *ASITooMuchRedirectionError;
return;
}
[progressLock lock];
[self setComplete:YES];
[self updateProgressIndicators];
[[self cancelledLock] lock];
if (readStream) {
CFReadStreamClose(readStream);
CFReadStreamSetClient(readStream, kCFStreamEventNone, NULL, NULL);
... ... @@ -1449,7 +1455,9 @@ static NSError *ASITooMuchRedirectionError;
}
}
}
[[self cancelledLock] unlock];
[progressLock unlock];
if (fileError) {
[self failWithError:fileError];
} else {
... ...
... ... @@ -6,13 +6,9 @@
// Copyright 2008 All-Seeing Interactive. All rights reserved.
//
#if TARGET_OS_IPHONE
#import "GHUnit.h"
#else
#import <GHUnit/GHUnit.h>
#endif
#import "ASITestCase.h"
@interface ASIFormDataRequestTests : GHTestCase {
@interface ASIFormDataRequestTests : ASITestCase {
float progress;
}
... ...
... ... @@ -24,7 +24,7 @@
//Create a 32kb file
unsigned int size = 1024*32;
NSMutableData *data = [NSMutableData dataWithLength:size];
NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"bigfile"];
NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"bigfile"];
[data writeToFile:path atomically:NO];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
... ... @@ -39,7 +39,6 @@
[request setPostValue:d forKey:@"post_var2"];
[request setPostValue:v forKey:@"post_var3"];
[request setFile:path forKey:@"file"];
[request setPostBodyFilePath:@"/Users/ben/Desktop/111.txt"];
[request start];
BOOL success = ([[request responseString] isEqualToString:[NSString stringWithFormat:@"post_var: %@\r\npost_var2: %@\r\npost_var3: %@\r\nfile_name: %@\r\nfile_size: %hu",@"foo",d,v,@"bigfile",size]]);
... ...
... ... @@ -6,13 +6,9 @@
// Copyright 2008 All-Seeing Interactive. All rights reserved.
//
#if TARGET_OS_IPHONE
#import "GHUnit.h"
#else
#import <GHUnit/GHUnit.h>
#endif
#import "ASITestCase.h"
@interface ASIHTTPRequestTests : GHTestCase {
@interface ASIHTTPRequestTests : ASITestCase {
float progress;
}
... ...
... ... @@ -20,7 +20,6 @@
@implementation ASIHTTPRequestTests
- (void)testBasicDownload
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
... ... @@ -204,7 +203,7 @@
- (void)testFileDownload
{
NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"testimage.png"];
NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testimage.png"];
NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/i/logo.png"] autorelease];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
... ... @@ -228,7 +227,7 @@
- (void)testCompressedResponseDownloadToFile
{
NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"testfile"];
NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile"];
NSURL *url = [[[NSURL alloc] initWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/first"] autorelease];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
... ... @@ -290,7 +289,7 @@
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com/ASIHTTPRequest/tests/print_request_body"];
NSString *requestBody = @"This is the request body";
NSString *requestContentPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"testfile.txt"];
NSString *requestContentPath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
[[requestBody dataUsingEncoding:NSUTF8StringEncoding] writeToFile:requestContentPath atomically:NO];
... ... @@ -630,8 +629,8 @@
- (void)testPartialFetch
{
NSString *downloadPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"testfile.txt"];
NSString *tempPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"tempfile.txt"];
NSString *downloadPath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
NSString *tempPath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"tempfile.txt"];
NSString *partialContent = @"This file should be exactly 163 bytes long when encoded as UTF8, Unix line breaks with no BOM.\n";
[partialContent writeToFile:tempPath atomically:NO encoding:NSASCIIStringEncoding error:nil];
... ... @@ -737,7 +736,8 @@
GHAssertTrue(success,@"Failed compress or decompress the correct data");
// Test file to file compression / decompression
NSString *basePath = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
NSString *basePath = [self filePathForTemporaryTestFiles];
NSString *sourcePath = [basePath stringByAppendingPathComponent:@"text.txt"];
NSString *destPath = [basePath stringByAppendingPathComponent:@"text.txt.compressed"];
NSString *newPath = [basePath stringByAppendingPathComponent:@"text2.txt"];
... ...
... ... @@ -6,11 +6,7 @@
// Copyright 2008 All-Seeing Interactive. All rights reserved.
//
#if TARGET_OS_IPHONE
#import "GHUnit.h"
#else
#import <GHUnit/GHUnit.h>
#endif
#import "ASITestCase.h"
/*
IMPORTANT
... ... @@ -23,7 +19,7 @@ IMPORTANT
@class ASIHTTPRequest;
@class ASINetworkQueue;
@interface ASINetworkQueueTests : GHTestCase {
@interface ASINetworkQueueTests : ASITestCase {
ASIHTTPRequest *requestThatShouldFail;
BOOL complete;
BOOL request_didfail;
... ...
... ... @@ -22,12 +22,11 @@ IMPORTANT
// Used for subclass test
@interface ASINetworkQueueSubclass : ASINetworkQueue {}
@end
@implementation ASINetworkQueueSubclass;
@implementation ASINetworkQueueSubclass
@end
@implementation ASINetworkQueueTests
- (void)testProgress
{
complete = NO;
... ... @@ -106,7 +105,7 @@ IMPORTANT
int i;
for (i=0; i<3; i++) {
NSData *data = [[[NSMutableData alloc] initWithLength:fileSizes[i]*1024] autorelease];
NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"file%hi",i]];
NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"file%hi",i]];
[data writeToFile:path atomically:NO];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setFile:path forKey:@"file"];
... ... @@ -130,7 +129,7 @@ IMPORTANT
for (i=0; i<3; i++) {
NSData *data = [[[NSMutableData alloc] initWithLength:fileSizes[i]*1024] autorelease];
NSString *path = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"file%hi",i]];
NSString *path = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"file%hi",i]];
[data writeToFile:path atomically:NO];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setFile:path forKey:@"file"];
... ... @@ -381,12 +380,12 @@ IMPORTANT
complete = NO;
progress = 0;
NSString *temporaryPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.download"];
NSString *temporaryPath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip.download"];
if ([[NSFileManager defaultManager] fileExistsAtPath:temporaryPath]) {
[[NSFileManager defaultManager] removeItemAtPath:temporaryPath error:nil];
}
NSString *downloadPath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip"];
NSString *downloadPath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"MemexTrails_1.0b1.zip"];
if ([[NSFileManager defaultManager] fileExistsAtPath:downloadPath]) {
[[NSFileManager defaultManager] removeItemAtPath:downloadPath error:nil];
}
... ...
... ... @@ -6,13 +6,9 @@
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#if TARGET_OS_IPHONE
#import "GHUnit.h"
#else
#import <GHUnit/GHUnit.h>
#endif
#import "ASITestCase.h"
@interface ASIS3RequestTests : GHTestCase {
@interface ASIS3RequestTests : ASITestCase {
}
- (void)testAuthenticationHeaderGeneration;
... ...
... ... @@ -35,7 +35,6 @@ static NSString *bucket = @"";
@implementation ASIS3RequestTests
// All these tests are based on Amazon's examples at: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/
- (void)testAuthenticationHeaderGeneration
{
... ... @@ -141,7 +140,7 @@ static NSString *bucket = @"";
// Create the file
NSString *text = @"This is my content";
NSString *filePath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"testfile.txt"];
NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
[[text dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];
// PUT the file
... ... @@ -231,7 +230,7 @@ static NSString *bucket = @"";
{
// Create the file
NSString *text = @"This is my content This is my content This is my content This is my content This is my content This is my content";
NSString *filePath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"testfile.txt"];
NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:@"testfile.txt"];
[[text dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];
NSString *path = @"/gzipped-data";
... ... @@ -274,7 +273,7 @@ static NSString *bucket = @"";
int i;
for (i=0; i<5; i++) {
NSString *text = [NSString stringWithFormat:@"This is the content of file #%hi",i];
NSString *filePath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.txt",i]];
NSString *filePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.txt",i]];
[[text dataUsingEncoding:NSUTF8StringEncoding] writeToFile:filePath atomically:NO];
NSString *path = [NSString stringWithFormat:@"/test-file/%hi",i];
ASIS3Request *request = [ASIS3Request PUTRequestForFile:filePath withBucket:bucket path:path];
... ... @@ -319,7 +318,7 @@ static NSString *bucket = @"";
i=0;
// For each one, we'll just upload the same content again
for (ASIS3BucketObject *object in [listRequest bucketObjects]) {
NSString *oldFilePath = [[[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.txt",i]];;
NSString *oldFilePath = [[self filePathForTemporaryTestFiles] stringByAppendingPathComponent:[NSString stringWithFormat:@"%hi.txt",i]];;
ASIS3Request *request = [object PUTRequestWithFile:oldFilePath];
[request setAccessKey:accessKey];
[request setSecretAccessKey:secretAccessKey];
... ...
//
// ASITestCase.h
// iPhone
//
// Created by Ben Copsey on 26/07/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
#import "GHUnit.h"
#else
#import <GHUnit/GHUnit.h>
#endif
@interface ASITestCase : GHTestCase {
}
- (NSString *)filePathForTemporaryTestFiles;
@end
... ...
//
// ASITestCase.m
// iPhone
//
// Created by Ben Copsey on 26/07/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import "ASITestCase.h"
@implementation ASITestCase
- (NSString *)filePathForTemporaryTestFiles
{
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"ASIHTTPRequest Test Files"];
if (![[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:NULL]) {
[[NSFileManager defaultManager] createDirectoryAtPath:path attributes:nil];
}
return path;
}
@end
... ...
This diff was suppressed by a .gitattributes entry.
... ... @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string>iphone-icon.png</string>
<key>CFBundleIdentifier</key>
<string>com.allseeinginteractive.trailsnetwork.asidemo</string>
<string>com.yaddy.yadda.blah</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
... ...
... ... @@ -4,10 +4,14 @@
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>ASIHTTPRequest Unit Tests</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>iphone-tests-icon.png</string>
<key>CFBundleIdentifier</key>
<string>com.allseeinginteractive.trailsnetwork.tests</string>
<string>com.your.company.blah</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
... ... @@ -18,9 +22,5 @@
<string>1.0</string>
<key>NSMainNibFile</key>
<string>GHUnitIPhone</string>
<key>CFBundleDisplayName</key>
<string>ASIHTTPRequest Unit Tests</string>
<key>CFBundleIconFile</key>
<string>iphone-icon.png</string>
</dict>
</plist>
... ...
//
// Prefix header for all source files of the 'asi-http-request' target in the 'asi-http-request' project
//
#ifdef __OBJC__
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <CFNetwork/CFNetwork.h>
#import <UIKit/UIKit.h>
#endif
//
// iPhone-Sample-main.m
// asi-http-request
//
// Created by Ben Copsey on 09/07/2008.
// Copyright 2008 All-Seeing Interactive. All rights reserved.
//
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil);
[pool release];
return retVal;
}
This diff was suppressed by a .gitattributes entry.