10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
19 #include "copyscan.hpp"
20 #include "regTypes.hpp"
21 #include "regscan.hpp"
35 CPPUNIT_TEST(testDataCheck);
36 CPPUNIT_TEST_SUITE_END();
53 case '<': out <<
"<";
break;
54 case '>': out <<
">";
break;
55 case '&': out <<
"&";
break;
56 default: out << (isprint(c) ? c :
' ');
63 void GetReferenceResults(
const string& fileName, list<match>& results)
68 string s = tstream.str();
69 string::size_type pos = 0;
70 string::size_type cpos = 0;
73 string::size_type tpos =
s.find(
"<s>", pos);
74 if (tpos == string::npos)
break;
78 pos =
s.find(
"</s>", tpos);
79 if (pos == string::npos)
break;
95 bool operator()(
const match& m2)
const
104 void Display(ostream& out, ifstream& data, list<match>& l, list<match>& lcmp,
const char*prein,
const char*postin,
const char*prenn,
const char*postnn)
111 bool in = find_if(lcmp.begin(), lcmp.end(),
overlappingMatch(m)) != lcmp.end();
113 int len = m.end - m.start;
114 char* str =
new char[len+1];
118 out <<
"<p><em>[" << m.start <<
":" << m.end <<
"]</em>" << (in ? prein : prenn);
121 out << (in ? postin : postnn) <<
"</p>" << endl;
151 string fileNameBase =
"../testdata/testdata";
154 regexScanner hauth(regAuthor::getRegex(), regAuthor::getType());
156 ofstream out(
"results.html");
158 out <<
"<html><head><style type=\"text/css\">"
159 "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; }"
160 "</style></head><body>" << endl;
165 string fileName = fileNameBase + to_string(i);
166 ifstream tstream(fileName);
167 list<match> lng, lauth, lrefs;
172 GetReferenceResults(fileName +
"_raw", lrefs);
174 out <<
"<h1>testdata" << i <<
"</h1>" << endl;
175 out <<
"<h2>HScanner</h2>" << endl;
176 Display(out, tstream, lng, lrefs,
"<code>",
"</code>",
"<code class=\"falsepos\">",
"</code>");
177 out <<
"<h2>Reference</h2>" << endl;
178 Display(out, tstream, lrefs, lng,
"<code>",
"</code>",
"<code class=\"falseneg\">",
"</code>");
180 out <<
"</body></html>" << endl;
181 cout << endl <<
"----- Test results written to results.html -----" << endl;
void testDataCheck()
Test agent on every file in ../testdata/ folder.
Implementation of scanner class for copyright.
Helper to check overlapping results.
Provides a regex scanner using predefined regexs.
virtual void ScanFile(const string &fileName, list< match > &results) const
Helper function to scan file.
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>....
Store the results of a regex match.
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.
bool cmpMatches(const match &a, const match &b)
Compare matches.
void HtmlEscapedOutput(ostream &out, const char *s)
Escape HTML special characters.