summaryrefslogtreecommitdiff
path: root/src/tests/edje/edje_test_edje.c
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-05-23 16:29:16 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-05-24 13:02:20 +0900
commit9d48350ae40eaa1ea6247c402dee06bb31553484 (patch)
tree38877339500e5beded999ca3ae646c832fe9e125 /src/tests/edje/edje_test_edje.c
parente7abfba03404bb8b594855ec712c9242ca9656eb (diff)
edje: Implement EO API for message_send
Since this uses generic_value (aka Eina_Value), there is an implicit type detection and conversion. I did not attempt to cover all types (namely string+int and string+float and even less sets of those) as I believe they aren't really used. Or they most likely could be replaced by multiple messages rather than a single message. Note: should we pass ptr(generic_value) instead of generic_value? The API looks a little odd in C when passing by value. @feature
Diffstat (limited to 'src/tests/edje/edje_test_edje.c')
-rw-r--r--src/tests/edje/edje_test_edje.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/src/tests/edje/edje_test_edje.c b/src/tests/edje/edje_test_edje.c
index e2723d8ee5..d92c8c051c 100644
--- a/src/tests/edje/edje_test_edje.c
+++ b/src/tests/edje/edje_test_edje.c
@@ -725,6 +725,148 @@ START_TEST(edje_test_combine_keywords)
725} 725}
726END_TEST 726END_TEST
727 727
728static void
729_message_signal_reply_cb(void *data, Evas_Object *obj EINA_UNUSED,
730 const char *emission, const char *source)
731{
732 int *id = data;
733
734 fprintf(stderr, "source %s emit %s id %d\n", source, emission, *id);
735 fflush(stderr);
736 ck_assert_str_eq(source, "edc");
737 ck_assert_ptr_nonnull(emission);
738
739 if (!strncmp(emission, "int set", 7))
740 ck_assert_str_eq(emission, "int set 7 12 42 255");
741 else if (!strncmp(emission, "int", 3))
742 ck_assert_str_eq(emission, "int 42");
743 else if (!strncmp(emission, "float", 5))
744 {
745 char buf[64];
746 sprintf(buf, "float %f", 0.12);
747 ck_assert_str_eq(emission, buf);
748 }
749 else if (!strncmp(emission, "str", 3))
750 ck_assert_str_eq(emission, "str hello world");
751 else ck_abort_msg("Invalid emission!");
752
753 (*id)++;
754}
755
756START_TEST(edje_test_message_send_legacy)
757{
758 Evas *evas;
759 Evas_Object *obj;
760 Edje_Message_Int msgi;
761 Edje_Message_Float msgf;
762 Edje_Message_String msgs;
763 Edje_Message_Int_Set *msgis;
764 int id = 0;
765
766 /* Ugly calls to process:
767 *
768 * 1. Send edje message (async)
769 * 2. Process edje message (sync)
770 * 3. EDC program emits edje signal (async)
771 * 4. Process edje signal (sync)
772 * 5. Finally reached signal cb
773 */
774
775 evas = EDJE_TEST_INIT_EVAS();
776
777 obj = edje_object_add(evas);
778 fail_unless(edje_object_file_set(obj, test_layout_get("test_messages.edj"), "test_group"));
779 edje_object_signal_callback_add(obj, "*", "edc", _message_signal_reply_cb, &id);
780
781 msgs.str = "hello world";
782 edje_object_message_send(obj, EDJE_MESSAGE_STRING, 0, &msgs);
783 edje_message_signal_process();
784 ck_assert_int_eq(id, 1);
785
786 msgi.val = 42;
787 edje_object_message_send(obj, EDJE_MESSAGE_INT, 1, &msgi);
788 edje_message_signal_process();
789 ck_assert_int_eq(id, 2);
790
791 msgf.val = 0.12;
792 edje_object_message_send(obj, EDJE_MESSAGE_FLOAT, 2, &msgf);
793 edje_message_signal_process();
794 ck_assert_int_eq(id, 3);
795
796 msgis = alloca(sizeof(*msgis) + 4 * sizeof(msgis->val));
797 msgis->count = 4;
798 msgis->val[0] = 7;
799 msgis->val[1] = 12;
800 msgis->val[2] = 42;
801 msgis->val[3] = 255;
802 edje_object_message_send(obj, EDJE_MESSAGE_INT_SET, 3, msgis);
803 edje_message_signal_process();
804 ck_assert_int_eq(id, 4);
805
806 evas_object_del(obj);
807
808 EDJE_TEST_FREE_EVAS();
809}
810END_TEST
811
812START_TEST(edje_test_message_send_eo)
813{
814 Evas *evas;
815 Evas_Object *obj;
816 Eina_Value v, *va;
817 int id = 0;
818
819 evas = EDJE_TEST_INIT_EVAS();
820
821 obj = efl_add(EDJE_OBJECT_CLASS, evas,
822 efl_file_set(efl_added, test_layout_get("test_messages.edj"), "test_group"));
823
824 // FIXME: EO API HERE
825 edje_object_signal_callback_add(obj, "*", "edc", _message_signal_reply_cb, &id);
826
827 // NOTE: edje_object_message_signal_process may or may not be in EO (TBD)
828
829 eina_value_setup(&v, EINA_VALUE_TYPE_STRING);
830 eina_value_set(&v, "hello world");
831 edje_obj_message_send(obj, 0, v);
832 eina_value_flush(&v);
833 edje_message_signal_process();
834 edje_object_calc_force(obj);
835 ck_assert_int_eq(id, 1);
836
837 eina_value_setup(&v, EINA_VALUE_TYPE_INT);
838 eina_value_set(&v, 42);
839 edje_obj_message_send(obj, 1, v);
840 eina_value_flush(&v);
841 edje_message_signal_process();
842 edje_object_calc_force(obj);
843 ck_assert_int_eq(id, 2);
844
845 eina_value_setup(&v, EINA_VALUE_TYPE_FLOAT);
846 eina_value_set(&v, 0.12);
847 edje_obj_message_send(obj, 2, v);
848 eina_value_flush(&v);
849 edje_message_signal_process();
850 edje_object_calc_force(obj);
851 ck_assert_int_eq(id, 3);
852
853 va = eina_value_array_new(EINA_VALUE_TYPE_INT, 4);
854 eina_value_array_append(va, 7);
855 eina_value_array_append(va, 12);
856 eina_value_array_append(va, 42);
857 eina_value_array_append(va, 255);
858 edje_obj_message_send(obj, 3, *va);
859 eina_value_free(va);
860 edje_message_signal_process();
861 edje_object_calc_force(obj);
862 ck_assert_int_eq(id, 4);
863
864 efl_del(obj);
865
866 EDJE_TEST_FREE_EVAS();
867}
868END_TEST
869
728void edje_test_edje(TCase *tc) 870void edje_test_edje(TCase *tc)
729{ 871{
730 tcase_add_test(tc, edje_test_edje_init); 872 tcase_add_test(tc, edje_test_edje_init);
@@ -746,4 +888,6 @@ void edje_test_edje(TCase *tc)
746 tcase_add_test(tc, edje_test_table); 888 tcase_add_test(tc, edje_test_table);
747 tcase_add_test(tc, edje_test_table_eoapi); 889 tcase_add_test(tc, edje_test_table_eoapi);
748 tcase_add_test(tc, edje_test_combine_keywords); 890 tcase_add_test(tc, edje_test_combine_keywords);
891 tcase_add_test(tc, edje_test_message_send_legacy);
892 tcase_add_test(tc, edje_test_message_send_eo);
749} 893}