summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJee-Yong Um <jc9.um@samsung.com>2016-05-10 15:18:33 -0700
committerCedric Bail <cedric@osg.samsung.com>2016-05-10 16:36:22 -0700
commit557381a070d818aa2353a0785a0d20bb6406afaf (patch)
tree23235a627f35f8a7f3e0c14bd11da565bea1c1de
parentfa5abb2967ca1a14770c5270b13200412a0fd345 (diff)
eet: add a helper to setup hash with generic value storage
Summary: add a macro to setup eet_data_descriptor for hash with generic value storage. Test Plan: make check (test case is included in eet test suite) Reviewers: cedric, raster Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D3925 Signed-off-by: Cedric Bail <cedric@osg.samsung.com>
-rw-r--r--src/lib/eet/Eet.h23
-rw-r--r--src/lib/eet/eet_data.c10
-rw-r--r--src/tests/eet/eet_test_data.c65
3 files changed, 95 insertions, 3 deletions
diff --git a/src/lib/eet/Eet.h b/src/lib/eet/Eet.h
index c861165c09..c69c1153b4 100644
--- a/src/lib/eet/Eet.h
+++ b/src/lib/eet/Eet.h
@@ -3579,6 +3579,29 @@ eet_data_descriptor_encode(Eet_Data_Descriptor *edd,
3579 } while (0) 3579 } while (0)
3580 3580
3581/** 3581/**
3582 * Add a hash of generic value storage to a data descriptor
3583 * @param edd The data descriptor to add the type to.
3584 * @param struct_type The type of the struct.
3585 * @param name The string name to use to encode/decode this member
3586 * (must be a constant global and never change).
3587 * @param member The struct member itself to be encoded.
3588 *
3589 * This macro lets you easily add a hash of value elements. All the
3590 * parameters are the same as for EET_DATA_DESCRIPTOR_ADD_HASH().
3591 *
3592 * @since 1.18
3593 * @ingroup Eet_Data_Group
3594 */
3595#define EET_DATA_DESCRIPTOR_ADD_HASH_VALUE(edd, struct_type, name, member) \
3596 do { \
3597 struct_type ___ett; \
3598 eet_data_descriptor_element_add(edd, name, EET_T_VALUE, EET_G_HASH, \
3599 (char *)(& (___ett.member)) - \
3600 (char *)(& (___ett)), \
3601 0, /* 0, */ NULL, NULL); \
3602 } while (0)
3603
3604/**
3582 * Add an array of basic data elements to a data descriptor. 3605 * Add an array of basic data elements to a data descriptor.
3583 * @param edd The data descriptor to add the type to. 3606 * @param edd The data descriptor to add the type to.
3584 * @param struct_type The type of the struct. 3607 * @param struct_type The type of the struct.
diff --git a/src/lib/eet/eet_data.c b/src/lib/eet/eet_data.c
index eb5a44aba2..0df96afac8 100644
--- a/src/lib/eet/eet_data.c
+++ b/src/lib/eet/eet_data.c
@@ -632,6 +632,7 @@ static int _eet_data_words_bigendian = -1;
632#define EET_I_STRING 1 << 4 632#define EET_I_STRING 1 << 4
633#define EET_I_INLINED_STRING 2 << 4 633#define EET_I_INLINED_STRING 2 << 4
634#define EET_I_NULL 3 << 4 634#define EET_I_NULL 3 << 4
635#define EET_I_VALUE 4 << 4
635 636
636#define EET_MAGIC_VARIANT 0xF1234BC 637#define EET_MAGIC_VARIANT 0xF1234BC
637/*---*/ 638/*---*/
@@ -1281,7 +1282,7 @@ _eet_type_to_eina_value_get(int eet_type)
1281 1282
1282 return NULL; 1283 return NULL;
1283} 1284}
1284 1285
1285static int 1286static int
1286_eina_value_to_eet_type_get(const Eina_Value_Type *eina_type) 1287_eina_value_to_eet_type_get(const Eina_Value_Type *eina_type)
1287{ 1288{
@@ -1361,7 +1362,7 @@ eet_data_put_value(Eet_Dictionary *ed,
1361 const void *src, 1362 const void *src,
1362 int *size_ret) 1363 int *size_ret)
1363{ 1364{
1364 const Eina_Value *value = *(void**)src; 1365 const Eina_Value *value = *(Eina_Value **)src;
1365 const Eina_Value_Type *value_type; 1366 const Eina_Value_Type *value_type;
1366 void *int_data; 1367 void *int_data;
1367 void *type_data; 1368 void *type_data;
@@ -1522,6 +1523,7 @@ case EET_I_ ## Type: chnk->type = EET_T_ ## Type; break;
1522 1523
1523 EET_UNMATCH_TYPE(STRING); 1524 EET_UNMATCH_TYPE(STRING);
1524 EET_UNMATCH_TYPE(INLINED_STRING); 1525 EET_UNMATCH_TYPE(INLINED_STRING);
1526 EET_UNMATCH_TYPE(VALUE);
1525 EET_UNMATCH_TYPE(NULL); 1527 EET_UNMATCH_TYPE(NULL);
1526 1528
1527 default: 1529 default:
@@ -1701,6 +1703,7 @@ case EET_T_ ## Type: type += EET_I_ ## Type; break;
1701 1703
1702 EET_MATCH_TYPE(STRING); 1704 EET_MATCH_TYPE(STRING);
1703 EET_MATCH_TYPE(INLINED_STRING); 1705 EET_MATCH_TYPE(INLINED_STRING);
1706 EET_MATCH_TYPE(VALUE);
1704 EET_MATCH_TYPE(NULL); 1707 EET_MATCH_TYPE(NULL);
1705 1708
1706 default: 1709 default:
@@ -2221,7 +2224,8 @@ eet_data_descriptor_element_add(Eet_Data_Descriptor *edd,
2221 if ((group_type > EET_G_UNKNOWN) 2224 if ((group_type > EET_G_UNKNOWN)
2222 && (group_type < EET_G_LAST) 2225 && (group_type < EET_G_LAST)
2223 && (((type > EET_T_UNKNOW) && (type < EET_T_STRING)) 2226 && (((type > EET_T_UNKNOW) && (type < EET_T_STRING))
2224 || ((type > EET_T_NULL) && (type < EET_T_LAST))) 2227 || ((type > EET_T_NULL) && (type < EET_T_VALUE))
2228 || ((type > EET_T_VALUE) && (type < EET_T_LAST)))
2225 && (!subtype)) 2229 && (!subtype))
2226 { 2230 {
2227 subtype = calloc(1, sizeof (Eet_Data_Descriptor)); 2231 subtype = calloc(1, sizeof (Eet_Data_Descriptor));
diff --git a/src/tests/eet/eet_test_data.c b/src/tests/eet/eet_test_data.c
index 60ec02761c..4899832392 100644
--- a/src/tests/eet/eet_test_data.c
+++ b/src/tests/eet/eet_test_data.c
@@ -18,6 +18,7 @@ typedef struct _Eet_St1 Eet_St1;
18typedef struct _Eet_St2 Eet_St2; 18typedef struct _Eet_St2 Eet_St2;
19typedef struct _Eet_St3 Eet_St3; 19typedef struct _Eet_St3 Eet_St3;
20typedef struct _Eet_List Eet_List; 20typedef struct _Eet_List Eet_List;
21typedef struct _Eet_Hash Eet_Hash;
21 22
22typedef enum _Eet_Union 23typedef enum _Eet_Union
23{ 24{
@@ -102,6 +103,11 @@ struct _Eet_List
102 Eina_List *list; 103 Eina_List *list;
103}; 104};
104 105
106struct _Eet_Hash
107{
108 Eina_Hash *hash;
109};
110
105static const char * 111static const char *
106_eet_union_type_get(const void *data, 112_eet_union_type_get(const void *data,
107 Eina_Bool *unknow) 113 Eina_Bool *unknow)
@@ -752,6 +758,64 @@ START_TEST(eet_test_data_variant)
752} /* START_TEST */ 758} /* START_TEST */
753END_TEST 759END_TEST
754 760
761START_TEST(eet_test_data_hash_value)
762{
763 Eet_Hash *h;
764 Eina_Value *val;
765 Eet_Data_Descriptor_Class eddc;
766 Eet_Data_Descriptor *edd;
767 void *blob;
768 int size;
769 int i;
770 double d;
771 char *s;
772
773 eina_init();
774 eet_init();
775
776 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, Eet_Hash);
777 edd = eet_data_descriptor_stream_new(&eddc);
778
779 EET_DATA_DESCRIPTOR_ADD_HASH_VALUE(edd, Eet_Hash, "hash", hash);
780
781 h = calloc(1, sizeof(Eet_Hash));
782 h->hash = eina_hash_string_small_new((Eina_Free_Cb)eina_value_free);
783
784 val = eina_value_new(EINA_VALUE_TYPE_INT);
785 eina_value_set(val, EET_TEST_INT);
786 eina_hash_direct_add(h->hash, "val/int", val);
787
788 val = eina_value_new(EINA_VALUE_TYPE_DOUBLE);
789 eina_value_set(val, EET_TEST_DOUBLE);
790 eina_hash_direct_add(h->hash, "val/double", val);
791
792 val = eina_value_new(EINA_VALUE_TYPE_STRING);
793 eina_value_set(val, EET_TEST_STRING);
794 eina_hash_direct_add(h->hash, "val/string", val);
795
796 blob = eet_data_descriptor_encode(edd, h, &size);
797 fail_if((!blob) || (size <= 0));
798
799 h = eet_data_descriptor_decode(edd, blob, size);
800 fail_if(!h);
801
802 val = (Eina_Value *)eina_hash_find(h->hash, "val/int");
803 eina_value_get(val, &i);
804 fail_if((!val) || (i != EET_TEST_INT));
805
806 val = (Eina_Value *)eina_hash_find(h->hash, "val/double");
807 eina_value_get(val, &d);
808 fail_if((!val) || (d != EET_TEST_DOUBLE));
809
810 val = (Eina_Value *)eina_hash_find(h->hash, "val/string");
811 eina_value_get(val, &s);
812 fail_if((!val) || strcmp(s, EET_TEST_STRING));
813
814 eet_shutdown();
815 eina_shutdown();
816} /* START_TEST */
817END_TEST
818
755void eet_test_data(TCase *tc) 819void eet_test_data(TCase *tc)
756{ 820{
757 tcase_add_test(tc, eet_test_data_basic_type_encoding_decoding); 821 tcase_add_test(tc, eet_test_data_basic_type_encoding_decoding);
@@ -761,4 +825,5 @@ void eet_test_data(TCase *tc)
761 tcase_add_test(tc, eet_test_data_fp); 825 tcase_add_test(tc, eet_test_data_fp);
762 tcase_add_test(tc, eet_test_data_union); 826 tcase_add_test(tc, eet_test_data_union);
763 tcase_add_test(tc, eet_test_data_variant); 827 tcase_add_test(tc, eet_test_data_variant);
828 tcase_add_test(tc, eet_test_data_hash_value);
764} 829}