Enlightenment CVS committal Author : cedric Project : e17 Module : proto/eina
Dir : e17/proto/eina/src/tests Modified Files: Makefile.am eina_bench_array.c eina_bench_hash.c eina_bench_stringshare.c eina_suite.c eina_suite.h eina_test_array.c eina_test_hash.c Added Files: eina_test_accessor.c eina_test_iterator.c Log Message: Add first try for an accessor and iterator API, comment welcome (lack inlist and list currently). Rewrite EINA_ARRAY_ITER_NEXT, still fast, need one more parameter, but no more EINA_ARRAY_ITER_END. =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -u -3 -r1.8 -r1.9 --- Makefile.am 8 Aug 2008 15:55:09 -0000 1.8 +++ Makefile.am 11 Aug 2008 16:30:16 -0000 1.9 @@ -22,6 +22,8 @@ eina_test_counter.c \ eina_test_lalloc.c \ eina_test_hash.c \ +eina_test_iterator.c \ +eina_test_accessor.c \ eina_test_list.c eina_suite_LDADD = @CHECK_LIBS@ $(top_builddir)/src/lib/libeina.la =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_bench_array.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- eina_bench_array.c 8 Aug 2008 14:20:11 -0000 1.2 +++ eina_bench_array.c 11 Aug 2008 16:30:16 -0000 1.3 @@ -54,6 +54,7 @@ { Eina_Array *array; Eina_Bench_Object *ebo; + Eina_Array_Iterator it; unsigned int i; unsigned int j; @@ -77,22 +78,86 @@ if (i == 500) { - EINA_ARRAY_ITER_NEXT(array, j, ebo) + EINA_ARRAY_ITER_NEXT(array, j, ebo, it) free(ebo); - EINA_ARRAY_ITER_END; eina_array_clean(array); } else if (i % 30 == 0) eina_array_remove(array, keep, NULL); - EINA_ARRAY_ITER_NEXT(array, j, ebo) + EINA_ARRAY_ITER_NEXT(array, j, ebo, it) ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE; - EINA_ARRAY_ITER_END; } - EINA_ARRAY_ITER_NEXT(array, j, ebo) + EINA_ARRAY_ITER_NEXT(array, j, ebo, it) free(ebo); - EINA_ARRAY_ITER_END; + + eina_array_free(array); + + eina_array_shutdown(); +} + +static Eina_Bool +eina_iterator_ebo_free(__UNUSED__ const Eina_Array *array, + Eina_Bench_Object *ebo, __UNUSED__ void *fdata) +{ + free(ebo); + return EINA_TRUE; +} + +static Eina_Bool +eina_iterator_ebo_rand(__UNUSED__ const Eina_Array *array, + Eina_Bench_Object *ebo, __UNUSED__ void *fdata) +{ + ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE; + return EINA_TRUE; +} + +static void +eina_bench_array_4evas_render_iterator(int request) +{ + Eina_Array *array; + Eina_Bench_Object *ebo; + Eina_Iterator *it; + unsigned int i; + unsigned int j; + + srand(time(NULL)); + + eina_array_init(); + + array = eina_array_new(64); + + for (i = 0; i < 1000; ++i) + { + for (j = 0; j < (unsigned int) request; ++j) + { + ebo = malloc(sizeof (Eina_Bench_Object)); + if (!ebo) continue ; + + ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE; + + eina_array_append(array, ebo); + } + + if (i == 500) + { + it = eina_array_iterator_new(array); + eina_iterator_foreach(it, EINA_EACH(eina_iterator_ebo_free), NULL); + eina_iterator_free(it); + + eina_array_clean(array); + } + else if (i % 30 == 0) eina_array_remove(array, keep, NULL); + + it = eina_array_iterator_new(array); + eina_iterator_foreach(it, EINA_EACH(eina_iterator_ebo_rand), NULL); + eina_iterator_free(it); + } + + it = eina_array_iterator_new(array); + eina_iterator_foreach(it, EINA_EACH(eina_iterator_ebo_free), NULL); + eina_iterator_free(it); eina_array_free(array); @@ -232,6 +297,7 @@ void eina_bench_array(Eina_Bench *bench) { eina_bench_register(bench, "array-inline", EINA_BENCH(eina_bench_array_4evas_render_inline), 200, 4000, 100); + eina_bench_register(bench, "array-iterator", EINA_BENCH(eina_bench_array_4evas_render_iterator), 200, 4000, 100); eina_bench_register(bench, "list", EINA_BENCH(eina_bench_list_4evas_render), 200, 4000, 100); eina_bench_register(bench, "inlist", EINA_BENCH(eina_bench_inlist_4evas_render), 200, 4000, 100); } =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_bench_hash.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- eina_bench_hash.c 8 Aug 2008 14:20:11 -0000 1.5 +++ eina_bench_hash.c 11 Aug 2008 16:30:16 -0000 1.6 @@ -31,6 +31,7 @@ Eina_Hash *hash = NULL; Eina_Array *array = NULL; int *tmp_val; + Eina_Array_Iterator it; unsigned int i; array = eina_array_new(1000); @@ -66,9 +67,8 @@ eina_hash_free(hash); - EINA_ARRAY_ITER_NEXT(array, i, tmp_val) + EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) free(tmp_val); - EINA_ARRAY_ITER_END; eina_array_free(array); } @@ -79,6 +79,7 @@ Eina_Hash *hash = NULL; Eina_Array *array = NULL; int *tmp_val; + Eina_Array_Iterator it; unsigned int i; array = eina_array_new(1000); @@ -114,9 +115,8 @@ eina_hash_free(hash); - EINA_ARRAY_ITER_NEXT(array, i, tmp_val) + EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) free(tmp_val); - EINA_ARRAY_ITER_END; eina_array_free(array); } @@ -127,6 +127,7 @@ Eina_Hash *hash = NULL; Eina_Array *array = NULL; int *tmp_val; + Eina_Array_Iterator it; unsigned int i; array = eina_array_new(1000); @@ -164,9 +165,8 @@ eina_hash_free(hash); - EINA_ARRAY_ITER_NEXT(array, i, tmp_val) + EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) free(tmp_val); - EINA_ARRAY_ITER_END; eina_array_free(array); } =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_bench_stringshare.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -3 -r1.1 -r1.2 --- eina_bench_stringshare.c 8 Aug 2008 15:55:09 -0000 1.1 +++ eina_bench_stringshare.c 11 Aug 2008 16:30:16 -0000 1.2 @@ -29,6 +29,7 @@ { const char *tmp; Eina_Array *ea; + Eina_Array_Iterator it; unsigned int j; int i; @@ -60,9 +61,8 @@ eina_array_append(ea, tmp); } - EINA_ARRAY_ITER_NEXT(ea, j, tmp) + EINA_ARRAY_ITER_NEXT(ea, j, tmp, it) eina_stringshare_del(tmp); - EINA_ARRAY_ITER_END; eina_array_shutdown(); eina_stringshare_shutdown(); =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_suite.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- eina_suite.c 7 Aug 2008 13:09:08 -0000 1.7 +++ eina_suite.c 11 Aug 2008 16:30:16 -0000 1.8 @@ -36,6 +36,8 @@ { "Counter", eina_test_counter }, { "Hash", eina_test_hash }, { "List", eina_test_list }, + { "Iterator", eina_test_iterator }, + { "Accessor", eina_test_accessor }, { NULL, NULL } }; =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_suite.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- eina_suite.h 7 Aug 2008 13:09:08 -0000 1.7 +++ eina_suite.h 11 Aug 2008 16:30:16 -0000 1.8 @@ -35,5 +35,7 @@ void eina_test_counter(TCase *tc); void eina_test_hash(TCase *tc); void eina_test_list(TCase *tc); +void eina_test_iterator(TCase *tc); +void eina_test_accessor(TCase *tc); #endif /* EINA_SUITE_H_ */ =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_test_array.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- eina_test_array.c 8 Aug 2008 14:20:11 -0000 1.4 +++ eina_test_array.c 11 Aug 2008 16:30:16 -0000 1.5 @@ -25,6 +25,7 @@ { Eina_Array *ea; char *tmp; + Eina_Array_Iterator it; unsigned int i; eina_array_init(); @@ -44,10 +45,11 @@ fail_if(eina_array_get(ea, 10) == NULL); fail_if(atoi(eina_array_get(ea, 10)) != 10); - EINA_ARRAY_ITER_NEXT(ea, i, tmp) - fail_if((unsigned int) atoi(tmp) != i); - free(tmp); - EINA_ARRAY_ITER_END + EINA_ARRAY_ITER_NEXT(ea, i, tmp, it) + { + fail_if((unsigned int) atoi(tmp) != i); + free(tmp); + } fail_if(i != 200); @@ -63,6 +65,7 @@ { Eina_Array sea = { NULL, 0, 0, 0 }; char *tmp; + Eina_Array_Iterator it; unsigned int i; eina_array_init(); @@ -81,10 +84,11 @@ fail_if(eina_array_get(&sea, 10) == NULL); fail_if(atoi(eina_array_get(&sea, 10)) != 10); - EINA_ARRAY_ITER_NEXT(&sea, i, tmp) - fail_if((unsigned int) atoi(tmp) != i); - free(tmp); - EINA_ARRAY_ITER_END + EINA_ARRAY_ITER_NEXT(&sea, i, tmp, it) + { + fail_if((unsigned int) atoi(tmp) != i); + free(tmp); + } fail_if(i != 200); @@ -111,6 +115,7 @@ { Eina_Array *ea; int *tmp; + Eina_Array_Iterator it; unsigned int i; eina_array_init(); @@ -137,9 +142,8 @@ eina_array_remove(ea, keep_int, NULL); fail_if(eina_array_count(ea) != 990); - EINA_ARRAY_ITER_NEXT(ea, i, tmp) + EINA_ARRAY_ITER_NEXT(ea, i, tmp, it) fail_if(*tmp == 0); - EINA_ARRAY_ITER_END; // Remove the last items for (i = 980; i < 990; ++i) @@ -152,12 +156,11 @@ // Remove all items fail_if(eina_array_count(ea) != 980); - EINA_ARRAY_ITER_NEXT(ea, i, tmp) + EINA_ARRAY_ITER_NEXT(ea, i, tmp, it) { fail_if(*tmp == 0); *tmp = 0; } - EINA_ARRAY_ITER_END; eina_array_remove(ea, keep_int, NULL); =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_test_hash.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -3 -r1.3 -r1.4 --- eina_test_hash.c 8 Aug 2008 15:54:26 -0000 1.3 +++ eina_test_hash.c 11 Aug 2008 16:30:16 -0000 1.4 @@ -16,6 +16,10 @@ * if not, see <http://www.gnu.org/licenses/>. */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + #include <stdio.h> #include <stdlib.h> @@ -35,6 +39,20 @@ } END_TEST +static Eina_Bool +eina_foreach_check(__UNUSED__ const Eina_Hash *hash, const void *key, void *data, __UNUSED__ void *fdata) +{ + int *j = data; + int i; + + if (strlen(key) <= 0) return EINA_TRUE; + + i = atoi(key); + fail_if(i != *j); + + return EINA_TRUE; +} + START_TEST(eina_hash_simple) { Eina_Hash *hash = NULL; @@ -59,6 +77,8 @@ test = eina_hash_find(hash, "42"); fail_if(!test); fail_if(*test != 42); + + eina_hash_foreach(hash, eina_foreach_check, NULL); test = eina_hash_modify(hash, "5", &array[4]); fail_if(!test); ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs