11 #include <libfocunit.h>
13 #include "serialize.h"
17 #include "libfocunit.h"
19 Licenses* getNLicensesWithText2(
int count, ...) {
20 GArray* licenseArray = g_array_new(TRUE, FALSE,
sizeof(
License));
22 va_start(texts, count);
23 for (
int i = 0; i < count; i++) {
24 char* text = g_strdup(va_arg(texts,
char*));
27 license.shortname = g_strdup_printf(
"%d-testLic", i);
28 license.tokens = tokenize(text,
"^" );
30 g_array_append_val(licenseArray,
license);
35 return buildLicenseIndexes(licenseArray, 1, 0);
42 out = open_memstream(&ptr, &size);
47 serialize(licenses, out);
50 in = fmemopen(ptr, size,
"r");
51 Licenses* lics = deserialize(in, MIN_ADJACENT_MATCHES, MAX_LEADING_DIFF);
58 void assert_Token(
Token* token1,
Token* token2) {
59 CU_ASSERT_EQUAL(token1->length, token2->length);
60 CU_ASSERT_EQUAL(token1->removedBefore, token2->removedBefore);
61 CU_ASSERT_EQUAL(token1->hashedContent, token2->hashedContent);
65 CU_ASSERT_EQUAL(lic1->refId, lic2->refId);
66 CU_ASSERT_STRING_EQUAL(lic1->shortname, lic2->shortname);
67 CU_ASSERT_EQUAL(lic1->tokens->len, lic2->tokens->len);
69 for (guint i = 0; i < lic1->tokens->len; i++) {
70 Token* tokenFrom1 = tokens_index(lic1->tokens, i);
71 Token* tokenFrom2 = tokens_index(lic2->tokens, i);
73 assert_Token(tokenFrom1, tokenFrom2);
78 CU_ASSERT_EQUAL(lics1->licenses->len, lics2->licenses->len);
80 for (guint i = 0; i < lics1->licenses->len; i++) {
81 License* licFrom1 = license_index(lics1->licenses, i);
82 License* licFrom2 = license_index(lics2->licenses, i);
84 assert_License(licFrom1, licFrom2);
88 void test_roundtrip_one() {
89 Licenses* licenses = getNLicensesWithText2(1,
"a b cde f");
90 Licenses* returnedLicenses = roundtrip(licenses);
92 assert_Licenses(licenses, returnedLicenses);
95 void test_roundtrip() {
96 Licenses* licenses = getNLicensesWithText2(6,
"a^b",
"a^b^c^d",
"d",
"e",
"f",
"e^f^g");
97 Licenses* returnedLicenses = roundtrip(licenses);
99 assert_Licenses(licenses, returnedLicenses);
102 CU_TestInfo serialize_testcases[] = {
103 {
"Test roundtrip with empty:", test_roundtrip_one},
104 {
"Test roundtrip with some licenses with tokens:", test_roundtrip},