21 #include <libfocunit.h> 23 #include "serialize.h" 27 #include "libfocunit.h" 29 Licenses* getNLicensesWithText2(
int count, ...) {
30 GArray* licenseArray = g_array_new(TRUE, FALSE,
sizeof(
License));
32 va_start(texts, count);
33 for (
int i = 0; i < count; i++) {
34 char* text = g_strdup(va_arg(texts,
char*));
37 license.shortname = g_strdup_printf(
"%d-testLic", i);
38 license.tokens = tokenize(text,
"^" );
40 g_array_append_val(licenseArray, license);
45 return buildLicenseIndexes(licenseArray, 1, 0);
52 out = open_memstream(&ptr, &size);
57 serialize(licenses, out);
60 in = fmemopen(ptr, size,
"r");
61 Licenses* lics = deserialize(in, MIN_ADJACENT_MATCHES, MAX_LEADING_DIFF);
68 void assert_Token(
Token* token1,
Token* token2) {
69 CU_ASSERT_EQUAL(token1->length, token2->length);
70 CU_ASSERT_EQUAL(token1->removedBefore, token2->removedBefore);
71 CU_ASSERT_EQUAL(token1->hashedContent, token2->hashedContent);
75 CU_ASSERT_EQUAL(lic1->refId, lic2->refId);
76 CU_ASSERT_STRING_EQUAL(lic1->shortname, lic2->shortname);
77 CU_ASSERT_EQUAL(lic1->tokens->len, lic2->tokens->len);
79 for (guint i = 0; i < lic1->tokens->len; i++) {
80 Token* tokenFrom1 = tokens_index(lic1->tokens, i);
81 Token* tokenFrom2 = tokens_index(lic2->tokens, i);
83 assert_Token(tokenFrom1, tokenFrom2);
88 CU_ASSERT_EQUAL(lics1->licenses->len, lics2->licenses->len);
90 for (guint i = 0; i < lics1->licenses->len; i++) {
91 License* licFrom1 = license_index(lics1->licenses, i);
92 License* licFrom2 = license_index(lics2->licenses, i);
94 assert_License(licFrom1, licFrom2);
98 void test_roundtrip_one() {
99 Licenses* licenses = getNLicensesWithText2(1,
"a b cde f");
100 Licenses* returnedLicenses = roundtrip(licenses);
102 assert_Licenses(licenses, returnedLicenses);
105 void test_roundtrip() {
106 Licenses* licenses = getNLicensesWithText2(6,
"a^b",
"a^b^c^d",
"d",
"e",
"f",
"e^f^g");
107 Licenses* returnedLicenses = roundtrip(licenses);
109 assert_Licenses(licenses, returnedLicenses);
112 CU_TestInfo serialize_testcases[] = {
113 {
"Test roundtrip with empty:", test_roundtrip_one},
114 {
"Test roundtrip with some licenses with tokens:", test_roundtrip},