|
6 | 6 | #include <stdint.h> |
7 | 7 | #include <string.h> |
8 | 8 |
|
| 9 | +static sentry_value_t |
| 10 | +breadcrumb_with_ts(const char *message, const char *timestamp) |
| 11 | +{ |
| 12 | + sentry_value_t breadcrumb = sentry_value_new_breadcrumb(NULL, message); |
| 13 | + sentry_value_set_by_key( |
| 14 | + breadcrumb, "timestamp", sentry_value_new_string(timestamp)); |
| 15 | + return breadcrumb; |
| 16 | +} |
| 17 | + |
9 | 18 | SENTRY_TEST(value_null) |
10 | 19 | { |
11 | 20 | sentry_value_t val = sentry_value_new_null(); |
@@ -1564,3 +1573,114 @@ SENTRY_TEST(value_from_msgpack_flat_buffer) |
1564 | 1573 | sentry_value_decref(val3); |
1565 | 1574 | sentry_value_decref(result); |
1566 | 1575 | } |
| 1576 | + |
| 1577 | +#define TEST_CHECK_MESSAGE_EQUAL(breadcrumbs, index, message) \ |
| 1578 | + TEST_CHECK_STRING_EQUAL( \ |
| 1579 | + sentry_value_as_string(sentry_value_get_by_key( \ |
| 1580 | + sentry_value_get_by_index(breadcrumbs, index), "message")), \ |
| 1581 | + message) |
| 1582 | + |
| 1583 | +SENTRY_TEST(value_merge_breadcrumbs_both_empty) |
| 1584 | +{ |
| 1585 | + sentry_value_t list_a = sentry_value_new_list(); |
| 1586 | + sentry_value_t list_b = sentry_value_new_list(); |
| 1587 | + |
| 1588 | + sentry_value_t result = sentry__value_merge_breadcrumbs(list_a, list_b, 10); |
| 1589 | + TEST_CHECK(sentry_value_is_null(result)); |
| 1590 | + |
| 1591 | + sentry_value_decref(list_a); |
| 1592 | + sentry_value_decref(list_b); |
| 1593 | +} |
| 1594 | + |
| 1595 | +SENTRY_TEST(value_merge_breadcrumbs_one_empty) |
| 1596 | +{ |
| 1597 | + sentry_value_t list_a = sentry_value_new_list(); |
| 1598 | + sentry_value_append( |
| 1599 | + list_a, breadcrumb_with_ts("a1", "2024-01-01T00:00:01")); |
| 1600 | + sentry_value_append( |
| 1601 | + list_a, breadcrumb_with_ts("a2", "2024-01-01T00:00:02")); |
| 1602 | + sentry_value_t list_b = sentry_value_new_list(); |
| 1603 | + |
| 1604 | + // list_b is empty -> return list_a |
| 1605 | + sentry_value_t result = sentry__value_merge_breadcrumbs(list_a, list_b, 10); |
| 1606 | + TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
| 1607 | + TEST_CHECK_INT_EQUAL(sentry_value_get_length(result), 2); |
| 1608 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "a1"); |
| 1609 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "a2"); |
| 1610 | + sentry_value_decref(result); |
| 1611 | + |
| 1612 | + // list_a is empty -> return list_b |
| 1613 | + sentry_value_t list_c = sentry_value_new_list(); |
| 1614 | + result = sentry__value_merge_breadcrumbs(list_c, list_a, 10); |
| 1615 | + TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
| 1616 | + TEST_CHECK_INT_EQUAL(sentry_value_get_length(result), 2); |
| 1617 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "a1"); |
| 1618 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "a2"); |
| 1619 | + sentry_value_decref(result); |
| 1620 | + |
| 1621 | + sentry_value_decref(list_a); |
| 1622 | + sentry_value_decref(list_b); |
| 1623 | + sentry_value_decref(list_c); |
| 1624 | +} |
| 1625 | + |
| 1626 | +SENTRY_TEST(value_merge_breadcrumbs_interleaved) |
| 1627 | +{ |
| 1628 | + sentry_value_t list_a = sentry_value_new_list(); |
| 1629 | + sentry_value_append( |
| 1630 | + list_a, breadcrumb_with_ts("a1", "2024-01-01T00:00:01")); |
| 1631 | + sentry_value_append( |
| 1632 | + list_a, breadcrumb_with_ts("a4", "2024-01-01T00:00:04")); |
| 1633 | + |
| 1634 | + sentry_value_t list_b = sentry_value_new_list(); |
| 1635 | + sentry_value_append( |
| 1636 | + list_b, breadcrumb_with_ts("b2", "2024-01-01T00:00:02")); |
| 1637 | + sentry_value_append( |
| 1638 | + list_b, breadcrumb_with_ts("b3", "2024-01-01T00:00:03")); |
| 1639 | + |
| 1640 | + sentry_value_t result = sentry__value_merge_breadcrumbs(list_a, list_b, 10); |
| 1641 | + TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
| 1642 | + TEST_CHECK_INT_EQUAL(sentry_value_get_length(result), 4); |
| 1643 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "a1"); |
| 1644 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "b2"); |
| 1645 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "b3"); |
| 1646 | + TEST_CHECK_MESSAGE_EQUAL(result, 3, "a4"); |
| 1647 | + |
| 1648 | + sentry_value_decref(result); |
| 1649 | + sentry_value_decref(list_a); |
| 1650 | + sentry_value_decref(list_b); |
| 1651 | +} |
| 1652 | + |
| 1653 | +SENTRY_TEST(value_merge_breadcrumbs_max_limit) |
| 1654 | +{ |
| 1655 | + sentry_value_t list_a = sentry_value_new_list(); |
| 1656 | + sentry_value_append( |
| 1657 | + list_a, breadcrumb_with_ts("a1", "2024-01-01T00:00:01")); |
| 1658 | + sentry_value_append( |
| 1659 | + list_a, breadcrumb_with_ts("a3", "2024-01-01T00:00:03")); |
| 1660 | + |
| 1661 | + sentry_value_t list_b = sentry_value_new_list(); |
| 1662 | + sentry_value_append( |
| 1663 | + list_b, breadcrumb_with_ts("b2", "2024-01-01T00:00:02")); |
| 1664 | + sentry_value_append( |
| 1665 | + list_b, breadcrumb_with_ts("b4", "2024-01-01T00:00:04")); |
| 1666 | + |
| 1667 | + // max=3 -> oldest (a1) should be dropped |
| 1668 | + sentry_value_t result = sentry__value_merge_breadcrumbs(list_a, list_b, 3); |
| 1669 | + TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
| 1670 | + TEST_CHECK_INT_EQUAL(sentry_value_get_length(result), 3); |
| 1671 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "b2"); |
| 1672 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "a3"); |
| 1673 | + TEST_CHECK_MESSAGE_EQUAL(result, 2, "b4"); |
| 1674 | + sentry_value_decref(result); |
| 1675 | + |
| 1676 | + // max=2 -> oldest two (a1, b2) should be dropped |
| 1677 | + result = sentry__value_merge_breadcrumbs(list_a, list_b, 2); |
| 1678 | + TEST_CHECK(sentry_value_get_type(result) == SENTRY_VALUE_TYPE_LIST); |
| 1679 | + TEST_CHECK_INT_EQUAL(sentry_value_get_length(result), 2); |
| 1680 | + TEST_CHECK_MESSAGE_EQUAL(result, 0, "a3"); |
| 1681 | + TEST_CHECK_MESSAGE_EQUAL(result, 1, "b4"); |
| 1682 | + sentry_value_decref(result); |
| 1683 | + |
| 1684 | + sentry_value_decref(list_a); |
| 1685 | + sentry_value_decref(list_b); |
| 1686 | +} |
0 commit comments