<commit_before>#include <unistd.h>
#include <string.h>

#include "cutest.h"
#include "queryablehost.h"
#include "rtgconf.h"
#include "rtgtargets.h"

void mock_set_speed(unsigned int newspeed); // From snmp-mock.cpp

void TestMeasureOneHostsAt10MbpsForTenSeconds(CuTest *tc)
{
        mock_set_speed(1000000 / 8);
        struct rtgconf *conf = rtgconf_create("test/example-rtg.conf");
        struct rtgtargets *hosts = rtgtargets_parse("test/example-targets.cfg", conf);

        char **queries = get_inserts(hosts->hosts[0]);
        unsigned queries_size;
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 0, queries_size); // No inserts first iteration

        sleep(10);

        queries = get_inserts(hosts->hosts[0]);
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 1, queries_size); // One insert next iteration
        char *pos = strstr(queries[0], ", 1250000, 125000)");
        CuAssertPtrNotNull(tc, pos);
        pos = strstr(pos + 1, ", 1250000, 125000)");
        CuAssertPtrNotNull(tc, pos);
}

void TestMeasureOneHostAt100MbpsForOneInterval(CuTest *tc)
{
        mock_set_speed(100000000 / 8);
        struct rtgconf *conf = rtgconf_create("test/example-rtg.conf");
        struct rtgtargets *hosts = rtgtargets_parse("test/example-targets.cfg", conf);

        char **queries = get_inserts(hosts->hosts[0]);
        unsigned queries_size;
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 0, queries_size); // No inserts first iteration

        sleep(conf->interval);

        queries = get_inserts(hosts->hosts[0]);
        for (queries_size = 0; queries[queries_size]; queries_size++);
        CuAssertIntEquals(tc, 0, queries_size); // No inserts next iteration due to too high speed
}

CuSuite *CuGetLongSuite(void)
{
        CuSuite *suite = CuSuiteNew();

        SUITE_ADD_TEST(suite, TestMeasureOneHostsAt10MbpsForTenSeconds);
        SUITE_ADD_TEST(suite, TestMeasureOneHostAt100MbpsForOneInterval);

        return suite;
}
<commit_msg>Test case for lack of rate column.<commit_after>#include <unistd.h>
#include <string.h>

#include "cutest.h"
#include "queryablehost.h"
#include "rtgconf.h"
#include "rtgtargets.h"
#include "globals.h"

void mock_set_speed(unsigned int newspeed); // From snmp-mock.cpp

void TestMeasureOneHostsAt10MbpsForTenSeconds(CuTest *tc)
{
        use_rate_column = 1;

        mock_set_speed(1000000 / 8);
        struct rtgconf *conf = rtgconf_create("test/example-rtg.conf");
        struct rtgtargets *hosts = rtgtargets_parse("test/example-targets.cfg", conf);

        char **queries = get_inserts(hosts->hosts[0]);
        unsigned queries_size;
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 0, queries_size); // No inserts first iteration

        sleep(10);

        queries = get_inserts(hosts->hosts[0]);
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 1, queries_size); // One insert next iteration
        char *pos = strstr(queries[0], "), 1250000, 125000)");
        CuAssertPtrNotNull(tc, pos);
        pos = strstr(pos + 1, "), 1250000, 125000)");
        CuAssertPtrNotNull(tc, pos);
}

void TestMeasureOneHostsAt10MbpsForTenSecondsNoRate(CuTest *tc)
{
        use_rate_column = 0;

        mock_set_speed(1000000 / 8);
        struct rtgconf *conf = rtgconf_create("test/example-rtg.conf");
        struct rtgtargets *hosts = rtgtargets_parse("test/example-targets.cfg", conf);

        char **queries = get_inserts(hosts->hosts[0]);
        unsigned queries_size;
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 0, queries_size); // No inserts first iteration

        sleep(10);

        queries = get_inserts(hosts->hosts[0]);
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 1, queries_size); // One insert next iteration
        char *pos = strstr(queries[0], "), 1250000)");
        CuAssertPtrNotNull(tc, pos);
        pos = strstr(pos + 1, "), 1250000)");
        CuAssertPtrNotNull(tc, pos);
}

void TestMeasureOneHostAt100MbpsForOneInterval(CuTest *tc)
{
        mock_set_speed(100000000 / 8);
        struct rtgconf *conf = rtgconf_create("test/example-rtg.conf");
        struct rtgtargets *hosts = rtgtargets_parse("test/example-targets.cfg", conf);

        char **queries = get_inserts(hosts->hosts[0]);
        unsigned queries_size;
        for (queries_size = 0; queries[queries_size]; queries_size++);

        CuAssertIntEquals(tc, 0, queries_size); // No inserts first iteration

        sleep(conf->interval);

        queries = get_inserts(hosts->hosts[0]);
        for (queries_size = 0; queries[queries_size]; queries_size++);
        CuAssertIntEquals(tc, 0, queries_size); // No inserts next iteration due to too high speed
}

CuSuite *CuGetLongSuite(void)
{
        CuSuite *suite = CuSuiteNew();

        SUITE_ADD_TEST(suite, TestMeasureOneHostsAt10MbpsForTenSeconds);
        SUITE_ADD_TEST(suite, TestMeasureOneHostsAt10MbpsForTenSecondsNoRate);
        SUITE_ADD_TEST(suite, TestMeasureOneHostAt100MbpsForOneInterval);

        return suite;
}

{'fraction_non_alphanumeric': 0.12218468468468469, 'fraction_numerical': 0.03340840840840841, 'mean_word_length': 3.4932546374367623, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '573458', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1710, 'n_words': 352}