Imported Upstream version 3.4
[platform/upstream/ccache.git] / unittest / test_stats.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 // This file contains tests for statistics handling.
18
19 #include "../src/ccache.h"
20 #include "../src/counters.h"
21 #include "framework.h"
22 #include "util.h"
23
24 TEST_SUITE(stats)
25
26 TEST(forward_compatibility)
27 {
28         unsigned i;
29         FILE *f;
30         struct counters *counters = counters_init(0);
31
32         f = fopen("stats", "w");
33         for (i = 0; i < 100; i++) {
34                 fprintf(f, "%u\n", i);
35         }
36         fclose(f);
37
38         stats_read("stats", counters);
39         CHECK_INT_EQ(100, counters->size);
40         CHECK_INT_EQ(73, counters->data[73]);
41
42         stats_write("stats", counters);
43         CHECK_INT_EQ(100, counters->size);
44         CHECK_INT_EQ(99, counters->data[99]);
45
46         counters_free(counters);
47 }
48
49 TEST_SUITE_END