|
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 | { |
@@ -558,119 +559,112 @@ SENTRY_TEST(scope_level) |
558 | 559 | sentry_close(); |
559 | 560 | } |
560 | 561 |
|
| 562 | +static sentry_value_t |
| 563 | +breadcrumb_ts(const char *message, uint64_t ts) |
| 564 | +{ |
| 565 | + sentry_value_t breadcrumb = sentry_value_new_breadcrumb(NULL, message); |
| 566 | + sentry_value_set_by_key(breadcrumb, "timestamp", |
| 567 | + sentry__value_new_string_owned(sentry__usec_time_to_iso8601(ts))); |
| 568 | + return breadcrumb; |
| 569 | +} |
| 570 | + |
561 | 571 | SENTRY_TEST(scope_breadcrumbs) |
562 | 572 | { |
563 | 573 | SENTRY_TEST_OPTIONS_NEW(options); |
| 574 | + sentry_options_set_max_breadcrumbs(options, 5); |
564 | 575 | sentry_init(options); |
565 | 576 |
|
566 | | - // global: ["global1", "global2"] |
567 | | - sentry_add_breadcrumb(sentry_value_new_breadcrumb(NULL, "global1")); |
568 | | - sentry_add_breadcrumb(sentry_value_new_breadcrumb(NULL, "global2")); |
| 577 | + // global: ["global1", "global4"] |
| 578 | + sentry_add_breadcrumb(breadcrumb_ts("global1", 1)); |
| 579 | + sentry_add_breadcrumb(breadcrumb_ts("global4", 4)); |
| 580 | + |
| 581 | +#define TEST_CHECK_MESSAGE_EQUAL(breadcrumbs, index, message) \ |
| 582 | + TEST_CHECK_STRING_EQUAL( \ |
| 583 | + sentry_value_as_string(sentry_value_get_by_key( \ |
| 584 | + sentry_value_get_by_index(breadcrumbs, index), "message")), \ |
| 585 | + message) |
569 | 586 |
|
570 | 587 | SENTRY_WITH_SCOPE (global_scope) { |
571 | 588 | // event: null |
572 | 589 | sentry_value_t event = sentry_value_new_object(); |
573 | 590 |
|
574 | | - // event <- global: ["global1", "global2"] |
| 591 | + // event <- global: ["global1", "global4"] |
575 | 592 | sentry__scope_apply_to_event( |
576 | 593 | global_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
577 | 594 |
|
578 | 595 | sentry_value_t result = sentry_value_get_by_key(event, "breadcrumbs"); |
579 | 596 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
580 | 597 | TEST_CHECK(sentry_value_get_length(result) == 2); |
581 | | - TEST_CHECK_STRING_EQUAL( |
582 | | - sentry_value_as_string(sentry_value_get_by_key( |
583 | | - sentry_value_get_by_index(result, 0), "message")), |
584 | | - "global1"); |
585 | | - TEST_CHECK_STRING_EQUAL( |
586 | | - sentry_value_as_string(sentry_value_get_by_key( |
587 | | - sentry_value_get_by_index(result, 1), "message")), |
588 | | - "global2"); |
| 598 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "global1"); |
| 599 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "global4"); |
589 | 600 |
|
590 | 601 | sentry_value_decref(event); |
591 | 602 | } |
592 | 603 |
|
593 | 604 | SENTRY_WITH_SCOPE (global_scope) { |
594 | | - // event: ["event1", "event2"] |
| 605 | + // event: ["event3", "event5"] |
595 | 606 | sentry_value_t event = sentry_value_new_object(); |
596 | 607 | { |
597 | 608 | sentry_value_t breadcrumbs = sentry_value_new_list(); |
598 | | - sentry_value_append( |
599 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event1")); |
600 | | - sentry_value_append( |
601 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event2")); |
| 609 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event3", 3)); |
| 610 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event5", 5)); |
602 | 611 | sentry_value_set_by_key(event, "breadcrumbs", breadcrumbs); |
603 | 612 | } |
604 | 613 |
|
605 | | - // event <- global: ["event1", "event2"] |
| 614 | + // event <- global: ["global1", "event3", "global4", "event5"] |
606 | 615 | sentry__scope_apply_to_event( |
607 | 616 | global_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
608 | 617 |
|
609 | 618 | sentry_value_t result = sentry_value_get_by_key(event, "breadcrumbs"); |
610 | 619 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
611 | | - TEST_CHECK(sentry_value_get_length(result) == 2); |
612 | | - TEST_CHECK_STRING_EQUAL( |
613 | | - sentry_value_as_string(sentry_value_get_by_key( |
614 | | - sentry_value_get_by_index(result, 0), "message")), |
615 | | - "event1"); |
616 | | - TEST_CHECK_STRING_EQUAL( |
617 | | - sentry_value_as_string(sentry_value_get_by_key( |
618 | | - sentry_value_get_by_index(result, 1), "message")), |
619 | | - "event2"); |
| 620 | + TEST_CHECK(sentry_value_get_length(result) == 4); |
| 621 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "global1"); |
| 622 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "event3"); |
| 623 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "global4"); |
| 624 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "event5"); |
620 | 625 |
|
621 | 626 | sentry_value_decref(event); |
622 | 627 | } |
623 | 628 |
|
624 | 629 | SENTRY_WITH_SCOPE (global_scope) { |
625 | | - // local: ["local1", "local2"] |
| 630 | + // local: ["local2", "local6"] |
626 | 631 | sentry_scope_t *local_scope = sentry_local_scope_new(); |
627 | | - sentry_scope_add_breadcrumb( |
628 | | - local_scope, sentry_value_new_breadcrumb(NULL, "local1")); |
629 | | - sentry_scope_add_breadcrumb( |
630 | | - local_scope, sentry_value_new_breadcrumb(NULL, "local2")); |
| 632 | + sentry_scope_add_breadcrumb(local_scope, breadcrumb_ts("local2", 2)); |
| 633 | + sentry_scope_add_breadcrumb(local_scope, breadcrumb_ts("local6", 6)); |
631 | 634 |
|
632 | | - // event: ["event1", "event2"] |
| 635 | + // event: ["event3", "event5"] |
633 | 636 | sentry_value_t event = sentry_value_new_object(); |
634 | 637 | { |
635 | 638 | sentry_value_t breadcrumbs = sentry_value_new_list(); |
636 | | - sentry_value_append( |
637 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event1")); |
638 | | - sentry_value_append( |
639 | | - breadcrumbs, sentry_value_new_breadcrumb(NULL, "event2")); |
| 639 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event3", 3)); |
| 640 | + sentry_value_append(breadcrumbs, breadcrumb_ts("event5", 5)); |
640 | 641 | sentry_value_set_by_key(event, "breadcrumbs", breadcrumbs); |
641 | 642 | } |
642 | 643 |
|
643 | | - // event <- local: ["event1", "event2"] |
| 644 | + // event <- local: ["local2", "event3", "event5", "local6"] |
644 | 645 | sentry__scope_apply_to_event( |
645 | 646 | local_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
646 | 647 |
|
647 | 648 | sentry_value_t result = sentry_value_get_by_key(event, "breadcrumbs"); |
648 | 649 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
649 | | - TEST_CHECK(sentry_value_get_length(result) == 2); |
650 | | - TEST_CHECK_STRING_EQUAL( |
651 | | - sentry_value_as_string(sentry_value_get_by_key( |
652 | | - sentry_value_get_by_index(result, 0), "message")), |
653 | | - "event1"); |
654 | | - TEST_CHECK_STRING_EQUAL( |
655 | | - sentry_value_as_string(sentry_value_get_by_key( |
656 | | - sentry_value_get_by_index(result, 1), "message")), |
657 | | - "event2"); |
658 | | - |
659 | | - // event <- global: ["event1", "event2"] |
| 650 | + TEST_CHECK(sentry_value_get_length(result) == 4); |
| 651 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "local2"); |
| 652 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "event3"); |
| 653 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "event5"); |
| 654 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "local6"); |
| 655 | + |
| 656 | + // event <- global: ["local2", "event3", "global4", "event5", "local6"] |
660 | 657 | sentry__scope_apply_to_event( |
661 | 658 | global_scope, options, event, SENTRY_SCOPE_BREADCRUMBS); |
662 | 659 |
|
663 | 660 | result = sentry_value_get_by_key(event, "breadcrumbs"); |
664 | 661 | TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
665 | | - TEST_CHECK(sentry_value_get_length(result) == 2); |
666 | | - TEST_CHECK_STRING_EQUAL( |
667 | | - sentry_value_as_string(sentry_value_get_by_key( |
668 | | - sentry_value_get_by_index(result, 0), "message")), |
669 | | - "event1"); |
670 | | - TEST_CHECK_STRING_EQUAL( |
671 | | - sentry_value_as_string(sentry_value_get_by_key( |
672 | | - sentry_value_get_by_index(result, 0), "message")), |
673 | | - "event1"); |
| 662 | + TEST_CHECK(sentry_value_get_length(result) == 5); |
| 663 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "local2"); |
| 664 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "event3"); |
| 665 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "global4"); |
| 666 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "event5"); |
| 667 | + TEST_CHECK_MESSAGE_EQUAL(result, 4, "local6"); |
674 | 668 |
|
675 | 669 | sentry_scope_free(local_scope); |
676 | 670 | sentry_value_decref(event); |
|
0 commit comments