18 #include <boost/format.hpp> 19 #include <boost/assign/list_of.hpp> 20 #include <cppunit/TestFixture.h> 21 #include <cppunit/extensions/HelperMacros.h> 22 #include "ninkawrapper.hpp" 25 using namespace boost;
35 return m1.getLicenseName() == m2.getLicenseName() && m1.getPercentage() == m2.getPercentage();
40 boost::format format(
"LicenseMatch(licenseName=\"%s\", percentage=\"%u\")");
41 return str(format % m.getLicenseName() % m.getPercentage());
49 CPPUNIT_TEST(test_extractLicensesFromNinkaResult);
50 CPPUNIT_TEST(test_extractLicensePartFromNinkaResult);
51 CPPUNIT_TEST(test_splitLicensePart);
52 CPPUNIT_TEST(test_createMatches);
53 CPPUNIT_TEST(test_mapLicenseFromNinkaToFossology);
54 CPPUNIT_TEST_SUITE_END();
57 void test_extractLicensesFromNinkaResult()
59 string ninkaResult(
"filename;UNKNOWN,LGPLv3+;more;fields\n");
61 vector<string> licenses = extractLicensesFromNinkaResult(ninkaResult);
63 CPPUNIT_ASSERT_EQUAL(2L, (
long) licenses.size());
64 CPPUNIT_ASSERT_EQUAL(
string(
"UNKNOWN"), licenses[0]);
65 CPPUNIT_ASSERT_EQUAL(
string(
"LGPLv3+"), licenses[1]);
68 void test_extractLicensePartFromNinkaResult()
73 licensePart = extractLicensePartFromNinkaResult(
"filename;license1,license2;more;fields\n");
74 CPPUNIT_ASSERT_EQUAL(
string(
"license1,license2"), licensePart);
77 licensePart = extractLicensePartFromNinkaResult(
"filename;NONE\n");
78 CPPUNIT_ASSERT_EQUAL(
string(
"NONE"), licensePart);
81 licensePart = extractLicensePartFromNinkaResult(
"");
82 CPPUNIT_ASSERT_EQUAL(
string(
""), licensePart);
85 licensePart = extractLicensePartFromNinkaResult(
"filename;\n");
86 CPPUNIT_ASSERT_EQUAL(
string(
""), licensePart);
89 licensePart = extractLicensePartFromNinkaResult(
"filename;;more;fields\n");
90 CPPUNIT_ASSERT_EQUAL(
string(
""), licensePart);
93 licensePart = extractLicensePartFromNinkaResult(
"filename;license;more;fields\nanother line\n");
94 CPPUNIT_ASSERT_EQUAL(
string(
"license"), licensePart);
97 void test_splitLicensePart()
99 vector<string> licenses;
102 licenses = splitLicensePart(
"");
103 CPPUNIT_ASSERT_EQUAL(0L, (
long) licenses.size());
106 licenses = splitLicensePart(
"NONE");
107 CPPUNIT_ASSERT_EQUAL(1L, (
long) licenses.size());
108 CPPUNIT_ASSERT_EQUAL(
string(
"NONE"), licenses[0]);
111 licenses = splitLicensePart(
"LGPLv3+,Apachev1.0");
112 CPPUNIT_ASSERT_EQUAL(2L, (
long) licenses.size());
113 CPPUNIT_ASSERT_EQUAL(
string(
"LGPLv3+"), licenses[0]);
114 CPPUNIT_ASSERT_EQUAL(
string(
"Apachev1.0"), licenses[1]);
117 void test_createMatches()
119 vector<LicenseMatch> matches;
122 matches = createMatches(list_of(
"NONE"));
123 CPPUNIT_ASSERT_EQUAL(1L, (
long) matches.size());
124 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"No_license_found", 0), matches[0]);
127 matches = createMatches(list_of(
"UNKNOWN"));
128 CPPUNIT_ASSERT_EQUAL(1L, (
long) matches.size());
129 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"UnclassifiedLicense", 0), matches[0]);
132 matches = createMatches(list_of(
"LGPLv3+")(
"Apachev1.0"));
133 CPPUNIT_ASSERT_EQUAL(2L, (
long) matches.size());
134 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"LGPL-3.0+", 100), matches[0]);
135 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"Apache-1.0", 100), matches[1]);
138 void test_mapLicenseFromNinkaToFossology()
141 CPPUNIT_ASSERT_EQUAL(
string(
"No_license_found"), mapLicenseFromNinkaToFossology(
string(
"NONE")));
142 CPPUNIT_ASSERT_EQUAL(
string(
"UnclassifiedLicense"), mapLicenseFromNinkaToFossology(
string(
"UNKNOWN")));
145 CPPUNIT_ASSERT_EQUAL(
string(
""), mapLicenseFromNinkaToFossology(
string(
"")));
146 CPPUNIT_ASSERT_EQUAL(
string(
"something"), mapLicenseFromNinkaToFossology(
string(
"something")));