« They do share a first name | Main | (Badass-mother-turtle) Feng shui »

Loading files from the project directory

If you're (say) working on an xml parser and you want to load some test files from the project directory and perhaps you're using otest and the senTesting framework...

Set-up your tests in the normal way. (Apple has a pdf that tells you how to do this.)
Set the executable's path to that of your project. In my case the executable is "otest" because I'm testing a framework. (Note: The default path for the executable is the build directory, so I guess you could use ../xml/ if you need the path to be the build dir.)
In your test code (let's pretend my xml files are in a subdirectory of my project called xml), you can do something like this in your test code:


NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:\
[@"./xml/2006-08-28 14;14;17.xml" stringByStandardizingPath]];

Since -[NSString stringByStandardizingPath] knows that "./" means "this here directory, yo" it will expand the path for you. This makes your test code all kinds of happily portable for when you release source to the rest of th e world. <--- I'll be choosing a (GPL or LGPL) license and doing that sometime this week for those of you who want to use my super awesome nike+ ipod cocoa objective-c objc xml parser (The previous string is for Googlebot... chew on *that*)

TrackBack

TrackBack URL for this entry:
http://www.jonathansaggau.com/blog/mt-tb.cgi/65

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)