summaryrefslogtreecommitdiff
path: root/src/tests/eina_test_counter.c
blob: 2a3f30ddee388d26c989b94ca93a9986b4900632 (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
/* EINA - EFL data type library
 * Copyright (C) 2008 Cedric Bail
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library;
 * if not, see <http://www.gnu.org/licenses/>.
 */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>

#include "eina_suite.h"
#include "Eina.h"
#include "eina_safety_checks.h"

START_TEST(eina_counter_simple)
{
   Eina_Counter *cnt;
   char *dump;
   int i;

   eina_init();

   cnt = eina_counter_new("eina_test");
   fail_if(!cnt);

   eina_counter_start(cnt);

   for (i = 0; i < 100000; ++i)
     {
        void *tmp = malloc(sizeof(long int));
        free(tmp);
     }

   eina_counter_stop(cnt, i);

   eina_counter_start(cnt);

   for (i = 0; i < 200000; ++i)
     {
        void *tmp = malloc(sizeof(long int));
        free(tmp);
     }

   eina_counter_stop(cnt, i);

   dump = eina_counter_dump(cnt);
   fail_if(!dump);

   fprintf(stderr, "%s", dump);

   free(dump);

   eina_counter_free(cnt);

   eina_shutdown();
}
END_TEST

START_TEST(eina_counter_break)
{
   Eina_Counter *cnt;

   eina_init();

   cnt = eina_counter_new("eina_test");
   fail_if(!cnt);

   eina_counter_stop(cnt, 10);

   eina_counter_free(cnt);

#ifdef EINA_SAFETY_CHECKS
   {
      char *dump;

      fprintf(stderr, "you should have a safety check failure below:\n");
      dump = eina_counter_dump(NULL);
      fail_if(dump);
      fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED);
      free(dump);
   }
#endif

   eina_shutdown();
}
END_TEST

void eina_test_counter(TCase *tc)
{
   tcase_add_test(tc, eina_counter_simple);
   tcase_add_test(tc, eina_counter_break);
}