gtest_main.cpp revision b1a885b014540a2f7798b5a35ea0f0ec150d93ee
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include <gtest/gtest.h> 18 19#include <android-base/logging.h> 20 21#include "get_test_data.h" 22#include "utils.h" 23 24static std::string testdata_dir; 25 26int main(int argc, char** argv) { 27 InitLogging(argv, android::base::StderrLogger); 28 testing::InitGoogleTest(&argc, argv); 29 for (int i = 1; i < argc; ++i) { 30 if (strcmp(argv[i], "-t") == 0 && i + 1 < argc) { 31 testdata_dir = argv[i + 1]; 32 break; 33 } 34 } 35 if (testdata_dir.empty()) { 36 printf("Usage: simpleperf_unit_test -t <testdata_dir>\n"); 37 return 1; 38 } 39 if (testdata_dir.back() != '/') { 40 testdata_dir.push_back('/'); 41 } 42 return RUN_ALL_TESTS(); 43} 44 45std::string GetTestData(const std::string& filename) { 46 return testdata_dir + filename; 47} 48 49const std::string& GetTestDataDir() { 50 return testdata_dir; 51} 52