summaryrefslogtreecommitdiff
path: root/src/tests/eina/eina_test_value.c
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-07-09 00:57:38 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2015-08-29 16:40:10 -0300
commite0b12153c84446c0588e5f163a3e86f4cb75f620 (patch)
tree56ce6f84af9b838171071b54469d45293b9d9660 /src/tests/eina/eina_test_value.c
parentd71182af7a3c787b30cd6a5747b9d5f055fee003 (diff)
eina: Created EINA_VALUE_TYPE_OPTIONAL that is a single-element container that can be empty
Eina Value Optional can be used to create a eina value that can be set or be empty and can be embedded in a eina_value_struct.
Diffstat (limited to '')
-rw-r--r--src/tests/eina/eina_test_value.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/tests/eina/eina_test_value.c b/src/tests/eina/eina_test_value.c
index 454aa6011d..9e1b8081eb 100644
--- a/src/tests/eina/eina_test_value.c
+++ b/src/tests/eina/eina_test_value.c
@@ -2731,6 +2731,147 @@ START_TEST(eina_value_test_array_of_struct)
2731} 2731}
2732END_TEST 2732END_TEST
2733 2733
2734START_TEST(eina_value_test_optional_int)
2735{
2736 eina_init();
2737
2738 /* Eina_Value *value = eina_value_new(EINA_VALUE_TYPE_OPTIONAL); */
2739 /* Eina_Bool is_empty; */
2740 /* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
2741 /* ck_assert(is_empty); */
2742
2743 /* // sets expectation */
2744 /* int expected_value = -12345; */
2745 /* ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_INT, &expected_value)); */
2746 /* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
2747 /* ck_assert(!is_empty); */
2748
2749 /* // gets the actual value */
2750 /* int actual_value; */
2751 /* ck_assert(eina_value_optional_pget(value, &actual_value)); */
2752 /* ck_assert_int_eq(expected_value, actual_value); */
2753
2754 /* // resets the optional */
2755 /* ck_assert(eina_value_optional_reset(value)); */
2756 /* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
2757 /* ck_assert(is_empty); */
2758
2759 /* // Sets expectation again after reset */
2760 /* expected_value = -54321; */
2761 /* ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_INT, &expected_value)); */
2762 /* ck_assert(eina_value_optional_empty_is(value, &is_empty)); */
2763 /* ck_assert(!is_empty); */
2764
2765 /* // gets the actual value */
2766 /* ck_assert(eina_value_optional_pget(value, &actual_value)); */
2767 /* ck_assert_int_eq(expected_value, actual_value); */
2768
2769 /* eina_value_free(value); */
2770 eina_shutdown();
2771}
2772END_TEST
2773
2774START_TEST(eina_value_test_optional_string)
2775{
2776 eina_init();
2777
2778 Eina_Value *value = eina_value_new(EINA_VALUE_TYPE_OPTIONAL);
2779 Eina_Bool is_empty;
2780 ck_assert(eina_value_optional_empty_is(value, &is_empty));
2781 ck_assert(is_empty);
2782 ck_assert(EINA_VALUE_TYPE_OPTIONAL);
2783
2784 // sets expectation
2785 const char *expected_value = "Hello world!";
2786 ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_STRING, &expected_value));
2787 ck_assert(eina_value_optional_empty_is(value, &is_empty));
2788 ck_assert(!is_empty);
2789
2790 // gets the actual value
2791 const char *actual_value;
2792 ck_assert(eina_value_optional_pget(value, &actual_value));
2793 ck_assert_str_eq(expected_value, actual_value);
2794
2795 // resets the optional
2796 ck_assert(eina_value_optional_reset(value));
2797 ck_assert(eina_value_optional_empty_is(value, &is_empty));
2798 ck_assert(is_empty);
2799
2800 // Sets expectation again after reset
2801 expected_value = "!dlrow olleH";
2802 ck_assert(eina_value_optional_pset(value, EINA_VALUE_TYPE_STRING, &expected_value));
2803 ck_assert(eina_value_optional_empty_is(value, &is_empty));
2804 ck_assert(!is_empty);
2805
2806 // gets the actual value
2807 ck_assert(eina_value_optional_pget(value, &actual_value));
2808 ck_assert_str_eq(expected_value, actual_value);
2809
2810 eina_value_free(value);
2811 eina_shutdown();
2812}
2813END_TEST
2814
2815START_TEST(eina_value_test_optional_struct_members)
2816{
2817 eina_init();
2818
2819 struct s {
2820 int64_t a;
2821 Eina_Value_Optional text;
2822 int64_t b;
2823 };
2824 const Eina_Value_Struct_Member members[] = {
2825 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT64, struct s, a),
2826 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_OPTIONAL, struct s, text),
2827 EINA_VALUE_STRUCT_MEMBER(EINA_VALUE_TYPE_INT64, struct s, b),
2828 EINA_VALUE_STRUCT_MEMBER_SENTINEL
2829 };
2830 const Eina_Value_Struct_Desc desc = {
2831 EINA_VALUE_STRUCT_DESC_VERSION,
2832 NULL, members, 3, sizeof(struct s)
2833 };
2834
2835 Eina_Value *value = eina_value_struct_new(&desc);
2836 ck_assert_ptr_ne(NULL, value);
2837
2838 int64_t expected_a = 0x1234567887654321ll;
2839 fail_unless(eina_value_struct_set(value, "a", expected_a));
2840 int64_t actual_a;
2841 fail_unless(eina_value_struct_get(value, "a", &actual_a));
2842 ck_assert_int_eq(expected_a, actual_a);
2843
2844 int64_t expected_b = 0xEEDCBA9889ABCDEFll;
2845 fail_unless(eina_value_struct_set(value, "b", expected_b));
2846 int64_t actual_b;
2847 fail_unless(eina_value_struct_get(value, "b", &actual_b));
2848 ck_assert_int_eq(expected_b, actual_b);
2849
2850 Eina_Value expected_value;
2851 fail_unless(eina_value_setup(&expected_value, EINA_VALUE_TYPE_OPTIONAL));
2852 const char* str = "Hello world!";
2853 fail_unless(eina_value_optional_pset(&expected_value, EINA_VALUE_TYPE_STRING, &str));
2854 fail_unless(eina_value_struct_value_set(value, "text", &expected_value));
2855
2856 Eina_Value actual_value;
2857 fail_unless(eina_value_struct_value_get(value, "text", &actual_value));
2858 fail_unless(eina_value_compare(&expected_value, &actual_value) == 0);
2859
2860 // tests if the value have been overriden
2861 fail_unless(eina_value_struct_get(value, "a", &actual_a));
2862 ck_assert_int_eq(expected_a, actual_a);
2863 fail_unless(eina_value_struct_get(value, "b", &actual_b));
2864 ck_assert_int_eq(expected_b, actual_b);
2865
2866 eina_value_flush(&actual_value);
2867 eina_value_flush(&expected_value);
2868
2869 eina_value_free(value);
2870
2871 eina_shutdown();
2872}
2873END_TEST
2874
2734#if 0 2875#if 0
2735START_TEST(eina_value_test_model) 2876START_TEST(eina_value_test_model)
2736{ 2877{
@@ -2801,6 +2942,9 @@ eina_test_value(TCase *tc)
2801 tcase_add_test(tc, eina_value_test_blob); 2942 tcase_add_test(tc, eina_value_test_blob);
2802 tcase_add_test(tc, eina_value_test_struct); 2943 tcase_add_test(tc, eina_value_test_struct);
2803 tcase_add_test(tc, eina_value_test_array_of_struct); 2944 tcase_add_test(tc, eina_value_test_array_of_struct);
2945 tcase_add_test(tc, eina_value_test_optional_int);
2946 tcase_add_test(tc, eina_value_test_optional_string);
2947 tcase_add_test(tc, eina_value_test_optional_struct_members);
2804#if 0 2948#if 0
2805 tcase_add_test(tc, eina_value_test_model); 2949 tcase_add_test(tc, eina_value_test_model);
2806#endif 2950#endif