Skip to content

Commit

Permalink
test2
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Aug 15, 2024
1 parent 0f40359 commit 8721c3c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 45 deletions.
8 changes: 5 additions & 3 deletions gui/test/resultstree/testresultstree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@

#include <QtTest>

class TestReport: public Report {
class TestReport : public Report {
public:
TestReport(QString format) : Report(QString()), format(format) {}
void writeHeader() override { output.clear(); }
void writeHeader() override {
output.clear();
}
void writeFooter() override {}
void writeError(const ErrorItem &error) override {
QString line = format;
Expand Down Expand Up @@ -125,7 +127,7 @@ void TestResultsTree::testReportType() const
TestReport report("{id},{classification},{guideline}");

int msgCount = 0;
auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem {
auto createErrorItem = [&msgCount](const Severity severity, const QString& errorId) -> ErrorItem {
++msgCount;
ErrorItem errorItem;
errorItem.errorPath << QErrorPathItem(ErrorMessage::FileLocation("file1.c", msgCount, 1));
Expand Down
60 changes: 34 additions & 26 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6158,41 +6158,49 @@ void Tokenizer::dump(std::ostream &out) const
if (list.front())
list.front()->printValueFlow(true, out);

if (!mTypedefInfo.empty()) {
outs += " <typedef-info>";
outs += '\n';
for (const TypedefInfo &typedefInfo: mTypedefInfo) {
outs += " <info";
outs += dumpTypedefInfo();

outs += " name=\"";
outs += typedefInfo.name;
outs += "\"";
outs += mTemplateSimplifier->dump();

outs += " file=\"";
outs += ErrorLogger::toxml(typedefInfo.filename);
outs += "\"";
out << outs;
}

outs += " line=\"";
outs += std::to_string(typedefInfo.lineNumber);
outs += "\"";
std::string Tokenizer::dumpTypedefInfo() const
{
if (mTypedefInfo.empty())
return "";
std::string outs = " <typedef-info>";
outs += '\n';
for (const TypedefInfo &typedefInfo: mTypedefInfo) {
outs += " <info";

outs += " column=\"";
outs += std::to_string(typedefInfo.column);
outs += "\"";
outs += " name=\"";
outs += typedefInfo.name;
outs += "\"";

outs += " used=\"";
outs += std::to_string(typedefInfo.used?1:0);
outs += "\"";
outs += " file=\"";
outs += ErrorLogger::toxml(typedefInfo.filename);
outs += "\"";

outs += "/>";
outs += '\n';
}
outs += " </typedef-info>";
outs += " line=\"";
outs += std::to_string(typedefInfo.lineNumber);
outs += "\"";

outs += " column=\"";
outs += std::to_string(typedefInfo.column);
outs += "\"";

outs += " used=\"";
outs += std::to_string(typedefInfo.used?1:0);
outs += "\"";

outs += "/>";
outs += '\n';
}
outs += mTemplateSimplifier->dump();
outs += " </typedef-info>";
outs += '\n';

out << outs;
return outs;
}

void Tokenizer::simplifyHeadersAndUnusedTemplates()
Expand Down
19 changes: 8 additions & 11 deletions lib/tokenize.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,17 +627,7 @@ class CPPCHECKLIB Tokenizer {

void setDirectives(std::list<Directive> directives);

struct TypedefInfo {
std::string name;
std::string filename;
int lineNumber;
int column;
bool used;
};
std::vector<TypedefInfo> getTypedefInfo() {
return mTypedefInfo;
}

std::string dumpTypedefInfo() const;
private:
const Token *processFunc(const Token *tok2, bool inOperator) const;
Token *processFunc(Token *tok2, bool inOperator);
Expand Down Expand Up @@ -671,6 +661,13 @@ class CPPCHECKLIB Tokenizer {
/** sizeof information for known types */
std::map<std::string, int> mTypeSize;

struct TypedefInfo {
std::string name;
std::string filename;
int lineNumber;
int column;
bool used;
};
std::vector<TypedefInfo> mTypedefInfo;

std::list<Directive> mDirectives;
Expand Down
12 changes: 7 additions & 5 deletions test/testsimplifytypedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class TestSimplifyTypedef : public TestFixture {
return tokenizer.tokens()->stringifyList(nullptr, false);
}

std::vector<Tokenizer::TypedefInfo> getTypedefInfo(const char code[]) {
std::string dumpTypedefInfo(const char code[]) {
Tokenizer tokenizer(settings1, *this);

std::istringstream istr(code);
Expand All @@ -322,7 +322,7 @@ class TestSimplifyTypedef : public TestFixture {
} catch (const InternalError&) {
return {};
}
return tokenizer.getTypedefInfo();
return tokenizer.dumpTypedefInfo();
}

void c1() {
Expand Down Expand Up @@ -4400,9 +4400,11 @@ class TestSimplifyTypedef : public TestFixture {
}

void typedefInfo1() {
const auto& t = getTypedefInfo("typedef int A;\nA x;");
ASSERT_EQUALS(1, t.size());
ASSERT_EQUALS("A", t[0].name);
const std::string xml = dumpTypedefInfo("typedef int A;\nA x;");
ASSERT_EQUALS(" <typedef-info>\n"
" <info name=\"A\" file=\"file.c\" line=\"1\" column=\"1\" used=\"1\"/>\n"
" </typedef-info>\n",
xml);
}
};

Expand Down

0 comments on commit 8721c3c

Please sign in to comment.