Debian Codegraph @

cppchecker/cppchecktestresults.cpp

raw
1 //////////////////////////////////////////////////////////////////////////////
2 //////////////////////////////////////////////////////////////////////////////
3 //
4 // copyright : (C) 2014 Eran Ifrah
5 // file name : cppchecktestresults.cpp
6 //
7 // -------------------------------------------------------------------------
8 // A
9 // _____ _ _ _ _
10 // / __ \ | | | | (_) |
11 // | / \/ ___ __| | ___| | _| |_ ___
12 // | | / _ \ / _ |/ _ \ | | | __/ _ )
13 // | \__/\ (_) | (_| | __/ |___| | || __/
14 // \____/\___/ \__,_|\___\_____/_|\__\___|
15 //
16 // F i l e
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 //////////////////////////////////////////////////////////////////////////////
24 //////////////////////////////////////////////////////////////////////////////
25
26 #include "cppchecktestresults.h"
27
28 #include "wx_xml_compatibility.h"
29
30 #include <wx/filename.h>
31 #include <wx/sstream.h>
32 #include <wx/xml/xml.h>
33
34 CppCheckResult::~CppCheckResult() {}
35
36 //------------------------------------------------------------
37
38 CppCheckTestResults::CppCheckTestResults()
39 : m_errorCount(0)
40 {
41 }
42
43 CppCheckTestResults::~CppCheckTestResults() {}
44
45 void CppCheckTestResults::AddResultsForFile(const wxString& xmlOutput)
46 {
47 // Create XML parser
48 wxStringInputStream xmlStream(xmlOutput);
49 wxXmlDocument xmlDoc(xmlStream);
50 if(!xmlDoc.IsOk()) {
51 return;
52 }
53
54 wxXmlNode* root = xmlDoc.GetRoot();
55 if(!root || root->GetName() != wxT("results")) {
56 return;
57 }
58
59 std::vector<CppCheckResult>* v(NULL);
60 wxString fileName;
61 for(wxXmlNode* child = root->GetChildren(); child; child = child->GetNext()) {
62 if(child->GetName() == wxT("error")) {
63 CppCheckResult cppCheckResult;
64 child->GetAttribute(wxT("id"), &cppCheckResult.id);
65 child->GetAttribute(wxT("file"), &fileName);
66
67 // Normalize the path
68 wxFileName fn(fileName);
69 fn.Normalize(wxPATH_NORM_ALL & ~(wxPATH_NORM_LONG));
70 cppCheckResult.filename = fn.GetFullPath();
71
72 wxString sLine;
73 child->GetAttribute(wxT("line"), &sLine);
74 sLine.ToLong(&cppCheckResult.lineno);
75 child->GetAttribute(wxT("severity"), &cppCheckResult.severity);
76 child->GetAttribute(wxT("msg"), &cppCheckResult.msg);
77
78 // Locate the entry that matches this file name
79 std::map<wxString, std::vector<CppCheckResult>*>::iterator iter = m_results.find(fileName);
80 if(iter == m_results.end()) {
81 v = new std::vector<CppCheckResult>();
82 m_results[fn.GetFullPath()] = v;
83 } else {
84 v = iter->second;
85 }
86
87 v->push_back(cppCheckResult);
88 m_errorCount++;
89 v = NULL;
90 }
91 }
92 }
93
94 std::vector<CppCheckResult>* CppCheckTestResults::GetResultsForFile(const wxString& filename)
95 {
96 std::map<wxString, std::vector<CppCheckResult>*>::iterator iter = m_results.find(filename);
97 if(iter != m_results.end())
98 return iter->second;
99
100 return NULL;
101 }
102
103 void CppCheckTestResults::ClearAll()
104 {
105 std::map<wxString, std::vector<CppCheckResult>*>::iterator iter = m_results.begin();
106 for(; iter != m_results.end(); iter++)
107 delete iter->second;
108 m_results.clear();
109 m_errorCount = 0;
110 }
111
112 wxArrayString CppCheckTestResults::GetFiles()
113 {
114 wxArrayString files;
115 std::map<wxString, std::vector<CppCheckResult>*>::iterator iter = m_results.begin();
116 for(; iter != m_results.end(); iter++)
117 files.Add(iter->first);
118 return files;
119 }