Skip to content

Commit

Permalink
Add all packages tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mi-La committed Jan 22, 2025
1 parent c1b1916 commit 210ff8f
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 1 deletion.
5 changes: 4 additions & 1 deletion test/language/packages/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ add_custom_test(packages
packages_zs
reader_zs
SOURCES
#
${CMAKE_CURRENT_SOURCE_DIR}/cpp/DefaultPackageTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/IndexTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/PackageNameConflictTest.cpp
${CMAKE_CURRENT_SOURCE_DIR}/cpp/ReaderTest.cpp
GENERATED_SOURCES
${GENERATED_SOURCES_DEFAULT_PACKAGE}
${GENERATED_SOURCES_INDEX}
Expand Down
25 changes: 25 additions & 0 deletions test/language/packages/cpp/DefaultPackageTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "gtest/gtest.h"

#include "DefaultPackageStructure.h"

TEST(DefaultPackageTest, defaultPackageStructure)
{
// just test that DefaultPackageStructure is available in global namespace
DefaultPackageStructure data;

data.value = 10;
default_package_import::top::TopStructure topStructure;
topStructure.type = 1;
topStructure.data = 1234;
data.topStructure = topStructure;
Child child;
child.value = 0xdeadbeef;
data.childStructure = child;

zserio::View view(data, 4);

ASSERT_EQ(10, view.value());
ASSERT_EQ(1, view.topStructure().type());
ASSERT_EQ(1234, view.topStructure().data());
ASSERT_EQ(0xdeadbeef, view.childStructure().value());
}
28 changes: 28 additions & 0 deletions test/language/packages/cpp/IndexTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "gtest/gtest.h"
#include "index_workaround/index/Test.h"
#include "test_utils/TestUtility.h"

namespace index_workaround
{

class IndexTest : public ::testing::Test
{
protected:
static constexpr uint32_t ARRAY_SIZE = 10;
};

TEST_F(IndexTest, writeRead)
{
::index_workaround::index::Test data;
data.indexes.resize(ARRAY_SIZE);
data.indexesForParameterized.resize(ARRAY_SIZE);
for (uint32_t i = 0; i < ARRAY_SIZE; ++i)
{
data.array.emplace_back(i);
data.parameterizedArray.emplace_back(i);
}

test_utils::writeReadTest(data);
}

} // namespace index_workaround
25 changes: 25 additions & 0 deletions test/language/packages/cpp/PackageNameConflictTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "gtest/gtest.h"
#include "package_name_conflict/PackageNameConflictImported.h"
#include "package_name_conflict/PackageNameConflictLocal.h"
#include "test_utils/WriteReadTest.h"

namespace package_name_conflict
{

TEST(PackageNameConflictTest, packageNameConflictLocal)
{
// just test that PackageNameConflictLocal includes correct Blob
PackageNameConflictLocal data{Blob{13}};

test_utils::writeReadTest(data);
}

TEST(PackageNameConflictTest, packageNameConflictImported)
{
// just test that PackageNameConflictImported includes correct Blob
PackageNameConflictImported data{::package_name_conflict::package_name_conflict::Blob{"test"}};

test_utils::writeReadTest(data);
}

} // namespace package_name_conflict
28 changes: 28 additions & 0 deletions test/language/packages/cpp/ReaderTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include "gtest/gtest.h"
#include "reader/Test.h"
#include "test_utils/WriteReadTest.h"

namespace reader
{

class ReaderTest : public ::testing::Test
{
protected:
static constexpr uint32_t ARRAY_SIZE = 10;
};

TEST_F(ReaderTest, writeRead)
{
::reader::Test data;
data.indexes.resize(ARRAY_SIZE);
data.indexesForParameterized.resize(ARRAY_SIZE);
for (uint32_t i = 0; i < ARRAY_SIZE; ++i)
{
data.array.emplace_back(i);
data.parameterizedArray.emplace_back(i);
}

test_utils::writeReadTest(data);
}

} // namespace reader

0 comments on commit 210ff8f

Please sign in to comment.