EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / tests / eina_test_ustringshare.c
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 #include <time.h>
27
28 #include "eina_suite.h"
29 #include "Eina.h"
30
31 static const Eina_Unicode TEST0[] = {'t', 'e', 's', 't', '/', '0', 0};
32 static const Eina_Unicode TEST1[] = {'t', 'e', 's', 't', '/', '1', 0};
33
34 START_TEST(eina_ustringshare_simple)
35 {
36    const Eina_Unicode *t0;
37    const Eina_Unicode *t1;
38
39    eina_init();
40
41    t0 = eina_ustringshare_add(TEST0);
42    t1 = eina_ustringshare_add(TEST1);
43
44    fail_if(t0 == NULL);
45    fail_if(t1 == NULL);
46    fail_if(eina_unicode_strcmp(t0, TEST0) != 0);
47    fail_if(eina_unicode_strcmp(t1, TEST1) != 0);
48    fail_if((int)eina_unicode_strlen(TEST0) != eina_ustringshare_strlen(t0));
49    fail_if((int)eina_unicode_strlen(TEST1) != eina_ustringshare_strlen(t1));
50
51    t0 = eina_ustringshare_ref(t0);
52    fail_if(t0 == NULL);
53    fail_if((int)strlen((char*)TEST0) != eina_stringshare_strlen((const char*)t0));
54
55    eina_ustringshare_del(t0);
56    eina_ustringshare_del(t0);
57    eina_ustringshare_del(t1);
58
59    eina_shutdown();
60 }
61 END_TEST
62
63
64 START_TEST(eina_ustringshare_test_share)
65 {
66    const Eina_Unicode *t0;
67    const Eina_Unicode *t1;
68
69    eina_init();
70
71    t0 = eina_ustringshare_add(TEST0);
72    t1 = eina_ustringshare_add(TEST0);
73
74    fail_if(t0 == NULL);
75    fail_if(t1 == NULL);
76    fail_if(eina_unicode_strcmp(t0, TEST0) != 0);
77    fail_if(eina_unicode_strcmp(t1, TEST0) != 0);
78    fail_if(t0 != t1);
79    fail_if((int)eina_unicode_strlen(TEST0) != eina_ustringshare_strlen(t0));
80    fail_if((int)eina_unicode_strlen(TEST0) != eina_ustringshare_strlen(t1));
81
82    eina_ustringshare_del(t0);
83    eina_ustringshare_del(t1);
84
85    eina_shutdown();
86 }
87 END_TEST
88
89 START_TEST(eina_ustringshare_putstuff)
90 {
91    const Eina_Unicode *tmp;
92    int i;
93
94    eina_init();
95
96    for (i = 10000; i > 0; --i)
97      {
98         Eina_Unicode string_[] = {'s', 't', 'r', 'i', 'n', 'g', '_', 0};
99         Eina_Unicode build[64];
100         eina_unicode_strcpy(build, string_);
101
102         build[7] = i;
103         build[8] = 0;
104         tmp = eina_ustringshare_add(build);
105         fail_if(tmp != eina_ustringshare_add(build));
106         fail_if((int)eina_unicode_strlen(build) != eina_ustringshare_strlen(tmp));
107      }
108
109         eina_shutdown();
110 }
111 END_TEST
112
113 void
114 eina_test_ustringshare(TCase *tc)
115 {
116    tcase_add_test(tc, eina_ustringshare_simple);
117    tcase_add_test(tc, eina_ustringshare_test_share);
118    tcase_add_test(tc, eina_ustringshare_putstuff);
119 }