简体   繁体   中英

Unable to read plist files from a command line target using XCode

I'm working on a iOS mobile game using cocos2d-x 3.10 and cocos studio on Mac.

I'm using Catch as a unit test framework. In order to use Catch I've added a new target to the original XCode project. In this target I've created my "testXXX.cpp" files which contains the code of the unit tests that I want to run.

I'm having some troubles in one of my unit tests. I'm trying to test a method. Inside this method I'm using cocos2d FileUtils to reach two .plist files that configure some behaviour in the game. Here is the code that I'm using:

std::string fullPathLevels = cocos2d::FileUtils::getInstance()->fullPathForFilename(OIR_CONFIG_LEVELS);
std::string fullPathRhythmTable = cocos2d::FileUtils::getInstance()->fullPathForFilename(OIR_CONFIG_RHYTHMS);

this->Levels = cocos2d::FileUtils::getInstance()->getValueMapFromFile(fullPathLevels);
this->rhythmTable = cocos2d::FileUtils::getInstance()->getValueMapFromFile(fullPathRhythmTable);

It works fine when I build the code aiming mobile or desktop target BUT when I change to the "command line" target that I've created to test using Catch then the plist files can't be found.

I've already added the plist files to the target membership and they appear on the "Copy Bundle Resources" section in Build Phases...

Well I've found that command-line applications doesn't support bundle model. I've found it here: https://developer.apple.com/library/content/documentation/CoreFoundation/Conceptual/CFBundles/AboutBundles/AboutBundles.html

Now I'm writing all my test cases using XCTest (default unit test framework for XCode).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM