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