Skip to content

Commit

Permalink
adjusted tests to reduce the amount of friend declarations necessary (
Browse files Browse the repository at this point in the history
#5435)

We were calling several interface functions through their inherited
classes instead of using the base classes requiring us to add `friend`
declarations to make the implementations accessible. This adjusts
several of those cases.
  • Loading branch information
firewave committed Sep 11, 2023
1 parent b31860b commit e7dd490
Show file tree
Hide file tree
Showing 24 changed files with 20 additions and 56 deletions.
2 changes: 0 additions & 2 deletions lib/checkassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class Token;
*/

class CPPCHECKLIB CheckAssert : public Check {
friend class TestFixture;

public:
CheckAssert() : Check(myName()) {}

Expand Down
2 changes: 0 additions & 2 deletions lib/checkautovariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ namespace ValueFlow {


class CPPCHECKLIB CheckAutoVariables : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckAutoVariables() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkbool.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Token;
/** @brief checks dealing with suspicious usage of boolean type (not for evaluating conditions) */

class CPPCHECKLIB CheckBool : public Check {
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckClass */
CheckBool() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkboost.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class Token;

/** @brief %Check Boost usage */
class CPPCHECKLIB CheckBoost : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckBoost() : Check(myName()) {}
Expand Down
3 changes: 0 additions & 3 deletions lib/checkbufferoverrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ class Token;
* other function and pass a buffer and reads or writes too much data.
*/
class CPPCHECKLIB CheckBufferOverrun : public Check {
friend class TestBufferOverrun;
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckBufferOverrun() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkcondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ namespace ValueFlow {
*/

class CPPCHECKLIB CheckCondition : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckAssignIf */
CheckCondition() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkexceptionsafety.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class Token;
*/

class CPPCHECKLIB CheckExceptionSafety : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckExceptionSafety() : Check(myName()) {}
Expand Down
3 changes: 0 additions & 3 deletions lib/checkfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ namespace ValueFlow {
*/

class CPPCHECKLIB CheckFunctions : public Check {
friend class TestFunctions;
friend class TestFixture;

public:
/** This constructor is used when registering the CheckFunctions */
CheckFunctions() : Check(myName()) {}
Expand Down
1 change: 0 additions & 1 deletion lib/checkinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class Token;

/** @brief %Check Internal cppcheck API usage */
class CPPCHECKLIB CheckInternal : public Check {
friend class TestFixture;
public:
/** This constructor is used when registering the CheckClass */
CheckInternal() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkleakautovar.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class CPPCHECKLIB VarInfo {
*/

class CPPCHECKLIB CheckLeakAutoVar : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckLeakAutoVar */
CheckLeakAutoVar() : Check(myName()) {}
Expand Down
1 change: 0 additions & 1 deletion lib/checknullpointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace tinyxml2 {

class CPPCHECKLIB CheckNullPointer : public Check {
friend class TestNullPointer;
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckNullPointer */
Expand Down
1 change: 0 additions & 1 deletion lib/checkother.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class CPPCHECKLIB CheckOther : public Check {
friend class TestCharVar;
friend class TestIncompleteStatement;
friend class TestOther;
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckClass */
Expand Down
2 changes: 0 additions & 2 deletions lib/checksizeof.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Token;
/** @brief checks on usage of sizeof() operator */

class CPPCHECKLIB CheckSizeof : public Check {
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckClass */
CheckSizeof() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkstl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class ErrorLogger;

/** @brief %Check STL usage (invalidation of iterators, mismatching containers, etc) */
class CPPCHECKLIB CheckStl : public Check {
friend class TestFixture;

public:
/** This constructor is used when registering the CheckClass */
CheckStl() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class Token;
/** @brief Detect misusage of C-style strings and related standard functions */

class CPPCHECKLIB CheckString : public Check {
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckClass */
CheckString() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checktype.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class ValueType;
/** @brief Various small checks */

class CPPCHECKLIB CheckType : public Check {
friend class TestFixture;

public:
/** @brief This constructor is used when registering the CheckClass */
CheckType() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkunusedfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ namespace CTU {
/// @{

class CPPCHECKLIB CheckUnusedFunctions : public Check {
friend class TestUnusedFunctions;

public:
/** @brief This constructor is used when registering the CheckUnusedFunctions */
CheckUnusedFunctions() : Check(myName()) {}
Expand Down
2 changes: 0 additions & 2 deletions lib/checkvaarg.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class Token;
*/

class CPPCHECKLIB CheckVaarg : public Check {
friend class TestFixture;

public:
CheckVaarg() : Check(myName()) {}

Expand Down
2 changes: 1 addition & 1 deletion test/fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class TestFixture : public ErrorLogger {
template<typename T>
static void runChecks(const Tokenizer &tokenizer, ErrorLogger *errorLogger)
{
T& check = getCheck<T>();
Check& check = getCheck<T>();
check.runChecks(tokenizer, errorLogger);
}

Expand Down
9 changes: 5 additions & 4 deletions test/testbufferoverrun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4966,7 +4966,8 @@ class TestBufferOverrun : public TestFixture {

void getErrorMessages() {
// Ticket #2292: segmentation fault when using --errorlist
getCheck<CheckBufferOverrun>().getErrorMessages(this, nullptr);
const Check& c = getCheck<CheckBufferOverrun>();
c.getErrorMessages(this, nullptr);
}

void arrayIndexThenCheck() {
Expand Down Expand Up @@ -5161,9 +5162,9 @@ class TestBufferOverrun : public TestFixture {

// Check code..
std::list<Check::FileInfo*> fileInfo;
CheckBufferOverrun checkBO(&tokenizer, &settings0, this);
fileInfo.push_back(checkBO.getFileInfo(&tokenizer, &settings0));
checkBO.analyseWholeProgram(ctu, fileInfo, settings0, *this);
Check& c = getCheck<CheckBufferOverrun>();
fileInfo.push_back(c.getFileInfo(&tokenizer, &settings0));
c.analyseWholeProgram(ctu, fileInfo, settings0, *this);
while (!fileInfo.empty()) {
delete fileInfo.back();
fileInfo.pop_back();
Expand Down
7 changes: 3 additions & 4 deletions test/testclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8777,7 +8777,7 @@ class TestClass : public TestFixture {

void ctu(const std::vector<std::string> &code) {
const Settings settings;
auto &check = getCheck<CheckClass>();
Check &check = getCheck<CheckClass>();

// getFileInfo
std::list<Check::FileInfo*> fileInfo;
Expand Down Expand Up @@ -8835,9 +8835,8 @@ class TestClass : public TestFixture {
ASSERT_LOC(tokenizer.tokenize(istr, "test.cpp"), file, line);

// Check..
CheckClass checkClass(&tokenizer, &settings1, this);

Check::FileInfo * fileInfo = (checkClass.getFileInfo)(&tokenizer, &settings1);
const Check& c = getCheck<CheckClass>();
Check::FileInfo * fileInfo = (c.getFileInfo)(&tokenizer, &settings1);

delete fileInfo;
}
Expand Down
11 changes: 5 additions & 6 deletions test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ class TestIO : public TestFixture {
ASSERT_LOC(tokenizer.tokenize(istr, file_in.c_str()), file, line);

// Check..
CheckIO checkIO(&tokenizer, &settings1, this);
checkIO.checkWrongPrintfScanfArguments();
if (!onlyFormatStr) {
checkIO.checkCoutCerrMisusage();
checkIO.checkFileUsage();
checkIO.invalidScanf();
if (onlyFormatStr) {
CheckIO checkIO(&tokenizer, &settings1, this);
checkIO.checkWrongPrintfScanfArguments();
return;
}
runChecks<CheckIO>(tokenizer, this);
}

void coutCerrMisusage() {
Expand Down
6 changes: 3 additions & 3 deletions test/testnullpointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4412,9 +4412,9 @@ class TestNullPointer : public TestFixture {

// Check code..
std::list<Check::FileInfo*> fileInfo;
CheckNullPointer checkNullPointer(&tokenizer, &settings, this);
fileInfo.push_back(checkNullPointer.getFileInfo(&tokenizer, &settings));
checkNullPointer.analyseWholeProgram(ctu, fileInfo, settings, *this);
Check& c = getCheck<CheckNullPointer>();
fileInfo.push_back(c.getFileInfo(&tokenizer, &settings));
c.analyseWholeProgram(ctu, fileInfo, settings, *this);
while (!fileInfo.empty()) {
delete fileInfo.back();
fileInfo.pop_back();
Expand Down
6 changes: 3 additions & 3 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7371,9 +7371,9 @@ class TestUninitVar : public TestFixture {

// Check code..
std::list<Check::FileInfo*> fileInfo;
CheckUninitVar check(&tokenizer, &settings, this);
fileInfo.push_back(check.getFileInfo(&tokenizer, &settings));
check.analyseWholeProgram(ctu, fileInfo, settings, *this);
Check& c = getCheck<CheckUninitVar>();
fileInfo.push_back(c.getFileInfo(&tokenizer, &settings));
c.analyseWholeProgram(ctu, fileInfo, settings, *this);
while (!fileInfo.empty()) {
delete fileInfo.back();
fileInfo.pop_back();
Expand Down

0 comments on commit e7dd490

Please sign in to comment.