James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 1 | #include "aos/util/mcap_logger.h" |
| 2 | |
| 3 | #include <iostream> |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 4 | |
James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 5 | #include "flatbuffers/reflection_generated.h" |
| 6 | #include "gtest/gtest.h" |
| 7 | |
| 8 | namespace aos::testing { |
| 9 | // TODO(james): Write a proper test for the McapLogger itself. However, that |
| 10 | // will require writing an MCAP reader (or importing an existing one). |
| 11 | |
| 12 | // Confirm that the schema for the reflection.Schema table itself hasn't |
James Kuszmaul | 1e418f6 | 2023-02-26 14:40:20 -0800 | [diff] [blame^] | 13 | // changed. reflection.Schema should be a very stable type, so this should |
| 14 | // need |
James Kuszmaul | 4ed5fb1 | 2022-03-22 15:20:04 -0700 | [diff] [blame] | 15 | // updating except when we change the JSON schema generation itself. |
| 16 | TEST(JsonSchemaTest, ReflectionSchema) { |
| 17 | std::string schema_json = |
| 18 | JsonSchemaForFlatbuffer({reflection::Schema::MiniReflectTypeTable()}) |
| 19 | .dump(4); |
| 20 | EXPECT_EQ(R"json({ |
| 21 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 22 | "properties": { |
| 23 | "advanced_features": { |
| 24 | "type": "number" |
| 25 | }, |
| 26 | "enums": { |
| 27 | "items": { |
| 28 | "properties": { |
| 29 | "attributes": { |
| 30 | "items": { |
| 31 | "properties": { |
| 32 | "key": { |
| 33 | "type": "string" |
| 34 | }, |
| 35 | "value": { |
| 36 | "type": "string" |
| 37 | } |
| 38 | }, |
| 39 | "type": "object" |
| 40 | }, |
| 41 | "type": "array" |
| 42 | }, |
| 43 | "declaration_file": { |
| 44 | "type": "string" |
| 45 | }, |
| 46 | "documentation": { |
| 47 | "items": { |
| 48 | "type": "string" |
| 49 | }, |
| 50 | "type": "array" |
| 51 | }, |
| 52 | "is_union": { |
| 53 | "type": "boolean" |
| 54 | }, |
| 55 | "name": { |
| 56 | "type": "string" |
| 57 | }, |
| 58 | "underlying_type": { |
| 59 | "properties": { |
| 60 | "base_size": { |
| 61 | "type": "number" |
| 62 | }, |
| 63 | "base_type": { |
| 64 | "type": "number" |
| 65 | }, |
| 66 | "element": { |
| 67 | "type": "number" |
| 68 | }, |
| 69 | "element_size": { |
| 70 | "type": "number" |
| 71 | }, |
| 72 | "fixed_length": { |
| 73 | "type": "number" |
| 74 | }, |
| 75 | "index": { |
| 76 | "type": "number" |
| 77 | } |
| 78 | }, |
| 79 | "type": "object" |
| 80 | }, |
| 81 | "values": { |
| 82 | "items": { |
| 83 | "properties": { |
| 84 | "documentation": { |
| 85 | "items": { |
| 86 | "type": "string" |
| 87 | }, |
| 88 | "type": "array" |
| 89 | }, |
| 90 | "name": { |
| 91 | "type": "string" |
| 92 | }, |
| 93 | "object": { |
| 94 | "properties": { |
| 95 | "attributes": { |
| 96 | "items": { |
| 97 | "properties": { |
| 98 | "key": { |
| 99 | "type": "string" |
| 100 | }, |
| 101 | "value": { |
| 102 | "type": "string" |
| 103 | } |
| 104 | }, |
| 105 | "type": "object" |
| 106 | }, |
| 107 | "type": "array" |
| 108 | }, |
| 109 | "bytesize": { |
| 110 | "type": "number" |
| 111 | }, |
| 112 | "declaration_file": { |
| 113 | "type": "string" |
| 114 | }, |
| 115 | "documentation": { |
| 116 | "items": { |
| 117 | "type": "string" |
| 118 | }, |
| 119 | "type": "array" |
| 120 | }, |
| 121 | "fields": { |
| 122 | "items": { |
| 123 | "properties": { |
| 124 | "attributes": { |
| 125 | "items": { |
| 126 | "properties": { |
| 127 | "key": { |
| 128 | "type": "string" |
| 129 | }, |
| 130 | "value": { |
| 131 | "type": "string" |
| 132 | } |
| 133 | }, |
| 134 | "type": "object" |
| 135 | }, |
| 136 | "type": "array" |
| 137 | }, |
| 138 | "default_integer": { |
| 139 | "type": "number" |
| 140 | }, |
| 141 | "default_real": { |
| 142 | "type": "number" |
| 143 | }, |
| 144 | "deprecated": { |
| 145 | "type": "boolean" |
| 146 | }, |
| 147 | "documentation": { |
| 148 | "items": { |
| 149 | "type": "string" |
| 150 | }, |
| 151 | "type": "array" |
| 152 | }, |
| 153 | "id": { |
| 154 | "type": "number" |
| 155 | }, |
| 156 | "key": { |
| 157 | "type": "boolean" |
| 158 | }, |
| 159 | "name": { |
| 160 | "type": "string" |
| 161 | }, |
| 162 | "offset": { |
| 163 | "type": "number" |
| 164 | }, |
| 165 | "optional": { |
| 166 | "type": "boolean" |
| 167 | }, |
| 168 | "padding": { |
| 169 | "type": "number" |
| 170 | }, |
| 171 | "required": { |
| 172 | "type": "boolean" |
| 173 | }, |
| 174 | "type": { |
| 175 | "properties": { |
| 176 | "base_size": { |
| 177 | "type": "number" |
| 178 | }, |
| 179 | "base_type": { |
| 180 | "type": "number" |
| 181 | }, |
| 182 | "element": { |
| 183 | "type": "number" |
| 184 | }, |
| 185 | "element_size": { |
| 186 | "type": "number" |
| 187 | }, |
| 188 | "fixed_length": { |
| 189 | "type": "number" |
| 190 | }, |
| 191 | "index": { |
| 192 | "type": "number" |
| 193 | } |
| 194 | }, |
| 195 | "type": "object" |
| 196 | } |
| 197 | }, |
| 198 | "type": "object" |
| 199 | }, |
| 200 | "type": "array" |
| 201 | }, |
| 202 | "is_struct": { |
| 203 | "type": "boolean" |
| 204 | }, |
| 205 | "minalign": { |
| 206 | "type": "number" |
| 207 | }, |
| 208 | "name": { |
| 209 | "type": "string" |
| 210 | } |
| 211 | }, |
| 212 | "type": "object" |
| 213 | }, |
| 214 | "union_type": { |
| 215 | "properties": { |
| 216 | "base_size": { |
| 217 | "type": "number" |
| 218 | }, |
| 219 | "base_type": { |
| 220 | "type": "number" |
| 221 | }, |
| 222 | "element": { |
| 223 | "type": "number" |
| 224 | }, |
| 225 | "element_size": { |
| 226 | "type": "number" |
| 227 | }, |
| 228 | "fixed_length": { |
| 229 | "type": "number" |
| 230 | }, |
| 231 | "index": { |
| 232 | "type": "number" |
| 233 | } |
| 234 | }, |
| 235 | "type": "object" |
| 236 | }, |
| 237 | "value": { |
| 238 | "type": "number" |
| 239 | } |
| 240 | }, |
| 241 | "type": "object" |
| 242 | }, |
| 243 | "type": "array" |
| 244 | } |
| 245 | }, |
| 246 | "type": "object" |
| 247 | }, |
| 248 | "type": "array" |
| 249 | }, |
| 250 | "fbs_files": { |
| 251 | "items": { |
| 252 | "properties": { |
| 253 | "filename": { |
| 254 | "type": "string" |
| 255 | }, |
| 256 | "included_filenames": { |
| 257 | "items": { |
| 258 | "type": "string" |
| 259 | }, |
| 260 | "type": "array" |
| 261 | } |
| 262 | }, |
| 263 | "type": "object" |
| 264 | }, |
| 265 | "type": "array" |
| 266 | }, |
| 267 | "file_ext": { |
| 268 | "type": "string" |
| 269 | }, |
| 270 | "file_ident": { |
| 271 | "type": "string" |
| 272 | }, |
| 273 | "objects": { |
| 274 | "items": { |
| 275 | "properties": { |
| 276 | "attributes": { |
| 277 | "items": { |
| 278 | "properties": { |
| 279 | "key": { |
| 280 | "type": "string" |
| 281 | }, |
| 282 | "value": { |
| 283 | "type": "string" |
| 284 | } |
| 285 | }, |
| 286 | "type": "object" |
| 287 | }, |
| 288 | "type": "array" |
| 289 | }, |
| 290 | "bytesize": { |
| 291 | "type": "number" |
| 292 | }, |
| 293 | "declaration_file": { |
| 294 | "type": "string" |
| 295 | }, |
| 296 | "documentation": { |
| 297 | "items": { |
| 298 | "type": "string" |
| 299 | }, |
| 300 | "type": "array" |
| 301 | }, |
| 302 | "fields": { |
| 303 | "items": { |
| 304 | "properties": { |
| 305 | "attributes": { |
| 306 | "items": { |
| 307 | "properties": { |
| 308 | "key": { |
| 309 | "type": "string" |
| 310 | }, |
| 311 | "value": { |
| 312 | "type": "string" |
| 313 | } |
| 314 | }, |
| 315 | "type": "object" |
| 316 | }, |
| 317 | "type": "array" |
| 318 | }, |
| 319 | "default_integer": { |
| 320 | "type": "number" |
| 321 | }, |
| 322 | "default_real": { |
| 323 | "type": "number" |
| 324 | }, |
| 325 | "deprecated": { |
| 326 | "type": "boolean" |
| 327 | }, |
| 328 | "documentation": { |
| 329 | "items": { |
| 330 | "type": "string" |
| 331 | }, |
| 332 | "type": "array" |
| 333 | }, |
| 334 | "id": { |
| 335 | "type": "number" |
| 336 | }, |
| 337 | "key": { |
| 338 | "type": "boolean" |
| 339 | }, |
| 340 | "name": { |
| 341 | "type": "string" |
| 342 | }, |
| 343 | "offset": { |
| 344 | "type": "number" |
| 345 | }, |
| 346 | "optional": { |
| 347 | "type": "boolean" |
| 348 | }, |
| 349 | "padding": { |
| 350 | "type": "number" |
| 351 | }, |
| 352 | "required": { |
| 353 | "type": "boolean" |
| 354 | }, |
| 355 | "type": { |
| 356 | "properties": { |
| 357 | "base_size": { |
| 358 | "type": "number" |
| 359 | }, |
| 360 | "base_type": { |
| 361 | "type": "number" |
| 362 | }, |
| 363 | "element": { |
| 364 | "type": "number" |
| 365 | }, |
| 366 | "element_size": { |
| 367 | "type": "number" |
| 368 | }, |
| 369 | "fixed_length": { |
| 370 | "type": "number" |
| 371 | }, |
| 372 | "index": { |
| 373 | "type": "number" |
| 374 | } |
| 375 | }, |
| 376 | "type": "object" |
| 377 | } |
| 378 | }, |
| 379 | "type": "object" |
| 380 | }, |
| 381 | "type": "array" |
| 382 | }, |
| 383 | "is_struct": { |
| 384 | "type": "boolean" |
| 385 | }, |
| 386 | "minalign": { |
| 387 | "type": "number" |
| 388 | }, |
| 389 | "name": { |
| 390 | "type": "string" |
| 391 | } |
| 392 | }, |
| 393 | "type": "object" |
| 394 | }, |
| 395 | "type": "array" |
| 396 | }, |
| 397 | "root_table": { |
| 398 | "properties": { |
| 399 | "attributes": { |
| 400 | "items": { |
| 401 | "properties": { |
| 402 | "key": { |
| 403 | "type": "string" |
| 404 | }, |
| 405 | "value": { |
| 406 | "type": "string" |
| 407 | } |
| 408 | }, |
| 409 | "type": "object" |
| 410 | }, |
| 411 | "type": "array" |
| 412 | }, |
| 413 | "bytesize": { |
| 414 | "type": "number" |
| 415 | }, |
| 416 | "declaration_file": { |
| 417 | "type": "string" |
| 418 | }, |
| 419 | "documentation": { |
| 420 | "items": { |
| 421 | "type": "string" |
| 422 | }, |
| 423 | "type": "array" |
| 424 | }, |
| 425 | "fields": { |
| 426 | "items": { |
| 427 | "properties": { |
| 428 | "attributes": { |
| 429 | "items": { |
| 430 | "properties": { |
| 431 | "key": { |
| 432 | "type": "string" |
| 433 | }, |
| 434 | "value": { |
| 435 | "type": "string" |
| 436 | } |
| 437 | }, |
| 438 | "type": "object" |
| 439 | }, |
| 440 | "type": "array" |
| 441 | }, |
| 442 | "default_integer": { |
| 443 | "type": "number" |
| 444 | }, |
| 445 | "default_real": { |
| 446 | "type": "number" |
| 447 | }, |
| 448 | "deprecated": { |
| 449 | "type": "boolean" |
| 450 | }, |
| 451 | "documentation": { |
| 452 | "items": { |
| 453 | "type": "string" |
| 454 | }, |
| 455 | "type": "array" |
| 456 | }, |
| 457 | "id": { |
| 458 | "type": "number" |
| 459 | }, |
| 460 | "key": { |
| 461 | "type": "boolean" |
| 462 | }, |
| 463 | "name": { |
| 464 | "type": "string" |
| 465 | }, |
| 466 | "offset": { |
| 467 | "type": "number" |
| 468 | }, |
| 469 | "optional": { |
| 470 | "type": "boolean" |
| 471 | }, |
| 472 | "padding": { |
| 473 | "type": "number" |
| 474 | }, |
| 475 | "required": { |
| 476 | "type": "boolean" |
| 477 | }, |
| 478 | "type": { |
| 479 | "properties": { |
| 480 | "base_size": { |
| 481 | "type": "number" |
| 482 | }, |
| 483 | "base_type": { |
| 484 | "type": "number" |
| 485 | }, |
| 486 | "element": { |
| 487 | "type": "number" |
| 488 | }, |
| 489 | "element_size": { |
| 490 | "type": "number" |
| 491 | }, |
| 492 | "fixed_length": { |
| 493 | "type": "number" |
| 494 | }, |
| 495 | "index": { |
| 496 | "type": "number" |
| 497 | } |
| 498 | }, |
| 499 | "type": "object" |
| 500 | } |
| 501 | }, |
| 502 | "type": "object" |
| 503 | }, |
| 504 | "type": "array" |
| 505 | }, |
| 506 | "is_struct": { |
| 507 | "type": "boolean" |
| 508 | }, |
| 509 | "minalign": { |
| 510 | "type": "number" |
| 511 | }, |
| 512 | "name": { |
| 513 | "type": "string" |
| 514 | } |
| 515 | }, |
| 516 | "type": "object" |
| 517 | }, |
| 518 | "services": { |
| 519 | "items": { |
| 520 | "properties": { |
| 521 | "attributes": { |
| 522 | "items": { |
| 523 | "properties": { |
| 524 | "key": { |
| 525 | "type": "string" |
| 526 | }, |
| 527 | "value": { |
| 528 | "type": "string" |
| 529 | } |
| 530 | }, |
| 531 | "type": "object" |
| 532 | }, |
| 533 | "type": "array" |
| 534 | }, |
| 535 | "calls": { |
| 536 | "items": { |
| 537 | "properties": { |
| 538 | "attributes": { |
| 539 | "items": { |
| 540 | "properties": { |
| 541 | "key": { |
| 542 | "type": "string" |
| 543 | }, |
| 544 | "value": { |
| 545 | "type": "string" |
| 546 | } |
| 547 | }, |
| 548 | "type": "object" |
| 549 | }, |
| 550 | "type": "array" |
| 551 | }, |
| 552 | "documentation": { |
| 553 | "items": { |
| 554 | "type": "string" |
| 555 | }, |
| 556 | "type": "array" |
| 557 | }, |
| 558 | "name": { |
| 559 | "type": "string" |
| 560 | }, |
| 561 | "request": { |
| 562 | "properties": { |
| 563 | "attributes": { |
| 564 | "items": { |
| 565 | "properties": { |
| 566 | "key": { |
| 567 | "type": "string" |
| 568 | }, |
| 569 | "value": { |
| 570 | "type": "string" |
| 571 | } |
| 572 | }, |
| 573 | "type": "object" |
| 574 | }, |
| 575 | "type": "array" |
| 576 | }, |
| 577 | "bytesize": { |
| 578 | "type": "number" |
| 579 | }, |
| 580 | "declaration_file": { |
| 581 | "type": "string" |
| 582 | }, |
| 583 | "documentation": { |
| 584 | "items": { |
| 585 | "type": "string" |
| 586 | }, |
| 587 | "type": "array" |
| 588 | }, |
| 589 | "fields": { |
| 590 | "items": { |
| 591 | "properties": { |
| 592 | "attributes": { |
| 593 | "items": { |
| 594 | "properties": { |
| 595 | "key": { |
| 596 | "type": "string" |
| 597 | }, |
| 598 | "value": { |
| 599 | "type": "string" |
| 600 | } |
| 601 | }, |
| 602 | "type": "object" |
| 603 | }, |
| 604 | "type": "array" |
| 605 | }, |
| 606 | "default_integer": { |
| 607 | "type": "number" |
| 608 | }, |
| 609 | "default_real": { |
| 610 | "type": "number" |
| 611 | }, |
| 612 | "deprecated": { |
| 613 | "type": "boolean" |
| 614 | }, |
| 615 | "documentation": { |
| 616 | "items": { |
| 617 | "type": "string" |
| 618 | }, |
| 619 | "type": "array" |
| 620 | }, |
| 621 | "id": { |
| 622 | "type": "number" |
| 623 | }, |
| 624 | "key": { |
| 625 | "type": "boolean" |
| 626 | }, |
| 627 | "name": { |
| 628 | "type": "string" |
| 629 | }, |
| 630 | "offset": { |
| 631 | "type": "number" |
| 632 | }, |
| 633 | "optional": { |
| 634 | "type": "boolean" |
| 635 | }, |
| 636 | "padding": { |
| 637 | "type": "number" |
| 638 | }, |
| 639 | "required": { |
| 640 | "type": "boolean" |
| 641 | }, |
| 642 | "type": { |
| 643 | "properties": { |
| 644 | "base_size": { |
| 645 | "type": "number" |
| 646 | }, |
| 647 | "base_type": { |
| 648 | "type": "number" |
| 649 | }, |
| 650 | "element": { |
| 651 | "type": "number" |
| 652 | }, |
| 653 | "element_size": { |
| 654 | "type": "number" |
| 655 | }, |
| 656 | "fixed_length": { |
| 657 | "type": "number" |
| 658 | }, |
| 659 | "index": { |
| 660 | "type": "number" |
| 661 | } |
| 662 | }, |
| 663 | "type": "object" |
| 664 | } |
| 665 | }, |
| 666 | "type": "object" |
| 667 | }, |
| 668 | "type": "array" |
| 669 | }, |
| 670 | "is_struct": { |
| 671 | "type": "boolean" |
| 672 | }, |
| 673 | "minalign": { |
| 674 | "type": "number" |
| 675 | }, |
| 676 | "name": { |
| 677 | "type": "string" |
| 678 | } |
| 679 | }, |
| 680 | "type": "object" |
| 681 | }, |
| 682 | "response": { |
| 683 | "properties": { |
| 684 | "attributes": { |
| 685 | "items": { |
| 686 | "properties": { |
| 687 | "key": { |
| 688 | "type": "string" |
| 689 | }, |
| 690 | "value": { |
| 691 | "type": "string" |
| 692 | } |
| 693 | }, |
| 694 | "type": "object" |
| 695 | }, |
| 696 | "type": "array" |
| 697 | }, |
| 698 | "bytesize": { |
| 699 | "type": "number" |
| 700 | }, |
| 701 | "declaration_file": { |
| 702 | "type": "string" |
| 703 | }, |
| 704 | "documentation": { |
| 705 | "items": { |
| 706 | "type": "string" |
| 707 | }, |
| 708 | "type": "array" |
| 709 | }, |
| 710 | "fields": { |
| 711 | "items": { |
| 712 | "properties": { |
| 713 | "attributes": { |
| 714 | "items": { |
| 715 | "properties": { |
| 716 | "key": { |
| 717 | "type": "string" |
| 718 | }, |
| 719 | "value": { |
| 720 | "type": "string" |
| 721 | } |
| 722 | }, |
| 723 | "type": "object" |
| 724 | }, |
| 725 | "type": "array" |
| 726 | }, |
| 727 | "default_integer": { |
| 728 | "type": "number" |
| 729 | }, |
| 730 | "default_real": { |
| 731 | "type": "number" |
| 732 | }, |
| 733 | "deprecated": { |
| 734 | "type": "boolean" |
| 735 | }, |
| 736 | "documentation": { |
| 737 | "items": { |
| 738 | "type": "string" |
| 739 | }, |
| 740 | "type": "array" |
| 741 | }, |
| 742 | "id": { |
| 743 | "type": "number" |
| 744 | }, |
| 745 | "key": { |
| 746 | "type": "boolean" |
| 747 | }, |
| 748 | "name": { |
| 749 | "type": "string" |
| 750 | }, |
| 751 | "offset": { |
| 752 | "type": "number" |
| 753 | }, |
| 754 | "optional": { |
| 755 | "type": "boolean" |
| 756 | }, |
| 757 | "padding": { |
| 758 | "type": "number" |
| 759 | }, |
| 760 | "required": { |
| 761 | "type": "boolean" |
| 762 | }, |
| 763 | "type": { |
| 764 | "properties": { |
| 765 | "base_size": { |
| 766 | "type": "number" |
| 767 | }, |
| 768 | "base_type": { |
| 769 | "type": "number" |
| 770 | }, |
| 771 | "element": { |
| 772 | "type": "number" |
| 773 | }, |
| 774 | "element_size": { |
| 775 | "type": "number" |
| 776 | }, |
| 777 | "fixed_length": { |
| 778 | "type": "number" |
| 779 | }, |
| 780 | "index": { |
| 781 | "type": "number" |
| 782 | } |
| 783 | }, |
| 784 | "type": "object" |
| 785 | } |
| 786 | }, |
| 787 | "type": "object" |
| 788 | }, |
| 789 | "type": "array" |
| 790 | }, |
| 791 | "is_struct": { |
| 792 | "type": "boolean" |
| 793 | }, |
| 794 | "minalign": { |
| 795 | "type": "number" |
| 796 | }, |
| 797 | "name": { |
| 798 | "type": "string" |
| 799 | } |
| 800 | }, |
| 801 | "type": "object" |
| 802 | } |
| 803 | }, |
| 804 | "type": "object" |
| 805 | }, |
| 806 | "type": "array" |
| 807 | }, |
| 808 | "declaration_file": { |
| 809 | "type": "string" |
| 810 | }, |
| 811 | "documentation": { |
| 812 | "items": { |
| 813 | "type": "string" |
| 814 | }, |
| 815 | "type": "array" |
| 816 | }, |
| 817 | "name": { |
| 818 | "type": "string" |
| 819 | } |
| 820 | }, |
| 821 | "type": "object" |
| 822 | }, |
| 823 | "type": "array" |
| 824 | } |
| 825 | }, |
| 826 | "type": "object" |
| 827 | })json", |
| 828 | schema_json); |
| 829 | } |
| 830 | |
| 831 | } // namespace aos::testing |