Skip to content

Commit

Permalink
Add a "mangled strings" test for SPDX classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
suve committed May 30, 2023
1 parent 1058e65 commit 26b482c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
65 changes: 65 additions & 0 deletions test/classifier-spdx.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,71 @@ void test__spdxStrict_caseSensitivity(void **state) {
}
}

// Test some strings that don't really make sense.
void test__spdxStrict_mangledStrings(void **state) {
struct LicenceClassifier *classifier = ((struct TestState*)*state)->spdxStrictClassifier;

// Valid licence string, but with extra parentheses
{
struct LicenceTreeNode *expected;
make_ltn_simple(expected, 1, "Good");
test_licence("(Good)", expected);
}
// Gimme more!
{
struct LicenceTreeNode *expected;
make_ltn_simple(expected, 1, "Good");
test_licence("(((Good)))", expected);
}

// WITH operator present, but no licensing exception (string ends)
{
struct LicenceTreeNode *expected;
make_ltn_simple(expected, 0, "Empty Licensing Exception String WITH ");
test_licence("(Empty Licensing Exception String WITH )", expected);
}
// WITH operator present, but no license
{
struct LicenceTreeNode *expected;
make_ltn_simple(expected, 0, " WITH Lol Where's The Licence");
test_licence("( WITH Lol Where's The Licence)", expected);
}

// AND joiner present, but no licence preceding it
{
struct LicenceTreeNode *left, *right, *expected;
make_ltn_simple(left, 0, "");
make_ltn_simple(right, 0, "Stuff");
make_ltn(expected, 0, LTNT_AND, left, right);
test_licence("( AND Stuff)", expected);
}
// AND joiner present, but no licence after it
{
struct LicenceTreeNode *left, *right, *expected;
make_ltn_simple(left, 0, "Other Stuff");
make_ltn_simple(right, 0, "");
make_ltn(expected, 0, LTNT_AND, left, right);
test_licence("(Other Stuff AND )", NULL);
}

// OR joiner present, but no licence preceding it
{
struct LicenceTreeNode *left, *right, *expected;
make_ltn_simple(left, 0, "");
make_ltn_simple(right, 0, "Things");
make_ltn(expected, 0, LTNT_OR, left, right);
test_licence("( OR Things)", NULL);
}
// OR joiner present, but no licence after it
{
struct LicenceTreeNode *left, *right, *expected;
make_ltn_simple(left, 0, "More Things");
make_ltn_simple(right, 0, "");
make_ltn(expected, 0, LTNT_OR, left, right);
test_licence("(More Things OR )", NULL);
}
}

// Test behaviour specific to SPDX classifier's lenient mode.
void test__spdxLenient(void **state) {
struct LicenceClassifier *classifier = ((struct TestState*)*state)->spdxLenientClassifier;
Expand Down
1 change: 1 addition & 0 deletions test/licences.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern void test__spdxStrict_tree(void **state);
extern void test__spdxStrict_precedence(void **state);
extern void test__spdxStrict_whitespace(void **state);
extern void test__spdxStrict_caseSensitivity(void **state);
extern void test__spdxStrict_mangledStrings(void **state);

extern void test__spdxLenient(void **state);

Expand Down
1 change: 1 addition & 0 deletions test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ int main(void) {
cmocka_unit_test(test__spdxStrict_precedence),
cmocka_unit_test(test__spdxStrict_whitespace),
cmocka_unit_test(test__spdxStrict_caseSensitivity),
cmocka_unit_test(test__spdxStrict_mangledStrings),
cmocka_unit_test(test__spdxLenient),
};
failures += cmocka_run_group_tests(licence_tests, test_setup__licences, test_teardown__licences);
Expand Down

0 comments on commit 26b482c

Please sign in to comment.