7 #include <boost/format.hpp>
8 #include <boost/assign/list_of.hpp>
9 #include <cppunit/TestFixture.h>
10 #include <cppunit/extensions/HelperMacros.h>
11 #include "ninkawrapper.hpp"
14 using namespace boost;
15 using namespace boost::assign;
24 return m1.getLicenseName() == m2.getLicenseName() && m1.getPercentage() == m2.getPercentage();
29 boost::format format(
"LicenseMatch(licenseName=\"%s\", percentage=\"%u\")");
30 return str(format % m.getLicenseName() % m.getPercentage());
38 CPPUNIT_TEST(test_extractLicensesFromNinkaResult);
39 CPPUNIT_TEST(test_extractLicensePartFromNinkaResult);
40 CPPUNIT_TEST(test_splitLicensePart);
41 CPPUNIT_TEST(test_createMatches);
42 CPPUNIT_TEST(test_mapLicenseFromNinkaToFossology);
43 CPPUNIT_TEST_SUITE_END();
46 void test_extractLicensesFromNinkaResult()
48 string ninkaResult(
"filename;UNKNOWN,LGPLv3+;more;fields\n");
50 vector<string> licenses = extractLicensesFromNinkaResult(ninkaResult);
52 CPPUNIT_ASSERT_EQUAL(2L, (
long) licenses.size());
53 CPPUNIT_ASSERT_EQUAL(
string(
"UNKNOWN"), licenses[0]);
54 CPPUNIT_ASSERT_EQUAL(
string(
"LGPLv3+"), licenses[1]);
57 void test_extractLicensePartFromNinkaResult()
62 licensePart = extractLicensePartFromNinkaResult(
"filename;license1,license2;more;fields\n");
63 CPPUNIT_ASSERT_EQUAL(
string(
"license1,license2"), licensePart);
66 licensePart = extractLicensePartFromNinkaResult(
"filename;NONE\n");
67 CPPUNIT_ASSERT_EQUAL(
string(
"NONE"), licensePart);
70 licensePart = extractLicensePartFromNinkaResult(
"");
71 CPPUNIT_ASSERT_EQUAL(
string(
""), licensePart);
74 licensePart = extractLicensePartFromNinkaResult(
"filename;\n");
75 CPPUNIT_ASSERT_EQUAL(
string(
""), licensePart);
78 licensePart = extractLicensePartFromNinkaResult(
"filename;;more;fields\n");
79 CPPUNIT_ASSERT_EQUAL(
string(
""), licensePart);
82 licensePart = extractLicensePartFromNinkaResult(
"filename;license;more;fields\nanother line\n");
83 CPPUNIT_ASSERT_EQUAL(
string(
"license"), licensePart);
86 void test_splitLicensePart()
88 vector<string> licenses;
91 licenses = splitLicensePart(
"");
92 CPPUNIT_ASSERT_EQUAL(0L, (
long) licenses.size());
95 licenses = splitLicensePart(
"NONE");
96 CPPUNIT_ASSERT_EQUAL(1L, (
long) licenses.size());
97 CPPUNIT_ASSERT_EQUAL(
string(
"NONE"), licenses[0]);
100 licenses = splitLicensePart(
"LGPLv3+,Apachev1.0");
101 CPPUNIT_ASSERT_EQUAL(2L, (
long) licenses.size());
102 CPPUNIT_ASSERT_EQUAL(
string(
"LGPLv3+"), licenses[0]);
103 CPPUNIT_ASSERT_EQUAL(
string(
"Apachev1.0"), licenses[1]);
106 void test_createMatches()
108 vector<LicenseMatch> matches;
111 matches = createMatches(list_of(
"NONE"));
112 CPPUNIT_ASSERT_EQUAL(1L, (
long) matches.size());
113 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"No_license_found", 0), matches[0]);
116 matches = createMatches(list_of(
"UNKNOWN"));
117 CPPUNIT_ASSERT_EQUAL(1L, (
long) matches.size());
118 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"UnclassifiedLicense", 0), matches[0]);
121 matches = createMatches(list_of(
"LGPLv3+")(
"Apachev1.0"));
122 CPPUNIT_ASSERT_EQUAL(2L, (
long) matches.size());
123 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"LGPL-3.0+", 100), matches[0]);
124 CPPUNIT_ASSERT_EQUAL(
LicenseMatch(
"Apache-1.0", 100), matches[1]);
127 void test_mapLicenseFromNinkaToFossology()
130 CPPUNIT_ASSERT_EQUAL(
string(
"No_license_found"), mapLicenseFromNinkaToFossology(
string(
"NONE")));
131 CPPUNIT_ASSERT_EQUAL(
string(
"UnclassifiedLicense"), mapLicenseFromNinkaToFossology(
string(
"UNKNOWN")));
134 CPPUNIT_ASSERT_EQUAL(
string(
""), mapLicenseFromNinkaToFossology(
string(
"")));
135 CPPUNIT_ASSERT_EQUAL(
string(
"something"), mapLicenseFromNinkaToFossology(
string(
"something")));