summaryrefslogtreecommitdiff
path: root/cesar/ce/tx/test/src/test_tm.c
blob: 07cdd3a1854ff3c1c649657615cd1832f3713be3 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/* Cesar project {{{
 *
 * Copyright (C) 2009 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    ce/tx/test/src/test_tm.c
 * \brief   Test function for tone maps cleaning.
 * \ingroup test
 */

#include "common/std.h"
#include "ce/tx/inc/tx.h"
#include "lib/test.h"
#include "lib/blk.h"
#include "mac/common/tonemap.h"
#include "mac/common/interval.h"
#include "cp/inc/context.h"

void
ce_test_tm_clean (test_t t)
{
    cp_t cp_ctx;
    tonemap_release_list_init (&cp_ctx.ce_tx.tonemap_release_list);
    tonemaps_t *tms = tonemaps_alloc ();
    test_begin (t, "Check if a tonemaps_t is cleaned ")
    {
        uint version;
        uint nb;
        uint i;

        for (i = 0; i < 4; i++)
        {
            version = 42;
            nb = 0;
            bool cleaned;

            /* Configure default tmi for deferent cases. */
            switch (i)
            {
                case 0:
                    tms->default_tmi = TONEMAP_INDEX_INITIAL_START;
                    cleaned = true;
                    break;
                case 1:
                    tms->default_tmi = TONEMAP_INDEX_INITIAL_ERROR;
                    cleaned = true;
                    break;
                case 2:
                    tms->default_tmi = TONEMAP_INDEX_INITIAL_SOUND_COMPLETE;
                    cleaned = true;
                    break;
                case 3:
                    tms->default_tmi = TONEMAP_INDEX_NEGOTIATED_FIRST;
                    cleaned = false;
                    break;
                default:
                    dbg_assert_default ();
                    break;
            }

            /* Makes some changes and commit. */
            nb++;
            test_fail_if (mac_interval_append (tms, nb, nb) == 0);
            nb++;
            test_fail_if (mac_interval_append (tms, nb, nb) == 0);
            nb++;
            test_fail_if (mac_interval_append (tms, nb, nb) == 0);
            mac_interval_commit_changes (tms, 0);

            /* Set version. */
            tms->intervals->version = version;

            /* Interval nb should not be 0. */
            test_fail_if (tms->intervals->intervals_nb != nb);

            /* Tests tone maps cleaning. */
            test_fail_if (ce_tx_clean_tonemaps (&cp_ctx, tms) != cleaned);

            if (tms->default_tmi == TONEMAP_INDEX_NEGOTIATED_FIRST)
            {
                /* Check that the interval number is not reset. */ 
                test_fail_if (tms->intervals->intervals_nb == 0);
                /* Check that the version number has not been increased. */
                test_fail_if (tms->intervals->version != version);
            }
            else
            {
                /* Check that interval number is reset. */
                test_fail_if (tms->intervals->intervals_nb != 0);
                /* Check that the version number increased. */
                test_fail_if (tms->intervals->version != version + 1);
            }
        }
    } test_end;
    /* Clean. */
    tonemaps_release (tms);
    while (!tonemap_release_list_clean (&cp_ctx.ce_tx.tonemap_release_list))
        ;
}

int
main (int argc, char **argv)
{
    test_t t;
    test_init (t, argc, argv);

    ce_test_tm_clean (t);

    test_begin (t, "memory")
    {
        test_fail_unless (blk_check_memory ());
    } test_end;

    test_result (t);
    return test_nb_failed (t) == 0 ? 0 : 1;
}