Permalink
Browse files

More restructuring

  • Loading branch information...
1 parent b38922e commit de85a408f94f6acb5409786eaced6c50c0d9b863 @stevestreza committed Jun 19, 2011
Showing with 169 additions and 441 deletions.
  1. +25 −0 Classes/MWURLOperation.h
  2. +144 −2 Classes/MWURLOperation.m
  3. +0 −15 MWNetworkingTests/Release/Library/Headers/OCMock/NSNotificationCenter+OCMAdditions.h
  4. +0 −33 MWNetworkingTests/Release/Library/Headers/OCMock/OCMArg.h
  5. +0 −64 MWNetworkingTests/Release/Library/Headers/OCMock/OCMConstraint.h
  6. +0 −10 MWNetworkingTests/Release/Library/Headers/OCMock/OCMock.h
  7. +0 −43 MWNetworkingTests/Release/Library/Headers/OCMock/OCMockObject.h
  8. +0 −32 MWNetworkingTests/Release/Library/Headers/OCMock/OCMockRecorder.h
  9. BIN MWNetworkingTests/Release/Library/libOCMock.a
  10. +0 −1 MWNetworkingTests/Release/OCMock.framework/Headers
  11. +0 −1 MWNetworkingTests/Release/OCMock.framework/OCMock
  12. +0 −1 MWNetworkingTests/Release/OCMock.framework/Resources
  13. +0 −15 MWNetworkingTests/Release/OCMock.framework/Versions/A/Headers/NSNotificationCenter+OCMAdditions.h
  14. +0 −33 MWNetworkingTests/Release/OCMock.framework/Versions/A/Headers/OCMArg.h
  15. +0 −64 MWNetworkingTests/Release/OCMock.framework/Versions/A/Headers/OCMConstraint.h
  16. +0 −10 MWNetworkingTests/Release/OCMock.framework/Versions/A/Headers/OCMock.h
  17. +0 −43 MWNetworkingTests/Release/OCMock.framework/Versions/A/Headers/OCMockObject.h
  18. +0 −32 MWNetworkingTests/Release/OCMock.framework/Versions/A/Headers/OCMockRecorder.h
  19. BIN MWNetworkingTests/Release/OCMock.framework/Versions/A/OCMock
  20. +0 −26 MWNetworkingTests/Release/OCMock.framework/Versions/A/Resources/Info.plist
  21. +0 −15 MWNetworkingTests/Release/OCMock.framework/Versions/A/Resources/License.txt
  22. +0 −1 MWNetworkingTests/Release/OCMock.framework/Versions/Current
View
@@ -110,3 +110,28 @@
-(void)operationHadError:(NSError *)error;
@end
+
+@interface NSData (Base64)
+
+/*! @function +dataWithBase64EncodedString:
+ @discussion This method returns an autoreleased NSData object. The NSData object is initialized with the
+ contents of the Base 64 encoded string. This is a convenience method.
+ @param inBase64String An NSString object that contains only Base 64 encoded data.
+ @result The NSData object. */
++ (NSData *) dataWithBase64EncodedString:(NSString *) string;
+
+/*! @function -initWithBase64EncodedString:
+ @discussion The NSData object is initialized with the contents of the Base 64 encoded string.
+ This method returns self as a convenience.
+ @param inBase64String An NSString object that contains only Base 64 encoded data.
+ @result This method returns self. */
+- (id) initWithBase64EncodedString:(NSString *) string;
+
+/*! @function -base64EncodingWithLineLength:
+ @discussion This method returns a Base 64 encoded string representation of the data object.
+ @param inLineLength A value of zero means no line breaks. This is crunched to a multiple of 4 (the next
+ one greater than inLineLength).
+ @result The base 64 encoded data. */
+- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength;
+
+@end
View
@@ -30,7 +30,6 @@
//
#import "MWURLOperation.h"
-#import "NSData+Base64.h"
#if TARGET_OS_IPHONE
#define kMWURLOperationRunLoopMode NSDefaultRunLoopMode
@@ -383,7 +382,9 @@ +(NSRunLoop *)backgroundRunLoop{
[self backgroundThread];
while(!sBackgroundRunLoop){
usleep(1000);
+ NSLog(@"Waiting for a run loop");
}
+ NSLog(@"We have a run loop");
return sBackgroundRunLoop;
}
@@ -394,6 +395,7 @@ @implementation MWURLOperation (NSURLConnectionDelegate)
-(NSURLRequest *)connection:(NSURLConnection *)connection
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse{
+ NSLog(@"Beginning operation for %@",[request URL]);
BOOL shouldReturn = [self operationShouldRedirectToURL:[request URL]];
[self operationDidBegin];
return (shouldReturn ? request : nil);
@@ -402,6 +404,7 @@ -(NSURLRequest *)connection:(NSURLConnection *)connection
-(void)connection:(NSURLConnection *)conn didReceiveResponse:(NSHTTPURLResponse *)response{
_response = [response retain];
+ NSLog(@"Connection received response %i", (int)[response statusCode]);
if([response statusCode] == 303 && [[response allHeaderFields] valueForKey:@"Location"]){
return;
@@ -454,7 +457,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection{
[[NSNotificationCenter defaultCenter] postNotificationName:kMWURLOperationDidFinishDownloadingNotification object:self];
- // NSLog(@"Calling delegate that we're done: %@",mDelegate);
+ NSLog(@"Calling delegate that we're done: %@",self.delegate);
[self operationFinished];
[self willChangeValueForKey:@"isExecuting"];
@@ -591,4 +594,143 @@ -(void)_startConnection{
[[NSNotificationCenter defaultCenter] postNotificationName:kMWURLOperationDidBeginDownloadingNotification object:self];
}
+@end
+
+#pragma mark Base64 Support
+
+static char encodingTable[64] = {
+ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
+ 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
+ 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
+ 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/' };
+
+@implementation NSData (Base64)
+
++ (NSData *) dataWithBase64EncodedString:(NSString *) string {
+ NSData *result = [[NSData alloc] initWithBase64EncodedString:string];
+ return [result autorelease];
+}
+
+- (id) initWithBase64EncodedString:(NSString *) string {
+ NSMutableData *mutableData = nil;
+
+ if( string ) {
+ unsigned long ixtext = 0;
+ unsigned long lentext = 0;
+ unsigned char ch = 0;
+ unsigned char inbuf[3], outbuf[4];
+ short i = 0, ixinbuf = 0;
+ BOOL flignore = NO;
+ BOOL flendtext = NO;
+ NSData *base64Data = nil;
+ const unsigned char *base64Bytes = nil;
+
+ // Convert the string to ASCII data.
+ base64Data = [string dataUsingEncoding:NSASCIIStringEncoding];
+ base64Bytes = [base64Data bytes];
+ mutableData = [NSMutableData dataWithCapacity:[base64Data length]];
+ lentext = [base64Data length];
+
+ while( YES ) {
+ if( ixtext >= lentext ) break;
+ ch = base64Bytes[ixtext++];
+ flignore = NO;
+
+ if( ( ch >= 'A' ) && ( ch <= 'Z' ) ) ch = ch - 'A';
+ else if( ( ch >= 'a' ) && ( ch <= 'z' ) ) ch = ch - 'a' + 26;
+ else if( ( ch >= '0' ) && ( ch <= '9' ) ) ch = ch - '0' + 52;
+ else if( ch == '+' ) ch = 62;
+ else if( ch == '=' ) flendtext = YES;
+ else if( ch == '/' ) ch = 63;
+ else flignore = YES;
+
+ if( ! flignore ) {
+ short ctcharsinbuf = 3;
+ BOOL flbreak = NO;
+
+ if( flendtext ) {
+ if( ! ixinbuf ) break;
+ if( ( ixinbuf == 1 ) || ( ixinbuf == 2 ) ) ctcharsinbuf = 1;
+ else ctcharsinbuf = 2;
+ ixinbuf = 3;
+ flbreak = YES;
+ }
+
+ inbuf [ixinbuf++] = ch;
+
+ if( ixinbuf == 4 ) {
+ ixinbuf = 0;
+ outbuf [0] = ( inbuf[0] << 2 ) | ( ( inbuf[1] & 0x30) >> 4 );
+ outbuf [1] = ( ( inbuf[1] & 0x0F ) << 4 ) | ( ( inbuf[2] & 0x3C ) >> 2 );
+ outbuf [2] = ( ( inbuf[2] & 0x03 ) << 6 ) | ( inbuf[3] & 0x3F );
+
+ for( i = 0; i < ctcharsinbuf; i++ )
+ [mutableData appendBytes:&outbuf[i] length:1];
+ }
+
+ if( flbreak ) break;
+ }
+ }
+ }
+
+ self = [self initWithData:mutableData];
+ return self;
+}
+
+- (NSString *) base64EncodingWithLineLength:(unsigned int) lineLength {
+ const unsigned char *bytes = [self bytes];
+ NSMutableString *result = [NSMutableString stringWithCapacity:[self length]];
+ unsigned long ixtext = 0;
+ unsigned long lentext = [self length];
+ long ctremaining = 0;
+ unsigned char inbuf[3], outbuf[4];
+ short i = 0;
+ short charsonline = 0, ctcopy = 0;
+ unsigned long ix = 0;
+
+ while( YES ) {
+ ctremaining = lentext - ixtext;
+ if( ctremaining <= 0 ) break;
+
+ for( i = 0; i < 3; i++ ) {
+ ix = ixtext + i;
+ if( ix < lentext ) inbuf[i] = bytes[ix];
+ else inbuf [i] = 0;
+ }
+
+ outbuf [0] = (inbuf [0] & 0xFC) >> 2;
+ outbuf [1] = ((inbuf [0] & 0x03) << 4) | ((inbuf [1] & 0xF0) >> 4);
+ outbuf [2] = ((inbuf [1] & 0x0F) << 2) | ((inbuf [2] & 0xC0) >> 6);
+ outbuf [3] = inbuf [2] & 0x3F;
+ ctcopy = 4;
+
+ switch( ctremaining ) {
+ case 1:
+ ctcopy = 2;
+ break;
+ case 2:
+ ctcopy = 3;
+ break;
+ }
+
+ for( i = 0; i < ctcopy; i++ )
+ [result appendFormat:@"%c", encodingTable[outbuf[i]]];
+
+ for( i = ctcopy; i < 4; i++ )
+ [result appendFormat:@"%c",'='];
+
+ ixtext += 3;
+ charsonline += 4;
+
+ if( lineLength > 0 ) {
+ if (charsonline >= lineLength) {
+ charsonline = 0;
+ [result appendString:@"\n"];
+ }
+ }
+ }
+
+ return result;
+}
+
@end
@@ -1,15 +0,0 @@
-//---------------------------------------------------------------------------------------
-// $Id: NSNotificationCenter+OCMAdditions.h 57 2010-07-19 06:14:27Z erik $
-// Copyright (c) 2009 by Mulle Kybernetik. See License file for details.
-//---------------------------------------------------------------------------------------
-
-#import <Foundation/Foundation.h>
-
-@class OCMockObserver;
-
-
-@interface NSNotificationCenter(OCMAdditions)
-
-- (void)addMockObserver:(OCMockObserver *)notificationObserver name:(NSString *)notificationName object:(id)notificationSender;
-
-@end
@@ -1,33 +0,0 @@
-//---------------------------------------------------------------------------------------
-// $Id: OCMArg.h 65 2010-07-28 01:49:42Z erik $
-// Copyright (c) 2009-2010 by Mulle Kybernetik. See License file for details.
-//---------------------------------------------------------------------------------------
-
-#import <Foundation/Foundation.h>
-
-@interface OCMArg : NSObject
-
-// constraining arguments
-
-+ (id)any;
-+ (void *)anyPointer;
-+ (id)isNil;
-+ (id)isNotNil;
-+ (id)isNotEqual:(id)value;
-+ (id)checkWithSelector:(SEL)selector onObject:(id)anObject;
-#if NS_BLOCKS_AVAILABLE
-+ (id)checkWithBlock:(BOOL (^)(id))block;
-#endif
-
-// manipulating arguments
-
-+ (id *)setTo:(id)value;
-
-// internal use only
-
-+ (id)resolveSpecialValues:(NSValue *)value;
-
-@end
-
-#define OCMOCK_ANY [OCMArg any]
-#define OCMOCK_VALUE(variable) [NSValue value:&variable withObjCType:@encode(__typeof__(variable))]
@@ -1,64 +0,0 @@
-//---------------------------------------------------------------------------------------
-// $Id: OCMConstraint.h 57 2010-07-19 06:14:27Z erik $
-// Copyright (c) 2007-2010 by Mulle Kybernetik. See License file for details.
-//---------------------------------------------------------------------------------------
-
-#import <Foundation/Foundation.h>
-
-
-@interface OCMConstraint : NSObject
-
-+ (id)constraint;
-- (BOOL)evaluate:(id)value;
-
-// if you are looking for any, isNil, etc, they have moved to OCMArg
-
-// try to use [OCMArg checkWith...] instead of the constraintWith... methods below
-
-+ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject;
-+ (id)constraintWithSelector:(SEL)aSelector onObject:(id)anObject withValue:(id)aValue;
-
-
-@end
-
-@interface OCMAnyConstraint : OCMConstraint
-@end
-
-@interface OCMIsNilConstraint : OCMConstraint
-@end
-
-@interface OCMIsNotNilConstraint : OCMConstraint
-@end
-
-@interface OCMIsNotEqualConstraint : OCMConstraint
-{
- @public
- id testValue;
-}
-
-@end
-
-@interface OCMInvocationConstraint : OCMConstraint
-{
- @public
- NSInvocation *invocation;
-}
-
-@end
-
-#if NS_BLOCKS_AVAILABLE
-
-@interface OCMBlockConstraint : OCMConstraint
-{
- BOOL (^block)(id);
-}
-
-- (id)initWithConstraintBlock:(BOOL (^)(id))block;
-
-@end
-
-#endif
-
-
-#define CONSTRAINT(aSelector) [OCMConstraint constraintWithSelector:aSelector onObject:self]
-#define CONSTRAINTV(aSelector, aValue) [OCMConstraint constraintWithSelector:aSelector onObject:self withValue:(aValue)]
@@ -1,10 +0,0 @@
-//---------------------------------------------------------------------------------------
-// $Id: OCMock.h 39 2009-04-09 05:31:28Z erik $
-// Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details.
-//---------------------------------------------------------------------------------------
-
-#import <OCMock/OCMockObject.h>
-#import <OCMock/OCMockRecorder.h>
-#import <OCMock/OCMConstraint.h>
-#import <OCMock/OCMArg.h>
-#import <OCMock/NSNotificationCenter+OCMAdditions.h>
@@ -1,43 +0,0 @@
-//---------------------------------------------------------------------------------------
-// $Id: OCMockObject.h 69 2010-08-20 16:05:58Z erik $
-// Copyright (c) 2004-2008 by Mulle Kybernetik. See License file for details.
-//---------------------------------------------------------------------------------------
-
-#import <Foundation/Foundation.h>
-
-@interface OCMockObject : NSProxy
-{
- BOOL isNice;
- BOOL expectationOrderMatters;
- NSMutableArray *recorders;
- NSMutableArray *expectations;
- NSMutableArray *rejections;
- NSMutableArray *exceptions;
-}
-
-+ (id)mockForClass:(Class)aClass;
-+ (id)mockForProtocol:(Protocol *)aProtocol;
-+ (id)partialMockForObject:(NSObject *)anObject;
-
-+ (id)niceMockForClass:(Class)aClass;
-+ (id)niceMockForProtocol:(Protocol *)aProtocol;
-
-+ (id)observerMock;
-
-- (id)init;
-
-- (void)setExpectationOrderMatters:(BOOL)flag;
-
-- (id)stub;
-- (id)expect;
-- (id)reject;
-
-- (void)verify;
-
-// internal use only
-
-- (id)getNewRecorder;
-- (BOOL)handleInvocation:(NSInvocation *)anInvocation;
-- (void)handleUnRecordedInvocation:(NSInvocation *)anInvocation;
-
-@end
Oops, something went wrong.

0 comments on commit de85a40

Please sign in to comment.