10 #include "CompatibilityUtils.hpp"
14 ostream&
operator<<(ostream& out,
const std::set<std::string>&
s)
36 std::string, std::string, std::string, std::string>& t)
38 out <<
"<" << std::get<0>(t) <<
", " << std::get<1>(t) <<
", "
39 << std::get<2>(t) <<
", " << std::get<3>(t) <<
">";
43 #include <cppunit/TestFixture.h>
44 #include <cppunit/extensions/HelperMacros.h>
53 CPPUNIT_TEST(testLicensesToSet);
54 CPPUNIT_TEST(testRuleLoader);
55 CPPUNIT_TEST_SUITE_END();
57 void testLicensesToSet();
58 void testRuleLoader();
71 const std::string licenseNormalCase =
"GPL-2.0-only AND LGPL-2.1-or-later";
72 const std::set<std::string> licenseSetNormalCase = {
"GPL-2.0-only",
"LGPL-2.1-or-later"};
74 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Set should contain 2 licenses",
77 const std::string licenseDuplicate =
"GPL-2.0-only AND GPL-2.0-only";
78 const std::set<std::string> licenseSetDuplicate = {
"GPL-2.0-only"};
80 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Set should not contain duplicates",
83 const std::string licenseInvalidEnd =
"GPL-2.0-only AND GPL-2.0-only AND ";
84 const std::set<std::string> licenseSetInvalidEnd = {
"GPL-2.0-only"};
86 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"There should be no empty string in set",
89 const std::string licenseEmpty =
"";
90 const std::set<std::string> licenseSetEmpty = {};
92 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Empty licenseList should return empty set",
96 void TestUtility::testRuleLoader()
98 std::string
const test_yaml_loc = TESTDATADIR
"/comp-rules-test.yaml";
101 const std::tuple<string, string, string, string> known_gpl_tuple =
102 make_tuple(
"GPL-2.0-only",
"",
"LGPL-2.1-or-later",
"");
104 auto result_check = rule_list.find(known_gpl_tuple);
106 CPPUNIT_ASSERT_MESSAGE(
"Unable to find tuple with name from YAML",
107 result_check != rule_list.end());
109 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Should find a known name tuple from YAML",
110 known_gpl_tuple, result_check->first);
111 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Invalid compatibility for name tuple from YAML",
112 true, result_check->second);
114 const std::tuple<string, string, string, string> known_type_tuple =
115 make_tuple(
"",
"Strong Copyleft",
"",
"Weak Copyleft");
117 result_check = rule_list.find(known_type_tuple);
119 CPPUNIT_ASSERT_MESSAGE(
"Unable to find tuple with type from YAML",
120 result_check != rule_list.end());
122 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Should find a known type tuple from YAML",
123 known_type_tuple, result_check->first);
124 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Invalid compatibility for type tuple from YAML",
125 false, result_check->second);
127 const std::tuple<string, string, string, string> default_tuple =
128 make_tuple(
"~",
"~",
"~",
"~");
130 result_check = rule_list.find(default_tuple);
132 CPPUNIT_ASSERT_MESSAGE(
"Unable to find default rule from YAML",
133 result_check != rule_list.end());
135 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Should find the default tuple from YAML",
136 default_tuple, result_check->first);
137 CPPUNIT_ASSERT_EQUAL_MESSAGE(
"Invalid compatibility for default tuple from YAML",
138 false, result_check->second);
map< tuple< string, string, string, string >, bool > initialize_rule_list(const string &file_location)
Read YAML file of rules and parse it as map.
std::set< std::string > mainLicenseToSet(const string &mainLicense)
Test helper/utility functions.
void testLicensesToSet()
Test utility function mainLicenseToSet.
int s
The socket that the CLI will use to communicate.
std::ostream & operator<<(std::ostream &os, const std::vector< int > &x)
<< operator overload to appends a vector to an ostream object