|
2 | 2 | #include "sentry_testsupport.h" |
3 | 3 |
|
4 | 4 | #include "sentry_envelope.h" |
| 5 | +#include <string.h> |
5 | 6 |
|
6 | 7 | #ifdef SENTRY_PLATFORM_WINDOWS |
7 | 8 | # include <windows.h> |
@@ -168,3 +169,106 @@ SENTRY_TEST(logs_param_conversion) |
168 | 169 | test_param_conversion_helper("%d %d %d", a, b, c); |
169 | 170 | #endif |
170 | 171 | } |
| 172 | + |
| 173 | +static void |
| 174 | +test_param_conversion_types(const char *format, ...) |
| 175 | +{ |
| 176 | + sentry_value_t attributes = sentry_value_new_object(); |
| 177 | + va_list args; |
| 178 | + va_start(args, format); |
| 179 | + int param_count = populate_message_parameters(attributes, format, args); |
| 180 | + va_end(args); |
| 181 | + |
| 182 | + // Verify we got the expected number of parameters |
| 183 | + TEST_CHECK_INT_EQUAL(param_count, 7); |
| 184 | + |
| 185 | + // Verify the parameters were extracted correctly |
| 186 | + sentry_value_t param0 |
| 187 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.0"); |
| 188 | + sentry_value_t param1 |
| 189 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.1"); |
| 190 | + sentry_value_t param2 |
| 191 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.2"); |
| 192 | + sentry_value_t param3 |
| 193 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.3"); |
| 194 | + sentry_value_t param4 |
| 195 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.4"); |
| 196 | + sentry_value_t param5 |
| 197 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.5"); |
| 198 | + sentry_value_t param6 |
| 199 | + = sentry_value_get_by_key(attributes, "sentry.message.parameter.6"); |
| 200 | + |
| 201 | + TEST_CHECK(!sentry_value_is_null(param0)); |
| 202 | + TEST_CHECK(!sentry_value_is_null(param1)); |
| 203 | + TEST_CHECK(!sentry_value_is_null(param2)); |
| 204 | + TEST_CHECK(!sentry_value_is_null(param3)); |
| 205 | + TEST_CHECK(!sentry_value_is_null(param4)); |
| 206 | + TEST_CHECK(!sentry_value_is_null(param5)); |
| 207 | + TEST_CHECK(!sentry_value_is_null(param6)); |
| 208 | + |
| 209 | + // Check the values and types |
| 210 | + sentry_value_t value0 = sentry_value_get_by_key(param0, "value"); |
| 211 | + sentry_value_t value1 = sentry_value_get_by_key(param1, "value"); |
| 212 | + sentry_value_t value2 = sentry_value_get_by_key(param2, "value"); |
| 213 | + sentry_value_t value3 = sentry_value_get_by_key(param3, "value"); |
| 214 | + sentry_value_t value4 = sentry_value_get_by_key(param4, "value"); |
| 215 | + sentry_value_t value5 = sentry_value_get_by_key(param5, "value"); |
| 216 | + sentry_value_t value6 = sentry_value_get_by_key(param6, "value"); |
| 217 | + |
| 218 | + sentry_value_t type0 = sentry_value_get_by_key(param0, "type"); |
| 219 | + sentry_value_t type1 = sentry_value_get_by_key(param1, "type"); |
| 220 | + sentry_value_t type2 = sentry_value_get_by_key(param2, "type"); |
| 221 | + sentry_value_t type3 = sentry_value_get_by_key(param3, "type"); |
| 222 | + sentry_value_t type4 = sentry_value_get_by_key(param4, "type"); |
| 223 | + sentry_value_t type5 = sentry_value_get_by_key(param5, "type"); |
| 224 | + sentry_value_t type6 = sentry_value_get_by_key(param6, "type"); |
| 225 | + |
| 226 | + // Validate %u (unsigned) - should be string type with UINT64_MAX value |
| 227 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type0), "string"); |
| 228 | + TEST_CHECK_STRING_EQUAL( |
| 229 | + sentry_value_as_string(value0), "18446744073709551615"); |
| 230 | + |
| 231 | + // Validate %d (signed integer) - should be integer type with INT64_MIN |
| 232 | + // value |
| 233 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type1), "integer"); |
| 234 | + TEST_CHECK_INT_EQUAL(sentry_value_as_int64(value1), INT64_MIN); |
| 235 | + |
| 236 | + // Validate %f (float) - should be double type with 3.14159 value |
| 237 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type2), "double"); |
| 238 | + TEST_CHECK(sentry_value_as_double(value2) == 3.14159); |
| 239 | + |
| 240 | + // Validate %c (character) - should be string type with 'A' value |
| 241 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type3), "string"); |
| 242 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(value3), "A"); |
| 243 | + |
| 244 | + // Validate %s (string) - should be string type with "test" value |
| 245 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type4), "string"); |
| 246 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(value4), "test"); |
| 247 | + |
| 248 | + // Validate %p (pointer) - should be string type with pointer representation |
| 249 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type5), "string"); |
| 250 | + // Pointer value format is platform-dependent, but should contain the hex |
| 251 | + // digits (can be upper- or lower-cased) |
| 252 | + const char *ptr_str = sentry_value_as_string(value5); |
| 253 | + TEST_CHECK(ptr_str != NULL); |
| 254 | + TEST_CHECK(strstr(ptr_str, "12345abc") != NULL |
| 255 | + || strstr(ptr_str, "12345ABC") != NULL); |
| 256 | + |
| 257 | + // Validate %x (hex uint64) - should be string type with hex representation |
| 258 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(type6), "string"); |
| 259 | + TEST_CHECK_STRING_EQUAL(sentry_value_as_string(value6), "deadbeefdeadbeef"); |
| 260 | + |
| 261 | + sentry_value_decref(attributes); |
| 262 | +} |
| 263 | + |
| 264 | +SENTRY_TEST(logs_param_types) |
| 265 | +{ |
| 266 | + uint64_t a = UINT64_MAX; |
| 267 | + int64_t b = INT64_MIN; |
| 268 | + double c = 3.14159; |
| 269 | + char d = 'A'; |
| 270 | + const char *e = "test"; |
| 271 | + void *f = (void *)0x12345abc; |
| 272 | + uint64_t g = 0xDEADBEEFDEADBEEF; |
| 273 | + test_param_conversion_types("%u %d %f %c %s %p %x", a, b, c, d, e, f, g); |
| 274 | +} |
0 commit comments