summaryrefslogtreecommitdiffstats
path: root/src/test/test_decoder.c
blob: 22295125891dd854d3610e927ebee222421ab8a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <dnswire/decoder.h>

#include <assert.h>

#include "create_dnstap.c"

int main(void)
{
    uint8_t                buf[1];
    struct dnswire_decoder d = DNSWIRE_DECODER_INITIALIZER;

    // decoder * need more
    d.state = dnswire_decoder_reading_control;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);
    d.state = dnswire_decoder_checking_ready;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);
    d.state = dnswire_decoder_checking_accept;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);
    d.state = dnswire_decoder_reading_start;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);
    d.state = dnswire_decoder_checking_start;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);
    d.state = dnswire_decoder_reading_frames;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);
    d.state = dnswire_decoder_checking_finish;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_need_more);

    // decoder done
    d.state = dnswire_decoder_done;
    assert(dnswire_decoder_decode(&d, buf, 1) == dnswire_error);

    return 0;
}