21 #include <cppunit/TestFixture.h> 22 #include <cppunit/extensions/HelperMacros.h> 23 #include <boost/regex.hpp> 35 CPPUNIT_TEST (regTest);
36 CPPUNIT_TEST (badNameTest);
38 CPPUNIT_TEST_SUITE_END ();
53 const std::string gplLicense =
"GPL-2.0";
54 const std::string lgplLicense =
"LGPL-2.1+";
55 std::string content =
"SPDX-License-Identifier: " + gplLicense +
" AND " 60 std::string::const_iterator begin = content.begin();
61 std::string::const_iterator end = content.end();
62 boost::match_results<std::string::const_iterator> what;
65 boost::regex_search(begin, end, what, listRegex);
66 licenseList = what[1].str();
69 CPPUNIT_ASSERT_EQUAL(gplLicense +
" AND " + lgplLicense, licenseList);
72 begin = licenseList.begin();
73 end = licenseList.end();
74 list<string> licensesFound;
79 if (boost::regex_search(begin, end, res, nameRegex))
81 licensesFound.push_back(res[1].str());
82 begin = res[0].second;
90 size_t expectedNos = 2;
91 size_t actualNos = licensesFound.size();
93 CPPUNIT_ASSERT_EQUAL(expectedNos, actualNos);
96 std::find(licensesFound.begin(), licensesFound.end(), gplLicense)
97 != licensesFound.end());
99 std::find(licensesFound.begin(), licensesFound.end(), lgplLicense)
100 != licensesFound.end());
115 const std::string gplLicense =
"GPL-2.0";
116 const std::string badLicense =
"AB";
117 std::string content =
"SPDX-License-Identifier: " + gplLicense +
" AND " 122 std::string::const_iterator begin = content.begin();
123 std::string::const_iterator end = content.end();
124 boost::match_results<std::string::const_iterator> what;
127 boost::regex_search(begin, end, what, listRegex);
128 licenseList = what[1].str();
131 CPPUNIT_ASSERT_EQUAL(gplLicense, licenseList);
134 begin = licenseList.begin();
135 end = licenseList.end();
136 list<string> licensesFound;
141 if (boost::regex_search(begin, end, res, nameRegex))
143 licensesFound.push_back(res[1].str());
144 begin = res[0].second;
152 size_t expectedNos = 1;
153 size_t actualNos = licensesFound.size();
155 CPPUNIT_ASSERT_EQUAL(expectedNos, actualNos);
158 std::find(licensesFound.begin(), licensesFound.end(), gplLicense)
159 != licensesFound.end());
162 std::find(licensesFound.begin(), licensesFound.end(), badLicense)
163 == licensesFound.end());
168 CPPUNIT_TEST_SUITE_REGISTRATION(
regexTest );
void regTest(void)
Test regex on a test string.
#define SPDX_LICENSE_NAMES
Regex to filter license names from list of license list.
void badNameTest(void)
Test regex on a string with bad identifier.
#define SPDX_LICENSE_LIST
Regex to filter the list of licenses.
Test fixture to test regex accuracy.