|
| 1 | +#include "sentry.h" |
| 2 | +#include "sentry_scope.h" |
| 3 | +#include "sentry_testsupport.h" |
| 4 | + |
| 5 | +SENTRY_TEST(scope_contexts) |
| 6 | +{ |
| 7 | + SENTRY_TEST_OPTIONS_NEW(options); |
| 8 | + sentry_init(options); |
| 9 | + |
| 10 | +#define TEST_CHECK_CONTEXT_EQUAL(event, key, value) \ |
| 11 | + do { \ |
| 12 | + sentry_value_t contexts = sentry_value_get_by_key(event, "contexts"); \ |
| 13 | + TEST_CHECK_STRING_EQUAL( \ |
| 14 | + sentry_value_as_string(sentry_value_get_by_key(contexts, key)), \ |
| 15 | + value); \ |
| 16 | + } while (0) |
| 17 | + |
| 18 | + // scope: {"both":"scope","scope":"scope"} |
| 19 | + sentry_set_context("both", sentry_value_new_string("scope")); |
| 20 | + sentry_set_context("scope", sentry_value_new_string("scope")); |
| 21 | + |
| 22 | + SENTRY_WITH_SCOPE (scope) { |
| 23 | + // event: {"both":"event","event":"event"} |
| 24 | + sentry_value_t event = sentry_value_new_object(); |
| 25 | + { |
| 26 | + sentry_value_t contexts = sentry_value_new_object(); |
| 27 | + sentry_value_set_by_key( |
| 28 | + contexts, "both", sentry_value_new_string("event")); |
| 29 | + sentry_value_set_by_key( |
| 30 | + contexts, "event", sentry_value_new_string("event")); |
| 31 | + sentry_value_set_by_key(event, "contexts", contexts); |
| 32 | + } |
| 33 | + |
| 34 | + // event <- scope: {"both":"event","event":"event","scope":"scope"} |
| 35 | + sentry__scope_apply_to_event(scope, options, event, SENTRY_SCOPE_NONE); |
| 36 | + TEST_CHECK_CONTEXT_EQUAL(event, "both", "event"); |
| 37 | + TEST_CHECK_CONTEXT_EQUAL(event, "event", "event"); |
| 38 | + TEST_CHECK_CONTEXT_EQUAL(event, "scope", "scope"); |
| 39 | + |
| 40 | + sentry_value_decref(event); |
| 41 | + } |
| 42 | + |
| 43 | +#undef TEST_CHECK_CONTEXT_EQUAL |
| 44 | + |
| 45 | + sentry_close(); |
| 46 | +} |
| 47 | + |
| 48 | +SENTRY_TEST(scope_extra) |
| 49 | +{ |
| 50 | + SENTRY_TEST_OPTIONS_NEW(options); |
| 51 | + sentry_init(options); |
| 52 | + |
| 53 | +#define TEST_CHECK_EXTRA_EQUAL(event, key, value) \ |
| 54 | + do { \ |
| 55 | + sentry_value_t extra = sentry_value_get_by_key(event, "extra"); \ |
| 56 | + TEST_CHECK_STRING_EQUAL( \ |
| 57 | + sentry_value_as_string(sentry_value_get_by_key(extra, key)), \ |
| 58 | + value); \ |
| 59 | + } while (0) |
| 60 | + |
| 61 | + // scope: {"both":"scope","scope":"scope"} |
| 62 | + sentry_set_extra("both", sentry_value_new_string("scope")); |
| 63 | + sentry_set_extra("scope", sentry_value_new_string("scope")); |
| 64 | + |
| 65 | + SENTRY_WITH_SCOPE (scope) { |
| 66 | + // event: {"both":"event","event":"event"} |
| 67 | + sentry_value_t event = sentry_value_new_object(); |
| 68 | + { |
| 69 | + sentry_value_t extra = sentry_value_new_object(); |
| 70 | + sentry_value_set_by_key( |
| 71 | + extra, "both", sentry_value_new_string("event")); |
| 72 | + sentry_value_set_by_key( |
| 73 | + extra, "event", sentry_value_new_string("event")); |
| 74 | + sentry_value_set_by_key(event, "extra", extra); |
| 75 | + } |
| 76 | + |
| 77 | + // event <- scope: {"both":"event","event":"event","scope":"scope"} |
| 78 | + sentry__scope_apply_to_event(scope, options, event, SENTRY_SCOPE_NONE); |
| 79 | + TEST_CHECK_EXTRA_EQUAL(event, "both", "event"); |
| 80 | + TEST_CHECK_EXTRA_EQUAL(event, "event", "event"); |
| 81 | + TEST_CHECK_EXTRA_EQUAL(event, "scope", "scope"); |
| 82 | + |
| 83 | + sentry_value_decref(event); |
| 84 | + } |
| 85 | + |
| 86 | +#undef TEST_CHECK_EXTRA_EQUAL |
| 87 | + |
| 88 | + sentry_close(); |
| 89 | +} |
| 90 | + |
| 91 | +SENTRY_TEST(scope_tags) |
| 92 | +{ |
| 93 | + SENTRY_TEST_OPTIONS_NEW(options); |
| 94 | + sentry_init(options); |
| 95 | + |
| 96 | +#define TEST_CHECK_TAG_EQUAL(event, key, value) \ |
| 97 | + do { \ |
| 98 | + sentry_value_t tags = sentry_value_get_by_key(event, "tags"); \ |
| 99 | + TEST_CHECK_STRING_EQUAL( \ |
| 100 | + sentry_value_as_string(sentry_value_get_by_key(tags, key)), \ |
| 101 | + value); \ |
| 102 | + } while (0) |
| 103 | + |
| 104 | + // scope: {"both":"scope","scope":"scope"} |
| 105 | + sentry_set_tag("both", "scope"); |
| 106 | + sentry_set_tag("scope", "scope"); |
| 107 | + |
| 108 | + SENTRY_WITH_SCOPE (scope) { |
| 109 | + // event: {"both":"event","event":"event"} |
| 110 | + sentry_value_t event = sentry_value_new_object(); |
| 111 | + { |
| 112 | + sentry_value_t tags = sentry_value_new_object(); |
| 113 | + sentry_value_set_by_key( |
| 114 | + tags, "both", sentry_value_new_string("event")); |
| 115 | + sentry_value_set_by_key( |
| 116 | + tags, "event", sentry_value_new_string("event")); |
| 117 | + sentry_value_set_by_key(event, "tags", tags); |
| 118 | + } |
| 119 | + |
| 120 | + // event <- scope: {"both":"event","event":"event","scope":"scope"} |
| 121 | + sentry__scope_apply_to_event(scope, options, event, SENTRY_SCOPE_NONE); |
| 122 | + TEST_CHECK_TAG_EQUAL(event, "both", "event"); |
| 123 | + TEST_CHECK_TAG_EQUAL(event, "event", "event"); |
| 124 | + TEST_CHECK_TAG_EQUAL(event, "scope", "scope"); |
| 125 | + |
| 126 | + sentry_value_decref(event); |
| 127 | + } |
| 128 | + |
| 129 | +#undef TEST_CHECK_TAG_EQUAL |
| 130 | + |
| 131 | + sentry_close(); |
| 132 | +} |
0 commit comments