Imported Upstream version 3.4
[platform/upstream/ccache.git] / unittest / test_counters.c
1 // Copyright (C) 2010-2018 Joel Rosdahl
2 //
3 // This program is free software; you can redistribute it and/or modify it
4 // under the terms of the GNU General Public License as published by the Free
5 // Software Foundation; either version 3 of the License, or (at your option)
6 // any later version.
7 //
8 // This program is distributed in the hope that it will be useful, but WITHOUT
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 // more details.
12 //
13 // You should have received a copy of the GNU General Public License along with
14 // this program; if not, write to the Free Software Foundation, Inc., 51
15 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17 #include "../src/ccache.h"
18 #include "../src/counters.h"
19 #include "framework.h"
20 #include "util.h"
21
22 TEST_SUITE(counters)
23
24 TEST(counters_init_0_should_allocate_0)
25 {
26         struct counters *counters = counters_init(0);
27
28         CHECK_INT_EQ(0, counters->allocated);
29         CHECK_INT_EQ(0, counters->size);
30
31         counters_free(counters);
32 }
33
34 TEST(counters_init_7_should_allocate_32)
35 {
36         int i;
37         struct counters *counters = counters_init(7);
38
39         CHECK_INT_EQ(32, counters->allocated);
40         CHECK_INT_EQ(7, counters->size);
41         for (i = 0; i < 7; i++) {
42                 CHECK_INT_EQ(0, counters->data[i]);
43         }
44
45         counters_free(counters);
46 }
47
48 TEST(counters_resize_50_should_allocate_96)
49 {
50         struct counters *counters = counters_init(0);
51
52         CHECK_INT_EQ(0, counters->allocated);
53         counters_resize(counters, 50);
54         CHECK_INT_EQ(50, counters->size);
55         CHECK_INT_EQ(96, counters->allocated);
56
57         counters_free(counters);
58 }
59
60 TEST_SUITE_END