21 #include <cppunit/TestFixture.h> 22 #include <cppunit/extensions/HelperMacros.h> 30 #include "copyscan.hpp" 31 #include "regTypes.hpp" 32 #include "regscan.hpp" 46 CPPUNIT_TEST(testDataCheck);
47 CPPUNIT_TEST_SUITE_END();
64 case '<': out <<
"<";
break;
65 case '>': out <<
">";
break;
66 case '&': out <<
"&";
break;
67 default: out << (isprint(c) ? c :
' ');
74 void GetReferenceResults(
const string& fileName, list<match>& results)
79 string s = tstream.str();
80 string::size_type pos = 0;
81 string::size_type cpos = 0;
84 string::size_type tpos = s.find(
"<s>", pos);
85 if (tpos == string::npos)
break;
89 pos = s.find(
"</s>", tpos);
90 if (pos == string::npos)
break;
93 results.push_back(
match(start, cpos,
"r"));
106 bool operator()(
const match& m2)
const 115 void Display(ostream& out, ifstream& data, list<match>& l, list<match>& lcmp,
const char*prein,
const char*postin,
const char*prenn,
const char*postnn)
122 bool in = find_if(lcmp.begin(), lcmp.end(),
overlappingMatch(m)) != lcmp.end();
124 int len = m.end - m.start;
125 char* str =
new char[len+1];
129 out <<
"<p><em>[" << m.start <<
":" << m.end <<
"]</em>" << (in ? prein : prenn);
132 out << (in ? postin : postnn) <<
"</p>" << endl;
162 string fileNameBase =
"../testdata/testdata";
165 regexScanner hauth(regAuthor::getRegex(), regAuthor::getType());
167 ofstream out(
"results.html");
169 out <<
"<html><head><style type=\"text/css\">" 170 "body { font-family: sans-serif; } h1 { font-size: 14pt; } h2 { font-size: 10pt; } p { font-size: 10pt; } .falsepos { background-color: #FFC080; } .falseneg { background-color: #FF8080; }" 171 "</style></head><body>" << endl;
176 string fileName = fileNameBase + to_string(i);
177 ifstream tstream(fileName);
178 list<match> lng, lauth, lrefs;
183 GetReferenceResults(fileName +
"_raw", lrefs);
185 out <<
"<h1>testdata" << i <<
"</h1>" << endl;
186 out <<
"<h2>HScanner</h2>" << endl;
187 Display(out, tstream, lng, lrefs,
"<code>",
"</code>",
"<code class=\"falsepos\">",
"</code>");
188 out <<
"<h2>Reference</h2>" << endl;
189 Display(out, tstream, lrefs, lng,
"<code>",
"</code>",
"<code class=\"falseneg\">",
"</code>");
191 out <<
"</body></html>" << endl;
192 cout << endl <<
"----- Test results written to results.html -----" << endl;
void HtmlEscapedOutput(ostream &out, const char *s)
Escape HTML special characters.
Store the results of a regex match.
int s
The socket that the CLI will use to communicate.
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>. The application passed in should match the script name in /etc/init.d
virtual void ScanFile(const string &fileName, list< match > &results) const
Helper function to scan file.
Provides a regex scanner using predefined regexs.
Helper to check overlapping results.
void testDataCheck()
Test agent on every file in ../testdata/ folder.
bool cmpMatches(const match &a, const match &b)
Compare matches.
void Display(ostream &out, ifstream &data, list< match > &l, list< match > &lcmp, const char *prein, const char *postin, const char *prenn, const char *postnn)
Print results to out.
Implementation of scanner class for copyright.