Frank: Is it possible to write step definitions in Objective-C - iphone

How could I write step definitions in Objective-C? E.g.:
Given(#"^the address book is empty$", ^{
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(addressBook);
for (int i = 0; i < CFArrayGetCount(people); i++) {
ABAddressBookRemoveRecord(addressBook,
CFArrayGetValueAtIndex(people, i), NULL);
}
});
The example above was derived from Rob Holland's blog post "BDD on iPhone: iCuke".
Why would I want to do such a thing? Because, as much as I love Ruby, I prefer to develop iOS apps in Objective-C and to write tests in the same language as that of the app I'm testing. Also, this would allow me to do low-level things, like erasing the address book or editing other data with Core Data.
Can I name the features directory Features with a capital "F"?

I responded to Matt's question on the Frank mailing list here

I agree; test your Objective-C applications in Objective-C. Personally, I use Cedar for this and would do it soup-to-nuts in Objective-C (no cuke), but I realize that might not be a very helpful answer. Not to hijack your thread, but did you find Frank to be any easier than Cedar to set up?

To attempt to answer your second question:
By default I think Cucumber looks for a 'features' directory. I don't know if it is case sensitive, but the fact that your asking means it probably is. You can specify the directory when you run Cucumber.
eg. a cucumber target in my Rakefile with non-standard location
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = ["--format pretty", "FunctionalTests/Frank"]
end

Related

reading file from Lua in cocos2d-x

I am working on a cocos2d-x project in Lua. I have a problem with syntax openien file, when I invoke:
cocos2d.CCFileData:new("file.txt", "w"+)
I always get error:
Cocos2d: ...80-C048-4F64-BC52-4849C0AD02F5/Main.lua:30: attempt to index field 'CCFileData' (a nil value)
What am I doing wrong? i cannot get any doc info. I am doing this on iOS.
1) Are you sure the call must be prefixed with "cocos2d"? Without knowing cocos2d-x but according to the error message maybe this is the correct call?
CCFileData:new("file.txt", "w+")
2) The "w"+ is certainly incorrect. It needs to be "w+" all in quotes:
cocos2d.CCFileData:new("file.txt", "w+")
Well the CCFileData is just not implemented yet in Cocos2d-x. I have managed this by using io.open lua funcion. It helped to have Lua file routines.
Use this type of call:
xmlFilePath = CCFileUtils::fullPathFromRelativePath("NameOfFile.xml");
I just spent a decent 30 minutes looking for a working version of this. The Cocos2d author, in January, recommends using a different file which I have yet to get working, but I just tested this and I am successfully reading an XML file finally. Thought I'd share this method, since iOS usually uses
[[NSBundle mainBundle] pathForResource:#"" ofType:#""];
styles to get the paths. We have to do similar, and that's the cocos2d-x method of doing it.

how to provide name-space to use xpath query in objective-c

i am trying to use xpath-query in my app for xml parsing. my work is almost completed upto name space concept came into picture.i am always writing query correctly but its returning me the 0 objects in my array.i tried many blogs and also many posts in our stackoverflow.com but none of them not working..i hope my problem need small modification can any one modify my code.my code
Thanks All.
I think many people try to show my question is duplicate but it is different bec none of the questions not worked for my problem.please provide me your suggestion.your answer more help full for my work.
I take it you're using libxml along with Matt Gallagher's Cocoa wrappers for it? (It's helpful to put which third party libraries you're using in your question.)
When I did this, I modified Matt's code so that PerformXPathQuery took an additional argument, an NSDictionary of namespaces. (The other functions such as PerformXMLXPathQuery also took this argument, and pass through the object.)
Then, in PerformXPathQuery, after creating the context, I registered the namespaces thus:
if (namespaces != nil)
{
for (NSString *key in namespaces)
{
xmlXPathRegisterNs(xpathCtx, (const xmlChar *)[key UTF8String], (const xmlChar *)[[namespaces objectForKey:key] UTF8String]);
}
}

What is scala.mobile supposed to accomplish?

...and why has the package this misleading name (I assumed it had something to do with JavaME or mobile/smart phones)?
I found no references on the internet about scala.mobile.Code or scala.mobile.Location at all nor did I manage to do anything with those classes except getting ClassCastExcetions or NoSuchMethodErrors.
Actually there is not even a single test against scala.mobile in the Scala's test tree which could help understanding that code.
The classes really smell like they were forgotten in the source tree a long time ago and got accidentally released since that.
Maybe I just missed something about them?
Update:
scala.mobile was removed in Scala 2.9.
I just checked the source code.
When Scala changed the name mangling of class files a few years ago and it seems people forgot to update these classes accordingly.
So my answer would be:
At least Location has no purpose, because it is not possible to get anything sensible out of it (except exceptions) and Code without Location is severely limited. It works though if you pass the class literal to Code directly:
import scala.mobile._
val c = new Code(classOf[scala.collection.mutable.StringBuilder])
c.apply[StringBuilder, String]("append")("Foo")
c.apply[String]("toString")() // returns "Foo"
c.apply[Int]("length")() // returns 3
Looks like yet-another implementation in the standard library of reflection-slightly-nicer.
The description of Location pretty much explains what that is about:
The class Location provides a create method to instantiate objects
from a network location by specifying the URL address of the jar/class file.
It might be used by remote actors. Maybe.
As for why it has this misleading name? Well, back in 2004 smart phones had really low penetration, so maybe the association wasn't all that strong.

Detecting the use of private APIs

I'm being rejected on the App Store for using private instance variables in my app. The ivars I am supposedly using are most definitely not being accessed in my code, but I am using one or two static libs from third parties. How would I test whether these could actually be the offenders?
Update:
Apple is accusing me (and 3rd party libs) of using private instance variables in the UITouch class, including
_locationInWindow
_tapCount
_previousLocationInWindow
_timestamp
_touchFlags
_phase
_window
I don't know anything about detecting the problem, but we encountered this problem recently; in our case it was caused by the Three20 library. If you are using it, see http://groups.google.com/group/three20/browse_thread/thread/c442af6e39a918b0/2375e7a158ee9d1b for a discussion/possible solutions.
You can use nm to scan for which library uses the ivar in question.
% nm static_lib.a | grep name_of_ivar
If you get a line, I think with a capital U, with the name of the ivar you probably have a suspect.
I am using one or two static libs
from third parties
Contact the third parties, requesting explanation, they wrote the code, they must know what's in there. They might have a forum or a comments section, where other users might have expressed these concerns already, and you can look for answers and alternatives.
For those who have many third-party libraries, can check your project in such a manner in your project path, for example if you want to find GraphicsService:
$ find . |grep "\\.a" | xargs grep GraphicsService

Getting started reverse-engineering OS X?

What is a good place to learn reverse engineering, specifically as it applies to Mac OS X? Two apps that I admire in terms of this subject:
Hyperspaces – Link
and
Orbit – http://www.steventroughtonsmith.com/orbit/
Thanks guys.
You should grab a copy of Mac OS X Internals which is an awesome book about everything that Apple does not tell you. Not only is this great if you are interested in reverse engineering, it will also make you a better OS X programmer in general.
Use class-dump-x/-z to get the private Objective-C headers for OS X/iPhone OS system frameworks. There are a lot of classes/methods hidden from the public (some rightly so)
Apple releases a ton of the foundation of OS X as open source. See here.
In addition, F-Script Anywhere will help a ton with dissecting the Finder and/or any other closed source application.
For iPhoneOS specifically, class-dump-z is a great way to dump headers. The only problem, of course, is that you can't actually see what is going on inside of each method. IDA Pro and a few scripts make it possible to see the assembly instructions for these system frameworks. (example picture: http://grab.by/1Vn6).
The most handy IDC scripts are fixobjc2 and dyldinfo. You can find each of these linked from this blog post: http://networkpx.blogspot.com/2010/01/two-ida-pro-5x-scripts-for-iphoneos.html
But, what good is this information if you can't use it? iPhone developer saurik has written something called MobileSubstrate that enables hooking onto any method. http://svn.saurik.com/repos/menes/trunk/mobilesubstrate/
Others have already mentioned class-dump, which is an excellent tool for retrieving the class definitions from a compiled executable. On a related note, you should also take a look at otx, which is provides very nice (readable), disassembled output.
If you need a way to quickly test snippets of code, use F-Script (mentioned by others), Nu or MacRuby. Of these, I've mainly used Nu. It has the capability to define bridged functions on the fly, and can handle pointers, both of which are pretty handy if you need to call arbitrary C functions.
Since you mentioned being interesting in Spaces and other screen managers, you should also read A brief tutorial on reverse engineering OS X. It's an old article by Rich Wareham (author of the pre-Spaces multi-desktop app: 'Desktop Manager') on how he figured out the call syntax for few private CoreGraphics methods in order to do nice desktop transitions. The source code for Desktop Manager is also available, which might be useful to you.
This site shows how to patch an existing Objective C program: http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering
Namely posing:
[[B class] poseAsClass:[A class]];
and method swizzling:
/**
* Renames the selector for a given method.
* Searches for a method with _oldSelector and reassigned _newSelector to that
* implementation.
* #return NO on an error and the methods were not swizzled
*/
BOOL DTRenameSelector(Class _class, SEL _oldSelector, SEL _newSelector)
{
Method method = nil;
// First, look for the methods
method = class_getInstanceMethod(_class, _oldSelector);
if (method == nil)
return NO;
method->method_name = _newSelector;
return YES;
}
// *** Example ***
// never implemented, just here to silence a compiler warning
#interface WebInternalImage (PHWebInternalImageSwizzle)
- (void) _webkit_scheduleFrame;
#end
#implementation WebInternalImage (PHWebInternalImage)
+ (void) initialize
{
DTRenameSelector([self class], #selector(scheduleFrame), #selector (_webkit_scheduleFrame));
DTRenameSelector([self class], #selector(_ph_scheduleFrame), #selector(scheduleFrame));
}
- (void) _ph_scheduleFrame
{
// do something crazy...
...
// call the "super" method - this method doesn't exist until runtime
[self _webkit_scheduleFrame];
}
#end
(code copied from http://www.culater.net/wiki/moin.cgi/CocoaReverseEngineering)
As an addition to the other answers, you are going to want to check out DYLD_INSERT_LIBRARIES to inject your code into a Cocoa program.
You should definitely consider using DTrace. There is an excellent BlackHat presentation on using DTrace for reverse engineering on OS X entitled, "DTRACE: The Reverse Engineer's Unexpected Swiss Army Knife".
You can get a copy and view the video presentation here.
There are also some excellent papers at www.uninformed.org on reverse engineering OS X.