From f82db64c94c32bf934c43395ecf744f86d45b6df Mon Sep 17 00:00:00 2001 From: Sven Konietzny Date: Fri, 14 Jun 2019 07:48:38 +0200 Subject: [PATCH] Add more asserts --- tests/test.cpp | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/test.cpp b/tests/test.cpp index a0a9f925b612..bfe0a575d8f7 100644 --- a/tests/test.cpp +++ b/tests/test.cpp @@ -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); @@ -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 }