Skip to content

Commit

Permalink
Add GTest infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaly committed May 5, 2020
1 parent c6086af commit e5b1814
Show file tree
Hide file tree
Showing 11 changed files with 213 additions and 7 deletions.
21 changes: 16 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.15)
project(ProtocolDeclarationLanguageFramework CXX)
project(PdlFramework CXX)

# Select CPP standard.
set(CMAKE_CXX_STANDARD 17)
Expand All @@ -8,14 +8,23 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Select output binary paths.
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH )

# Info about a compiler.
message("Compiler ID is '${CMAKE_CXX_COMPILER_ID}'.")
message("[info] Compiler is '${CMAKE_CXX_COMPILER_ID}'.")

# Find Boost library.
find_package(Boost 1.73 REQUIRED)
include_directories(${Boost_INCLUDE_DIRS})

# Find GTest library.
if (DEFINED PDL_WITH_TESTS)
message("[info] PDL Tests Included.")
find_package(GTest 1.10 REQUIRED)
add_subdirectory(tests)
pdl_test_init()
endif()

set(DISABLE_WARNINGS "-Wno-unknown-pragmas -Wno-unused-parameter -Wno-zero-as-null-pointer-constant -Wno-deprecated-declarations")
set(DISABLE_WARNINGS_GCC "-Wno-variadic-macros -Wno-unknown-pragmas")
set(DISABLE_WARNINGS_CLANG "-Wno-return-std-move-in-c++11 -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-exit-time-destructors -Wno-missing-prototypes -Wno-documentation")
Expand Down Expand Up @@ -47,10 +56,12 @@ endif()

# Output compile flags.
if (${CMAKE_BUILD_TYPE} MATCHES "Release")
message("Compiler flags: ${CMAKE_CXX_FLAGS_RELEASE}.")
message("[info] Compiler flags: ${CMAKE_CXX_FLAGS_RELEASE}.")
else()
message("Compiler flags: ${CMAKE_CXX_FLAGS_DEBUG}.")
message("[info] Compiler flags: ${CMAKE_CXX_FLAGS_DEBUG}.")
endif()

add_subdirectory(tools)
add_subdirectory(common)
add_subdirectory(parser)
add_subdirectory(model)
add_subdirectory(tools)
8 changes: 8 additions & 0 deletions common/BinaryData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// ============================================================================
// Copyright (c) 2017-2020, by Vitaly Grigoriev, <Vit.link420@gmail.com>.
// This file is part of PdlFramework open source project under MIT License.
// ============================================================================

#include "BinaryData.hpp"


75 changes: 75 additions & 0 deletions common/BinaryData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// ============================================================================
// Copyright (c) 2017-2020, by Vitaly Grigoriev, <Vit.link420@gmail.com>.
// This file is part of PdlFramework open source project under MIT License.
// ============================================================================

#pragma once

// ////////////// DATA ENDIAN TYPE ////////////////
//
// Little Endian Model.
// |7______0|15______8|23______16|31______24|
//
// Big Endian Model.
// |31______24|23______16|15______8|7______0|
//
// Reverse Big Endian Model.
// |24______31|16______23|8______15|0______7|
//
// Endian Independent Model.
// |0______7|8______15|16______23|24______31|
//
//
// Another endian models (not supported).
//
// Middle Endian Big Model. (PDP-11)
// |23______16|31______24|7______0|15______8|
//
// Middle Endian Little Model. (Honeywell 316)
// |15______8|7______0|31______24|23______16|
//
// ////////////////////////////////////////////////


namespace pdl::common::data
{

/**
* @defgroup BYTE_CONSTANTS Byte defines.
* @brief This group of constants defines all bytes which are used in BinaryData class.
* @{
*/
inline constexpr std::byte HighByte = std::byte(0xFF);
inline constexpr std::byte LowByte = std::byte(0x00);

inline constexpr std::byte HighPartByte = std::byte(0xF0);
inline constexpr std::byte LowPartByte = std::byte(0x0F);

inline constexpr std::byte HighAlternateByte = std::byte(0xAA);
inline constexpr std::byte LowAlternateByte = std::byte(0x55);

inline constexpr std::byte HighBitsInHalvesByte = std::byte(0xCC);
inline constexpr std::byte LowBitsInHalvesByte = std::byte(0x33);

inline constexpr std::byte HighBitInByte = std::byte(0x80);
inline constexpr std::byte LowBitInByte = std::byte(0x01);
/** @} */

/**
* @enum DATA_ENDIAN_TYPE
* @brief Endian type of data in BinaryData class.
*
* @note Default initial type of internal data in BinaryDataEngine class the same as system type.
*/
enum class DATA_ENDIAN_TYPE
{
DATA_BIG_ENDIAN = 0x01, // First byte of the multibyte data-type is stored first.
DATA_LITTLE_ENDIAN = 0x02, // Last byte of the multibyte data-type is stored first.
DATA_REVERSE_BIG_ENDIAN = 0x03, // First byte of the multibyte data-type is stored first in reverse bit sequence.
DATA_SYSTEM_ENDIAN = 0xFE, // This endian type determine the system endian type and using only in constructors.
DATA_NO_ENDIAN = 0xFF // This endian type means that endian value does not set.
};



} // namespace data.
17 changes: 17 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project(PdlCommon CXX)

# Build PDL Common library.
add_library(pdl_common STATIC)
add_library(pdl::common ALIAS pdl_common)
set_target_properties(pdl_common PROPERTIES OUTPUT_NAME common)

target_sources(pdl_common
PRIVATE
BinaryData.cpp
PUBLIC
Types.hpp
BinaryData.hpp
ClassDeclaration.hpp
)

add_subdirectory(tests)
20 changes: 20 additions & 0 deletions common/ClassDeclaration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once


namespace pdl::common
{

template <typename Type>
class ClassDeclaration
{
public:
using Ref = Type &;
using CRef = const Type &;
using Ptr = Type *;
using CPtr = const Type *;

ClassDeclaration() = default;
virtual ~ClassDeclaration() = default;
};

} // namespace common.
13 changes: 13 additions & 0 deletions common/Types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <string>
#include <string_view>


namespace pdl::common
{

using Type = std::string;
using TypeRef = std::string_view;

} // namespace common.
5 changes: 5 additions & 0 deletions common/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pdl_test_create(binary_data)

pdl_test_add_source(binary_data dummy.cpp)

pdl_test_register(binary_data)
7 changes: 7 additions & 0 deletions common/tests/dummy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <gtest/gtest.h>


TEST(pdl_binary_data, test_test)
{
ASSERT_EQ(1 ,1);
}
4 changes: 2 additions & 2 deletions parser/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ set(PDL_TEST_SOURCES
)

# Build PDL tests.
add_executable(test ${PDL_TEST_SOURCES})
target_link_libraries(test pdl::parser)
add_executable(_test ${PDL_TEST_SOURCES})
target_link_libraries(_test pdl::parser)
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_subdirectory(unit_tests)
49 changes: 49 additions & 0 deletions tests/unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
project(PdlUnitTest CXX)

macro(pdl_test_init)

enable_testing()
include(GoogleTest)

endmacro()

macro(pdl_test_create _name)

add_executable(${_name}_test)
target_link_libraries(${_name}_test
PRIVATE
gtest
gtest_main
)

endmacro()

macro(pdl_test_add_dependency _name _lib)

target_link_libraries(${_name}_test
PRIVATE
${_lib}
)

endmacro()

macro(pdl_test_add_source _name)

target_sources(${_name}_test
PRIVATE
${ARGN}
)

endmacro()

macro(pdl_test_register _name)

gtest_discover_tests(${_name}_test
EXTRA_ARGS
--gtest_shuffle
--gtest_repeat=5
--gtest_random_seed=0
--gtest_output=xml:${PROJECT_BINARY_DIR}/reports/
)

endmacro()

0 comments on commit e5b1814

Please sign in to comment.