Skip to content

Commit

Permalink
Add more asserts
Browse files Browse the repository at this point in the history
  • Loading branch information
svenk177 committed Jun 14, 2019
1 parent 396259c commit f82db64
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions tests/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2687,19 +2687,27 @@ void FixedLengthArrayTest() {
// VS10 does not support typed enums, exclude from tests
#if !defined(_MSC_VER) || _MSC_VER >= 1700
MyGame::Example::NestedStruct nStruct0(MyGame::Example::TestEnum::B);
TEST_ASSERT(nStruct0.mutable_a());
nStruct0.mutable_a()->Mutate(0, 1);
nStruct0.mutable_a()->Mutate(1, 2);
TEST_ASSERT(nStruct0.mutable_c());
nStruct0.mutable_c()->Mutate(0, MyGame::Example::TestEnum::C);
nStruct0.mutable_c()->Mutate(1, MyGame::Example::TestEnum::A);

MyGame::Example::NestedStruct nStruct1(MyGame::Example::TestEnum::C);
TEST_ASSERT(nStruct1.mutable_a());
nStruct1.mutable_a()->Mutate(0, 3);
nStruct1.mutable_a()->Mutate(1, 4);
TEST_ASSERT(nStruct1.mutable_c());
nStruct1.mutable_c()->Mutate(0, MyGame::Example::TestEnum::C);
nStruct1.mutable_c()->Mutate(1, MyGame::Example::TestEnum::A);

MyGame::Example::ArrayStruct aStruct(2, 12);
for (int i = 0; i < 15; i++) aStruct.mutable_b()->Mutate(i, i + 1);
TEST_ASSERT(aStruct.b());
TEST_ASSERT(aStruct.mutable_b());
TEST_ASSERT(aStruct.mutable_d());
for (int i = 0; i < aStruct.b()->size(); i++)
aStruct.mutable_b()->Mutate(i, i + 1);
aStruct.mutable_d()->Mutate(0, nStruct0);
aStruct.mutable_d()->Mutate(1, nStruct1);

Expand All @@ -2709,28 +2717,42 @@ void FixedLengthArrayTest() {

auto p = MyGame::Example::GetMutableArrayTable(fbb.GetBufferPointer());
auto mArStruct = p->mutable_a();
TEST_ASSERT(mArStruct);
TEST_ASSERT(mArStruct->a());
TEST_ASSERT(mArStruct->b());
TEST_ASSERT(mArStruct->c());
TEST_ASSERT(mArStruct->d());
TEST_ASSERT(mArStruct->mutable_b());
TEST_ASSERT(mArStruct->mutable_d());
mArStruct->mutable_b()->Mutate(14, -14);
TEST_EQ(mArStruct->a(), 2);
TEST_EQ(mArStruct->b()->size(), 15);
TEST_EQ(mArStruct->b()->Get(aStruct.b()->size() - 1), -14);
TEST_EQ(mArStruct->c(), 12);
TEST_EQ(mArStruct->b()->Get(14), -14);
TEST_ASSERT(mArStruct->d()->Get(0).a());
TEST_EQ(mArStruct->d()->Get(0).a()->Get(0), 1);
TEST_EQ(mArStruct->d()->Get(0).a()->Get(1), 2);
TEST_ASSERT(mArStruct->d()->Get(1).a());
TEST_EQ(mArStruct->d()->Get(1).a()->Get(0), 3);
TEST_EQ(mArStruct->d()->Get(1).a()->Get(1), 4);
TEST_ASSERT(mArStruct->mutable_d()->GetMutablePointer(1));
TEST_ASSERT(mArStruct->mutable_d()->GetMutablePointer(1)->mutable_a());
mArStruct->mutable_d()->GetMutablePointer(1)->mutable_a()->Mutate(1, 5);
TEST_EQ(mArStruct->d()->Get(1).a()->Get(1), 5);
TEST_EQ(mArStruct->d()->Get(0).b() == MyGame::Example::TestEnum::B, true);
TEST_ASSERT(mArStruct->d()->Get(0).c());
TEST_EQ(mArStruct->d()->Get(0).c()->Get(0) == MyGame::Example::TestEnum::C,
true);
TEST_EQ(mArStruct->d()->Get(0).c()->Get(1) == MyGame::Example::TestEnum::A,
true);
TEST_EQ(mArStruct->d()->Get(1).b() == MyGame::Example::TestEnum::C, true);
TEST_ASSERT(mArStruct->d()->Get(1).c());
TEST_EQ(mArStruct->d()->Get(1).c()->Get(0) == MyGame::Example::TestEnum::C,
true);
TEST_EQ(mArStruct->d()->Get(1).c()->Get(1) == MyGame::Example::TestEnum::A,
true);
for (int i = 0; i < 14; i++) TEST_EQ(mArStruct->b()->Get(i), i + 1);
for (int i = 0; i < mArStruct->b()->size() - 1; i++)
TEST_EQ(mArStruct->b()->Get(i), i + 1);
#endif
}

Expand Down

0 comments on commit f82db64

Please sign in to comment.