How to get $ (ProjectDir) path in Visual C ++ Unit Testing using CppUnitTestFramework?
1 answer
Ok, this is how I did it:
-
In my project Properties -> Configuration -> C / C ++ -> Preprocessor I added this preprocessor definition
UNITTESTPRJ="$(ProjectDir)."
-
Then in my cpp file I did:
#define STRINGIFY(x) #x
#define EXPAND(x) STRINGIFY(x)
string s = EXPAND(UNITTESTPRJ);
s.erase(0, 1); // erase the first quote
s.erase(s.size() - 2); // erase the last quote and the dot
string my_project_dir = s;
Silly .
at the end was necessary to avoid ending up \"
in the project directory.
+5
source to share