18 #include <cppunit/TestFixture.h> 19 #include <cppunit/extensions/HelperMacros.h> 30 ostream& operator<<(ostream& out, const vector<ojomatch>& l)
33 out <<
'[' << m.start <<
':' << m.end <<
"]: '" << m.content <<
"'";
40 const std::string testContent =
"!/usr/bin/env python3\n" 41 "# -*- coding: utf-8 -*-\n" 45 "SPDX-License-Identifier: GPL-2.0\n" 47 "This program is free software; you can redistribute it and/or\n" 48 "modify it under the terms of the GNU General Public License\n" 49 "version 2 as published by the Free Software Foundation.\n" 50 "This program is distributed in the hope that it will be useful,\n" 51 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 52 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 53 "GNU General Public License for more details.\n" 55 "You should have received a copy of the GNU General Public License along\n" 56 "with this program; if not, write to the Free Software Foundation, Inc.,\n" 57 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" 60 const std::string testContentWithoutIdentifier =
"!/usr/bin/env python3\n" 61 "# -*- coding: utf-8 -*-\n" 64 "This program is free software; you can redistribute it and/or\n" 65 "modify it under the terms of the GNU General Public License\n" 66 "version 2 as published by the Free Software Foundation.\n" 67 "This program is distributed in the hope that it will be useful,\n" 68 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 69 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 70 "GNU General Public License for more details.\n" 72 "You should have received a copy of the GNU General Public License along\n" 73 "with this program; if not, write to the Free Software Foundation, Inc.,\n" 74 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" 77 const std::string multipleSpdxLicense =
"!/usr/bin/env python3\n" 78 "# -*- coding: utf-8 -*-\n" 82 "SPDX-License-Identifier: GPL-2.0 AND LGPL-2.1+ WITH Classpath-exception-2.0\n" 84 "This program is free software; you can redistribute it and/or\n" 85 "modify it under the terms of the GNU General Public License\n" 86 "version 2 as published by the Free Software Foundation.\n" 87 "This program is distributed in the hope that it will be useful,\n" 88 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" 89 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" 90 "GNU General Public License for more details.\n" 92 "You should have received a copy of the GNU General Public License along\n" 93 "with this program; if not, write to the Free Software Foundation, Inc.,\n" 94 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n" 99 CPPUNIT_TEST (spdxContentTest);
100 CPPUNIT_TEST (nonSpdxContentTest);
101 CPPUNIT_TEST (multiSpdxContentTest);
103 CPPUNIT_TEST_SUITE_END ();
111 void scannerTest (
const string& content, vector<string> expectedStrings)
114 char* tempFilePath = strdup(
"/tmp/ojo-XXXXXX");
115 mkstemp(tempFilePath);
117 fstream tempFile(tempFilePath);
122 vector<ojomatch> matches = ojo.processFile(tempFilePath);
125 unlink(tempFilePath);
127 CPPUNIT_ASSERT_EQUAL(expectedStrings.size(), matches.size());
129 for (
auto expected : expectedStrings)
131 CPPUNIT_ASSERT(std::find(matches.begin(), matches.end(), expected) != matches.end());
145 scannerTest(testContent, {
"GPL-2.0"});
157 scannerTest(testContentWithoutIdentifier, {});
169 scannerTest(multipleSpdxLicense, {
"GPL-2.0",
"LGPL-2.1+",
170 "Classpath-exception-2.0",
"Dual-license"});
void nonSpdxContentTest()
Test ojo on content without 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 spdxContentTest()
Test ojo on content with SPDX license.