James Kuszmaul | 3b15b0c | 2022-11-08 14:03:16 -0800 | [diff] [blame] | 1 | #include "alignment_test.h" |
| 2 | |
| 3 | #include "flatbuffers/flatbuffer_builder.h" |
| 4 | #include "alignment_test_generated.h" |
| 5 | #include "test_assert.h" |
| 6 | |
| 7 | namespace flatbuffers { |
| 8 | namespace tests { |
| 9 | |
| 10 | void AlignmentTest() { |
| 11 | FlatBufferBuilder builder; |
| 12 | |
| 13 | BadAlignmentLarge large; |
| 14 | Offset<OuterLarge> outer_large = CreateOuterLarge(builder, &large); |
| 15 | |
| 16 | BadAlignmentSmall *small; |
| 17 | Offset<Vector<const BadAlignmentSmall *>> small_offset = |
| 18 | builder.CreateUninitializedVectorOfStructs(9, &small); |
| 19 | (void)small; // We do not have to write data to trigger the test failure |
| 20 | |
| 21 | Offset<BadAlignmentRoot> root = |
| 22 | CreateBadAlignmentRoot(builder, outer_large, small_offset); |
| 23 | |
| 24 | builder.Finish(root); |
| 25 | |
| 26 | Verifier verifier(builder.GetBufferPointer(), builder.GetSize()); |
| 27 | TEST_ASSERT(VerifyBadAlignmentRootBuffer(verifier)); |
| 28 | } |
| 29 | |
| 30 | } // namespace tests |
| 31 | } // namespace flatbuffers |