Coverage Report

Created: 2024-01-26 01:52

/work/auto_tests/typing_test.c
Line
Count
Source
1
/* Tests that our typing notifications work.
2
 */
3
4
#include <stdio.h>
5
#include <stdlib.h>
6
#include <time.h>
7
8
#include "../testing/misc_tools.h"
9
#include "../toxcore/ccompat.h"
10
#include "../toxcore/tox.h"
11
#include "../toxcore/util.h"
12
#include "check_compat.h"
13
14
typedef struct State {
15
    bool friend_is_typing;
16
} State;
17
18
#include "auto_test_support.h"
19
20
static void typing_callback(Tox *m, const Tox_Event_Friend_Typing *event, void *user_data)
21
10
{
22
10
    const AutoTox *autotox = (AutoTox *)user_data;
23
10
    State *state = (State *)autotox->state;
24
25
    //const uint32_t friend_number = tox_event_friend_typing_get_friend_number(event);
26
10
    const bool typing = tox_event_friend_typing_get_typing(event);
27
28
10
    state->friend_is_typing = typing;
29
10
}
30
31
static void test_typing(AutoTox *autotoxes)
32
13
{
33
13
    time_t cur_time = time(nullptr);
34
35
13
    tox_events_callback_friend_typing(autotoxes[1].dispatch, &typing_callback);
36
13
    tox_self_set_typing(autotoxes[0].tox, 0, true, nullptr);
37
38
42
    do {
39
42
        iterate_all_wait(autotoxes, 2, 200);
40
42
    } while (!((State *)autotoxes[1].state)->friend_is_typing);
41
42
13
    ck_assert_msg(tox_friend_get_typing(autotoxes[1].tox, 0, nullptr) == 1,
43
13
                  "tox_friend_get_typing should have returned true, but it didn't");
44
13
    tox_self_set_typing(autotoxes[0].tox, 0, false, nullptr);
45
46
20
    do {
47
20
        iterate_all_wait(autotoxes, 2, 200);
48
20
    } while (((State *)autotoxes[1].state)->friend_is_typing);
49
50
13
    Tox_Err_Friend_Query err_t;
51
13
    ck_assert_msg(tox_friend_get_typing(autotoxes[1].tox, 0, &err_t) == 0,
52
13
                  "tox_friend_get_typing should have returned false, but it didn't");
53
13
    ck_assert_msg(err_t == TOX_ERR_FRIEND_QUERY_OK, "tox_friend_get_typing call did not return correct error");
54
55
13
    printf("test_typing succeeded, took %lu seconds\n", (unsigned long)(time(nullptr) - cur_time));
56
13
}
57
58
int main(void)
59
721
{
60
721
    setvbuf(stdout, nullptr, _IONBF, 0);
61
62
721
    Run_Auto_Options options = default_run_auto_options();
63
721
    options.graph = GRAPH_LINEAR;
64
721
    run_auto_test(nullptr, 2, test_typing, sizeof(State), &options);
65
66
721
    return 0;
67
721
}