<commit_before>
// Copyright (c) 2008-2010, Regents of the University of Colorado.
// This work was supported by NASA contracts NNJ05HE10G, NNC06CB40C, and
// NNC07CB47C.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#include <check.h>

#include "cal-event.h"

#include "check-common.h"
#include "check-cal.h"




START_TEST (test_cal_event_free_NULL) {
    cal_event_free(NULL);
} END_TEST




START_TEST (test_cal_event_free_empty) {
    cal_event_t *e;

    e = cal_event_new(CAL_EVENT_JOIN);
    fail_if(e == NULL, "failed to create a Join event");
    cal_event_free(e);
} END_TEST




START_TEST (test_cal_event_is_valid_None) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_NONE);
    fail_if(e == NULL, "failed to create a None event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a None event was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Subscribe_without_peer) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_SUBSCRIBE);
    fail_if(e == NULL, "failed to create a Subscribe event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Subscribe event without a peer was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Subscribe_with_peer_but_no_topic) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_SUBSCRIBE);
    fail_if(e == NULL, "failed to create a Subscribe event");

    e->peer_name = "dummy-peer";

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Subscribe event with a peer but without a topic was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Unsubscribe_without_peer) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_UNSUBSCRIBE);
    fail_if(e == NULL, "failed to create an Unsubscribe event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, an Unsubscribe event without a peer was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Unsubscribe_with_peer_but_no_topic) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_UNSUBSCRIBE);
    fail_if(e == NULL, "failed to create an Unsubscribe event");

    e->peer_name = "dummy-peer";

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, an Unsubscribe event with a peer but no topic was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Publish_with_no_peer_and_invalid_topic) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_PUBLISH);
    fail_if(e == NULL, "failed to create a Publish event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Publish event with NULL peer and with an invalid topic was accepted as valid");
} END_TEST




void cal_event_test_suite(Suite *s)
{
    TCase *tc = tcase_create("cal event test suite");
    suite_add_tcase(s, tc);

    tcase_add_test(tc, test_cal_event_free_NULL);
    tcase_add_test(tc, test_cal_event_free_empty);

    tcase_add_test(tc, test_cal_event_is_valid_None);

    tcase_add_test(tc, test_cal_event_is_valid_Subscribe_without_peer);
    tcase_add_test(tc, test_cal_event_is_valid_Subscribe_with_peer_but_no_topic);

    tcase_add_test(tc, test_cal_event_is_valid_Unsubscribe_without_peer);
    tcase_add_test(tc, test_cal_event_is_valid_Unsubscribe_with_peer_but_no_topic);

    tcase_add_test(tc, test_cal_event_is_valid_Publish_with_no_peer_and_invalid_topic);

    return;
} 


// vim: ts=8 sw=4 sta expandtab
// Emacs cruft
// Local Variables:
// mode: C
// c-file-style: "Stroustrup"
// indent-tabs-mode: nil<commit_msg>add a cal-event unit test<commit_after>
// Copyright (c) 2008-2010, Regents of the University of Colorado.
// This work was supported by NASA contracts NNJ05HE10G, NNC06CB40C, and
// NNC07CB47C.

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>

#include <check.h>

#include "cal-event.h"

#include "check-common.h"
#include "check-cal.h"




START_TEST (test_cal_event_free_NULL) {
    cal_event_free(NULL);
} END_TEST




START_TEST (test_cal_event_free_empty) {
    cal_event_t *e;

    e = cal_event_new(CAL_EVENT_JOIN);
    fail_if(e == NULL, "failed to create a Join event");
    cal_event_free(e);
} END_TEST




START_TEST (test_cal_event_is_valid_None) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_NONE);
    fail_if(e == NULL, "failed to create a None event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a None event was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Subscribe_without_peer) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_SUBSCRIBE);
    fail_if(e == NULL, "failed to create a Subscribe event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Subscribe event without a peer was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Subscribe_with_peer_but_no_topic) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_SUBSCRIBE);
    fail_if(e == NULL, "failed to create a Subscribe event");

    e->peer_name = "dummy-peer";

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Subscribe event with a peer but without a topic was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Unsubscribe_without_peer) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_UNSUBSCRIBE);
    fail_if(e == NULL, "failed to create an Unsubscribe event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, an Unsubscribe event without a peer was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Unsubscribe_with_peer_but_no_topic) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_UNSUBSCRIBE);
    fail_if(e == NULL, "failed to create an Unsubscribe event");

    e->peer_name = "dummy-peer";

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, an Unsubscribe event with a peer but no topic was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Publish_with_no_peer_and_no_topic) {
    cal_event_t *e;
    int r;

    e = cal_event_new(CAL_EVENT_PUBLISH);
    fail_if(e == NULL, "failed to create a Publish event");

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Publish event with NULL peer and with an invalid topic was accepted as valid");
} END_TEST




START_TEST (test_cal_event_is_valid_Publish_with_peer_but_invalid_topic) {
    cal_event_t *e;
    int r;
    char invalid_topic[] = { 'H', 'i', 0xff, 0x01 };

    e = cal_event_new(CAL_EVENT_PUBLISH);
    fail_if(e == NULL, "failed to create a Publish event");

    e->peer_name = "dummy-peer";
    e->topic = invalid_topic;

    r = cal_event_is_valid(e);
    fail_if(r != 0, "oh no, a Publish event with a peer but invalid topic was accepted as valid");
} END_TEST




void cal_event_test_suite(Suite *s)
{
    TCase *tc = tcase_create("cal event test suite");
    suite_add_tcase(s, tc);

    tcase_add_test(tc, test_cal_event_free_NULL);
    tcase_add_test(tc, test_cal_event_free_empty);

    tcase_add_test(tc, test_cal_event_is_valid_None);

    tcase_add_test(tc, test_cal_event_is_valid_Subscribe_without_peer);
    tcase_add_test(tc, test_cal_event_is_valid_Subscribe_with_peer_but_no_topic);

    tcase_add_test(tc, test_cal_event_is_valid_Unsubscribe_without_peer);
    tcase_add_test(tc, test_cal_event_is_valid_Unsubscribe_with_peer_but_no_topic);

    tcase_add_test(tc, test_cal_event_is_valid_Publish_with_no_peer_and_no_topic);
    tcase_add_test(tc, test_cal_event_is_valid_Publish_with_peer_but_invalid_topic);

    return;
} 


// vim: ts=8 sw=4 sta expandtab
// Emacs cruft
// Local Variables:
// mode: C
// c-file-style: "Stroustrup"
// indent-tabs-mode: nil
{'fraction_non_alphanumeric': 0.10091743119266056, 'fraction_numerical': 0.007882155317224448, 'mean_word_length': 4.2051109616677875, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '3486699', 'n_tokens_mistral': 3085, 'n_tokens_neox': 2932, 'n_words': 673}