summaryrefslogtreecommitdiff
path: root/src/tests/ecore/ecore_test_promise.c
diff options
context:
space:
mode:
authorCedric Bail <cedric@osg.samsung.com>2016-07-07 18:01:38 -0700
committerCedric BAIL <cedric@osg.samsung.com>2016-09-08 14:58:05 -0700
commit674acaf63d6c17e96c8ddb4fcaee10130d820c1a (patch)
tree2b595045fe5a7036e11181ba03ccb0a4e86cd64f /src/tests/ecore/ecore_test_promise.c
parentcd6a8aa6b3ed49c7d246bad27837a306acff9630 (diff)
ecore: add tests for Efl.Promise.
Diffstat (limited to 'src/tests/ecore/ecore_test_promise.c')
-rw-r--r--src/tests/ecore/ecore_test_promise.c625
1 files changed, 625 insertions, 0 deletions
diff --git a/src/tests/ecore/ecore_test_promise.c b/src/tests/ecore/ecore_test_promise.c
index 50df508..d813aca 100644
--- a/src/tests/ecore/ecore_test_promise.c
+++ b/src/tests/ecore/ecore_test_promise.c
@@ -376,6 +376,618 @@ START_TEST(ecore_test_promise_progress_promise)
376} 376}
377END_TEST 377END_TEST
378 378
379typedef struct _Future_Ok Future_Ok;
380struct _Future_Ok
381{
382 Eina_Bool then : 1;
383 Eina_Bool cancel : 1;
384 Eina_Bool progress : 1;
385};
386
387static void
388_then(void *data, const Efl_Event *ev)
389{
390 Efl_Future_Event_Success *s = ev->info;
391 int *value = s->value;
392 Future_Ok *fo = data;
393
394 fail_if(*value != 42);
395 fo->then = EINA_TRUE;
396}
397
398static void
399_cancel(void *data, const Efl_Event *ev)
400{
401 Efl_Future_Event_Failure *f = ev->info;
402 Future_Ok *fo = data;
403
404 fail_if(f->error != EINA_ERROR_FUTURE_CANCEL);
405 fo->cancel = EINA_TRUE;
406}
407
408static void
409_progress(void *data, const Efl_Event *ev)
410{
411 Efl_Future_Event_Progress *p = ev->info;
412 int *value = p->progress;
413 Future_Ok *fo = data;
414
415 fail_if(*value != 7);
416 fo->progress = EINA_TRUE;
417}
418
419static void
420_death(void *data, const Efl_Event *ev EINA_UNUSED)
421{
422 Eina_Bool *death = data;
423
424 *death = EINA_TRUE;
425}
426
427// Test value set after then
428START_TEST(efl_test_promise_future_success)
429{
430 Efl_Promise *p;
431 Efl_Future *f;
432 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
433 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
434 int progress = 7;
435 int value = 42;
436
437 ecore_init();
438
439 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
440 fail_if(!p);
441
442 f = efl_promise_future_get(p);
443 fail_if(!f);
444
445 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
446 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
447
448 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
449
450 fail_if(deadp || deadf);
451
452 efl_promise_progress_set(p, &progress);
453 efl_promise_value_set(p, &value, NULL);
454
455 fail_if(!fo.then || fo.cancel || !fo.progress);
456 fail_if(!deadf || deadp);
457
458 efl_del(p);
459
460 fail_if(!deadp);
461
462 ecore_shutdown();
463}
464END_TEST
465
466START_TEST(efl_test_promise_future_cancel)
467{
468 Efl_Promise *p;
469 Efl_Future *f;
470 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
471 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
472 int progress = 7;
473 int value = 42;
474
475 ecore_init();
476
477 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
478 fail_if(!p);
479
480 efl_future_use(&f, efl_promise_future_get(p));
481 fail_if(!f);
482
483 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
484 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
485 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
486
487 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
488
489 fail_if(deadp || deadf);
490
491 efl_promise_progress_set(p, &progress);
492 efl_future_cancel(f);
493
494 efl_promise_value_set(p, &value, NULL);
495
496 fail_if(fo.then || !fo.cancel || !fo.progress);
497 fail_if(!deadf || deadp);
498 fail_if(!none);
499
500 efl_del(p);
501
502 fail_if(!deadp);
503
504 ecore_shutdown();
505}
506END_TEST
507
508// Test value set before then
509START_TEST(efl_test_promise_before_future_success)
510{
511 Efl_Promise *p;
512 Efl_Future *f;
513 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
514 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
515 int progress = 7;
516 int value = 42;
517
518 ecore_init();
519
520 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
521 fail_if(!p);
522
523 f = efl_promise_future_get(p);
524 fail_if(!f);
525
526 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
527 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
528
529 efl_promise_progress_set(p, &progress);
530 efl_promise_value_set(p, &value, NULL);
531
532 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
533
534 fail_if(deadp || !deadf);
535 fail_if(!fo.then || fo.cancel || fo.progress);
536
537 efl_del(p);
538
539 fail_if(!deadp);
540
541 ecore_shutdown();
542}
543END_TEST
544
545START_TEST(efl_test_promise_before_future_cancel)
546{
547 Efl_Promise *p;
548 Efl_Future *f;
549 Future_Ok fo = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
550 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
551 int progress = 7;
552 int value = 42;
553
554 ecore_init();
555
556 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
557 fail_if(!p);
558
559 efl_future_use(&f, efl_promise_future_get(p));
560 fail_if(!f);
561
562 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
563 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
564 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
565
566 efl_promise_progress_set(p, &progress);
567 efl_future_cancel(f);
568
569 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo));
570
571 fail_if(deadp || !deadf);
572
573 efl_promise_value_set(p, &value, NULL);
574
575 fail_if(fo.then || !fo.cancel || fo.progress);
576 fail_if(!none);
577
578 efl_del(p);
579
580 fail_if(!deadp);
581
582 ecore_shutdown();
583}
584END_TEST
585
586static void
587_chain_then(void *data, const Efl_Event *ev)
588{
589 Efl_Future_Event_Success *s = ev->info;
590 int *v = s->value;
591 Future_Ok *fo = data;
592
593 fo->then = EINA_TRUE;
594
595 fail_if(*v != 42);
596
597 efl_promise_value_set(s->next, v, NULL);
598}
599
600static void
601_chain_fail(void *data, const Efl_Event *ev)
602{
603 Efl_Future_Event_Failure *f = ev->info;
604 Future_Ok *fo = data;
605
606 fo->cancel = EINA_TRUE;
607
608 efl_promise_failed(f->next, f->error);
609}
610
611static void
612_chain_progress(void *data, const Efl_Event *ev)
613{
614 Efl_Future_Event_Progress *p = ev->info;
615 Future_Ok *fo = data;
616
617 fo->progress = EINA_TRUE;
618
619 efl_promise_progress_set(p->next, p->progress);
620}
621
622// Test chained then
623START_TEST(efl_test_promise_future_chain_success)
624{
625 Efl_Promise *p;
626 Efl_Future *f1, *f2;
627 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
628 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
629 Eina_Bool deadf1 = EINA_FALSE, deadf2 = EINA_FALSE, deadp = EINA_FALSE;
630 int progress = 7;
631 int value = 42;
632
633 ecore_init();
634
635 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
636 fail_if(!p);
637
638 f1 = efl_promise_future_get(p);
639 fail_if(!f1);
640
641 efl_event_callback_add(f1, EFL_EVENT_DEL, _death, &deadf1);
642 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
643
644 f2 = efl_future_then(f1, _chain_then, _chain_fail, _chain_progress, &fo1);
645 fail_if(!f2);
646
647 efl_event_callback_add(f2, EFL_EVENT_DEL, _death, &deadf2);
648
649 fail_if(!efl_future_then(f2, _then, _cancel, _progress, &fo2));
650
651 fail_if(deadp || deadf1 || deadf2);
652
653 efl_promise_progress_set(p, &progress);
654 efl_promise_value_set(p, &value, NULL);
655
656 fail_if(!fo1.then || fo1.cancel || !fo1.progress);
657 fail_if(!fo2.then || fo2.cancel || !fo2.progress);
658 fail_if(!deadf1 || !deadf2 || deadp);
659
660 efl_del(p);
661
662 fail_if(!deadp);
663
664 ecore_shutdown();
665}
666END_TEST
667
668START_TEST(efl_test_promise_future_chain_cancel)
669{
670 Efl_Promise *p;
671 Efl_Future *f1, *f2;
672 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
673 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
674 Eina_Bool deadf1 = EINA_FALSE, deadf2 = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
675 int progress = 7;
676 int value = 42;
677
678 ecore_init();
679
680 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
681 fail_if(!p);
682
683 efl_future_use(&f1, efl_promise_future_get(p));
684 fail_if(!f1);
685
686 efl_event_callback_add(f1, EFL_EVENT_DEL, _death, &deadf1);
687 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
688 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
689
690 f2 = efl_future_then(f1, _chain_then, _chain_fail, _chain_progress, &fo1);
691 fail_if(!f2);
692
693 efl_event_callback_add(f2, EFL_EVENT_DEL, _death, &deadf2);
694
695 fail_if(!efl_future_then(f2, _then, _cancel, _progress, &fo2));
696
697 fail_if(deadp || deadf1 || deadf2);
698
699 efl_promise_progress_set(p, &progress);
700 efl_future_cancel(f1);
701
702 efl_promise_value_set(p, &value, NULL);
703
704 fail_if(fo1.then || !fo1.cancel || !fo1.progress);
705 fail_if(fo2.then || !fo2.cancel || !fo2.progress);
706 fail_if(!deadf1 || !deadf2 || deadp);
707 fail_if(!none);
708
709 efl_del(p);
710
711 fail_if(!deadp);
712
713 ecore_shutdown();
714}
715END_TEST
716
717// Test value set after multi then
718START_TEST(efl_test_promise_future_multi_success)
719{
720 Efl_Promise *p;
721 Efl_Future *f;
722 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
723 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
724 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
725 int progress = 7;
726 int value = 42;
727
728 ecore_init();
729
730 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
731 fail_if(!p);
732
733 f = efl_promise_future_get(p);
734 fail_if(!f);
735
736 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
737 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
738
739 efl_ref(f);
740 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
741 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
742 efl_unref(f);
743
744 fail_if(deadp || deadf);
745
746 efl_promise_progress_set(p, &progress);
747 efl_promise_value_set(p, &value, NULL);
748
749 fail_if(!fo1.then || fo1.cancel || !fo1.progress);
750 fail_if(!fo2.then || fo2.cancel || !fo2.progress);
751 fail_if(!deadf || deadp);
752
753 efl_del(p);
754
755 fail_if(!deadp);
756
757 ecore_shutdown();
758}
759END_TEST
760
761START_TEST(efl_test_promise_future_multi_cancel)
762{
763 Efl_Promise *p;
764 Efl_Future *f;
765 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
766 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
767 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
768 int progress = 7;
769 int value = 42;
770
771 ecore_init();
772
773 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
774 fail_if(!p);
775
776 efl_future_use(&f, efl_promise_future_get(p));
777 fail_if(!f);
778
779 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
780 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
781 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
782
783 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
784 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
785
786 fail_if(deadp || deadf);
787
788 efl_promise_progress_set(p, &progress);
789 efl_future_cancel(f);
790
791 efl_promise_value_set(p, &value, NULL);
792
793 fail_if(fo1.then || !fo1.cancel || !fo1.progress);
794 fail_if(fo2.then || !fo2.cancel || !fo2.progress);
795 fail_if(!deadf || deadp);
796 fail_if(!none);
797
798 efl_del(p);
799
800 fail_if(!deadp);
801
802 ecore_shutdown();
803}
804END_TEST
805
806// Test value set before multi then
807START_TEST(efl_test_promise_before_future_multi_success)
808{
809 Efl_Promise *p;
810 Efl_Future *f;
811 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
812 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
813 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
814 int progress = 7;
815 int value = 42;
816
817 ecore_init();
818
819 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
820 fail_if(!p);
821
822 f = efl_promise_future_get(p);
823 fail_if(!f);
824
825 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
826 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
827
828 efl_promise_progress_set(p, &progress);
829 efl_promise_value_set(p, &value, NULL);
830
831 efl_ref(f);
832 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
833 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
834 efl_unref(f);
835
836 fail_if(deadp || !deadf);
837 fail_if(!fo1.then || fo1.cancel || fo1.progress);
838 fail_if(!fo2.then || fo2.cancel || fo2.progress);
839
840 efl_del(p);
841
842 fail_if(!deadp);
843
844 ecore_shutdown();
845}
846END_TEST
847
848START_TEST(efl_test_promise_before_future_multi_cancel)
849{
850 Efl_Promise *p;
851 Efl_Future *f;
852 Future_Ok fo1 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
853 Future_Ok fo2 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
854 Future_Ok fo3 = { EINA_FALSE, EINA_FALSE, EINA_FALSE };
855 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
856 int progress = 7;
857 int value = 42;
858
859 ecore_init();
860
861 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
862 fail_if(!p);
863
864 efl_future_use(&f, efl_promise_future_get(p));
865 fail_if(!f);
866
867 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
868 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
869 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
870
871 efl_promise_progress_set(p, &progress);
872 efl_future_cancel(f);
873
874 efl_ref(f);
875 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo1));
876 fail_if(!efl_future_then(f, _then, _cancel, _progress, &fo2));
877 efl_unref(f);
878
879 fail_if(efl_future_then(f, _then, _cancel, _progress, &fo3));
880
881 fail_if(deadp || !deadf);
882
883 efl_promise_value_set(p, &value, NULL);
884
885 fail_if(fo1.then || !fo1.cancel || fo1.progress);
886 fail_if(fo2.then || !fo2.cancel || fo2.progress);
887 fail_if(fo3.then || fo3.cancel || fo3.progress);
888 fail_if(!none);
889
890 efl_del(p);
891
892 fail_if(!deadp);
893
894 ecore_shutdown();
895}
896END_TEST
897
898static Eina_Bool cleanup = EINA_FALSE;
899
900static void
901_cleanup_called(void *s EINA_UNUSED)
902{
903 cleanup = EINA_TRUE;
904}
905
906// Test optional value set without then
907START_TEST(efl_test_promise_future_optional_success)
908{
909 Efl_Promise *p;
910 Efl_Future *f;
911 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE;
912 int progress = 7;
913 int value = 42;
914
915 cleanup = EINA_FALSE;
916
917 ecore_init();
918
919 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
920 fail_if(!p);
921
922 f = efl_promise_future_get(p);
923 fail_if(!f);
924
925 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
926 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
927
928 fail_if(deadp || deadf);
929
930 efl_promise_progress_set(p, &progress);
931 efl_promise_value_set(p, &value, _cleanup_called);
932
933 fail_if(deadf || deadp);
934
935 ecore_main_loop_iterate();
936
937 fail_if(!deadf);
938
939 efl_del(p);
940
941 fail_if(!deadp || !cleanup);
942
943 ecore_shutdown();
944}
945END_TEST
946
947START_TEST(efl_test_promise_future_optional_cancel)
948{
949 Efl_Promise *p;
950 Efl_Future *f;
951 Eina_Bool deadf = EINA_FALSE, deadp = EINA_FALSE, none = EINA_FALSE;
952 int progress = 7;
953 int value = 42;
954
955 cleanup = EINA_FALSE;
956
957 ecore_init();
958
959 p = efl_add(EFL_PROMISE_CLASS, ecore_main_loop_get());
960 fail_if(!p);
961
962 efl_future_use(&f, efl_promise_future_get(p));
963 fail_if(!f);
964
965 efl_event_callback_add(f, EFL_EVENT_DEL, _death, &deadf);
966 efl_event_callback_add(p, EFL_EVENT_DEL, _death, &deadp);
967 efl_event_callback_add(p, EFL_PROMISE_EVENT_FUTURE_NONE, _death, &none);
968
969 fail_if(deadp || deadf);
970
971 efl_promise_progress_set(p, &progress);
972 efl_future_cancel(f);
973
974 efl_promise_value_set(p, &value, _cleanup_called);
975
976 fail_if(deadf || deadp);
977 fail_if(!none);
978
979 ecore_main_loop_iterate();
980
981 fail_if(!deadf || deadp);
982
983 efl_del(p);
984
985 fail_if(!deadp);
986
987 ecore_shutdown();
988}
989END_TEST
990
379void ecore_test_ecore_promise(TCase *tc) 991void ecore_test_ecore_promise(TCase *tc)
380{ 992{
381 tcase_add_test(tc, ecore_test_promise); 993 tcase_add_test(tc, ecore_test_promise);
@@ -390,4 +1002,17 @@ void ecore_test_ecore_promise(TCase *tc)
390 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime_all); 1002 tcase_add_test(tc, ecore_test_promise_immediate_set_lifetime_all);
391 tcase_add_test(tc, ecore_test_promise_cancel_promise); 1003 tcase_add_test(tc, ecore_test_promise_cancel_promise);
392 tcase_add_test(tc, ecore_test_promise_progress_promise); 1004 tcase_add_test(tc, ecore_test_promise_progress_promise);
1005
1006 tcase_add_test(tc, efl_test_promise_future_success);
1007 tcase_add_test(tc, efl_test_promise_future_cancel);
1008 tcase_add_test(tc, efl_test_promise_future_chain_success);
1009 tcase_add_test(tc, efl_test_promise_future_chain_cancel);
1010 tcase_add_test(tc, efl_test_promise_before_future_success);
1011 tcase_add_test(tc, efl_test_promise_before_future_cancel);
1012 tcase_add_test(tc, efl_test_promise_future_multi_success);
1013 tcase_add_test(tc, efl_test_promise_future_multi_cancel);
1014 tcase_add_test(tc, efl_test_promise_before_future_multi_success);
1015 tcase_add_test(tc, efl_test_promise_before_future_multi_cancel);
1016 tcase_add_test(tc, efl_test_promise_future_optional_success);
1017 tcase_add_test(tc, efl_test_promise_future_optional_cancel);
393} 1018}