7 #include <cppunit/TestFixture.h>
8 #include <cppunit/extensions/HelperMacros.h>
19 ostream&
operator<<(ostream& out,
const vector<ojomatch>& l)
22 out <<
'[' << m.start <<
':' << m.end <<
"]: '" << m.content <<
"'";
30 const std::string testContent =
"!/usr/bin/env python3\n"
31 "# -*- coding: utf-8 -*-\n"
35 "SPDX-License-Identifier: GPL-2.0\n"
37 "This program is free software; you can redistribute it and/or\n"
38 "modify it under the terms of the GNU General Public License\n"
39 "version 2 as published by the Free Software Foundation.\n"
40 "This program is distributed in the hope that it will be useful,\n"
41 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
42 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
43 "GNU General Public License for more details.\n"
45 "You should have received a copy of the GNU General Public License along\n"
46 "with this program; if not, write to the Free Software Foundation, Inc.,\n"
47 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
51 const std::string testContentWithoutIdentifier =
"!/usr/bin/env python3\n"
52 "# -*- coding: utf-8 -*-\n"
55 "This program is free software; you can redistribute it and/or\n"
56 "modify it under the terms of the GNU General Public License\n"
57 "version 2 as published by the Free Software Foundation.\n"
58 "This program is distributed in the hope that it will be useful,\n"
59 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
60 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
61 "GNU General Public License for more details.\n"
63 "You should have received a copy of the GNU General Public License along\n"
64 "with this program; if not, write to the Free Software Foundation, Inc.,\n"
65 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
69 const std::string multipleSpdxLicense =
"!/usr/bin/env python3\n"
70 "# -*- coding: utf-8 -*-\n"
74 "SPDX-License-Identifier: GPL-2.0 AND LGPL-2.1+ WITH Classpath-exception-2.0\n"
76 "This program is free software; you can redistribute it and/or\n"
77 "modify it under the terms of the GNU General Public License\n"
78 "version 2 as published by the Free Software Foundation.\n"
79 "This program is distributed in the hope that it will be useful,\n"
80 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
81 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
82 "GNU General Public License for more details.\n"
84 "You should have received a copy of the GNU General Public License along\n"
85 "with this program; if not, write to the Free Software Foundation, Inc.,\n"
86 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
92 CPPUNIT_TEST (spdxContentTest);
93 CPPUNIT_TEST (nonSpdxContentTest);
94 CPPUNIT_TEST (multiSpdxContentTest);
96 CPPUNIT_TEST_SUITE_END ();
104 void scannerTest (
const string& content, vector<string> expectedStrings)
107 char* tempFilePath = strdup(
"/tmp/ojo-XXXXXX");
108 mkstemp(tempFilePath);
110 fstream tempFile(tempFilePath);
115 vector<ojomatch> matches = ojo.processFile(tempFilePath);
118 unlink(tempFilePath);
120 CPPUNIT_ASSERT_EQUAL(expectedStrings.size(), matches.size());
122 for (
auto expected : expectedStrings)
124 CPPUNIT_ASSERT(std::find(matches.begin(), matches.end(), expected) != matches.end());
138 scannerTest(testContent, {
"GPL-2.0"});
150 scannerTest(testContentWithoutIdentifier, {});
162 scannerTest(multipleSpdxLicense, {
"GPL-2.0",
"LGPL-2.1+",
163 "Classpath-exception-2.0",
"Dual-license"});
void spdxContentTest()
Test ojo on content with SPDX license.
void scannerTest(const string &content, vector< string > expectedStrings)
Runs a scan on content and check matches against expectedStrings.
void multiSpdxContentTest()
Test ojo on content with multiple SPDX license.
void nonSpdxContentTest()
Test ojo on content without SPDX license.
std::ostream & operator<<(std::ostream &os, const std::vector< int > &x)
<< operator overload to appends a vector to an ostream object