2020#include " analyzerinfo.h"
2121#include " filesettings.h"
2222#include " fixture.h"
23+ #include " xml.h"
2324
2425#include < sstream>
26+ #include < tinyxml2.h>
2527
2628class TestAnalyzerInformation : public TestFixture , private AnalyzerInformation {
2729public:
@@ -34,6 +36,7 @@ class TestAnalyzerInformation : public TestFixture, private AnalyzerInformation
3436 TEST_CASE (duplicateFile);
3537 TEST_CASE (filesTextDuplicateFile);
3638 TEST_CASE (parse);
39+ TEST_CASE (skipAnalysis);
3740 }
3841
3942 void getAnalyzerInfoFile () const {
@@ -95,6 +98,135 @@ class TestAnalyzerInformation : public TestFixture, private AnalyzerInformation
9598 ASSERT_EQUALS (0 , info.fileIndex );
9699 ASSERT_EQUALS (" C:/dm/cppcheck-fix-13333/test/cli/whole-program/odr1.cpp" , info.sourceFile );
97100 }
101+
102+ void skipAnalysis () const {
103+ // Matching hash with license error (don't skip)
104+ {
105+ std::list<ErrorMessage> errorList;
106+ tinyxml2::XMLDocument doc;
107+
108+ const tinyxml2::XMLError xmlError = doc.Parse (
109+ " <?xml version=\" 1.0\" ?>"
110+ " <analyzerinfo hash=\" 100\" >"
111+ " <error id=\" premium-invalidLicense\" severity=\" error\" msg=\" Invalid license: No license file was found, contact sales@cppchecksolutions.com\" verbose=\" Invalid license: No license file was found, contact sales@cppchecksolutions.com\" file0=\" test.c\" >"
112+ " <location file=\" Cppcheck Premium\" line=\" 0\" column=\" 0\" />"
113+ " </error>"
114+ " </analyzerinfo>"
115+ );
116+ ASSERT_EQUALS (tinyxml2::XML_SUCCESS, xmlError);
117+
118+ ASSERT_EQUALS (false , AnalyzerInformation::skipAnalysis (doc, 100 , errorList));
119+ ASSERT_EQUALS (0 , errorList.size ());
120+ }
121+
122+ // Matching hash with premium internal error (don't skip)
123+ {
124+ std::list<ErrorMessage> errorList;
125+ tinyxml2::XMLDocument doc;
126+
127+ const tinyxml2::XMLError xmlError = doc.Parse (
128+ " <?xml version=\" 1.0\" ?>"
129+ " <analyzerinfo hash=\" 100\" >"
130+ " <error id=\" premium-internalError\" severity=\" error\" msg=\" Something went wrong\" verbose=\" Something went wrong\" file0=\" test.c\" >"
131+ " <location file=\" Cppcheck\" line=\" 0\" column=\" 0\" />"
132+ " </error>"
133+ " </analyzerinfo>"
134+ );
135+ ASSERT_EQUALS (tinyxml2::XML_SUCCESS, xmlError);
136+
137+ ASSERT_EQUALS (false , AnalyzerInformation::skipAnalysis (doc, 100 , errorList));
138+ ASSERT_EQUALS (0 , errorList.size ());
139+ }
140+
141+ // Matching hash with internal error (don't skip)
142+ {
143+ std::list<ErrorMessage> errorList;
144+ tinyxml2::XMLDocument doc;
145+
146+ const tinyxml2::XMLError xmlError = doc.Parse (
147+ " <?xml version=\" 1.0\" ?>"
148+ " <analyzerinfo hash=\" 100\" >"
149+ " <error id=\" internalError\" severity=\" error\" msg=\" Something went wrong\" verbose=\" Something went wrong\" file0=\" test.c\" >"
150+ " <location file=\" Cppcheck\" line=\" 0\" column=\" 0\" />"
151+ " </error>"
152+ " </analyzerinfo>"
153+ );
154+ ASSERT_EQUALS (tinyxml2::XML_SUCCESS, xmlError);
155+
156+ ASSERT_EQUALS (false , AnalyzerInformation::skipAnalysis (doc, 100 , errorList));
157+ ASSERT_EQUALS (0 , errorList.size ());
158+ }
159+
160+ // Matching hash with normal error (skip)
161+ {
162+ std::list<ErrorMessage> errorList;
163+ tinyxml2::XMLDocument doc;
164+
165+ const tinyxml2::XMLError xmlError = doc.Parse (
166+ " <?xml version=\" 1.0\" ?>"
167+ " <analyzerinfo hash=\" 100\" >"
168+ " <error id=\" nullPointer\" severity=\" error\" msg=\" Null pointer dereference: ptr\" verbose=\" Null pointer dereference: ptr\" cwe=\" 476\" file0=\" test.c\" >"
169+ " <location file=\" test.c\" line=\" 4\" column=\" 3\" info=\" Null pointer dereference\" />"
170+ " <location file=\" test.c\" line=\" 3\" column=\" 12\" info=\" Assignment 'ptr=NULL', assigned value is 0\" />"
171+ " <symbol>ptr</symbol>"
172+ " </error>"
173+ " </analyzerinfo>"
174+ );
175+ ASSERT_EQUALS (tinyxml2::XML_SUCCESS, xmlError);
176+
177+ ASSERT_EQUALS (true , AnalyzerInformation::skipAnalysis (doc, 100 , errorList));
178+ ASSERT_EQUALS (1 , errorList.size ());
179+ }
180+
181+ // Matching hash with no error (skip)
182+ {
183+ std::list<ErrorMessage> errorList;
184+ tinyxml2::XMLDocument doc;
185+
186+ const tinyxml2::XMLError xmlError = doc.Parse (
187+ " <?xml version=\" 1.0\" ?>"
188+ " <analyzerinfo hash=\" 100\" >"
189+ " </analyzerinfo>"
190+ );
191+ ASSERT_EQUALS (tinyxml2::XML_SUCCESS, xmlError);
192+
193+ ASSERT_EQUALS (true , AnalyzerInformation::skipAnalysis (doc, 100 , errorList));
194+ ASSERT_EQUALS (0 , errorList.size ());
195+ }
196+
197+ // Different hash with normal error (don't skip)
198+ {
199+ std::list<ErrorMessage> errorList;
200+ tinyxml2::XMLDocument doc;
201+
202+ const tinyxml2::XMLError xmlError = doc.Parse (
203+ " <?xml version=\" 1.0\" ?>"
204+ " <analyzerinfo hash=\" 100\" >"
205+ " <error id=\" nullPointer\" severity=\" error\" msg=\" Null pointer dereference: ptr\" verbose=\" Null pointer dereference: ptr\" cwe=\" 476\" file0=\" test.c\" >"
206+ " <location file=\" test.c\" line=\" 4\" column=\" 3\" info=\" Null pointer dereference\" />"
207+ " <location file=\" test.c\" line=\" 3\" column=\" 12\" info=\" Assignment 'ptr=NULL', assigned value is 0\" />"
208+ " <symbol>ptr</symbol>"
209+ " </error>"
210+ " </analyzerinfo>"
211+ );
212+ ASSERT_EQUALS (tinyxml2::XML_SUCCESS, xmlError);
213+
214+ ASSERT_EQUALS (false , AnalyzerInformation::skipAnalysis (doc, 99 , errorList));
215+ ASSERT_EQUALS (0 , errorList.size ());
216+ }
217+
218+ // Empty document (don't skip)
219+ {
220+ std::list<ErrorMessage> errorList;
221+ tinyxml2::XMLDocument doc;
222+
223+ const tinyxml2::XMLError xmlError = doc.Parse (" " );
224+ ASSERT_EQUALS (tinyxml2::XML_ERROR_EMPTY_DOCUMENT, xmlError);
225+
226+ ASSERT_EQUALS (false , AnalyzerInformation::skipAnalysis (doc, 100 , errorList));
227+ ASSERT_EQUALS (0 , errorList.size ());
228+ }
229+ }
98230};
99231
100232REGISTER_TEST (TestAnalyzerInformation)
0 commit comments