NASA-Tensegrity-Robotics-Toolkit/NTRTsim — pull request #63 by PerryBhandal (2014-09-04 12:21:47+00:00)
Title: Resources folder

This PR resolves issue #60.

Usage
======
I've updated my 3_prism_serialize example to use a file loaded from the resources folder. Here are the relevant lines:

std::string configPath = FileHelpers::getResourcePath("3_prism_serialize/config.json");
bool parsingSuccessful = reader.parse( FileHelpers::getFileString(configPath), root );

In the first line we're using the getResourcePath helper. When we use that helper in src/, it will load resources from NTRTsim/resources/src/. If we use that helper in tests, it will load from NTRTsim/resources/test/.

The next line uses the getFileString helper to read config.json into a string.

Design
======
Making the resource folder work required using cmake's environment variables. I initially tried to have a single copy of FileHelpers in src that both test and src would use, but that proved difficult to implement cleanly. As a result, we now have a copy of FileHelpers in both src and test. If any changes are made to src/FileHelpers/FileHelpers.cpp/.h, they should be manually copied into test as well.

I wanted to avoid this approach as it's not the DRYest, but the only alternatives I could come up with were even less clean.

This also introduced one more issue: we no longer have tests for the copy of FileHelpers. This isn't a problem now as FileHelpers is very basic, but if FileHelpers becomes complex we may need to sort something out. You can find a revision where tests existed at the link below (this is useful if you need to see an example of how tests work in NTRT):

https://github.com/NASA-Tensegrity-Robotics-Toolkit/NTRTsim/tree/7c345aed9856c193fd5384964f1bb1b87d2f9fe7/test

Potential Problems
======
It's possible that tests against classes in src which use the src version of FileHelpers may have problems (tests of src/examples/3_prism_serialize, for example). I'm not certain yet, but I'm sure we'll find out shortly. If you experience any problems, please let me know.