FOSSology  4.4.0
Open Source License Compliance by Open Source Software
test_compatibility.cc
Go to the documentation of this file.
1 /*
2  SPDX-FileCopyrightText: © 2024 Siemens AG
3 
4  SPDX-License-Identifier: GPL-2.0-only
5 */
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 
13 #include "CompatibilityUtils.hpp"
14 
15 using namespace std;
16 
21 class TestCompatibility : public CPPUNIT_NS::TestFixture
22 {
23  CPPUNIT_TEST_SUITE(TestCompatibility);
24  CPPUNIT_TEST(test_license_compatible);
25  CPPUNIT_TEST_SUITE_END();
26 protected:
27  void test_license_compatible();
28 } ;
29 
44 {
45  const auto test_rule_list = initialize_rule_list(
46  TESTDATADIR "/comp-rules-test.yaml");
47 
48  CPPUNIT_ASSERT_EQUAL_MESSAGE("Permissive licenses should be compatible",
49  true, are_licenses_compatible("MIT", "Permissive", "BSD-3-Clause",
50  "Permissive", test_rule_list));
51 
52  CPPUNIT_ASSERT_EQUAL_MESSAGE("Strong copyleft and weak copyleft licenses "
53  "should not be compatible", false,
54  are_licenses_compatible("Sleepycat", "Strong Copyleft", "Apache-2.0",
55  "Weak Copyleft", test_rule_list));
56 
57  CPPUNIT_ASSERT_EQUAL_MESSAGE("GPL and Apache should not be compatible "
58  "explicitly even with wrong types", false,
59  are_licenses_compatible("GPL-2.0-only", "Permissive", "Apache-2.0",
60  "Permissive", test_rule_list));
61 
62  CPPUNIT_ASSERT_EQUAL_MESSAGE("GPL and MIT should be compatible explicitly",
63  true, are_licenses_compatible("GPL-2.0-only", "Strong Copyleft", "MIT",
64  "Permissive", test_rule_list));
65 
66  CPPUNIT_ASSERT_EQUAL_MESSAGE("Sleepycat and MIT should not be compatible",
67  false, are_licenses_compatible("Sleepycat", "Strong Copyleft", "MIT",
68  "Permissive", test_rule_list));
69 
70  CPPUNIT_ASSERT_EQUAL_MESSAGE("License name and type in reverse order should "
71  "be compatible", true,
72  are_licenses_compatible("BSD-3-Clause", "Permissive", "GPL-2.0-only",
73  "Do Not Care", test_rule_list));
74 
75  CPPUNIT_ASSERT_EQUAL_MESSAGE("default rule should be false",
76  false, are_licenses_compatible("Custom license", "My Type",
77  "What license?", "Another type", test_rule_list));
78 }
79 
80 CPPUNIT_TEST_SUITE_REGISTRATION( TestCompatibility );
map< tuple< string, string, string, string >, bool > initialize_rule_list(const string &file_location)
Read YAML file of rules and parse it as map.
bool are_licenses_compatible(const string &first_name, const string &first_type, const string &second_name, const string &second_type, const map< tuple< string, string, string, string >, bool > &rule_list)
Check the licenses against rules and get the compatibility result.
Test compatibility functions.
void test_license_compatible()
Test are_licenses_compatible()