Merge pull request #8 from microsoft/brhick/googletest
Integrate Google Test into project
This commit is contained in:
Коммит
cd69856870
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cmake_minimum_required (VERSION 3.11)
|
||||
|
@ -14,6 +14,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
|
||||
option(BUILD_EXAMPLE "Build example executable (on by default)" ON)
|
||||
option(BUILD_TESTS "Build test executable (on by default)" ON)
|
||||
|
||||
add_library(AccessorFramework
|
||||
${PROJECT_SOURCE_DIR}/src/Accessor.cpp
|
||||
|
@ -118,3 +119,9 @@ export(EXPORT AccessorFrameworkTargets
|
|||
)
|
||||
|
||||
export(PACKAGE AccessorFramework)
|
||||
|
||||
if (BUILD_TESTS)
|
||||
add_definitions(-DUSE_GTEST)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif (BUILD_TESTS)
|
|
@ -0,0 +1,27 @@
|
|||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cmake_minimum_required (VERSION 3.11)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
googletest
|
||||
GIT_REPOSITORY https://github.com/google/googletest.git
|
||||
GIT_TAG release-1.10.0
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(googletest)
|
||||
FetchContent_GetProperties(googletest)
|
||||
if(NOT googletest_POPULATED)
|
||||
FetchContent_Populate(googletest)
|
||||
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR})
|
||||
endif()
|
||||
|
||||
add_executable(AccessorFrameworkTests src/CommonAccessorTests.cpp)
|
||||
target_link_libraries(AccessorFrameworkTests
|
||||
gtest
|
||||
gmock_main
|
||||
AccessorFramework::AccessorFramework
|
||||
)
|
||||
|
||||
add_test(NAME AccessorFrameworkTests COMMAND AccessorFrameworkTests)
|
|
@ -0,0 +1,67 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include <AccessorFramework/Accessor.h>
|
||||
|
||||
namespace CommonAccessorTests
|
||||
{
|
||||
// A name cannot be empty, cannot contain periods, and cannot contain whitespace
|
||||
TEST(Accessor_NameIsValidTests, ValidName)
|
||||
{
|
||||
// Arrange
|
||||
const std::string targetName = "TargetName";
|
||||
|
||||
// Act
|
||||
bool nameIsValid = Accessor::NameIsValid(targetName);
|
||||
|
||||
// Assert
|
||||
ASSERT_TRUE(nameIsValid);
|
||||
}
|
||||
|
||||
TEST(Accessor_NameIsValidTests, EmptyName)
|
||||
{
|
||||
// Arrange
|
||||
const std::string targetName = "";
|
||||
|
||||
// Act
|
||||
bool nameIsValid = Accessor::NameIsValid(targetName);
|
||||
|
||||
// Assert
|
||||
ASSERT_FALSE(nameIsValid);
|
||||
}
|
||||
|
||||
TEST(Accessor_NameIsValidTests, NameWithPeriods)
|
||||
{
|
||||
// Arrange
|
||||
const std::string targetName = "Target.Name";
|
||||
|
||||
// Act
|
||||
bool nameIsValid = Accessor::NameIsValid(targetName);
|
||||
|
||||
// Assert
|
||||
ASSERT_FALSE(nameIsValid);
|
||||
}
|
||||
|
||||
TEST(Accessor_NameIsValidTests, NameWithWhitespace)
|
||||
{
|
||||
// Arrange
|
||||
const std::string targetName = "Target Name";
|
||||
|
||||
// Act
|
||||
bool nameIsValid = Accessor::NameIsValid(targetName);
|
||||
|
||||
// Assert
|
||||
ASSERT_FALSE(nameIsValid);
|
||||
}
|
||||
|
||||
TEST(Accessor_GetNameTests, ValidName)
|
||||
{
|
||||
// Arrange
|
||||
const std::string expectedTargetName = "TargetName";
|
||||
AtomicAccessor target(expectedTargetName);
|
||||
|
||||
// Act
|
||||
std::string actualTargetName = target.GetName();
|
||||
|
||||
// Assert
|
||||
ASSERT_EQ(expectedTargetName, actualTargetName);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче