efl

Форк
0
/
eina_test_tmpstr.c 
148 строк · 3.7 Кб
1
/* EINA - EFL data type library
2
 * Copyright (C) 2013 Vlad Brovko
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 <Eina.h>
24
#include "eina_tmpstr.h"
25

26
#include "eina_suite.h"
27

28
EFL_START_TEST(tmpstr_simple)
29
{
30

31
   const int cnt_tmp_strings = 10;
32
   const int max_str_len = 255;
33
   char buf[max_str_len + 1];
34
   Eina_Tmpstr *tmp_strings[cnt_tmp_strings];
35

36
   // Add several tmp strings
37
   for (int i = 0; i != cnt_tmp_strings; ++i)
38
     {
39
        snprintf(buf, max_str_len, "Tmp string %d", (i + 1));
40
        tmp_strings[i] = eina_tmpstr_add(buf);
41

42
        fail_if(strcmp(buf, tmp_strings[i]));
43
     }
44

45
   // Delete these tmp strings
46
   for (int i = 0; i != cnt_tmp_strings; ++i)
47
     {
48
        snprintf(buf, max_str_len, "Tmp string %d", (cnt_tmp_strings - i - 1 + 1));
49

50
        fail_if(strcmp(buf, tmp_strings[cnt_tmp_strings - i - 1]));
51

52
        eina_tmpstr_del(tmp_strings[cnt_tmp_strings - i - 1]);
53
        tmp_strings[cnt_tmp_strings - i - 1] = 0;
54
     }
55

56
   // Delete non tmp string (should do nothing)
57
   eina_tmpstr_del("Some non tmp string");
58

59
}
60
EFL_END_TEST
61

62
EFL_START_TEST(tmpstr_simple_len)
63
{
64

65
   const int cnt_tmp_strings = 10;
66
   const int max_str_len = 255;
67
   char buf[max_str_len + 1];
68
   Eina_Tmpstr *tmp_strings[cnt_tmp_strings];
69

70
   // Add several tmp strings
71
   for (int i = 0; i != cnt_tmp_strings; ++i)
72
     {
73
        snprintf(buf, max_str_len, "Tmp string %d", (i + 1));
74
        tmp_strings[i] = eina_tmpstr_add_length(buf, (max_str_len + 1));
75

76
        fail_if(strcmp(buf, tmp_strings[i]));
77
     }
78

79
   // Delete these tmp strings
80
   for (int i = 0; i != cnt_tmp_strings; ++i)
81
     {
82
        snprintf(buf, max_str_len, "Tmp string %d", (cnt_tmp_strings - i - 1 + 1));
83

84
        fail_if(strcmp(buf, tmp_strings[cnt_tmp_strings - i - 1]));
85

86
        eina_tmpstr_del(tmp_strings[cnt_tmp_strings - i - 1]);
87
        tmp_strings[cnt_tmp_strings - i - 1] = 0;
88
     }
89

90
   // Delete non tmp string (should do nothing)
91
   eina_tmpstr_del("Some non tmp string");
92

93
}
94
EFL_END_TEST
95

96
EFL_START_TEST(tmpstr_manage)
97
{
98

99
   char *buf = malloc(7);
100
   strcpy(buf, "tmpstr");
101
   Eina_Tmpstr *tstr1 = eina_tmpstr_manage_new(buf);
102
   fail_if(strcmp(buf, tstr1));
103
   eina_tmpstr_del(tstr1);
104

105
}
106
EFL_END_TEST
107

108
EFL_START_TEST(tmpstr_manage_len)
109
{
110

111
   char *buf = malloc(10);
112
   strcpy(buf, "tmpstr");
113
   Eina_Tmpstr *tstr1 = eina_tmpstr_manage_new_length(buf, 7);
114
   fail_if(strcmp(buf, tstr1));
115
   eina_tmpstr_del(tstr1);
116

117
}
118
EFL_END_TEST
119

120
EFL_START_TEST(tmpstr_len)
121
{
122

123
   const char *str1 = "12345";
124
   const char *str2 = "123456789";
125
   Eina_Tmpstr *tstr1 = eina_tmpstr_add(str1);
126
   Eina_Tmpstr *tstr2 = eina_tmpstr_add(str2);
127
   Eina_Tmpstr *tstr_empty = eina_tmpstr_add("");
128

129
   ck_assert_int_eq(eina_tmpstr_len(tstr1), strlen(str1));
130
   ck_assert_int_eq(eina_tmpstr_len(tstr2), strlen(str2));
131

132
   ck_assert_int_eq(eina_tmpstr_len(tstr_empty), 0);
133

134
   eina_tmpstr_del(tstr1);
135
   eina_tmpstr_del(tstr2);
136

137
}
138
EFL_END_TEST
139

140
void
141
eina_test_tmpstr(TCase *tc)
142
{
143
   tcase_add_test(tc, tmpstr_simple);
144
   tcase_add_test(tc, tmpstr_simple_len);
145
   tcase_add_test(tc, tmpstr_manage);
146
   tcase_add_test(tc, tmpstr_manage_len);
147
   tcase_add_test(tc, tmpstr_len);
148
}
149

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.