|
| 1 | +// Cppcheck - A tool for static C/C++ code analysis |
| 2 | +// Copyright (C) 2007-2010 Daniel Marjamäki and Cppcheck team. |
| 3 | +// |
| 4 | +// This program is free software: you can redistribute it and/or modify |
| 5 | +// it under the terms of the GNU General Public License as published by |
| 6 | +// the Free Software Foundation, either version 3 of the License, or |
| 7 | +// (at your option) any later version. |
| 8 | +// |
| 9 | +// This program is distributed in the hope that it will be useful, |
| 10 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +// GNU General Public License for more details. |
| 13 | +// |
| 14 | +// You should have received a copy of the GNU General Public License |
| 15 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + |
| 17 | +#include "options.h" |
| 18 | +#include "testsuite.h" |
| 19 | +#include <sstream> |
| 20 | + |
| 21 | +extern std::ostringstream errout; |
| 22 | + |
| 23 | +class TestOptions: public TestFixture |
| 24 | +{ |
| 25 | +public: |
| 26 | + TestOptions() |
| 27 | + :TestFixture("TestOptions") |
| 28 | + { |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | +private: |
| 33 | + void run() |
| 34 | + { |
| 35 | + TEST_CASE(which_test); |
| 36 | + TEST_CASE(which_test_method); |
| 37 | + TEST_CASE(not_quiet); |
| 38 | + TEST_CASE(quiet); |
| 39 | + TEST_CASE(gcc_errors); |
| 40 | + TEST_CASE(multiple_testcases); |
| 41 | + TEST_CASE(invalid_switches); |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + void which_test() |
| 46 | + { |
| 47 | + const char* argv[] = {"./test_runner", "TestClass"}; |
| 48 | + options args(sizeof argv / sizeof argv[0], argv); |
| 49 | + ASSERT_EQUALS("TestClass", args.which_test()); |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + void which_test_method() |
| 54 | + { |
| 55 | + const char* argv[] = {"./test_runner", "TestClass::TestMethod"}; |
| 56 | + options args(sizeof argv / sizeof argv[0], argv); |
| 57 | + ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + void not_quiet() |
| 62 | + { |
| 63 | + const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-v"}; |
| 64 | + options args(sizeof argv / sizeof argv[0], argv); |
| 65 | + ASSERT_EQUALS(false, args.quiet()); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + void quiet() |
| 70 | + { |
| 71 | + const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-q"}; |
| 72 | + options args(sizeof argv / sizeof argv[0], argv); |
| 73 | + ASSERT_EQUALS(true, args.quiet()); |
| 74 | + } |
| 75 | + |
| 76 | + |
| 77 | + void gcc_errors() |
| 78 | + { |
| 79 | + const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-g"}; |
| 80 | + options args(sizeof argv / sizeof argv[0], argv); |
| 81 | + ASSERT_EQUALS(true, args.gcc_style_errors()); |
| 82 | + } |
| 83 | + |
| 84 | + |
| 85 | + void multiple_testcases() |
| 86 | + { |
| 87 | + const char* argv[] = {"./test_runner", "TestClass::TestMethod", "Ignore::ThisOne"}; |
| 88 | + options args(sizeof argv / sizeof argv[0], argv); |
| 89 | + ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); |
| 90 | + } |
| 91 | + |
| 92 | + |
| 93 | + void invalid_switches() |
| 94 | + { |
| 95 | + const char* argv[] = {"./test_runner", "TestClass::TestMethod", "-a", "-v", "-q", "-g"}; |
| 96 | + options args(sizeof argv / sizeof argv[0], argv); |
| 97 | + ASSERT_EQUALS("TestClass::TestMethod", args.which_test()); |
| 98 | + ASSERT_EQUALS(true, args.gcc_style_errors()); |
| 99 | + ASSERT_EQUALS(true, args.quiet()); |
| 100 | + } |
| 101 | +}; |
| 102 | + |
| 103 | +REGISTER_TEST(TestOptions) |
0 commit comments