refactor cfg testing in TestClass
This commit is contained in:
parent
d9deabe2ce
commit
b43c2de63a
|
@ -22,6 +22,7 @@
|
||||||
#include "checkclass.h"
|
#include "checkclass.h"
|
||||||
#include "testsuite.h"
|
#include "testsuite.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <tinyxml2.h>
|
||||||
|
|
||||||
extern std::ostringstream errout;
|
extern std::ostringstream errout;
|
||||||
|
|
||||||
|
@ -2072,18 +2073,17 @@ private:
|
||||||
ASSERT_EQUALS("[test.cpp:3]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:3]: (error) Class 'Base' which is inherited by class 'Derived' does not have a virtual destructor.\n", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkNoMemset(const char code[], bool load_std_cfg = false, bool portability = false) {
|
void checkNoMemset(const char code[]) {
|
||||||
// Clear the error log
|
|
||||||
errout.str("");
|
|
||||||
|
|
||||||
Settings settings;
|
Settings settings;
|
||||||
settings.addEnabled("warning");
|
settings.addEnabled("warning");
|
||||||
if (portability)
|
|
||||||
settings.addEnabled("portability");
|
settings.addEnabled("portability");
|
||||||
if (load_std_cfg) {
|
checkNoMemset(code,settings);
|
||||||
LOAD_LIB_2(settings.library, "std.cfg");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void checkNoMemset(const char code[], const Settings &settings) {
|
||||||
|
// Clear the error log
|
||||||
|
errout.str("");
|
||||||
|
|
||||||
// Tokenize..
|
// Tokenize..
|
||||||
Tokenizer tokenizer(&settings, this);
|
Tokenizer tokenizer(&settings, this);
|
||||||
std::istringstream istr(code);
|
std::istringstream istr(code);
|
||||||
|
@ -2512,6 +2512,17 @@ private:
|
||||||
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
"[test.cpp:11]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||||
"[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
"[test.cpp:12]: (error) Using 'memset' on struct that contains a 'std::string'.\n"
|
||||||
"[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
"[test.cpp:13]: (error) Using 'memset' on struct that contains a 'std::string'.\n", errout.str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void memsetOnStdPodType() { // Ticket #5901
|
||||||
|
Settings settings;
|
||||||
|
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||||
|
"<def>\n"
|
||||||
|
" <podtype name=\"uint8_t\" sign=\"u\" size=\"1\"/>\n"
|
||||||
|
"</def>";
|
||||||
|
tinyxml2::XMLDocument doc;
|
||||||
|
doc.Parse(xmldata, sizeof(xmldata));
|
||||||
|
settings.library.load(doc);
|
||||||
|
|
||||||
checkNoMemset("class A {\n"
|
checkNoMemset("class A {\n"
|
||||||
" std::array<int, 10> ints;\n"
|
" std::array<int, 10> ints;\n"
|
||||||
|
@ -2519,11 +2530,9 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}", true);
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str()); // std::array is POD (#5481)
|
ASSERT_EQUALS("", errout.str()); // std::array is POD (#5481)
|
||||||
}
|
|
||||||
|
|
||||||
void memsetOnStdPodType() { // Ticket #5901
|
|
||||||
checkNoMemset("struct st {\n"
|
checkNoMemset("struct st {\n"
|
||||||
" std::uint8_t a;\n"
|
" std::uint8_t a;\n"
|
||||||
" std::uint8_t b;\n"
|
" std::uint8_t b;\n"
|
||||||
|
@ -2533,7 +2542,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" st s;\n"
|
" st s;\n"
|
||||||
" std::memset(&s, 0, sizeof(st));\n"
|
" std::memset(&s, 0, sizeof(st));\n"
|
||||||
"}", true);
|
"}", settings);
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2544,7 +2553,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}", false, true);
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A {\n"
|
checkNoMemset("struct A {\n"
|
||||||
|
@ -2553,7 +2562,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}", false, true);
|
"}");
|
||||||
ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
|
ASSERT_EQUALS("[test.cpp:6]: (portability) Using memset() on struct which contains a floating point number.\n", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A {\n"
|
checkNoMemset("struct A {\n"
|
||||||
|
@ -2562,7 +2571,7 @@ private:
|
||||||
"void f(const A& b) {\n"
|
"void f(const A& b) {\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memcpy(&a, &b, sizeof(A));\n"
|
" memcpy(&a, &b, sizeof(A));\n"
|
||||||
"}", false, true);
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
|
|
||||||
checkNoMemset("struct A {\n"
|
checkNoMemset("struct A {\n"
|
||||||
|
@ -2571,16 +2580,7 @@ private:
|
||||||
"void f() {\n"
|
"void f() {\n"
|
||||||
" A a;\n"
|
" A a;\n"
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
" memset(&a, 0, sizeof(A));\n"
|
||||||
"}", false, true);
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
|
||||||
|
|
||||||
checkNoMemset("struct A {\n"
|
|
||||||
" float f;\n"
|
|
||||||
"};\n"
|
|
||||||
"void f() {\n"
|
|
||||||
" A a;\n"
|
|
||||||
" memset(&a, 0, sizeof(A));\n"
|
|
||||||
"}", false, false);
|
|
||||||
ASSERT_EQUALS("", errout.str());
|
ASSERT_EQUALS("", errout.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue