|
1 | 1 | #include "sentry.h" |
2 | 2 | #include "sentry_scope.h" |
3 | 3 | #include "sentry_testsupport.h" |
| 4 | +#include "sentry_utils.h" |
4 | 5 |
|
5 | 6 | SENTRY_TEST(scope_contexts) |
6 | 7 | { |
@@ -645,119 +646,112 @@ SENTRY_TEST(scope_level) |
645 | 646 | sentry_close(); |
646 | 647 | } |
647 | 648 |
|
| 649 | +static sentry_value_t |
| 650 | +breadcrumb_ts(const char *message, uint64_t ts) |
| 651 | +{ |
| 652 | + sentry_value_t breadcrumb = sentry_value_new_breadcrumb(NULL, message); |
| 653 | + sentry_value_set_by_key(breadcrumb, "timestamp", |
| 654 | + sentry__value_new_string_owned(sentry__usec_time_to_iso8601(ts))); |
| 655 | + return breadcrumb; |
| 656 | +} |
| 657 | + |
648 | 658 | SENTRY_TEST(scope_breadcrumbs) |
649 | 659 | { |
650 | 660 | SENTRY_TEST_OPTIONS_NEW(options); |
| 661 | + sentry_options_set_max_breadcrumbs(options, 5); |
651 | 662 | sentry_init(options); |
652 | 663 |
|
653 | | - // global: ["global1", "global2"] |
654 | | - sentry_add_breadcrumb(sentry_value_new_breadcrumb(NULL, "global1")); |
655 | | - sentry_add_breadcrumb(sentry_value_new_breadcrumb(NULL, "global2")); |
| 664 | + // global: ["global1", "global4"] |
| 665 | + sentry_add_breadcrumb(breadcrumb_ts("global1", 1)); |
| 666 | + sentry_add_breadcrumb(breadcrumb_ts("global4", 4)); |
| 667 | + |
| 668 | +#define TEST_CHECK_MESSAGE_EQUAL(breadcrumbs, index, message) \ |
| 669 | + TEST_CHECK_STRING_EQUAL( \ |
| 670 | + sentry_value_as_string(sentry_value_get_by_key( \ |
| 671 | + sentry_value_get_by_index(breadcrumbs, index), "message")), \ |
| 672 | + message) |
656 | 673 |
|
657 | 674 | SENTRY_WITH_SCOPE (global_scope) { |
658 | 675 | // event: null |
659 | 676 | sentry_value_t event = sentry_value_new_object(); |
660 | 677 |
|
661 | | - // event <- global: ["global1", "global2"] |
| 678 | + // event <- global: ["global1", "global4"] |
662 | 679 | sentry__scope_apply_to_event( |
663 | 680 | global_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
664 | 681 |
|
665 | 682 | sentry_value_t result = sentry_value_get_by_key(event, "breadcrumbs"); |
666 | 683 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
667 | 684 | TEST_CHECK(sentry_value_get_length(result) == 2); |
668 | | - TEST_CHECK_STRING_EQUAL( |
669 | | - sentry_value_as_string(sentry_value_get_by_key( |
670 | | - sentry_value_get_by_index(result, 0), "message")), |
671 | | - "global1"); |
672 | | - TEST_CHECK_STRING_EQUAL( |
673 | | - sentry_value_as_string(sentry_value_get_by_key( |
674 | | - sentry_value_get_by_index(result, 1), "message")), |
675 | | - "global2"); |
| 685 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "global1"); |
| 686 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "global4"); |
676 | 687 |
|
677 | 688 | sentry_value_decref(event); |
678 | 689 | } |
679 | 690 |
|
680 | 691 | SENTRY_WITH_SCOPE (global_scope) { |
681 | | - // event: ["event1", "event2"] |
| 692 | + // event: ["event3", "event5"] |
682 | 693 | sentry_value_t event = sentry_value_new_object(); |
683 | 694 | { |
684 | 695 | sentry_value_t breadcrumbs = sentry_value_new_list(); |
685 | | - sentry_value_append( |
686 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event1")); |
687 | | - sentry_value_append( |
688 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event2")); |
| 696 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event3", 3)); |
| 697 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event5", 5)); |
689 | 698 | sentry_value_set_by_key(event, "breadcrumbs", breadcrumbs); |
690 | 699 | } |
691 | 700 |
|
692 | | - // event <- global: ["event1", "event2"] |
| 701 | + // event <- global: ["global1", "event3", "global4", "event5"] |
693 | 702 | sentry__scope_apply_to_event( |
694 | 703 | global_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
695 | 704 |
|
696 | 705 | sentry_value_t result = sentry_value_get_by_key(event, "breadcrumbs"); |
697 | 706 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
698 | | - TEST_CHECK(sentry_value_get_length(result) == 2); |
699 | | - TEST_CHECK_STRING_EQUAL( |
700 | | - sentry_value_as_string(sentry_value_get_by_key( |
701 | | - sentry_value_get_by_index(result, 0), "message")), |
702 | | - "event1"); |
703 | | - TEST_CHECK_STRING_EQUAL( |
704 | | - sentry_value_as_string(sentry_value_get_by_key( |
705 | | - sentry_value_get_by_index(result, 1), "message")), |
706 | | - "event2"); |
| 707 | + TEST_CHECK(sentry_value_get_length(result) == 4); |
| 708 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "global1"); |
| 709 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "event3"); |
| 710 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "global4"); |
| 711 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "event5"); |
707 | 712 |
|
708 | 713 | sentry_value_decref(event); |
709 | 714 | } |
710 | 715 |
|
711 | 716 | SENTRY_WITH_SCOPE (global_scope) { |
712 | | - // local: ["local1", "local2"] |
| 717 | + // local: ["local2", "local6"] |
713 | 718 | sentry_scope_t *local_scope = sentry_local_scope_new(); |
714 | | - sentry_scope_add_breadcrumb( |
715 | | - local_scope, sentry_value_new_breadcrumb(NULL, "local1")); |
716 | | - sentry_scope_add_breadcrumb( |
717 | | - local_scope, sentry_value_new_breadcrumb(NULL, "local2")); |
| 719 | + sentry_scope_add_breadcrumb(local_scope, breadcrumb_ts("local2", 2)); |
| 720 | + sentry_scope_add_breadcrumb(local_scope, breadcrumb_ts("local6", 6)); |
718 | 721 |
|
719 | | - // event: ["event1", "event2"] |
| 722 | + // event: ["event3", "event5"] |
720 | 723 | sentry_value_t event = sentry_value_new_object(); |
721 | 724 | { |
722 | 725 | sentry_value_t breadcrumbs = sentry_value_new_list(); |
723 | | - sentry_value_append( |
724 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event1")); |
725 | | - sentry_value_append( |
726 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event2")); |
| 726 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event3", 3)); |
| 727 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event5", 5)); |
727 | 728 | sentry_value_set_by_key(event, "breadcrumbs", breadcrumbs); |
728 | 729 | } |
729 | 730 |
|
730 | | - // event <- local: ["event1", "event2"] |
| 731 | + // event <- local: ["local2", "event3", "event5", "local6"] |
731 | 732 | sentry__scope_apply_to_event( |
732 | 733 | local_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
733 | 734 |
|
734 | 735 | sentry_value_t result = sentry_value_get_by_key(event, "breadcrumbs"); |
735 | 736 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
736 | | - TEST_CHECK(sentry_value_get_length(result) == 2); |
737 | | - TEST_CHECK_STRING_EQUAL( |
738 | | - sentry_value_as_string(sentry_value_get_by_key( |
739 | | - sentry_value_get_by_index(result, 0), "message")), |
740 | | - "event1"); |
741 | | - TEST_CHECK_STRING_EQUAL( |
742 | | - sentry_value_as_string(sentry_value_get_by_key( |
743 | | - sentry_value_get_by_index(result, 1), "message")), |
744 | | - "event2"); |
| 737 | + TEST_CHECK(sentry_value_get_length(result) == 4); |
| 738 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "local2"); |
| 739 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "event3"); |
| 740 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "event5"); |
| 741 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "local6"); |
745 | 742 |
|
746 | | - // event <- global: ["event1", "event2"] |
| 743 | + // event <- global: ["local2", "event3", "global4", "event5", "local6"] |
747 | 744 | sentry__scope_apply_to_event( |
748 | 745 | global_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
749 | 746 |
|
750 | 747 | result = sentry_value_get_by_key(event, "breadcrumbs"); |
751 | 748 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
752 | | - TEST_CHECK(sentry_value_get_length(result) == 2); |
753 | | - TEST_CHECK_STRING_EQUAL( |
754 | | - sentry_value_as_string(sentry_value_get_by_key( |
755 | | - sentry_value_get_by_index(result, 0), "message")), |
756 | | - "event1"); |
757 | | - TEST_CHECK_STRING_EQUAL( |
758 | | - sentry_value_as_string(sentry_value_get_by_key( |
759 | | - sentry_value_get_by_index(result, 0), "message")), |
760 | | - "event1"); |
| 749 | + TEST_CHECK(sentry_value_get_length(result) == 5); |
| 750 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "local2"); |
| 751 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "event3"); |
| 752 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "global4"); |
| 753 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "event5"); |
| 754 | + TEST_CHECK_MESSAGE_EQUAL(result, 4, "local6"); |
761 | 755 |
|
762 | 756 | sentry_scope_free(local_scope); |
763 | 757 | sentry_value_decref(event); |
|
0 commit comments