11be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Copyright 2008, Google Inc. 21be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// All rights reserved. 31be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 41be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Redistribution and use in source and binary forms, with or without 51be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// modification, are permitted provided that the following conditions are 61be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// met: 71be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 81be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Redistributions of source code must retain the above copyright 91be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// notice, this list of conditions and the following disclaimer. 101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Redistributions in binary form must reproduce the above 111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// copyright notice, this list of conditions and the following disclaimer 121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// in the documentation and/or other materials provided with the 131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// distribution. 141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// * Neither the name of Google Inc. nor the names of its 151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// contributors may be used to endorse or promote products derived from 161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// this software without specific prior written permission. 171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 281be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// 301be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// Author: wan@google.com (Zhanyong Wan) 311be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 321be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// A helper program for testing that Google Test parses the environment 331be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// variables correctly. 341be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 3541d0579e8de9ef4ff178fc4991043c61a19943f7Brett Chabot#include "gtest/gtest.h" 361be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 371be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#include <iostream> 381be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 391be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#define GTEST_IMPLEMENTATION_ 1 401be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#include "src/gtest-internal-inl.h" 411be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania#undef GTEST_IMPLEMENTATION_ 421be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 431be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniausing ::std::cout; 441be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 451be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catanianamespace testing { 461be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 471be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// The purpose of this is to make the test more realistic by ensuring 481be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// that the UnitTest singleton is created before main() is entered. 491be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania// We don't actual run the TEST itself. 501be2c9def7187e4e643c00a31dd9986395795d7dNicolas CataniaTEST(GTestEnvVarTest, Dummy) { 511be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 521be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 531be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniavoid PrintFlag(const char* flag) { 541be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "break_on_failure") == 0) { 551be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(break_on_failure); 561be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 571be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 581be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 591be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "catch_exceptions") == 0) { 601be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(catch_exceptions); 611be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 621be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 631be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 641be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "color") == 0) { 651be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(color); 661be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 671be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 681be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 691be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "death_test_style") == 0) { 701be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(death_test_style); 711be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 721be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 731be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 741be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "death_test_use_fork") == 0) { 751be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(death_test_use_fork); 761be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 771be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 781be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 791be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "filter") == 0) { 801be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(filter); 811be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 821be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 831be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 841be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "output") == 0) { 851be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(output); 861be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 871be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 881be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 891be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "print_time") == 0) { 901be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(print_time); 911be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 921be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 931be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 941be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "repeat") == 0) { 951be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(repeat); 961be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 971be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 981be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 991be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "stack_trace_depth") == 0) { 1001be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(stack_trace_depth); 1011be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 1021be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 1031be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1041be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (strcmp(flag, "throw_on_failure") == 0) { 1051be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << GTEST_FLAG(throw_on_failure); 1061be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return; 1071be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 1081be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1091be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << "Invalid flag name " << flag 1101be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania << ". Valid names are break_on_failure, color, filter, etc.\n"; 1111be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania exit(1); 1121be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 1131be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1141be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} // namespace testing 1151be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1161be2c9def7187e4e643c00a31dd9986395795d7dNicolas Cataniaint main(int argc, char** argv) { 1171be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania testing::InitGoogleTest(&argc, argv); 1181be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1191be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania if (argc != 2) { 1201be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania cout << "Usage: gtest_env_var_test_ NAME_OF_FLAG\n"; 1211be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return 1; 1221be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania } 1231be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania 1241be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania testing::PrintFlag(argv[1]); 1251be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania return 0; 1261be2c9def7187e4e643c00a31dd9986395795d7dNicolas Catania} 127