Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 4

CodeTiger/Cppcheck

Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (95)
Tags (95)
master
main
remove_tinyxml_use_stl_flag
fp-uninit
cleanup-threadsafety
gui-platform
11734
tokenizer-alignas
11013
typedef-function
11707
11443
11700
qml
check-level-doc
check-level
color
performance-valueflow
cleanup
valueflow-too-many-ifs
2.10.3
2.10.2
2.10.1
2.10
2.9.3
2.9.2
2.9.1
2.9
2.8.2
2.8.1
2.8
2.7.5
2.7.4
2.7.3
2.7.2
2.7.1
2.7
2.6.3
2.6.2
2.6.1
master
Branches (95)
Tags (95)
master
main
remove_tinyxml_use_stl_flag
fp-uninit
cleanup-threadsafety
gui-platform
11734
tokenizer-alignas
11013
typedef-function
11707
11443
11700
qml
check-level-doc
check-level
color
performance-valueflow
cleanup
valueflow-too-many-ifs
2.10.3
2.10.2
2.10.1
2.10
2.9.3
2.9.2
2.9.1
2.9
2.8.2
2.8.1
2.8
2.7.5
2.7.4
2.7.3
2.7.2
2.7.1
2.7
2.6.3
2.6.2
2.6.1
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (95)
Tags (95)
master
main
remove_tinyxml_use_stl_flag
fp-uninit
cleanup-threadsafety
gui-platform
11734
tokenizer-alignas
11013
typedef-function
11707
11443
11700
qml
check-level-doc
check-level
color
performance-valueflow
cleanup
valueflow-too-many-ifs
2.10.3
2.10.2
2.10.1
2.10
2.9.3
2.9.2
2.9.1
2.9
2.8.2
2.8.1
2.8
2.7.5
2.7.4
2.7.3
2.7.2
2.7.1
2.7
2.6.3
2.6.2
2.6.1
cppcheck
/
test
/
testplatform.cpp
cppcheck
/
test
/
testplatform.cpp
testplatform.cpp 14.95 KB
Copy Edit Raw Blame History
Daniel Marjamäki authored 2020年05月10日 17:16 +08:00 . Update copyright year
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
/*
* Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2020 Cppcheck team.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "platform.h"
#include "testsuite.h"
#include <tinyxml2.h>
class TestPlatform : public TestFixture {
public:
TestPlatform() : TestFixture("TestPlatform") { }
private:
void run() OVERRIDE {
TEST_CASE(empty);
TEST_CASE(valid_config_native_1);
TEST_CASE(valid_config_native_2);
TEST_CASE(valid_config_file_1);
TEST_CASE(valid_config_file_2);
TEST_CASE(valid_config_file_3);
TEST_CASE(valid_config_file_4);
TEST_CASE(invalid_config_file_1);
// TEST_CASE(empty_elements); // TODO: Trac issue #8409
}
static bool readPlatform(cppcheck::Platform& platform, const char* xmldata) {
tinyxml2::XMLDocument doc;
doc.Parse(xmldata);
return platform.loadFromXmlDocument(&doc);
}
void empty() const {
// An empty platform file does not change values, only the type.
const char xmldata[] = "<?xml version=\"1.0\"?>\n<platform/>";
cppcheck::Platform platform;
ASSERT(platform.platform(cppcheck::Platform::Win64));
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(cppcheck::Platform::PlatformFile, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS(8, platform.char_bit);
ASSERT_EQUALS('0円', platform.defaultSign);
ASSERT_EQUALS(1, platform.sizeof_bool);
ASSERT_EQUALS(2, platform.sizeof_short);
ASSERT_EQUALS(4, platform.sizeof_int);
ASSERT_EQUALS(4, platform.sizeof_long);
ASSERT_EQUALS(8, platform.sizeof_long_long);
}
void valid_config_native_1() {
// Verify if native Win32A platform is loaded correctly
cppcheck::Platform platform;
ASSERT(platform.platform(cppcheck::Platform::Win32A));
ASSERT_EQUALS(cppcheck::Platform::Win32A, platform.platformType);
ASSERT(platform.isWindowsPlatform());
ASSERT_EQUALS('0円', platform.defaultSign);
ASSERT_EQUALS(8, platform.char_bit);
ASSERT_EQUALS(1, platform.sizeof_bool);
ASSERT_EQUALS(2, platform.sizeof_short);
ASSERT_EQUALS(4, platform.sizeof_int);
ASSERT_EQUALS(4, platform.sizeof_long);
ASSERT_EQUALS(8, platform.sizeof_long_long);
ASSERT_EQUALS(16, platform.short_bit);
ASSERT_EQUALS(32, platform.int_bit);
ASSERT_EQUALS(32, platform.long_bit);
ASSERT_EQUALS(64, platform.long_long_bit);
}
void valid_config_native_2() {
// Verify if native Unix64 platform is loaded correctly
cppcheck::Platform platform;
ASSERT(platform.platform(cppcheck::Platform::Unix64));
ASSERT_EQUALS(cppcheck::Platform::Unix64, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS('0円', platform.defaultSign);
ASSERT_EQUALS(8, platform.char_bit);
ASSERT_EQUALS(4, platform.sizeof_int);
ASSERT_EQUALS(32, platform.int_bit);
ASSERT_EQUALS(8, platform.sizeof_long);
ASSERT_EQUALS(64, platform.long_bit);
}
void valid_config_file_1() {
// Valid platform configuration with all possible values specified.
// Similar to the avr8 platform file.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>8</char_bit>\n"
" <default-sign>unsigned</default-sign>\n"
" <sizeof>\n"
" <bool>1</bool>\n"
" <short>2</short>\n"
" <int>2</int>\n"
" <long>4</long>\n"
" <long-long>8</long-long>\n"
" <float>4</float>\n"
" <double>4</double>\n"
" <long-double>4</long-double>\n"
" <pointer>2</pointer>\n"
" <size_t>2</size_t>\n"
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
cppcheck::Platform platform;
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS(8, platform.char_bit);
ASSERT_EQUALS('u', platform.defaultSign);
ASSERT_EQUALS(1, platform.sizeof_bool);
ASSERT_EQUALS(2, platform.sizeof_short);
ASSERT_EQUALS(2, platform.sizeof_int);
ASSERT_EQUALS(4, platform.sizeof_long);
ASSERT_EQUALS(8, platform.sizeof_long_long);
ASSERT_EQUALS(4, platform.sizeof_float);
ASSERT_EQUALS(4, platform.sizeof_double);
ASSERT_EQUALS(4, platform.sizeof_long_double);
ASSERT_EQUALS(2, platform.sizeof_pointer);
ASSERT_EQUALS(2, platform.sizeof_size_t);
ASSERT_EQUALS(2, platform.sizeof_wchar_t);
ASSERT_EQUALS(16, platform.short_bit);
ASSERT_EQUALS(16, platform.int_bit);
ASSERT_EQUALS(32, platform.long_bit);
ASSERT_EQUALS(64, platform.long_long_bit);
}
void valid_config_file_2() {
// Valid platform configuration with all possible values specified and
// char_bit > 8.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>20</char_bit>\n"
" <default-sign>signed</default-sign>\n"
" <sizeof>\n"
" <bool>1</bool>\n"
" <short>2</short>\n"
" <int>3</int>\n"
" <long>4</long>\n"
" <long-long>5</long-long>\n"
" <float>6</float>\n"
" <double>7</double>\n"
" <long-double>8</long-double>\n"
" <pointer>9</pointer>\n"
" <size_t>10</size_t>\n"
" <wchar_t>11</wchar_t>\n"
" </sizeof>\n"
" </platform>";
cppcheck::Platform platform;
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS(20, platform.char_bit);
ASSERT_EQUALS('s', platform.defaultSign);
ASSERT_EQUALS(1, platform.sizeof_bool);
ASSERT_EQUALS(2, platform.sizeof_short);
ASSERT_EQUALS(3, platform.sizeof_int);
ASSERT_EQUALS(4, platform.sizeof_long);
ASSERT_EQUALS(5, platform.sizeof_long_long);
ASSERT_EQUALS(6, platform.sizeof_float);
ASSERT_EQUALS(7, platform.sizeof_double);
ASSERT_EQUALS(8, platform.sizeof_long_double);
ASSERT_EQUALS(9, platform.sizeof_pointer);
ASSERT_EQUALS(10, platform.sizeof_size_t);
ASSERT_EQUALS(11, platform.sizeof_wchar_t);
ASSERT_EQUALS(40, platform.short_bit);
ASSERT_EQUALS(60, platform.int_bit);
ASSERT_EQUALS(80, platform.long_bit);
ASSERT_EQUALS(100, platform.long_long_bit);
}
void valid_config_file_3() {
// Valid platform configuration without any usable information.
// Similar like an empty file.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit1>8</char_bit1>\n"
" <default-sign1>unsigned</default-sign1>\n"
" <sizeof1>\n"
" <bool1>1</bool1>\n"
" <short1>2</short1>\n"
" <int1>3</int1>\n"
" <long1>4</long1>\n"
" <long-long1>5</long-long1>\n"
" <float1>6</float1>\n"
" <double1>7</double1>\n"
" <long-double1>8</long-double1>\n"
" <pointer1>9</pointer1>\n"
" <size_t1>10</size_t1>\n"
" <wchar_t1>11</wchar_t1>\n"
" </sizeof1>\n"
" </platform>";
cppcheck::Platform platform;
ASSERT(platform.platform(cppcheck::Platform::Win64));
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS(8, platform.char_bit);
ASSERT_EQUALS('0円', platform.defaultSign);
ASSERT_EQUALS(1, platform.sizeof_bool);
ASSERT_EQUALS(2, platform.sizeof_short);
ASSERT_EQUALS(4, platform.sizeof_int);
ASSERT_EQUALS(4, platform.sizeof_long);
ASSERT_EQUALS(8, platform.sizeof_long_long);
}
void valid_config_file_4() {
// Valid platform configuration with all possible values specified and
// set to 0.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>0</char_bit>\n"
" <default-sign>z</default-sign>\n"
" <sizeof>\n"
" <bool>0</bool>\n"
" <short>0</short>\n"
" <int>0</int>\n"
" <long>0</long>\n"
" <long-long>0</long-long>\n"
" <float>0</float>\n"
" <double>0</double>\n"
" <long-double>0</long-double>\n"
" <pointer>0</pointer>\n"
" <size_t>0</size_t>\n"
" <wchar_t>0</wchar_t>\n"
" </sizeof>\n"
" </platform>";
cppcheck::Platform platform;
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS(0, platform.char_bit);
ASSERT_EQUALS('z', platform.defaultSign);
ASSERT_EQUALS(0, platform.sizeof_bool);
ASSERT_EQUALS(0, platform.sizeof_short);
ASSERT_EQUALS(0, platform.sizeof_int);
ASSERT_EQUALS(0, platform.sizeof_long);
ASSERT_EQUALS(0, platform.sizeof_long_long);
ASSERT_EQUALS(0, platform.sizeof_float);
ASSERT_EQUALS(0, platform.sizeof_double);
ASSERT_EQUALS(0, platform.sizeof_long_double);
ASSERT_EQUALS(0, platform.sizeof_pointer);
ASSERT_EQUALS(0, platform.sizeof_size_t);
ASSERT_EQUALS(0, platform.sizeof_wchar_t);
ASSERT_EQUALS(0, platform.short_bit);
ASSERT_EQUALS(0, platform.int_bit);
ASSERT_EQUALS(0, platform.long_bit);
ASSERT_EQUALS(0, platform.long_long_bit);
}
void invalid_config_file_1() {
// Invalid XML file: mismatching elements "boolt" vs "bool".
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit>8</char_bit>\n"
" <default-sign>unsigned</default-sign>\n"
" <sizeof>\n"
" <boolt>1</bool>\n"
" <short>2</short>\n"
" <int>2</int>\n"
" <long>4</long>\n"
" <long-long>8</long-long>\n"
" <float>4</float>\n"
" <double>4</double>\n"
" <long-double>4</long-double>\n"
" <pointer>2</pointer>\n"
" <size_t>2</size_t>\n"
" <wchar_t>2</wchar_t>\n"
" </sizeof>\n"
" </platform>";
cppcheck::Platform platform;
ASSERT(!readPlatform(platform, xmldata));
}
#if 0 // @TODO: Enable when Trac issue #8409 has been fixed
void empty_elements() {
// Valid platform configuration without any usable information.
// Similar like an empty file.
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
"<platform>\n"
" <char_bit></char_bit>\n"
" <default-sign></default-sign>\n"
" <sizeof>\n"
" <bool></bool>\n"
" <short></short>\n"
" <int></int>\n"
" <long></long>\n"
" <long-long></long-long>\n"
" <float></float>\n"
" <double></double>\n"
" <long-double></long-double>\n"
" <pointer></pointer>\n"
" <size_t></size_t>\n"
" <wchar_t></wchar_t>\n"
" </sizeof>\n"
" </platform>";
cppcheck::Platform platform;
ASSERT(platform.platform(cppcheck::Platform::Win64));
ASSERT(readPlatform(platform, xmldata));
ASSERT_EQUALS(platform.PlatformFile, platform.platformType);
ASSERT(!platform.isWindowsPlatform());
ASSERT_EQUALS(8, platform.char_bit);
ASSERT_EQUALS('0円', platform.defaultSign);
ASSERT_EQUALS(1, platform.sizeof_bool);
ASSERT_EQUALS(2, platform.sizeof_short);
ASSERT_EQUALS(4, platform.sizeof_int);
ASSERT_EQUALS(4, platform.sizeof_long);
ASSERT_EQUALS(8, platform.sizeof_long_long);
}
#endif
};
REGISTER_TEST(TestPlatform)
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/codepool/cppcheck.git
git@gitee.com:codepool/cppcheck.git
codepool
cppcheck
Cppcheck
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /