<commit_before>/*
 * balde: A microframework for C based on GLib and bad intentions.
 * Copyright (C) 2013-2014 <NAME> <<EMAIL>>
 *
 * This program can be distributed under the terms of the LGPL-2 License.
 * See the file COPYING.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */

#include <glib.h>
#include <balde/utils-private.h>


void
test_base64_encode(void)
{
    gchar *t = balde_base64_encode((const guchar*) "\xd3V\xbeo\xf7\x1d", 6);
    g_assert_cmpstr(t, ==, "01a-b_cd");
    g_free(t);
}


void
test_base64_decode(void)
{
    gsize len;
    guchar *t = balde_base64_decode("01a-b_cd", &len);
    gchar *v = g_strndup((const gchar*) t, len);
    g_assert(len == 6);
    g_assert_cmpstr((gchar*) v, ==, "\xd3V\xbeo\xf7\x1d");
    g_free(v);
    g_free(t);
}


void
test_timestamp(void)
{
    g_assert(balde_timestamp() == 100000);
}


void
test_encoded_timestamp(void)
{
    gchar *now = balde_encoded_timestamp();
    g_assert_cmpstr(now, ==, "MTAwMDAw");
    g_free(now);
}


void
test_validate_timestamp(void)
{
    // token generated at 99950, "now" is 100000.
    g_assert(balde_validate_timestamp("OTk5NTA=", 100));
    g_assert(balde_validate_timestamp("OTk5NTA=", 50));
    g_assert(!balde_validate_timestamp("OTk5NTA=", 40));

    // guda
    g_assert(!balde_validate_timestamp("Z3VkYQ==", 100));
}


void
test_constant_time_compare(void)
{
    g_assert(balde_constant_time_compare("bola", "bola"));
    g_assert(!balde_constant_time_compare("bola", "guda"));
    g_assert(!balde_constant_time_compare("guda", "gude"));
    g_assert(balde_constant_time_compare("\xd3V\xbeo\xf7\x1d", "\xd3V\xbeo\xf7\x1d"));
    g_assert(balde_constant_time_compare("ação", "ação"));
    g_assert(!balde_constant_time_compare("ação", "açã"));
}


int<commit_msg>added missing test<commit_after>/*
 * balde: A microframework for C based on GLib and bad intentions.
 * Copyright (C) 2013-2014 <NAME> <<EMAIL>>
 *
 * This program can be distributed under the terms of the LGPL-2 License.
 * See the file COPYING.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */

#include <glib.h>
#include <balde/utils-private.h>


void
test_base64_encode(void)
{
    gchar *t = balde_base64_encode((const guchar*) "\xd3V\xbeo\xf7\x1d", 6);
    g_assert_cmpstr(t, ==, "01a-b_cd");
    g_free(t);
}


void
test_base64_decode(void)
{
    gsize len;
    guchar *t = balde_base64_decode("01a-b_cd", &len);
    gchar *v = g_strndup((const gchar*) t, len);
    g_assert(len == 6);
    g_assert_cmpstr((gchar*) v, ==, "\xd3V\xbeo\xf7\x1d");
    g_free(v);
    g_free(t);
}


void
test_timestamp(void)
{
    g_assert(balde_timestamp() == 100000);
}


void
test_encoded_timestamp(void)
{
    gchar *now = balde_encoded_timestamp();
    g_assert_cmpstr(now, ==, "MTAwMDAw");
    g_free(now);
}


void
test_validate_timestamp(void)
{
    // token generated at <PASSWORD>, "now" is 100000.
    g_assert(balde_validate_timestamp("OTk5NTA=", 100));
    g_assert(balde_validate_timestamp("OTk5NTA=", 50));
    g_assert(!balde_validate_timestamp("OTk5NTA=", 40));

    // guda
    g_assert(!balde_validate_timestamp("Z3VkYQ==", 100));
}


void
test_constant_time_compare(void)
{
    g_assert(balde_constant_time_compare("bola", "bola"));
    g_assert(!balde_constant_time_compare("bola", "guda"));
    g_assert(!balde_constant_time_compare("guda", "gude"));
    g_assert(balde_constant_time_compare("\xd3V\xbeo\xf7\x1d",
        "\xd3V\xbeo\xf7\x1d"));
    g_assert(!balde_constant_time_compare("\xd3V\xbeo\xf7\x1d",
        "\xd3V\xbe\xf7\x1d"));
    g_assert(balde_constant_time_compare("ação", "ação"));
    g_assert(!balde_constant_time_compare("ação", "açã"));
}


int
{'fraction_non_alphanumeric': 0.16137781394087333, 'fraction_numerical': 0.03607268782207757, 'mean_word_length': 4.579425113464448, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2443179', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1490, 'n_words': 243}