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