Making it gtest compile for iphone/simulator wasn't anymore trouble some than compiling other libraries cross platform. Instead, the trouble came when trying to execute the compiled tests through the simulator.
At a previous occasion, I had tried (unsuccessfully) to build and execute my entire project with the help of my own build system (which is built upon waf). I just couldn't get the executable to start. Since then I found this link giving me the option to launch my executable explicitly:
<path to simulator> -SimulateApplication <path to my executable>
That works, but it launches the springboard and that means that the application won't quit like you'd expect: when you return from your main-function, the application will simply be respawned.
Instead, I looked into some other frameworks to see how they achieve this. Perhaps the most famous one is the Google Testing Framework. That package has a RunIPhoneTest.sh which contains some clues.
Another clue can be found in GH-Unit that contains a RunTests.sh which is less cluttered.
In the end, it was all very simple. Set the DYLD_ROOT_PATH to the simulator sdk choice.
This lets you run your executable from your command line in a straight forward manner.
Here's a quick example.
First, save your your code into test.cpp:
Compile this with:
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++ -arch i386 -m32 -Wall -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk test.cpp -o a.out -framework OpenGLES
I added the OpenGLES framework merely to demonstrate that this test works.
Save your environment settings into a bash script runsim.sh:
#!/bin/sh export DYLD_ROOT_PATH=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk #runs the executable $@ unset DYLD_ROOT_PATH
Make the script executable:
chmod +x runsim.sh
Now you should be able to run your executable with:
./runsim.sh a.out
And the expected output is:
./a.out
Inga kommentarer:
Skicka en kommentar