From 5c170bfbfc4f0c21f71c1f174f6788125761c023 Mon Sep 17 00:00:00 2001 From: Miki Rozloznik Date: Tue, 29 Mar 2022 14:26:15 +0200 Subject: [PATCH] Update warnings tests to check C++ and Python generators as well --- .../choice_types_warning/CMakeLists.txt | 25 ++++ .../cpp/ChoiceTypesWarningTest.cpp | 23 ++++ .../cpp/CppcheckSuppressions.txt | 1 + .../python/ChoiceTypesWarningTest.py | 19 +++ test/warnings/comments_warning/CMakeLists.txt | 80 ++++++++++++ .../cpp/CommentsWarningTest.cpp | 74 +++++++++++ .../python/CommentsWarningTest.py | 115 ++++++++++++++++++ .../compatibility_warning/CMakeLists.txt | 25 ++-- .../file_encoding_warning/CMakeLists.txt | 23 ++++ .../cpp/FileEncodingWarningTest.cpp | 34 ++++++ .../python/FileEncodingWarningTest.py | 34 ++++++ .../warnings/functions_warning/CMakeLists.txt | 23 ++++ .../cpp/FunctionsWarningTest.cpp | 27 ++++ .../python/FunctionsWarningTest.py | 27 ++++ .../not_handled_warning/CMakeLists.txt | 27 ++++ .../cpp/CppcheckSuppressions.txt | 1 + .../cpp/NotHandledWarningTest.cpp | 30 +++++ .../python/NotHandledWarningTest.py | 28 +++++ test/warnings/packages_warning/CMakeLists.txt | 33 +++++ .../cpp/PackagesWarningTest.cpp | 46 +++++++ .../python/PackagesWarningTest.py | 48 ++++++++ .../sql_tables_warning/CMakeLists.txt | 54 ++++++++ .../cpp/SqlTablesWarningTest.cpp | 62 ++++++++++ .../python/SqlTablesWarningTest.py | 72 +++++++++++ .../CMakeLists.txt | 27 ++++ .../cpp/SqlWithoutRowIdTablesWarningTest.cpp | 24 ++++ .../SqlWithoutRowIdTablesWarningTest.py | 20 +++ .../unused_type_warning/CMakeLists.txt | 50 ++++++++ .../cpp/CppcheckSuppressions.txt | 8 ++ .../cpp/UnusedTypeWarningTest.cpp | 58 +++++++++ .../python/UnusedTypeWarningTest.py | 64 ++++++++++ 31 files changed, 1175 insertions(+), 7 deletions(-) create mode 100644 test/warnings/choice_types_warning/CMakeLists.txt create mode 100644 test/warnings/choice_types_warning/cpp/ChoiceTypesWarningTest.cpp create mode 100644 test/warnings/choice_types_warning/cpp/CppcheckSuppressions.txt create mode 100644 test/warnings/choice_types_warning/python/ChoiceTypesWarningTest.py create mode 100644 test/warnings/comments_warning/CMakeLists.txt create mode 100644 test/warnings/comments_warning/cpp/CommentsWarningTest.cpp create mode 100644 test/warnings/comments_warning/python/CommentsWarningTest.py create mode 100644 test/warnings/file_encoding_warning/CMakeLists.txt create mode 100644 test/warnings/file_encoding_warning/cpp/FileEncodingWarningTest.cpp create mode 100644 test/warnings/file_encoding_warning/python/FileEncodingWarningTest.py create mode 100644 test/warnings/functions_warning/CMakeLists.txt create mode 100644 test/warnings/functions_warning/cpp/FunctionsWarningTest.cpp create mode 100644 test/warnings/functions_warning/python/FunctionsWarningTest.py create mode 100644 test/warnings/not_handled_warning/CMakeLists.txt create mode 100644 test/warnings/not_handled_warning/cpp/CppcheckSuppressions.txt create mode 100644 test/warnings/not_handled_warning/cpp/NotHandledWarningTest.cpp create mode 100644 test/warnings/not_handled_warning/python/NotHandledWarningTest.py create mode 100644 test/warnings/packages_warning/CMakeLists.txt create mode 100644 test/warnings/packages_warning/cpp/PackagesWarningTest.cpp create mode 100644 test/warnings/packages_warning/python/PackagesWarningTest.py create mode 100644 test/warnings/sql_tables_warning/CMakeLists.txt create mode 100644 test/warnings/sql_tables_warning/cpp/SqlTablesWarningTest.cpp create mode 100644 test/warnings/sql_tables_warning/python/SqlTablesWarningTest.py create mode 100644 test/warnings/sql_without_rowid_tables_warning/CMakeLists.txt create mode 100644 test/warnings/sql_without_rowid_tables_warning/cpp/SqlWithoutRowIdTablesWarningTest.cpp create mode 100644 test/warnings/sql_without_rowid_tables_warning/python/SqlWithoutRowIdTablesWarningTest.py create mode 100644 test/warnings/unused_type_warning/CMakeLists.txt create mode 100644 test/warnings/unused_type_warning/cpp/CppcheckSuppressions.txt create mode 100644 test/warnings/unused_type_warning/cpp/UnusedTypeWarningTest.cpp create mode 100644 test/warnings/unused_type_warning/python/UnusedTypeWarningTest.py diff --git a/test/warnings/choice_types_warning/CMakeLists.txt b/test/warnings/choice_types_warning/CMakeLists.txt new file mode 100644 index 000000000..e31b636d4 --- /dev/null +++ b/test/warnings/choice_types_warning/CMakeLists.txt @@ -0,0 +1,25 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/Selector.cpp + ${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/Selector.h + ${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/TestChoice.cpp + ${ZSERIO_GEN_DIR}/choice_types_warning/optional_references_in_selector/TestChoice.h +) + +zserio_add_library(TARGET choice_types_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE choice_types_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 1 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +add_test_sources( + cpp/ChoiceTypesWarningTest.cpp +) + +add_test_dependencies(choice_types_warning_zs) diff --git a/test/warnings/choice_types_warning/cpp/ChoiceTypesWarningTest.cpp b/test/warnings/choice_types_warning/cpp/ChoiceTypesWarningTest.cpp new file mode 100644 index 000000000..3e6aab705 --- /dev/null +++ b/test/warnings/choice_types_warning/cpp/ChoiceTypesWarningTest.cpp @@ -0,0 +1,23 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class ChoiceTypesWarningTest : public ::testing::Test +{ +protected: + ChoiceTypesWarningTest() + : zserioWarnings("warnings/choice_types_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(ChoiceTypesWarningTest, optionalReferencesInSelector) +{ + const std::string warning = "optional_references_in_selector.zs:8:41: Choice 'TestChoice' selector " + "contains reference to optional field 'numBits'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/choice_types_warning/cpp/CppcheckSuppressions.txt b/test/warnings/choice_types_warning/cpp/CppcheckSuppressions.txt new file mode 100644 index 000000000..a82c1d31d --- /dev/null +++ b/test/warnings/choice_types_warning/cpp/CppcheckSuppressions.txt @@ -0,0 +1 @@ +uninitMemberVar:*/choice_types_warning/optional_references_in_selector/TestChoice.cpp diff --git a/test/warnings/choice_types_warning/python/ChoiceTypesWarningTest.py b/test/warnings/choice_types_warning/python/ChoiceTypesWarningTest.py new file mode 100644 index 000000000..b629f040f --- /dev/null +++ b/test/warnings/choice_types_warning/python/ChoiceTypesWarningTest.py @@ -0,0 +1,19 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class ArrayTypesWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "choice_types_warning.zs", + expectedWarnings=1, errorOutputDict=cls.warnings) + + def testOptionalReferencesInSelector(self): + assertWarningsPresent(self, + "choice_types_warning.zs", + [ + "optional_references_in_selector.zs:8:41: Choice 'TestChoice' selector " + "contains reference to optional field 'numBits'." + ] + ) diff --git a/test/warnings/comments_warning/CMakeLists.txt b/test/warnings/comments_warning/CMakeLists.txt new file mode 100644 index 000000000..6ab8eccf2 --- /dev/null +++ b/test/warnings/comments_warning/CMakeLists.txt @@ -0,0 +1,80 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/OtherTestStruct.cpp + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/OtherTestStruct.h + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestDatabase.cpp + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestDatabase.h + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestStruct.cpp + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestStruct.h + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestTable.cpp + ${ZSERIO_GEN_DIR}/comments_warning/markdown_comment_with_wrong_terminator/TestTable.h + + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructString.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructString.h + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructUInt32.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_in_templated_struct/TemplatedStructUInt32.h + + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Database.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Database.h + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Table.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Table.h + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Test.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/Test.h + ${ZSERIO_GEN_DIR}/comments_warning/unresolved_see_tag_reference/VALUE.h + + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/BasicComment.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/BasicComment.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByAlignmentAndType.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByAlignmentAndType.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByIndexedOffsetAndType.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByIndexedOffsetAndType.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOffsetAndType.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOffsetAndType.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOptionalAndType.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/ByOptionalAndType.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Database.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Database.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleComments.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleComments.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleFieldComments.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleFieldComments.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleUnmaskedComments.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/MultipleUnmaskedComments.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Table.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/Table.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/UnusedCommentById.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_field_comments/UnusedCommentById.h + + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Database.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Database.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Table.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Table.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Test.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_by_id/Test.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Database.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Database.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Table.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Table.h + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Test.cpp + ${ZSERIO_GEN_DIR}/comments_warning/unused_struct_comment_multiple_comments/Test.h +) + +zserio_add_library(TARGET comments_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE comments_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 13 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +target_include_directories(comments_warning_zs SYSTEM PRIVATE ${SQLITE_INCDIR}) + +add_test_sources( + cpp/CommentsWarningTest.cpp +) + +add_test_dependencies(comments_warning_zs) diff --git a/test/warnings/comments_warning/cpp/CommentsWarningTest.cpp b/test/warnings/comments_warning/cpp/CommentsWarningTest.cpp new file mode 100644 index 000000000..d776bf2c4 --- /dev/null +++ b/test/warnings/comments_warning/cpp/CommentsWarningTest.cpp @@ -0,0 +1,74 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class CommentsWarningTest : public ::testing::Test +{ +protected: + CommentsWarningTest() + : zserioWarnings("warnings/comments_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(CommentsWarningTest, markdownCommentWithWrongTerminator) +{ + ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:3:1: " + "Markdown documentation comment should be terminated by '!*/'!")); + + ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:7:1: " + "Markdown documentation comment should be terminated by '!*/'!")); + + ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:21:1: " + "Markdown documentation comment should be terminated by '!*/'!")); + + ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:26:5: " + "Markdown documentation comment should be terminated by '!*/'!")); + + ASSERT_TRUE(zserioWarnings.isPresent("markdown_comment_with_wrong_terminator.zs:38:5: " + "Markdown documentation comment should be terminated by '!*/'!")); +} + +TEST_F(CommentsWarningTest, unresolvedSeeTagInTemplatedStruct) +{ + ASSERT_TRUE(zserioWarnings.isPresent("unresolved_see_tag_in_templated_struct.zs:3:5: " + "Documentation: Unresolved referenced symbol 'unknown' for type 'TemplatedStruct'!")); +} + +TEST_F(CommentsWarningTest, unresolvedSeeTagReference) +{ + ASSERT_TRUE(zserioWarnings.isPresent("unresolved_see_tag_reference.zs:8:4: " + "Documentation: Unresolved referenced symbol 'Unexisting'!")); + + ASSERT_TRUE(zserioWarnings.isPresent("unresolved_see_tag_reference.zs:15:4: " + "Documentation: Unresolved referenced symbol 'Unexisting' for type 'Table'!")); +} + +TEST_F(CommentsWarningTest, unusedFieldComments) +{ + ASSERT_TRUE(zserioWarnings.isPresent( + "unused_field_comments.zs:11:11: Documentation comment is not used!")); + + ASSERT_TRUE(zserioWarnings.isPresent( + "unused_field_comments.zs:55:45: Documentation comment is not used!")); + + ASSERT_TRUE(zserioWarnings.isPresent( + "unused_field_comments.zs:61:45: Documentation comment is not used!")); +} + +TEST_F(CommentsWarningTest, unusedStructCommentById) +{ + const std::string warning = "unused_struct_comment_by_id.zs:3:8: Documentation comment is not used!"; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(CommentsWarningTest, unusedStructCommentMultipleComments) +{ + const std::string warning = "unused_struct_comment_multiple_comments.zs:5:9: " + "Documentation comment is not used!"; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/comments_warning/python/CommentsWarningTest.py b/test/warnings/comments_warning/python/CommentsWarningTest.py new file mode 100644 index 000000000..0e3b80e3f --- /dev/null +++ b/test/warnings/comments_warning/python/CommentsWarningTest.py @@ -0,0 +1,115 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class CommentsWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "comments_warning.zs", + expectedWarnings=13, errorOutputDict=cls.warnings) + + def testMarkdownCommentWithWrongTerminator(self): + assertWarningsPresent(self, + "comments_warning.zs", + [ + "markdown_comment_with_wrong_terminator.zs:3:1: " + "Markdown documentation comment should be terminated by '!*/'!" + ] + ) + + assertWarningsPresent(self, + "comments_warning.zs", + [ + "markdown_comment_with_wrong_terminator.zs:7:1: " + "Markdown documentation comment should be terminated by '!*/'!" + ] + ) + + assertWarningsPresent(self, + "comments_warning.zs", + [ + "markdown_comment_with_wrong_terminator.zs:21:1: " + "Markdown documentation comment should be terminated by '!*/'!" + ] + ) + + assertWarningsPresent(self, + "comments_warning.zs", + [ + "markdown_comment_with_wrong_terminator.zs:26:5: " + "Markdown documentation comment should be terminated by '!*/'!" + ] + ) + + assertWarningsPresent(self, + "comments_warning.zs", + [ + "markdown_comment_with_wrong_terminator.zs:38:5: " + "Markdown documentation comment should be terminated by '!*/'!" + ] + ) + + def testUnresolvedSeeTagInTemplatedStruct(self): + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unresolved_see_tag_in_templated_struct.zs:3:5: " + "Documentation: Unresolved referenced symbol 'unknown' for type 'TemplatedStruct'!" + ] + ) + + def testUnresolvedSeeTagReference(self): + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unresolved_see_tag_reference.zs:8:4: " + "Documentation: Unresolved referenced symbol 'Unexisting'!" + ] + ) + + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unresolved_see_tag_reference.zs:15:4: " + "Documentation: Unresolved referenced symbol 'Unexisting' for type 'Table'!" + ] + ) + + def testUnusedFieldComments(self): + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unused_field_comments.zs:11:11: Documentation comment is not used!" + ] + ) + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unused_field_comments.zs:55:45: Documentation comment is not used!" + ] + ) + + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unused_field_comments.zs:61:45: Documentation comment is not used!" + ] + ) + + def testUnusedStructCommentById(self): + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unused_struct_comment_by_id.zs:3:8: Documentation comment is not used!" + ] + ) + + def testUnusedStructCommentMultipleComments(self): + assertWarningsPresent(self, + "comments_warning.zs", + [ + "unused_struct_comment_multiple_comments.zs:5:9: " + "Documentation comment is not used!" + ] + ) diff --git a/test/warnings/compatibility_warning/CMakeLists.txt b/test/warnings/compatibility_warning/CMakeLists.txt index f518b949a..7f0810be7 100644 --- a/test/warnings/compatibility_warning/CMakeLists.txt +++ b/test/warnings/compatibility_warning/CMakeLists.txt @@ -1,17 +1,28 @@ -set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GEN_DIR_ROOT_WITH ${CMAKE_CURRENT_BINARY_DIR}/gen_root_with) +set(ZSERIO_GEN_DIR_ROOT_WITHOUT ${CMAKE_CURRENT_BINARY_DIR}/gen_root_without) set(LOG_FILENAME zserio_log.txt) # clean old log file file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${LOG_FILENAME}) +set(ZSERIO_GENERATED_SOURCES_ROOT_WITH + ${ZSERIO_GEN_DIR_ROOT_WITH}/compatibility_warning/subpackage/TestStruct.cpp + ${ZSERIO_GEN_DIR_ROOT_WITH}/compatibility_warning/subpackage/TestStruct.h +) + +set(ZSERIO_GENERATED_SOURCES_ROOT_WITHOUT + ${ZSERIO_GEN_DIR_ROOT_WITHOUT}/compatibility_warning/subpackage/TestStruct.cpp + ${ZSERIO_GEN_DIR_ROOT_WITHOUT}/compatibility_warning/subpackage/TestStruct.h +) + zserio_add_library(TARGET root_with_diff_compatibility_warning_zs SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs MAIN_SOURCE compatibility_warning/root_with_diff_compatibility_warning.zs - OUT_DIR ${ZSERIO_GEN_DIR} - OUT_FILES EMPTY + OUT_DIR ${ZSERIO_GEN_DIR_ROOT_WITH} + OUT_FILES ${ZSERIO_GENERATED_SOURCES_ROOT_WITH} ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} - ZSERIO_OPTIONS -withoutCrossExtensionCheck + ZSERIO_OPTIONS -withoutCrossExtensionCheck -withoutSourcesAmalgamation EXPECTED_WARNINGS 1 ZSERIO_LOG_FILENAME ${LOG_FILENAME} APPEND_TO_ZSERIO_LOG_FILE ON @@ -20,11 +31,11 @@ zserio_add_library(TARGET root_with_diff_compatibility_warning_zs zserio_add_library(TARGET root_without_compatibility_warning_zs SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs MAIN_SOURCE compatibility_warning/root_without_compatibility_warning.zs - OUT_DIR ${ZSERIO_GEN_DIR} - OUT_FILES EMPTY + OUT_DIR ${ZSERIO_GEN_DIR_ROOT_WITHOUT} + OUT_FILES ${ZSERIO_GENERATED_SOURCES_ROOT_WITHOUT} ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} - ZSERIO_OPTIONS -withoutCrossExtensionCheck + ZSERIO_OPTIONS -withoutCrossExtensionCheck -withoutSourcesAmalgamation EXPECTED_WARNINGS 1 ZSERIO_LOG_FILENAME ${LOG_FILENAME} APPEND_TO_ZSERIO_LOG_FILE ON diff --git a/test/warnings/file_encoding_warning/CMakeLists.txt b/test/warnings/file_encoding_warning/CMakeLists.txt new file mode 100644 index 000000000..d535b775b --- /dev/null +++ b/test/warnings/file_encoding_warning/CMakeLists.txt @@ -0,0 +1,23 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/file_encoding_warning/NON_PRINTABLE_ASCII_STRING.h + ${ZSERIO_GEN_DIR}/file_encoding_warning/NON_UTF8_STRING.h +) + +zserio_add_library(TARGET file_encoding_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE file_encoding_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 3 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +add_test_sources( + cpp/FileEncodingWarningTest.cpp +) + +add_test_dependencies(file_encoding_warning_zs) diff --git a/test/warnings/file_encoding_warning/cpp/FileEncodingWarningTest.cpp b/test/warnings/file_encoding_warning/cpp/FileEncodingWarningTest.cpp new file mode 100644 index 000000000..c9475cc1b --- /dev/null +++ b/test/warnings/file_encoding_warning/cpp/FileEncodingWarningTest.cpp @@ -0,0 +1,34 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class FileEncodingWarningTest : public ::testing::Test +{ +protected: + FileEncodingWarningTest() + : zserioWarnings("warnings/file_encoding_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(FileEncodingWarningTest, nonUtf8Characters) +{ + const std::string warning = "file_encoding_warning.zs:1:1: Found non-UTF8 encoded characters."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(FileEncodingWarningTest, tabCharacters) +{ + const std::string warning = "file_encoding_warning.zs:1:1: Found tab characters."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(FileEncodingWarningTest, nonPrintableAsciiCharacters) +{ + const std::string warning = "file_encoding_warning.zs:1:1: Found non-printable ASCII characters."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/file_encoding_warning/python/FileEncodingWarningTest.py b/test/warnings/file_encoding_warning/python/FileEncodingWarningTest.py new file mode 100644 index 000000000..65099b6a3 --- /dev/null +++ b/test/warnings/file_encoding_warning/python/FileEncodingWarningTest.py @@ -0,0 +1,34 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class FileEncodingWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "file_encoding_warning.zs", + expectedWarnings=3, errorOutputDict=cls.warnings) + + def testNonUtf8Characters(self): + assertWarningsPresent(self, + "file_encoding_warning.zs", + [ + "file_encoding_warning.zs:1:1: Found non-UTF8 encoded characters." + ] + ) + + def testTabCharacters(self): + assertWarningsPresent(self, + "file_encoding_warning.zs", + [ + "file_encoding_warning.zs:1:1: Found tab characters." + ] + ) + + def testNonPrintableAsciiCharacters(self): + assertWarningsPresent(self, + "file_encoding_warning.zs", + [ + "file_encoding_warning.zs:1:1: Found non-printable ASCII characters." + ] + ) diff --git a/test/warnings/functions_warning/CMakeLists.txt b/test/warnings/functions_warning/CMakeLists.txt new file mode 100644 index 000000000..924e5e211 --- /dev/null +++ b/test/warnings/functions_warning/CMakeLists.txt @@ -0,0 +1,23 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/functions_warning/optional_references_in_function/SingleOptionalFieldFunction.cpp + ${ZSERIO_GEN_DIR}/functions_warning/optional_references_in_function/SingleOptionalFieldFunction.h +) + +zserio_add_library(TARGET functions_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE functions_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 2 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +add_test_sources( + cpp/FunctionsWarningTest.cpp +) + +add_test_dependencies(functions_warning_zs) diff --git a/test/warnings/functions_warning/cpp/FunctionsWarningTest.cpp b/test/warnings/functions_warning/cpp/FunctionsWarningTest.cpp new file mode 100644 index 000000000..4b2e6a915 --- /dev/null +++ b/test/warnings/functions_warning/cpp/FunctionsWarningTest.cpp @@ -0,0 +1,27 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class FunctionsWarningTest : public ::testing::Test +{ +protected: + FunctionsWarningTest() + : zserioWarnings("warnings/functions_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(FunctionsWarningTest, optionalReferencesInFunction) +{ + const std::string warning1 = "optional_references_in_function.zs:11:16: Function " + "'suspicionFunction' contains reference to optional field 'additionalValue'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning1)); + + const std::string warning2 = "optional_references_in_function.zs:16:16: Function " + "'autoSuspicionFunction' contains reference to optional field 'autoAdditionalValue'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning2)); +} diff --git a/test/warnings/functions_warning/python/FunctionsWarningTest.py b/test/warnings/functions_warning/python/FunctionsWarningTest.py new file mode 100644 index 000000000..84b81210b --- /dev/null +++ b/test/warnings/functions_warning/python/FunctionsWarningTest.py @@ -0,0 +1,27 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class FunctionsWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "functions_warning.zs", + expectedWarnings=2, errorOutputDict=cls.warnings) + + def testOptionalReferencesInFunction(self): + assertWarningsPresent(self, + "functions_warning.zs", + [ + "optional_references_in_function.zs:11:16: Function " + "'suspicionFunction' contains reference to optional field 'additionalValue'." + ] + ) + + assertWarningsPresent(self, + "functions_warning.zs", + [ + "optional_references_in_function.zs:16:16: Function " + "'autoSuspicionFunction' contains reference to optional field 'autoAdditionalValue'." + ] + ) diff --git a/test/warnings/not_handled_warning/CMakeLists.txt b/test/warnings/not_handled_warning/CMakeLists.txt new file mode 100644 index 000000000..9c0af6b87 --- /dev/null +++ b/test/warnings/not_handled_warning/CMakeLists.txt @@ -0,0 +1,27 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/not_handled_warning/Black.h + ${ZSERIO_GEN_DIR}/not_handled_warning/EnumParamChoice.cpp + ${ZSERIO_GEN_DIR}/not_handled_warning/EnumParamChoice.h + ${ZSERIO_GEN_DIR}/not_handled_warning/Grey.h + ${ZSERIO_GEN_DIR}/not_handled_warning/Selector.cpp + ${ZSERIO_GEN_DIR}/not_handled_warning/Selector.h +) + +zserio_add_library(TARGET not_handled_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE not_handled_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 2 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +add_test_sources( + cpp/NotHandledWarningTest.cpp +) + +add_test_dependencies(not_handled_warning_zs) diff --git a/test/warnings/not_handled_warning/cpp/CppcheckSuppressions.txt b/test/warnings/not_handled_warning/cpp/CppcheckSuppressions.txt new file mode 100644 index 000000000..42476d6a6 --- /dev/null +++ b/test/warnings/not_handled_warning/cpp/CppcheckSuppressions.txt @@ -0,0 +1 @@ +uninitMemberVar:*/not_handled_warning/gen/not_handled_warning/EnumParamChoice.cpp diff --git a/test/warnings/not_handled_warning/cpp/NotHandledWarningTest.cpp b/test/warnings/not_handled_warning/cpp/NotHandledWarningTest.cpp new file mode 100644 index 000000000..a4b0d4afe --- /dev/null +++ b/test/warnings/not_handled_warning/cpp/NotHandledWarningTest.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class NotHandledWarningTest : public ::testing::Test +{ +protected: + NotHandledWarningTest() + : zserioWarnings("warnings/not_handled_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(NotHandledWarningTest, notHandledWhite) +{ + const std::string warning = "not_handled_warning.zs:15:8: " + "Enumeration value 'WHITE' is not handled in choice 'EnumParamChoice'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(NotHandledWarningTest, notHandledRed) +{ + const std::string warning = "not_handled_warning.zs:15:8: " + "Enumeration value 'RED' is not handled in choice 'EnumParamChoice'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/not_handled_warning/python/NotHandledWarningTest.py b/test/warnings/not_handled_warning/python/NotHandledWarningTest.py new file mode 100644 index 000000000..a910b183c --- /dev/null +++ b/test/warnings/not_handled_warning/python/NotHandledWarningTest.py @@ -0,0 +1,28 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class NotHandledWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "not_handled_warning.zs", + expectedWarnings=2, errorOutputDict=cls.warnings) + + def testNotHandledWhite(self): + assertWarningsPresent(self, + "not_handled_warning.zs", + [ + "not_handled_warning.zs:15:8: " + "Enumeration value 'WHITE' is not handled in choice 'EnumParamChoice'." + ] + ) + + def testNotHandledRed(self): + assertWarningsPresent(self, + "not_handled_warning.zs", + [ + "not_handled_warning.zs:15:8: " + "Enumeration value 'RED' is not handled in choice 'EnumParamChoice'." + ] + ) diff --git a/test/warnings/packages_warning/CMakeLists.txt b/test/warnings/packages_warning/CMakeLists.txt new file mode 100644 index 000000000..4a553700b --- /dev/null +++ b/test/warnings/packages_warning/CMakeLists.txt @@ -0,0 +1,33 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/packages_warning/package_import_overwrite_warning/TopDatabase.cpp + ${ZSERIO_GEN_DIR}/packages_warning/package_import_overwrite_warning/TopDatabase.h + + ${ZSERIO_GEN_DIR}/packages_warning/simple_database/SimpleDatabase.cpp + ${ZSERIO_GEN_DIR}/packages_warning/simple_database/SimpleDatabase.h + ${ZSERIO_GEN_DIR}/packages_warning/simple_database/SimpleTable.cpp + ${ZSERIO_GEN_DIR}/packages_warning/simple_database/SimpleTable.h + + ${ZSERIO_GEN_DIR}/packages_warning/single_type_already_imported_warning/TopDatabase.cpp + ${ZSERIO_GEN_DIR}/packages_warning/single_type_already_imported_warning/TopDatabase.h +) + +zserio_add_library(TARGET packages_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE packages_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 4 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +target_include_directories(packages_warning_zs SYSTEM PRIVATE ${SQLITE_INCDIR}) + +add_test_sources( + cpp/PackagesWarningTest.cpp +) + +add_test_dependencies(packages_warning_zs) diff --git a/test/warnings/packages_warning/cpp/PackagesWarningTest.cpp b/test/warnings/packages_warning/cpp/PackagesWarningTest.cpp new file mode 100644 index 000000000..25d7dbec2 --- /dev/null +++ b/test/warnings/packages_warning/cpp/PackagesWarningTest.cpp @@ -0,0 +1,46 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class PackagesWarningTest : public ::testing::Test +{ +protected: + PackagesWarningTest() + : zserioWarnings("warnings/packages_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(PackagesWarningTest, optionalReferencesInSelector) +{ + const std::string warning = "duplicated_package_import_warning.zs:6:8: " + "Duplicated import of package 'packages_warning.simple_database'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(PackagesWarningTest, duplicatedSingleTypeImport) +{ + const std::string warning = "duplicated_single_type_import_warning.zs:6:8: " + "Duplicated import of 'packages_warning.simple_database.SimpleTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(PackagesWarningTest, packageImportOverwrite) +{ + const std::string warning = "package_import_overwrite_warning.zs:6:8: " + "Import of package 'packages_warning.simple_database' overwrites single import of " + "'packages_warning.simple_database.SimpleTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(PackagesWarningTest, singleTypeAlreadyImported) +{ + const std::string warning = "single_type_already_imported_warning.zs:6:8: " + "Single import of 'packages_warning.simple_database.SimpleTable' " + "already covered by package import."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/packages_warning/python/PackagesWarningTest.py b/test/warnings/packages_warning/python/PackagesWarningTest.py new file mode 100644 index 000000000..4e7289c4b --- /dev/null +++ b/test/warnings/packages_warning/python/PackagesWarningTest.py @@ -0,0 +1,48 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class PackagesWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "packages_warning.zs", + expectedWarnings=4, errorOutputDict=cls.warnings) + + def testDuplicatedPackageImport(self): + assertWarningsPresent(self, + "packages_warning.zs", + [ + "duplicated_package_import_warning.zs:6:8: " + "Duplicated import of package 'packages_warning.simple_database'." + ] + ) + + def testDuplicatedSingleTypeImport(self): + assertWarningsPresent(self, + "packages_warning.zs", + [ + "duplicated_single_type_import_warning.zs:6:8: " + "Duplicated import of 'packages_warning.simple_database.SimpleTable'." + ] + ) + + def testPackageImportOverwrite(self): + assertWarningsPresent(self, + "packages_warning.zs", + [ + "package_import_overwrite_warning.zs:6:8: " + "Import of package 'packages_warning.simple_database' overwrites single import of " + "'packages_warning.simple_database.SimpleTable'." + ] + ) + + def testSingleTypeAlreadyImported(self): + assertWarningsPresent(self, + "packages_warning.zs", + [ + "single_type_already_imported_warning.zs:6:8: " + "Single import of 'packages_warning.simple_database.SimpleTable' " + "already covered by package import." + ] + ) diff --git a/test/warnings/sql_tables_warning/CMakeLists.txt b/test/warnings/sql_tables_warning/CMakeLists.txt new file mode 100644 index 000000000..ba955dc0e --- /dev/null +++ b/test/warnings/sql_tables_warning/CMakeLists.txt @@ -0,0 +1,54 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/sql_tables_warning/bad_ordered_primary_key_warning/BadOrderedPrimaryKeyDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/bad_ordered_primary_key_warning/BadOrderedPrimaryKeyDatabase.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/bad_ordered_primary_key_warning/BadOrderedPrimaryKeyTable.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/bad_ordered_primary_key_warning/BadOrderedPrimaryKeyTable.h + + ${ZSERIO_GEN_DIR}/sql_tables_warning/duplicated_primary_key_warning/DuplicatedPrimaryKeyDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/duplicated_primary_key_warning/DuplicatedPrimaryKeyDatabase.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/duplicated_primary_key_warning/DuplicatedPrimaryKeyTable.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/duplicated_primary_key_warning/DuplicatedPrimaryKeyTable.h + + ${ZSERIO_GEN_DIR}/sql_tables_warning/multiple_primary_keys_warning/MultiplePrimaryKeysDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/multiple_primary_keys_warning/MultiplePrimaryKeysDatabase.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/multiple_primary_keys_warning/MultiplePrimaryKeysTable.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/multiple_primary_keys_warning/MultiplePrimaryKeysTable.h + + ${ZSERIO_GEN_DIR}/sql_tables_warning/no_primary_key_warning/NoPrimaryKeyDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/no_primary_key_warning/NoPrimaryKeyDatabase.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/no_primary_key_warning/NoPrimaryKeyTable.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/no_primary_key_warning/NoPrimaryKeyTable.h + + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_first_primary_key_warning/NotFirstPrimaryKeyDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_first_primary_key_warning/NotFirstPrimaryKeyDatabase.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_first_primary_key_warning/NotFirstPrimaryKeyTable.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_first_primary_key_warning/NotFirstPrimaryKeyTable.h + + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_null_primary_key_warning/NotNullPrimaryKeyDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_null_primary_key_warning/NotNullPrimaryKeyDatabase.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_null_primary_key_warning/NotNullPrimaryKeyTable1.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_null_primary_key_warning/NotNullPrimaryKeyTable1.h + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_null_primary_key_warning/NotNullPrimaryKeyTable2.cpp + ${ZSERIO_GEN_DIR}/sql_tables_warning/not_null_primary_key_warning/NotNullPrimaryKeyTable2.h +) + +zserio_add_library(TARGET sql_tables_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE sql_tables_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 7 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +target_include_directories(sql_tables_warning_zs SYSTEM PRIVATE ${SQLITE_INCDIR}) + +add_test_sources( + cpp/SqlTablesWarningTest.cpp +) + +add_test_dependencies(sql_tables_warning_zs) diff --git a/test/warnings/sql_tables_warning/cpp/SqlTablesWarningTest.cpp b/test/warnings/sql_tables_warning/cpp/SqlTablesWarningTest.cpp new file mode 100644 index 000000000..fd43f2a0d --- /dev/null +++ b/test/warnings/sql_tables_warning/cpp/SqlTablesWarningTest.cpp @@ -0,0 +1,62 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class SqlTablesWarningTest : public ::testing::Test +{ +protected: + SqlTablesWarningTest() + : zserioWarnings("warnings/sql_tables_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(SqlTablesWarningTest, badOrderedPrimaryKey) +{ + const std::string warning = "bad_ordered_primary_key_warning.zs:9:9: " + "Primary key column 'classId' is in bad order in sql table 'BadOrderedPrimaryKeyTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(SqlTablesWarningTest, duplicatedPrimaryKey) +{ + const std::string warning = "duplicated_primary_key_warning.zs:6:33: " + "Duplicated primary key column 'classId' in sql table 'DuplicatedPrimaryKeyTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(SqlTablesWarningTest, multiplePrimaryKeys) +{ + const std::string warning = "multiple_primary_keys_warning.zs:9:9: " + "Multiple primary keys in sql table 'MultiplePrimaryKeysTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(SqlTablesWarningTest, noPrimaryKey) +{ + const std::string warning = "no_primary_key_warning.zs:3:11: " + "No primary key in sql table 'NoPrimaryKeyTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(SqlTablesWarningTest, notFirstPrimaryKey) +{ + const std::string warning = "not_first_primary_key_warning.zs:6:29: " + "Primary key column 'classId' is not the first one in sql table 'NotFirstPrimaryKeyTable'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(SqlTablesWarningTest, notNullPrimaryKey) +{ + const std::string warning1 = "not_null_primary_key_warning.zs:5:17: " + "Primary key column 'schoolId' can contain NULL in sql table 'NotNullPrimaryKeyTable1'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning1)); + + const std::string warning2 = "not_null_primary_key_warning.zs:14:17: " + "Primary key column 'schoolId' can contain NULL in sql table 'NotNullPrimaryKeyTable2'."; + ASSERT_TRUE(zserioWarnings.isPresent(warning2)); +} diff --git a/test/warnings/sql_tables_warning/python/SqlTablesWarningTest.py b/test/warnings/sql_tables_warning/python/SqlTablesWarningTest.py new file mode 100644 index 000000000..cc6e0cd64 --- /dev/null +++ b/test/warnings/sql_tables_warning/python/SqlTablesWarningTest.py @@ -0,0 +1,72 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class SqlTablesWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "sql_tables_warning.zs", + expectedWarnings=7, errorOutputDict=cls.warnings) + + def testBadOrderedPrimaryKey(self): + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "bad_ordered_primary_key_warning.zs:9:9: " + "Primary key column 'classId' is in bad order in sql table 'BadOrderedPrimaryKeyTable'." + ] + ) + + def testDuplicatedPrimaryKey(self): + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "duplicated_primary_key_warning.zs:6:33: " + "Duplicated primary key column 'classId' in sql table 'DuplicatedPrimaryKeyTable'." + ] + ) + + def testMultiplePrimaryKeys(self): + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "multiple_primary_keys_warning.zs:9:9: " + "Multiple primary keys in sql table 'MultiplePrimaryKeysTable'." + ] + ) + + def testNoPrimaryKey(self): + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "no_primary_key_warning.zs:3:11: " + "No primary key in sql table 'NoPrimaryKeyTable'." + ] + ) + + def testNotFirstPrimaryKey(self): + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "not_first_primary_key_warning.zs:6:29: " + "Primary key column 'classId' is not the first one in sql table 'NotFirstPrimaryKeyTable'." + ] + ) + + def testNotNullPrimaryKey(self): + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "not_null_primary_key_warning.zs:5:17: " + "Primary key column 'schoolId' can contain NULL in sql table 'NotNullPrimaryKeyTable1'." + ] + ) + + assertWarningsPresent(self, + "sql_tables_warning.zs", + [ + "not_null_primary_key_warning.zs:14:17: " + "Primary key column 'schoolId' can contain NULL in sql table 'NotNullPrimaryKeyTable2'." + ] + ) diff --git a/test/warnings/sql_without_rowid_tables_warning/CMakeLists.txt b/test/warnings/sql_without_rowid_tables_warning/CMakeLists.txt new file mode 100644 index 000000000..9cb9f56e7 --- /dev/null +++ b/test/warnings/sql_without_rowid_tables_warning/CMakeLists.txt @@ -0,0 +1,27 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/sql_without_rowid_tables_warning/integer_primary_key_warning/WithoutRowIdDatabase.cpp + ${ZSERIO_GEN_DIR}/sql_without_rowid_tables_warning/integer_primary_key_warning/WithoutRowIdDatabase.h + ${ZSERIO_GEN_DIR}/sql_without_rowid_tables_warning/integer_primary_key_warning/WithoutRowIdTable.cpp + ${ZSERIO_GEN_DIR}/sql_without_rowid_tables_warning/integer_primary_key_warning/WithoutRowIdTable.h +) + +zserio_add_library(TARGET sql_without_rowid_tables_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE sql_without_rowid_tables_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withoutSourcesAmalgamation + EXPECTED_WARNINGS 1 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +target_include_directories(sql_without_rowid_tables_warning_zs SYSTEM PRIVATE ${SQLITE_INCDIR}) + +add_test_sources( + cpp/SqlWithoutRowIdTablesWarningTest.cpp +) + +add_test_dependencies(sql_without_rowid_tables_warning_zs) diff --git a/test/warnings/sql_without_rowid_tables_warning/cpp/SqlWithoutRowIdTablesWarningTest.cpp b/test/warnings/sql_without_rowid_tables_warning/cpp/SqlWithoutRowIdTablesWarningTest.cpp new file mode 100644 index 000000000..d52bbb834 --- /dev/null +++ b/test/warnings/sql_without_rowid_tables_warning/cpp/SqlWithoutRowIdTablesWarningTest.cpp @@ -0,0 +1,24 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class SqlWithoutRowIdTablesWarningTest : public ::testing::Test +{ +protected: + SqlWithoutRowIdTablesWarningTest() + : zserioWarnings("warnings/sql_without_rowid_tables_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(SqlWithoutRowIdTablesWarningTest, integerPrimaryKey) +{ + const std::string warning = "integer_primary_key_warning.zs:3:11: " + "Single integer primary key in without rowid table 'WithoutRowIdTable' " + "brings performance drop."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/sql_without_rowid_tables_warning/python/SqlWithoutRowIdTablesWarningTest.py b/test/warnings/sql_without_rowid_tables_warning/python/SqlWithoutRowIdTablesWarningTest.py new file mode 100644 index 000000000..b47de58b5 --- /dev/null +++ b/test/warnings/sql_without_rowid_tables_warning/python/SqlWithoutRowIdTablesWarningTest.py @@ -0,0 +1,20 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class SqlWithoutRowIdTablesWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "sql_without_rowid_tables_warning.zs", + expectedWarnings=1, errorOutputDict=cls.warnings) + + def testIntegerPrimaryKey(self): + assertWarningsPresent(self, + "sql_without_rowid_tables_warning.zs", + [ + "integer_primary_key_warning.zs:3:11: " + "Single integer primary key in without rowid table 'WithoutRowIdTable' " + "brings performance drop." + ] + ) diff --git a/test/warnings/unused_type_warning/CMakeLists.txt b/test/warnings/unused_type_warning/CMakeLists.txt new file mode 100644 index 000000000..d1fe19b5f --- /dev/null +++ b/test/warnings/unused_type_warning/CMakeLists.txt @@ -0,0 +1,50 @@ +set(ZSERIO_GEN_DIR ${CMAKE_CURRENT_BINARY_DIR}/gen) +set(ZSERIO_GENERATED_SOURCES + ${ZSERIO_GEN_DIR}/unused_type_warning/Black.h + ${ZSERIO_GEN_DIR}/unused_type_warning/Blue.h + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolChoice.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolChoice.h + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolStructure.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolStructureDatabase.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolStructureDatabase.h + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolStructure.h + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolStructureTable.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolStructureTable.h + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolUnion.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/BoolUnion.h + ${ZSERIO_GEN_DIR}/unused_type_warning/Color.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/Color.h + ${ZSERIO_GEN_DIR}/unused_type_warning/DARK_BLUE.h + ${ZSERIO_GEN_DIR}/unused_type_warning/Red.h + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedChoice.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedChoice.h + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedEnumeration.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedEnumeration.h + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedStructure.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedStructure.h + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedSubtype.h + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedTable.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedTable.h + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedUnion.cpp + ${ZSERIO_GEN_DIR}/unused_type_warning/UnusedUnion.h +) + +zserio_add_library(TARGET unused_type_warning_zs + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zs + MAIN_SOURCE unused_type_warning.zs + OUT_DIR ${ZSERIO_GEN_DIR} + OUT_FILES ${ZSERIO_GENERATED_SOURCES} + ZSERIO_CORE_DIR ${ZSERIO_JAR_DIR} + ZSERIO_CPP_DIR ${ZSERIO_CPP_DISTR_DIR} + ZSERIO_OPTIONS -withUnusedWarnings -withoutSourcesAmalgamation + EXPECTED_WARNINGS 6 + ZSERIO_LOG_FILENAME zserio_log.txt +) + +target_include_directories(unused_type_warning_zs SYSTEM PRIVATE ${SQLITE_INCDIR}) + +add_test_sources( + cpp/UnusedTypeWarningTest.cpp +) + +add_test_dependencies(unused_type_warning_zs) diff --git a/test/warnings/unused_type_warning/cpp/CppcheckSuppressions.txt b/test/warnings/unused_type_warning/cpp/CppcheckSuppressions.txt new file mode 100644 index 000000000..2296bafdc --- /dev/null +++ b/test/warnings/unused_type_warning/cpp/CppcheckSuppressions.txt @@ -0,0 +1,8 @@ +uninitMemberVar:*/unused_type_warning/gen/unused_type_warning/BoolChoice.cpp +uninitMemberVar:*/unused_type_warning/gen/unused_type_warning/BoolStructure.cpp +uninitMemberVar:*/unused_type_warning/gen/unused_type_warning/BoolStructure.h +uninitMemberVar:*/unused_type_warning/gen/unused_type_warning/UnusedChoice.cpp +uninitMemberVar:*/unused_type_warning/gen/unused_type_warning/UnusedStructure.cpp +uninitMemberVar:*/unused_type_warning/gen/unused_type_warning/UnusedStructure.h + +variableScope:*/unused_type_warning/gen/unused_type_warning/BoolStructureTable.cpp diff --git a/test/warnings/unused_type_warning/cpp/UnusedTypeWarningTest.cpp b/test/warnings/unused_type_warning/cpp/UnusedTypeWarningTest.cpp new file mode 100644 index 000000000..638152c68 --- /dev/null +++ b/test/warnings/unused_type_warning/cpp/UnusedTypeWarningTest.cpp @@ -0,0 +1,58 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "test_utils/ZserioErrorOutput.h" + +class UnusedTypeWarningTest : public ::testing::Test +{ +protected: + UnusedTypeWarningTest() + : zserioWarnings("warnings/unused_type_warning") + {} + + const test_utils::ZserioErrorOutput zserioWarnings; +}; + +TEST_F(UnusedTypeWarningTest, unusedEnumeration) +{ + const std::string warning = "unused_type_warning.zs:4:12: " + "Type 'unused_type_warning.UnusedEnumeration' is not used."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(UnusedTypeWarningTest, unusedSubtype) +{ + const std::string warning = "unused_type_warning.zs:18:15: " + "Type 'unused_type_warning.UnusedSubtype' is not used."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(UnusedTypeWarningTest, unusedChoice) +{ + const std::string warning = "unused_type_warning.zs:28:8: " + "Type 'unused_type_warning.UnusedChoice' is not used."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(UnusedTypeWarningTest, unusedUnion) +{ + const std::string warning = "unused_type_warning.zs:48:7: " + "Type 'unused_type_warning.UnusedUnion' is not used."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(UnusedTypeWarningTest, unusedStructure) +{ + const std::string warning = "unused_type_warning.zs:62:8: " + "Type 'unused_type_warning.UnusedStructure' is not used."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} + +TEST_F(UnusedTypeWarningTest, unusedTable) +{ + const std::string warning = "unused_type_warning.zs:76:11: " + "Type 'unused_type_warning.UnusedTable' is not used."; + ASSERT_TRUE(zserioWarnings.isPresent(warning)); +} diff --git a/test/warnings/unused_type_warning/python/UnusedTypeWarningTest.py b/test/warnings/unused_type_warning/python/UnusedTypeWarningTest.py new file mode 100644 index 000000000..6386088c6 --- /dev/null +++ b/test/warnings/unused_type_warning/python/UnusedTypeWarningTest.py @@ -0,0 +1,64 @@ +import unittest + +from testutils import getZserioApi, assertWarningsPresent + +class UnusedTypeWarningTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.warnings = {} + cls.api = getZserioApi(__file__, "unused_type_warning.zs", extraArgs=["-withUnusedWarnings"], + expectedWarnings=6, errorOutputDict=cls.warnings) + + def testUnusedEnumeration(self): + assertWarningsPresent(self, + "unused_type_warning.zs", + [ + "unused_type_warning.zs:4:12: " + "Type 'unused_type_warning.UnusedEnumeration' is not used." + ] + ) + + def testUnusedSubtype(self): + assertWarningsPresent(self, + "unused_type_warning.zs", + [ + "unused_type_warning.zs:18:15: " + "Type 'unused_type_warning.UnusedSubtype' is not used." + ] + ) + + def testUnusedChoice(self): + assertWarningsPresent(self, + "unused_type_warning.zs", + [ + "unused_type_warning.zs:28:8: " + "Type 'unused_type_warning.UnusedChoice' is not used." + ] + ) + + def testUnusedUnion(self): + assertWarningsPresent(self, + "unused_type_warning.zs", + [ + "unused_type_warning.zs:48:7: " + "Type 'unused_type_warning.UnusedUnion' is not used." + ] + ) + + def testUnusedStructure(self): + assertWarningsPresent(self, + "unused_type_warning.zs", + [ + "unused_type_warning.zs:62:8: " + "Type 'unused_type_warning.UnusedStructure' is not used." + ] + ) + + def testUnusedTable(self): + assertWarningsPresent(self, + "unused_type_warning.zs", + [ + "unused_type_warning.zs:76:11: " + "Type 'unused_type_warning.UnusedTable' is not used." + ] + )