|
| 1 | +/* |
| 2 | + * Cppcheck - A tool for static C/C++ code analysis |
| 3 | + * Copyright (C) 2007-2024 Cppcheck team. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | +#include "fixture.h" |
| 20 | +#include "standards.h" |
| 21 | + |
| 22 | +class TestStandards : public TestFixture { |
| 23 | +public: |
| 24 | + TestStandards() : TestFixture("TestStandards") {} |
| 25 | + |
| 26 | +private: |
| 27 | + void run() override { |
| 28 | + TEST_CASE(set); |
| 29 | + TEST_CASE(setAlias1); |
| 30 | + TEST_CASE(setAlias2); |
| 31 | + TEST_CASE(getC); |
| 32 | + TEST_CASE(getCPP); |
| 33 | + TEST_CASE(setStd); |
| 34 | + } |
| 35 | + |
| 36 | + void set() const { |
| 37 | + Standards stds; |
| 38 | + ASSERT_EQUALS_ENUM(Standards::CLatest, stds.c); |
| 39 | + ASSERT_EQUALS("", stds.stdValueC); |
| 40 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, stds.cpp); |
| 41 | + ASSERT_EQUALS("", stds.stdValueCPP); |
| 42 | + |
| 43 | + ASSERT_EQUALS(true, stds.setC("c99")); |
| 44 | + ASSERT_EQUALS_ENUM(Standards::C99, stds.c); |
| 45 | + ASSERT_EQUALS("c99", stds.stdValueC); |
| 46 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, stds.cpp); |
| 47 | + ASSERT_EQUALS("", stds.stdValueCPP); |
| 48 | + |
| 49 | + ASSERT_EQUALS(true, stds.setC("c11")); |
| 50 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 51 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 52 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, stds.cpp); |
| 53 | + ASSERT_EQUALS("", stds.stdValueCPP); |
| 54 | + |
| 55 | + ASSERT_EQUALS(true, stds.setCPP("c++11")); |
| 56 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 57 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 58 | + ASSERT_EQUALS_ENUM(Standards::CPP11, stds.cpp); |
| 59 | + ASSERT_EQUALS("c++11", stds.stdValueCPP); |
| 60 | + |
| 61 | + ASSERT_EQUALS(true, stds.setCPP("c++23")); |
| 62 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 63 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 64 | + ASSERT_EQUALS_ENUM(Standards::CPP23, stds.cpp); |
| 65 | + ASSERT_EQUALS("c++23", stds.stdValueCPP); |
| 66 | + |
| 67 | + ASSERT_EQUALS(false, stds.setC("c77")); |
| 68 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 69 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 70 | + ASSERT_EQUALS_ENUM(Standards::CPP23, stds.cpp); |
| 71 | + ASSERT_EQUALS("c++23", stds.stdValueCPP); |
| 72 | + |
| 73 | + ASSERT_EQUALS(false, stds.setCPP("c+77")); |
| 74 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 75 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 76 | + ASSERT_EQUALS_ENUM(Standards::CPP23, stds.cpp); |
| 77 | + ASSERT_EQUALS("c++23", stds.stdValueCPP); |
| 78 | + |
| 79 | + ASSERT_EQUALS(false, stds.setC("C23")); |
| 80 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 81 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 82 | + ASSERT_EQUALS_ENUM(Standards::CPP23, stds.cpp); |
| 83 | + ASSERT_EQUALS("c++23", stds.stdValueCPP); |
| 84 | + |
| 85 | + ASSERT_EQUALS(false, stds.setCPP("C++11")); |
| 86 | + ASSERT_EQUALS_ENUM(Standards::C11, stds.c); |
| 87 | + ASSERT_EQUALS("c11", stds.stdValueC); |
| 88 | + ASSERT_EQUALS_ENUM(Standards::CPP23, stds.cpp); |
| 89 | + ASSERT_EQUALS("c++23", stds.stdValueCPP); |
| 90 | + } |
| 91 | + |
| 92 | + void setAlias1() const { |
| 93 | + Standards stds; |
| 94 | + TODO_ASSERT_EQUALS(true, false, stds.setCPP("gnu++11")); |
| 95 | + ASSERT_EQUALS_ENUM(Standards::CLatest, stds.c); |
| 96 | + ASSERT_EQUALS("", stds.stdValueC); |
| 97 | + TODO_ASSERT_EQUALS_ENUM(Standards::CPP11, Standards::CPPLatest, stds.cpp); |
| 98 | + TODO_ASSERT_EQUALS("gnu++11", "", stds.stdValueCPP); |
| 99 | + } |
| 100 | + |
| 101 | + void setAlias2() const { |
| 102 | + Standards stds; |
| 103 | + TODO_ASSERT_EQUALS(true, false, stds.setC("gnu17")); |
| 104 | + TODO_ASSERT_EQUALS_ENUM(Standards::C17, Standards::CLatest, stds.c); |
| 105 | + TODO_ASSERT_EQUALS("gnu17", "", stds.stdValueC); |
| 106 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, stds.cpp); |
| 107 | + ASSERT_EQUALS("", stds.stdValueCPP); |
| 108 | + } |
| 109 | + |
| 110 | + void getC() const { |
| 111 | + ASSERT_EQUALS_ENUM(Standards::C99, Standards::getC("c99")); |
| 112 | + ASSERT_EQUALS_ENUM(Standards::C11, Standards::getC("c11")); |
| 113 | + TODO_ASSERT_EQUALS_ENUM(Standards::C17, Standards::CLatest, Standards::getC("gnu17")); |
| 114 | + TODO_ASSERT_EQUALS_ENUM(Standards::C11, Standards::CLatest, Standards::getC("iso9899:2011")); |
| 115 | + |
| 116 | + ASSERT_EQUALS_ENUM(Standards::CLatest, Standards::getC("")); |
| 117 | + ASSERT_EQUALS_ENUM(Standards::CLatest, Standards::getC("c77")); |
| 118 | + ASSERT_EQUALS_ENUM(Standards::CLatest, Standards::getC("C99")); |
| 119 | + } |
| 120 | + |
| 121 | + void getCPP() const { |
| 122 | + ASSERT_EQUALS_ENUM(Standards::CPP11, Standards::getCPP("c++11")); |
| 123 | + ASSERT_EQUALS_ENUM(Standards::CPP23, Standards::getCPP("c++23")); |
| 124 | + TODO_ASSERT_EQUALS_ENUM(Standards::CPP23, Standards::CPPLatest, Standards::getCPP("gnu++23")); |
| 125 | + |
| 126 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, Standards::getCPP("")); |
| 127 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, Standards::getCPP("c++77")); |
| 128 | + ASSERT_EQUALS_ENUM(Standards::CPPLatest, Standards::getCPP("C++11")); |
| 129 | + } |
| 130 | + |
| 131 | + void setStd() const { |
| 132 | + Standards stds; |
| 133 | + ASSERT(stds.setStd("c11")); |
| 134 | + ASSERT(stds.setStd("c++11")); |
| 135 | + TODO_ASSERT(stds.setStd("gnu11")); |
| 136 | + TODO_ASSERT(stds.setStd("gnu++17")); |
| 137 | + TODO_ASSERT(stds.setStd("iso9899:2011")); |
| 138 | + |
| 139 | + ASSERT(!stds.setStd("C++11")); |
| 140 | + ASSERT(!stds.setStd("Gnu++11")); |
| 141 | + } |
| 142 | +}; |
| 143 | + |
| 144 | +REGISTER_TEST(TestStandards) |
0 commit comments