summaryrefslogtreecommitdiff
path: root/test/fixtures/main.cpp
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2015-01-22 12:24:00 +0100
committerKonstantin Käfer <mail@kkaefer.com>2015-02-04 10:49:06 +0100
commitaa09aa321b24981bf0f8f2dec97ac100727266a5 (patch)
tree9291597f54e8d86357a285f9ffd426ff435f9387 /test/fixtures/main.cpp
parent8a1fce547e9ad0bf750418c844c9b23a3ee6d8dd (diff)
downloadqtlocation-mapboxgl-aa09aa321b24981bf0f8f2dec97ac100727266a5.tar.gz
rearrange tests and make more robust
Diffstat (limited to 'test/fixtures/main.cpp')
-rw-r--r--test/fixtures/main.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/fixtures/main.cpp b/test/fixtures/main.cpp
new file mode 100644
index 0000000000..303a0b9ab5
--- /dev/null
+++ b/test/fixtures/main.cpp
@@ -0,0 +1,33 @@
+#include "util.hpp"
+
+#include <libgen.h>
+
+std::string baseDirectory;
+
+namespace mbgl {
+namespace test {
+
+const std::string &getBaseDirectory() {
+ return baseDirectory;
+}
+
+}
+}
+
+GTEST_API_ int main(int argc, char *argv[]) {
+ // Note: glibc's dirname() **modifies** the argument and can't handle static strings.
+ std::string file { __FILE__ };
+ file = dirname(const_cast<char *>(file.c_str()));
+ if (file[0] == '/') {
+ // If __FILE__ is an absolute path, we don't have to guess from the argv 0.
+ baseDirectory = file + "/..";
+ } else {
+ std::string argv0 { argv[0] }; argv0 = dirname(const_cast<char *>(argv0.c_str()));
+ baseDirectory = argv0 + "/" + file + "/..";
+ }
+
+ fprintf(stderr, "basedir: %s\n", mbgl::test::getBaseDirectory().c_str());
+
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}