Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "alignment_test.h" | ||
|
||
#include "flatbuffers/flatbuffer_builder.h" | ||
#include "alignment_test_generated.h" | ||
#include "test_assert.h" | ||
|
||
namespace flatbuffers { | ||
namespace tests { | ||
|
||
void AlignmentTest() { | ||
FlatBufferBuilder builder; | ||
|
||
BadAlignmentLarge large; | ||
Offset<OuterLarge> outer_large = CreateOuterLarge(builder, &large); | ||
|
||
BadAlignmentSmall *small; | ||
Offset<Vector<const BadAlignmentSmall *>> small_offset = | ||
builder.CreateUninitializedVectorOfStructs(9, &small); | ||
(void)small; // We do not have to write data to trigger the test failure | ||
|
||
Offset<BadAlignmentRoot> root = | ||
CreateBadAlignmentRoot(builder, outer_large, small_offset); | ||
|
||
builder.Finish(root); | ||
|
||
Verifier verifier(builder.GetBufferPointer(), builder.GetSize()); | ||
TEST_ASSERT(VerifyBadAlignmentRootBuffer(verifier)); | ||
} | ||
|
||
} // namespace tests | ||
} // namespace flatbuffers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// sizeof(BadAlignmentSmall) == 12 | ||
// alignof(BadAlignmentSmall) == 4 | ||
struct BadAlignmentSmall { | ||
var_0: uint; | ||
var_1: uint; | ||
var_2: uint; | ||
} | ||
|
||
table OuterSmall { | ||
// ar: [BadAlignmentSmall]; | ||
small: BadAlignmentSmall; | ||
var_0: uint; | ||
var_1: uint; | ||
var_2: uint; | ||
} | ||
|
||
// sizeof(BadAlignmentLarge) == 8 | ||
// alignof(BadAlignmentLarge) == 8 | ||
struct BadAlignmentLarge { | ||
var_0: ulong; | ||
} | ||
|
||
table OuterLarge { | ||
large: BadAlignmentLarge; | ||
} | ||
|
||
table BadAlignmentRoot { | ||
large: OuterLarge; | ||
small: [BadAlignmentSmall]; | ||
} | ||
|
||
root_type BadAlignmentRoot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TESTS_ALIGNMENT_TEST_H | ||
#define TESTS_ALIGNMENT_TEST_H | ||
|
||
namespace flatbuffers { | ||
namespace tests { | ||
|
||
void AlignmentTest(); | ||
|
||
} // namespace tests | ||
} // namespace flatbuffers | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters