diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/tests/eina_test_magic.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_test_magic.c b/libraries/eina/src/tests/eina_test_magic.c new file mode 100644 index 0000000..d2c3d49 --- /dev/null +++ b/libraries/eina/src/tests/eina_test_magic.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* EINA - EFL data type library | ||
2 | * Copyright (C) 2008 Cedric Bail | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * This library is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with this library; | ||
16 | * if not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #ifdef HAVE_CONFIG_H | ||
20 | # include "config.h" | ||
21 | #endif | ||
22 | |||
23 | #include <stdlib.h> | ||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | |||
27 | #define EINA_MAGIC_DEBUG | ||
28 | |||
29 | #include "eina_suite.h" | ||
30 | #include "Eina.h" | ||
31 | #include "eina_safety_checks.h" | ||
32 | |||
33 | #define EINA_MAGIC_TEST 0x7781fee7 | ||
34 | #define EINA_MAGIC_TEST2 0x42241664 | ||
35 | #define EINA_MAGIC_STRING "Eina Magic Test" | ||
36 | |||
37 | typedef struct _Eina_Magic_Struct Eina_Magic_Struct; | ||
38 | struct _Eina_Magic_Struct | ||
39 | { | ||
40 | EINA_MAGIC | ||
41 | }; | ||
42 | |||
43 | START_TEST(eina_magic_simple) | ||
44 | { | ||
45 | Eina_Magic_Struct *ems = NULL; | ||
46 | |||
47 | eina_init(); | ||
48 | |||
49 | eina_magic_string_set(EINA_MAGIC_TEST, EINA_MAGIC_STRING); | ||
50 | |||
51 | #ifdef EINA_SAFETY_CHECKS | ||
52 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
53 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); | ||
54 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
55 | |||
56 | fprintf(stderr, "you should have a safety check failure below:\n"); | ||
57 | eina_magic_string_set(EINA_MAGIC_TEST2, NULL); | ||
58 | fail_if(eina_error_get() != EINA_ERROR_SAFETY_FAILED); | ||
59 | #endif | ||
60 | |||
61 | eina_magic_string_set(EINA_MAGIC_TEST2, EINA_MAGIC_STRING); | ||
62 | |||
63 | fail_if(eina_magic_string_get(EINA_MAGIC_TEST) == NULL); | ||
64 | fail_if(strcmp(eina_magic_string_get( | ||
65 | EINA_MAGIC_TEST), EINA_MAGIC_STRING) != 0); | ||
66 | |||
67 | #ifdef EINA_MAGIC_DEBUG | ||
68 | fail_if(EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); | ||
69 | fprintf(stderr, "you should see 'Input handle pointer is NULL' below\n"); | ||
70 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | ||
71 | |||
72 | ems = malloc(sizeof (Eina_Magic_Struct)); | ||
73 | fail_if(!ems); | ||
74 | EINA_MAGIC_SET(ems, EINA_MAGIC_TEST); | ||
75 | |||
76 | fail_if(!EINA_MAGIC_CHECK(ems, EINA_MAGIC_TEST)); | ||
77 | |||
78 | EINA_MAGIC_SET(ems, EINA_MAGIC_NONE); | ||
79 | fprintf(stderr, | ||
80 | "you should see 'Input handle has already been freed' below\n"); | ||
81 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | ||
82 | |||
83 | EINA_MAGIC_SET(ems, 42424242); | ||
84 | fprintf(stderr, "you should see 'Input handle is wrong type' below\n"); | ||
85 | EINA_MAGIC_FAIL(ems, EINA_MAGIC_TEST); | ||
86 | #endif | ||
87 | |||
88 | eina_shutdown(); | ||
89 | } | ||
90 | END_TEST | ||
91 | |||
92 | void eina_test_magic(TCase *tc) | ||
93 | { | ||
94 | tcase_add_test(tc, eina_magic_simple); | ||
95 | } | ||
96 | |||