Eina: Added ustringshare and binshare tests.
Fixed a small bug in binshare (in the length function). Moved some debug messages around. SVN revision: 50541
This commit is contained in:
parent
b7b6e3c585
commit
6b69189efd
|
@ -150,7 +150,7 @@ eina_binshare_del(const char *str, unsigned int slen)
|
|||
EAPI const char *
|
||||
eina_binshare_add_length(const char *str, unsigned int slen)
|
||||
{
|
||||
return (const char *) eina_share_common_add_length(share,(const char *) str, (slen + 1) * sizeof(char), 0);
|
||||
return (const char *) eina_share_common_add_length(share,(const char *) str, (slen) * sizeof(char), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -665,7 +665,6 @@ eina_share_common_add_length(Eina_Share *share, const char *str, unsigned int sl
|
|||
Eina_Share_Common_Node *el;
|
||||
int hash_num, hash;
|
||||
|
||||
DBG("str=%p (%.*s), slen=%u", str, slen, str ? str : "", slen);
|
||||
if (!str) return NULL;
|
||||
|
||||
eina_share_common_population_add(share, slen);
|
||||
|
@ -721,13 +720,12 @@ eina_share_common_ref(Eina_Share *share, const char *str)
|
|||
{
|
||||
Eina_Share_Common_Node *node;
|
||||
|
||||
DBG("str=%p (%s)", str, str ? str : "");
|
||||
if (!str) return NULL;
|
||||
|
||||
SHARE_COMMON_LOCK_BIG();
|
||||
node = _eina_share_common_node_from_str(str, share->node_magic);
|
||||
node->references++;
|
||||
DBG("str=%p (%s) refs=%u", str, str, node->references);
|
||||
DBG("str=%p refs=%u", str, node->references);
|
||||
|
||||
SHARE_COMMON_UNLOCK_BIG();
|
||||
|
||||
|
@ -745,7 +743,6 @@ eina_share_common_del(Eina_Share *share, const char *str, int slen)
|
|||
Eina_Share_Common_Node *node;
|
||||
int hash_num, hash;
|
||||
|
||||
DBG("str=%p (%s)", str, str ? str : "");
|
||||
if (!str) return;
|
||||
|
||||
eina_share_common_population_del(share, slen);
|
||||
|
@ -756,12 +753,12 @@ eina_share_common_del(Eina_Share *share, const char *str, int slen)
|
|||
if (node->references > 1)
|
||||
{
|
||||
node->references--;
|
||||
DBG("str=%p (%s) refs=%u", str, str, node->references);
|
||||
DBG("str=%p refs=%u", str, node->references);
|
||||
SHARE_COMMON_UNLOCK_BIG();
|
||||
return;
|
||||
}
|
||||
|
||||
DBG("str=%p (%s) refs=0, delete.", str, str);
|
||||
DBG("str=%p refs=0, delete.", str);
|
||||
node->references = 0;
|
||||
slen = node->length;
|
||||
|
||||
|
|
|
@ -557,6 +557,7 @@ EAPI void
|
|||
eina_stringshare_del(const char *str)
|
||||
{
|
||||
int slen;
|
||||
DBG("str=%p (%s)", str, str ? str : "");
|
||||
if (!str)
|
||||
return;
|
||||
|
||||
|
@ -605,6 +606,8 @@ eina_stringshare_del(const char *str)
|
|||
EAPI const char *
|
||||
eina_stringshare_add_length(const char *str, unsigned int slen)
|
||||
{
|
||||
DBG("str=%p (%.*s), slen=%u", str, slen, str ? str : "", slen);
|
||||
|
||||
if (slen <= 0)
|
||||
return "";
|
||||
else if (slen == 1)
|
||||
|
@ -798,6 +801,8 @@ EAPI const char *
|
|||
eina_stringshare_ref(const char *str)
|
||||
{
|
||||
int slen;
|
||||
DBG("str=%p (%s)", str, str ? str : "");
|
||||
|
||||
if (!str)
|
||||
{
|
||||
return eina_share_common_ref(share, str);
|
||||
|
|
|
@ -34,6 +34,8 @@ eina_suite_SOURCES = \
|
|||
eina_suite.c \
|
||||
eina_test_fp.c \
|
||||
eina_test_stringshare.c \
|
||||
eina_test_ustringshare.c\
|
||||
eina_test_binshare.c\
|
||||
eina_test_array.c \
|
||||
eina_test_error.c \
|
||||
eina_test_log.c \
|
||||
|
|
|
@ -35,7 +35,9 @@ struct _Eina_Test_Case
|
|||
static const Eina_Test_Case etc[] = {
|
||||
{ "FixedPoint", eina_test_fp },
|
||||
{ "Array", eina_test_array },
|
||||
{ "Binary Share", eina_test_binshare },
|
||||
{ "String Share", eina_test_stringshare },
|
||||
{ "UString Share", eina_test_ustringshare },
|
||||
{ "Log", eina_test_log },
|
||||
{ "Error", eina_test_error },
|
||||
{ "Magic", eina_test_magic },
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <check.h>
|
||||
|
||||
void eina_test_stringshare(TCase *tc);
|
||||
void eina_test_ustringshare(TCase *tc);
|
||||
void eina_test_binshare(TCase *tc);
|
||||
void eina_test_array(TCase *tc);
|
||||
void eina_test_log(TCase *tc);
|
||||
void eina_test_error(TCase *tc);
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
/* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "eina_suite.h"
|
||||
#include "Eina.h"
|
||||
|
||||
#define TEST0 "te\0st/0"
|
||||
#define TEST0_SIZE 7
|
||||
#define TEST1 "te\0st/11"
|
||||
#define TEST1_SIZE 8
|
||||
|
||||
START_TEST(eina_binshare_simple)
|
||||
{
|
||||
const char *t0;
|
||||
const char *t1;
|
||||
|
||||
eina_init();
|
||||
eina_binshare_init();
|
||||
|
||||
t0 = eina_binshare_add_length(TEST0, TEST0_SIZE);
|
||||
t1 = eina_binshare_add_length(TEST1, TEST1_SIZE);
|
||||
|
||||
fail_if(t0 == NULL);
|
||||
fail_if(t1 == NULL);
|
||||
fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
|
||||
fail_if(memcmp(t1, TEST1, TEST1_SIZE) != 0);
|
||||
|
||||
t0 = eina_binshare_ref(t0);
|
||||
fail_if(t0 == NULL);
|
||||
fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
|
||||
|
||||
eina_binshare_del(t0);
|
||||
eina_binshare_del(t0);
|
||||
eina_binshare_del(t1);
|
||||
|
||||
eina_binshare_shutdown();
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eina_binshare_small)
|
||||
{
|
||||
char buf[4];
|
||||
int i;
|
||||
|
||||
eina_init();
|
||||
eina_binshare_init();
|
||||
|
||||
for (i = 1; i < 3; i++)
|
||||
{
|
||||
const char *t0, *t1;
|
||||
int j;
|
||||
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
char c;
|
||||
for (c = 'a'; c <= 'z'; c++)
|
||||
buf[j] = c;
|
||||
}
|
||||
buf[i] = '\0';
|
||||
t0 = eina_binshare_add_length(buf, i);
|
||||
t1 = eina_binshare_add_length(buf, i);
|
||||
|
||||
fail_if(t0 == NULL);
|
||||
fail_if(t1 == NULL);
|
||||
fail_if(t0 != t1);
|
||||
fail_if(memcmp(t0, buf, i) != 0);
|
||||
|
||||
eina_binshare_del(t0);
|
||||
eina_binshare_del(t1);
|
||||
}
|
||||
eina_binshare_shutdown();
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST(eina_binshare_test_share)
|
||||
{
|
||||
const char *t0;
|
||||
const char *t1;
|
||||
|
||||
eina_init();
|
||||
eina_binshare_init();
|
||||
|
||||
t0 = eina_binshare_add_length(TEST0, TEST0_SIZE);
|
||||
t1 = eina_binshare_add_length(TEST0, TEST0_SIZE);
|
||||
|
||||
fail_if(t0 == NULL);
|
||||
fail_if(t1 == NULL);
|
||||
fail_if(memcmp(t0, TEST0, TEST0_SIZE) != 0);
|
||||
fail_if(memcmp(t1, TEST0, TEST0_SIZE) != 0);
|
||||
fail_if(t0 != t1);
|
||||
fail_if(TEST0_SIZE != eina_binshare_length(t0));
|
||||
|
||||
eina_binshare_del(t0);
|
||||
eina_binshare_del(t1);
|
||||
eina_binshare_shutdown();
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eina_binshare_putstuff)
|
||||
{
|
||||
const char *tmp;
|
||||
int i;
|
||||
|
||||
eina_init();
|
||||
eina_binshare_init();
|
||||
|
||||
for (i = 10000; i > 0; --i)
|
||||
{
|
||||
char build[64] = "string_";
|
||||
|
||||
eina_convert_xtoa(i, build + 7);
|
||||
tmp = eina_binshare_add_length(build, strlen(build));
|
||||
fail_if(tmp != eina_binshare_add_length(build, strlen(build)));
|
||||
fail_if((int) strlen(build) != eina_binshare_length(tmp));
|
||||
}
|
||||
eina_binshare_shutdown();
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eina_binshare_collision)
|
||||
{
|
||||
Eina_Array *ea;
|
||||
char buffer[50];
|
||||
int i;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
eina_init();
|
||||
eina_binshare_init();
|
||||
|
||||
ea = eina_array_new(256);
|
||||
fail_if(!ea);
|
||||
|
||||
for (i = 0; i < 10000; ++i)
|
||||
{
|
||||
eina_convert_itoa(rand(), buffer);
|
||||
eina_array_push(ea, (void*) eina_binshare_add_length(buffer, strlen(buffer)));
|
||||
if (rand() > RAND_MAX / 2)
|
||||
{
|
||||
const char *r = eina_binshare_add_length(buffer, strlen(buffer));
|
||||
fail_if(r == NULL);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < 10000; ++i)
|
||||
{
|
||||
const char *r;
|
||||
|
||||
eina_convert_itoa(60000 - i, buffer);
|
||||
eina_array_push(ea, (void*) eina_binshare_add_length(buffer, strlen(buffer)));
|
||||
r = eina_binshare_add_length(buffer, strlen(buffer));
|
||||
fail_if(r == NULL);
|
||||
r = eina_binshare_add_length(buffer, strlen(buffer));
|
||||
fail_if(r == NULL);
|
||||
}
|
||||
|
||||
for (i = 0; i < 200; ++i)
|
||||
eina_binshare_del(eina_array_data_get(ea, i));
|
||||
|
||||
for (i = 0; i < 1000; ++i)
|
||||
eina_binshare_del(eina_array_pop(ea));
|
||||
|
||||
eina_binshare_shutdown();
|
||||
eina_shutdown();
|
||||
|
||||
eina_array_free(ea);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eina_test_binshare(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, eina_binshare_simple);
|
||||
tcase_add_test(tc, eina_binshare_small);
|
||||
tcase_add_test(tc, eina_binshare_test_share);
|
||||
tcase_add_test(tc, eina_binshare_collision);
|
||||
tcase_add_test(tc, eina_binshare_putstuff);
|
||||
}
|
|
@ -45,7 +45,14 @@ START_TEST(eina_stringshare_simple)
|
|||
fail_if(t1 == NULL);
|
||||
fail_if(strcmp(t0, TEST0) != 0);
|
||||
fail_if(strcmp(t1, TEST1) != 0);
|
||||
fail_if((int) strlen(TEST0) != eina_stringshare_strlen(t0));
|
||||
fail_if((int) strlen(TEST1) != eina_stringshare_strlen(t1));
|
||||
|
||||
t0 = eina_stringshare_ref(t0);
|
||||
fail_if(t0 == NULL);
|
||||
fail_if((int) strlen(TEST0) != eina_stringshare_strlen(t0));
|
||||
|
||||
eina_stringshare_del(t0);
|
||||
eina_stringshare_del(t0);
|
||||
eina_stringshare_del(t1);
|
||||
|
||||
|
@ -79,6 +86,8 @@ START_TEST(eina_stringshare_small)
|
|||
fail_if(t1 == NULL);
|
||||
fail_if(t0 != t1);
|
||||
fail_if(strcmp(t0, buf) != 0);
|
||||
fail_if((int) strlen(buf) != eina_stringshare_strlen(t0));
|
||||
fail_if((int) strlen(buf) != eina_stringshare_strlen(t1));
|
||||
|
||||
eina_stringshare_del(t0);
|
||||
eina_stringshare_del(t1);
|
||||
|
@ -104,6 +113,7 @@ START_TEST(eina_stringshare_test_share)
|
|||
fail_if(strcmp(t0, TEST0) != 0);
|
||||
fail_if(strcmp(t1, TEST0) != 0);
|
||||
fail_if(t0 != t1);
|
||||
fail_if((int) strlen(t0) != eina_stringshare_strlen(t0));
|
||||
|
||||
eina_stringshare_del(t0);
|
||||
eina_stringshare_del(t1);
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/* 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 <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "eina_suite.h"
|
||||
#include "Eina.h"
|
||||
|
||||
static const Eina_Unicode TEST0[] = {'t', 'e', 's', 't', '/', '0', 0};
|
||||
static const Eina_Unicode TEST1[] = {'t', 'e', 's', 't', '/', '1', 0};
|
||||
|
||||
START_TEST(eina_ustringshare_simple)
|
||||
{
|
||||
const Eina_Unicode *t0;
|
||||
const Eina_Unicode *t1;
|
||||
|
||||
eina_init();
|
||||
|
||||
t0 = eina_ustringshare_add(TEST0);
|
||||
t1 = eina_ustringshare_add(TEST1);
|
||||
|
||||
fail_if(t0 == NULL);
|
||||
fail_if(t1 == NULL);
|
||||
fail_if(eina_unicode_strcmp(t0, TEST0) != 0);
|
||||
fail_if(eina_unicode_strcmp(t1, TEST1) != 0);
|
||||
fail_if((int) eina_unicode_strlen(TEST0) != eina_ustringshare_strlen(t0));
|
||||
fail_if((int) eina_unicode_strlen(TEST1) != eina_ustringshare_strlen(t1));
|
||||
|
||||
t0 = eina_ustringshare_ref(t0);
|
||||
fail_if(t0 == NULL);
|
||||
fail_if((int) strlen(TEST0) != eina_stringshare_strlen(t0));
|
||||
|
||||
eina_ustringshare_del(t0);
|
||||
eina_ustringshare_del(t0);
|
||||
eina_ustringshare_del(t1);
|
||||
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
||||
START_TEST(eina_ustringshare_test_share)
|
||||
{
|
||||
const Eina_Unicode *t0;
|
||||
const Eina_Unicode *t1;
|
||||
|
||||
eina_init();
|
||||
|
||||
t0 = eina_ustringshare_add(TEST0);
|
||||
t1 = eina_ustringshare_add(TEST0);
|
||||
|
||||
fail_if(t0 == NULL);
|
||||
fail_if(t1 == NULL);
|
||||
fail_if(eina_unicode_strcmp(t0, TEST0) != 0);
|
||||
fail_if(eina_unicode_strcmp(t1, TEST0) != 0);
|
||||
fail_if(t0 != t1);
|
||||
fail_if((int) eina_unicode_strlen(TEST0) != eina_ustringshare_strlen(t0));
|
||||
fail_if((int) eina_unicode_strlen(TEST0) != eina_ustringshare_strlen(t1));
|
||||
|
||||
eina_ustringshare_del(t0);
|
||||
eina_ustringshare_del(t1);
|
||||
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(eina_ustringshare_putstuff)
|
||||
{
|
||||
const Eina_Unicode *tmp;
|
||||
int i;
|
||||
|
||||
eina_init();
|
||||
|
||||
for (i = 10000; i > 0; --i)
|
||||
{
|
||||
Eina_Unicode string_[] = {'s', 't', 'r', 'i', 'n', 'g', '_', 0};
|
||||
Eina_Unicode build[64];
|
||||
eina_unicode_strcpy(build, string_);
|
||||
|
||||
build[7] = i;
|
||||
build[8] = 0;
|
||||
tmp = eina_ustringshare_add(build);
|
||||
fail_if(tmp != eina_ustringshare_add(build));
|
||||
fail_if((int) eina_unicode_strlen(build) != eina_ustringshare_strlen(tmp));
|
||||
}
|
||||
|
||||
eina_shutdown();
|
||||
}
|
||||
END_TEST
|
||||
|
||||
void
|
||||
eina_test_ustringshare(TCase *tc)
|
||||
{
|
||||
tcase_add_test(tc, eina_ustringshare_simple);
|
||||
tcase_add_test(tc, eina_ustringshare_test_share);
|
||||
tcase_add_test(tc, eina_ustringshare_putstuff);
|
||||
}
|
Loading…
Reference in New Issue