You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ia...@apache.org on 2013/07/15 18:32:42 UTC
[6/6] ios commit: [CB-4202] [CB-3726] Remove File Transfer plugin
unit tests
[CB-4202] [CB-3726] Remove File Transfer plugin unit tests
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/9fb953d5
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/9fb953d5
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/9fb953d5
Branch: refs/heads/master
Commit: 9fb953d58b97e136deb73c32bb897415c6cae413
Parents: a7d8a16
Author: Ian Clelland <ic...@chromium.org>
Authored: Mon Jul 15 12:28:43 2013 -0400
Committer: Ian Clelland <ic...@chromium.org>
Committed: Mon Jul 15 12:31:38 2013 -0400
----------------------------------------------------------------------
CordovaLibTests/CDVFileTransferTests.m | 218 -------------------
.../CordovaTests.xcodeproj/project.pbxproj | 4 -
2 files changed, 222 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9fb953d5/CordovaLibTests/CDVFileTransferTests.m
----------------------------------------------------------------------
diff --git a/CordovaLibTests/CDVFileTransferTests.m b/CordovaLibTests/CDVFileTransferTests.m
deleted file mode 100644
index 2effc98..0000000
--- a/CordovaLibTests/CDVFileTransferTests.m
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import <SenTestingKit/SenTestingKit.h>
-
-#import "CDV.h"
-#import "CDVCommandDelegateImpl.h"
-
-static NSString* const kDummyArgCallbackId = @"cid0";
-static NSString* const kDummyArgFileKey = @"image.jpg";
-static NSString* const kDummyArgTarget = @"/path/to/image.jpg";
-static NSString* const kDummyArgServer = @"http://apache.org";
-static NSString* const kDummyFileContents = @"0123456789";
-
-// Reads the given stream and returns the contents as an NSData.
-static NSData *readStream(NSInputStream* stream)
-{
- static const NSUInteger kBufferSize = 1024;
-
- UInt8* buffer = malloc(kBufferSize);
- NSMutableData* streamData = [NSMutableData data];
-
- [stream open];
-
- for (;; ) {
- NSInteger read = [stream read:buffer maxLength:kBufferSize];
- if (read > 0) {
- [streamData appendBytes:buffer length:read];
- } else {
- break;
- }
- }
-
- free(buffer);
- [stream close];
- return streamData;
-}
-
-@interface CDVFileTransferTests : SenTestCase {
- NSMutableArray* _arguments;
- CDVFileTransfer* _fileTransfer;
- NSData* _dummyFileData;
- CDVCommandDelegateImpl* _commandDelegate;
-}
-@end
-
-@implementation CDVFileTransferTests
-
-- (void)setUp
-{
- [super setUp];
-
- _arguments = [[NSMutableArray alloc] initWithObjects:
- kDummyArgTarget, kDummyArgServer, kDummyArgFileKey, [NSNull null],
- [NSNull null], [NSNull null], [NSNull null], [NSNull null], [NSNull null], nil];
- _dummyFileData = [kDummyFileContents dataUsingEncoding:NSUTF8StringEncoding];
- _commandDelegate = [[CDVCommandDelegateImpl alloc] initWithViewController:nil];
- _fileTransfer = [[CDVFileTransfer alloc] init];
- _fileTransfer.commandDelegate = _commandDelegate;
-}
-
-- (void)tearDown
-{
- _arguments = nil;
- _dummyFileData = nil;
- _fileTransfer = nil;
- _commandDelegate = nil;
- [super tearDown];
-}
-
-- (void)setFilePathArg:(NSString*)filePath
-{
- [_arguments replaceObjectAtIndex:0 withObject:filePath];
-}
-
-- (void)setServerUrlArg:(NSString*)serverUrl
-{
- [_arguments replaceObjectAtIndex:1 withObject:serverUrl];
-}
-
-- (void)setChunkedModeArg:(BOOL)chunk
-{
- [_arguments replaceObjectAtIndex:7 withObject:[NSNumber numberWithBool:chunk]];
-}
-
-- (void)setParams:(NSDictionary*)params
-{
- [_arguments replaceObjectAtIndex:5 withObject:params];
-}
-
-- (void)setHeaders:(NSDictionary*)headers
-{
- [_arguments replaceObjectAtIndex:8 withObject:headers];
-}
-
-- (NSURLRequest*)requestForUpload
-{
- CDVInvokedUrlCommand* command = [[CDVInvokedUrlCommand alloc] initWithArguments:_arguments
- callbackId:kDummyArgCallbackId
- className:@"FileTransfer"
- methodName:@"upload"];
-
- return [_fileTransfer requestForUploadCommand:command fileData:_dummyFileData];
-}
-
-- (void)checkUploadRequest:(NSURLRequest*)request chunked:(BOOL)chunked
-{
- STAssertTrue([@"POST" isEqualToString:[request HTTPMethod]], nil);
- NSData* payloadData = nil;
- if (chunked) {
- STAssertNil([request HTTPBody], nil);
- STAssertNotNil([request HTTPBodyStream], nil);
- payloadData = readStream([request HTTPBodyStream]);
- } else {
- STAssertNotNil([request HTTPBody], nil);
- STAssertNil([request HTTPBodyStream], nil);
- payloadData = [request HTTPBody];
- }
- STAssertNotNil([request valueForHTTPHeaderField:@"X-Requested-With"], nil);
- NSUInteger contentLength = [[request valueForHTTPHeaderField:@"Content-Length"] intValue];
- STAssertEquals([payloadData length], contentLength, nil);
-}
-
-- (void)testEscapePathComponentForUrlString
-{
- STAssertTrue([@"" isEqualToString:
- [_fileTransfer escapePathComponentForUrlString:@""]], nil);
- STAssertTrue([@"foo" isEqualToString:
- [_fileTransfer escapePathComponentForUrlString:@"foo"]], nil);
- STAssertTrue([@"http://a.org/spa%20ce%25" isEqualToString:
- [_fileTransfer escapePathComponentForUrlString:@"http://a.org/spa ce%"]], nil);
- STAssertTrue([@"http://a.org/spa%20ce%25/" isEqualToString:
- [_fileTransfer escapePathComponentForUrlString:@"http://a.org/spa ce%/"]], nil);
- STAssertTrue([@"http://a.org/%25/%25/" isEqualToString:
- [_fileTransfer escapePathComponentForUrlString:@"http://a.org/%/%/"]], nil);
-}
-
-- (void)testUpload_invalidServerUrl
-{
- [self setServerUrlArg:@"invalid url"];
- STAssertNil([self requestForUpload], nil);
-}
-
-- (void)testUpload_missingFileData
-{
- _dummyFileData = nil;
- STAssertNil([self requestForUpload], nil);
-}
-
-- (void)testUpload_serverUrlPathEscaping
-{
- [self setServerUrlArg:[_fileTransfer escapePathComponentForUrlString:@"http://apache.org/spa ce%"]]; // uri encode first now
- NSURLRequest* request = [self requestForUpload];
- STAssertTrue([[[request URL] absoluteString] isEqualToString:@"http://apache.org/spa%20ce%25"], nil);
-}
-
-- (void)testUpload_nonChunked
-{
- [self setChunkedModeArg:NO];
- NSURLRequest* request = [self requestForUpload];
- [self checkUploadRequest:request chunked:NO];
-}
-
-- (void)testUpload_chunked
-{
- // As noted in the implementation, chunked upload is disabled pre 5.0.
- if (!IsAtLeastiOSVersion(@"5.0")) {
- return;
- }
- // Chunked is the default.
- NSURLRequest* request = [self requestForUpload];
- [self checkUploadRequest:request chunked:YES];
-}
-
-- (void)testUpload_withParams
-{
- [self setChunkedModeArg:NO];
- NSDictionary* params = [NSDictionary dictionaryWithObjectsAndKeys:@"cookieval", kOptionsKeyCookie,
- @"val3", @"key3", nil];
- [self setParams:params];
- NSURLRequest* request = [self requestForUpload];
- NSString* payload = [[NSString alloc] initWithData:[request HTTPBody] encoding:NSUTF8StringEncoding];
- // Check that the cookie is set, and that it is not in the payload like others in the options dict.
- STAssertTrue([@"cookieval" isEqualToString:[request valueForHTTPHeaderField:@"Cookie"]], nil);
- STAssertEquals([payload rangeOfString:@"cookieval"].length, 0U, nil);
- // Check that key3 is in the payload.
- STAssertTrue([payload rangeOfString:@"key3"].length > 0, nil);
- STAssertTrue([payload rangeOfString:@"val3"].length > 0, nil);
-}
-
-- (void)testUpload_withHeaders
-{
- [self setChunkedModeArg:NO];
- [self setHeaders:[NSDictionary dictionaryWithObjectsAndKeys:@"val1", @"key1",
- [NSArray arrayWithObjects:@"val2a", @"val2b", nil], @"key2", [NSNull null], @"X-Requested-With", nil]];
- NSURLRequest* request = [self requestForUpload];
- STAssertTrue([@"val1" isEqualToString:[request valueForHTTPHeaderField:@"key1"]], nil);
- STAssertTrue([@"val2a,val2b" isEqualToString:[request valueForHTTPHeaderField:@"key2"]], nil);
- STAssertTrue([@"null" isEqualToString:[request valueForHTTPHeaderField:@"X-Requested-With"]], nil);
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/9fb953d5/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj b/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj
index 5de43de..05480e4 100644
--- a/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj
+++ b/CordovaLibTests/CordovaTests.xcodeproj/project.pbxproj
@@ -48,7 +48,6 @@
EB89634A15FE66EA00E12277 /* CDVInvokedUrlCommandTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */; };
EB96677216ADBCF500D86CDF /* CDVUserAgentTest.m in Sources */ = {isa = PBXBuildFile; fileRef = EB96677116ADBCF500D86CDF /* CDVUserAgentTest.m */; };
EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */; };
- EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */; };
F8EB14D1165FFD3200616F39 /* config.xml in Resources */ = {isa = PBXBuildFile; fileRef = F8EB14D0165FFD3200616F39 /* config.xml */; };
/* End PBXBuildFile section */
@@ -114,7 +113,6 @@
EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CDVWebViewTest.h; sourceTree = "<group>"; };
EBA3554415A731F100F4DE24 /* CDVFakeFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CDVFakeFileManager.h; sourceTree = "<group>"; };
EBA3554515A731F100F4DE24 /* CDVFakeFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVFakeFileManager.m; sourceTree = "<group>"; };
- EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CDVFileTransferTests.m; sourceTree = "<group>"; };
F8EB14D0165FFD3200616F39 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = config.xml; path = CordovaLibApp/config.xml; sourceTree = "<group>"; };
/* End PBXFileReference section */
@@ -254,7 +252,6 @@
EBA3550F15A5F18900F4DE24 /* CDVWebViewTest.h */,
30B342F415224B360070E6A5 /* CDVWebViewTest.m */,
30D1B08B15A2B36D0060C291 /* CDVBase64Tests.m */,
- EBA3556E15ABD0C900F4DE24 /* CDVFileTransferTests.m */,
EB89634915FE66EA00E12277 /* CDVInvokedUrlCommandTests.m */,
3062D1AD151D4D9D000D9128 /* CDVLocalStorageTests.m */,
686357B9141002F200DF4CF2 /* CDVPluginResultJSONSerializationTests.m */,
@@ -425,7 +422,6 @@
30B342F515224B360070E6A5 /* CDVWebViewTest.m in Sources */,
30D1B08C15A2B36D0060C291 /* CDVBase64Tests.m in Sources */,
EBA3554615A731F100F4DE24 /* CDVFakeFileManager.m in Sources */,
- EBA3556F15ABD0C900F4DE24 /* CDVFileTransferTests.m in Sources */,
EB89634A15FE66EA00E12277 /* CDVInvokedUrlCommandTests.m in Sources */,
EB96677216ADBCF500D86CDF /* CDVUserAgentTest.m in Sources */,
7E91406017711D88002C6A3F /* CDVWebViewDelegateTests.m in Sources */,