Know your mascots?


I got 17 out of twenty on the AOL Mascot quiz. I cussed when I missed two of the three that I got wrong, Ernie and the pink Bunny. Does Ernie have a tie? Does the Energizer bunny wear flip flops? Just plain over thought my answers both times. Go with your initial instinct and you could get them all correct. A couple of other tough ones are the Lacoste gator and the Travelocity elf. Lots of fun.

I can’t make an HTTP call from an iPhone unit test!


I know I’m not supposed to do this in a unit test but as a learning test how would one go about making an NSURLConnection in a GTMSenTestCase? According to all the docs I’ve read for an NSURLConnection to work correctly the calling thread’s run loop must be operating in default mode. Does that mean I’ll have to setup my own RunLoop to get things working correctly? I thought I read somewhere that GTMSenTestCases don’t execute on a runloop and that their runloop needs to be manually set. Help?

OCMock Return a struct


Why do I always seem to be the one person with these difficult problems? First, it was like murder to run OCMock under the iPhone SDK. Frameworks, dependencies, debugging, chaos! Then it was the whole tests fail but the build passes thing. I seriously believe I must the only person on the planet who’s trying to do REAL agile development on an iPhone project. Getting to the point, if you ever try using OCMock and you’ve run into the issue with struct return values then the following is for you.

The other day I find myself trying to mock some stuff around CoreLocation and I hit a snag! I can’t return a CLLocationCoordinate2D type from a mock! Try it yourself and you’ll see what I mean. I tried using the OCMOCK_VALUE macro to no avail. I posted on various forums for help and received no valuable replies. The true answer is a slight variation of another similar blog post. Rather than go into an in depth explanation I’ll post my fix here. I put the following in the header/impl of a SenTestCase subclass and all is good for any object that subclasses my subclass.

@interface OCMockRecorder (ExtraMethods)
- (id) andReturnBoolean:(BOOL)aValue;
- (id) andReturnStruct:(void*)aValue objCType:(const char *)type;
@end

@implementation OCMockRecorder (ExtraMethods)

- (id) andReturnBoolean:(BOOL)aValue {
    NSValue *wrappedValue = nil;
    wrappedValue = [NSValue valueWithBytes:&aValue
                                  objCType:@encode(BOOL)];
	
    return [self andReturnValue:wrappedValue];
}

- (id) andReturnStruct:(void*)aValue objCType:(const char *)type{
    NSValue *wrappedValue = nil;
    wrappedValue = [NSValue valueWithBytes:aValue
                                  objCType:type];
	
    return [self andReturnValue:wrappedValue];
}

@end