24
#include "eina_tmpstr.h"
26
#include "eina_suite.h"
28
EFL_START_TEST(tmpstr_simple)
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];
37
for (int i = 0; i != cnt_tmp_strings; ++i)
39
snprintf(buf, max_str_len, "Tmp string %d", (i + 1));
40
tmp_strings[i] = eina_tmpstr_add(buf);
42
fail_if(strcmp(buf, tmp_strings[i]));
46
for (int i = 0; i != cnt_tmp_strings; ++i)
48
snprintf(buf, max_str_len, "Tmp string %d", (cnt_tmp_strings - i - 1 + 1));
50
fail_if(strcmp(buf, tmp_strings[cnt_tmp_strings - i - 1]));
52
eina_tmpstr_del(tmp_strings[cnt_tmp_strings - i - 1]);
53
tmp_strings[cnt_tmp_strings - i - 1] = 0;
57
eina_tmpstr_del("Some non tmp string");
62
EFL_START_TEST(tmpstr_simple_len)
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];
71
for (int i = 0; i != cnt_tmp_strings; ++i)
73
snprintf(buf, max_str_len, "Tmp string %d", (i + 1));
74
tmp_strings[i] = eina_tmpstr_add_length(buf, (max_str_len + 1));
76
fail_if(strcmp(buf, tmp_strings[i]));
80
for (int i = 0; i != cnt_tmp_strings; ++i)
82
snprintf(buf, max_str_len, "Tmp string %d", (cnt_tmp_strings - i - 1 + 1));
84
fail_if(strcmp(buf, tmp_strings[cnt_tmp_strings - i - 1]));
86
eina_tmpstr_del(tmp_strings[cnt_tmp_strings - i - 1]);
87
tmp_strings[cnt_tmp_strings - i - 1] = 0;
91
eina_tmpstr_del("Some non tmp string");
96
EFL_START_TEST(tmpstr_manage)
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);
108
EFL_START_TEST(tmpstr_manage_len)
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);
120
EFL_START_TEST(tmpstr_len)
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("");
129
ck_assert_int_eq(eina_tmpstr_len(tstr1), strlen(str1));
130
ck_assert_int_eq(eina_tmpstr_len(tstr2), strlen(str2));
132
ck_assert_int_eq(eina_tmpstr_len(tstr_empty), 0);
134
eina_tmpstr_del(tstr1);
135
eina_tmpstr_del(tstr2);
141
eina_test_tmpstr(TCase *tc)
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);