fishlim: Minor test improvements

- Don't have tests repeat themselves, meson has a `--repeat` flag
- Fix a minor leak of a GRand
- Speed up a test
- Increase timeout

This still needs a lot of improvements, it runs at lot of loops within
loops generating random strings that could be optimized. This means
it can take a very long time on some computers.

Closes #2629
This commit is contained in:
Patrick Griffis 2021-11-03 09:59:24 -05:00
parent b54593e752
commit 4f3ef3505a
2 changed files with 31 additions and 35 deletions

View File

@ -12,4 +12,5 @@ fishlim_tests = executable('fishlim_tests', fishlim_test_sources,
test('Fishlim Tests', fishlim_tests,
protocol: 'tap',
timeout: 600,
)

View File

@ -129,17 +129,17 @@ static void
test_base64_len (void)
{
char *b64 = NULL;
int i, message_len = 0;
char message[1000];
int message_end = sizeof (message) - 1;
for (i = 0; i < 10; ++i) {
for (message_len = 1; message_len < 1000; ++message_len) {
random_string(message, message_len);
b64 = g_base64_encode((const unsigned char *) message, message_len);
g_assert_nonnull(b64);
g_assert_cmpuint(strlen(b64), == , base64_len(message_len));
g_free(b64);
}
random_string(message, message_end);
for (; message_end >= 0; --message_end) {
message[message_end] = '\0'; /* Truncate instead of generating new strings */
b64 = g_base64_encode((const unsigned char *) message, message_end);
g_assert_nonnull(b64);
g_assert_cmpuint(strlen(b64), == , base64_len(message_end));
g_free(b64);
}
}
@ -150,18 +150,15 @@ static void
test_base64_fish_len (void)
{
char *b64 = NULL;
int i, message_len = 0;
int message_len = 0;
char message[1000];
for (i = 0; i < 10; ++i) {
for (message_len = 1; message_len < 1000; ++message_len) {
random_string(message, message_len);
b64 = fish_base64_encode(message, message_len);
g_assert_nonnull(b64);
g_assert_cmpuint(strlen(b64), == , base64_fish_len(message_len));
g_free(b64);
}
for (message_len = 1; message_len < 1000; ++message_len) {
random_string(message, message_len);
b64 = fish_base64_encode(message, message_len);
g_assert_nonnull(b64);
g_assert_cmpuint(strlen(b64), == , base64_fish_len(message_len));
g_free(b64);
}
}
@ -242,30 +239,28 @@ test_foreach_utf8_data_chunks(void)
{
GRand *rand = NULL;
GString *chunks = NULL;
int tests, max_chunks_len, chunks_len;
int max_chunks_len, chunks_len;
char ascii_message[1001];
char *data_chunk = NULL;
rand = g_rand_new();
max_chunks_len = g_rand_int_range(rand, 2, 301);
random_string(ascii_message, 1000);
for (tests = 0; tests < 1000; ++tests) {
data_chunk = ascii_message;
max_chunks_len = g_rand_int_range(rand, 2, 301);
random_string(ascii_message, 1000);
chunks = g_string_new(NULL);
data_chunk = ascii_message;
chunks = g_string_new(NULL);
while (foreach_utf8_data_chunks(data_chunk, max_chunks_len, &chunks_len)) {
g_string_append(chunks, g_strndup(data_chunk, chunks_len));
/* Next chunk */
data_chunk += chunks_len;
}
/* Check data loss */
g_assert_cmpstr(chunks->str, == , ascii_message);
g_string_free(chunks, TRUE);
while (foreach_utf8_data_chunks(data_chunk, max_chunks_len, &chunks_len)) {
g_string_append(chunks, g_strndup(data_chunk, chunks_len));
/* Next chunk */
data_chunk += chunks_len;
}
/* Check data loss */
g_assert_cmpstr(chunks->str, == , ascii_message);
g_string_free(chunks, TRUE);
g_rand_free (rand);
}
int