From 281dd37945f00223ea86ff99f893141f643a4594 Mon Sep 17 00:00:00 2001 From: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> Date: Mon, 8 Feb 2021 13:01:44 -0800 Subject: [PATCH] Add simplified header test for Identity (#1625) * Add simplified header test for Identity Co-authored-by: Anton Kolesnyk --- CMakeLists.txt | 2 + .../azure-identity/test/CMakeLists.txt | 45 +++++++++++++++++++ sdk/identity/azure-identity/test/main.cpp | 11 +++++ .../azure-identity/test/simplified_header.cpp | 23 ++++++++++ 4 files changed, 81 insertions(+) create mode 100644 sdk/identity/azure-identity/test/CMakeLists.txt create mode 100644 sdk/identity/azure-identity/test/main.cpp create mode 100644 sdk/identity/azure-identity/test/simplified_header.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index d126b1984..741654fef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,6 +44,8 @@ if(BUILD_TESTING) if(DEFINED ENV{AZURE_CORE_ENABLE_JSON_TESTS}) add_subdirectory(sdk/core/azure-core/test/nlohmann-json-test) endif() + + add_subdirectory(sdk/identity/azure-identity/test) endif() # compiler warning flags globally diff --git a/sdk/identity/azure-identity/test/CMakeLists.txt b/sdk/identity/azure-identity/test/CMakeLists.txt new file mode 100644 index 000000000..ca722938a --- /dev/null +++ b/sdk/identity/azure-identity/test/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# SPDX-License-Identifier: MIT + +cmake_minimum_required (VERSION 3.13) + +set(azure-identity-test) + +project (azure-identity-test LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +include(GoogleTest) + +add_executable ( + azure-identity-test + main.cpp + simplified_header.cpp +) + +if (MSVC) + # Disable warnings: + # - C26495: Variable + # - 'testing::internal::Mutex::critical_section_' + # - 'testing::internal::Mutex::critical_section_init_phase_' + # - 'testing::internal::Mutex::owner_thread_id_' + # - 'testing::internal::Mutex::type_' + # is uninitialized. Always initialize member variables (type.6). + # - C26812: The enum type + # - 'testing::internal::Mutex::StaticConstructorSelector' + # - 'testing::TestPartResult::Type' + # is unscoped. Prefer 'enum class' over 'enum' (Enum.3) + target_compile_options(azure-identity-test PUBLIC /wd26495 /wd26812) +endif() + +# Adding private headers from identity to the tests so we can test the private APIs with no relative paths include. +target_include_directories (azure-identity-test PRIVATE $) + +target_link_libraries(azure-identity-test PRIVATE azure-identity gtest gmock) + +# gtest_discover_tests will scan the test from azure-identity-test and call add_test +# for each test to ctest. This enables `ctest -r` to run specific tests directly. +gtest_discover_tests(azure-identity-test + TEST_PREFIX azure-identity. + NO_PRETTY_TYPES + NO_PRETTY_VALUES) diff --git a/sdk/identity/azure-identity/test/main.cpp b/sdk/identity/azure-identity/test/main.cpp new file mode 100644 index 000000000..471d6e961 --- /dev/null +++ b/sdk/identity/azure-identity/test/main.cpp @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +#include + +int main(int argc, char** argv) +{ + testing::InitGoogleTest(&argc, argv); + auto r = RUN_ALL_TESTS(); + return r; +} diff --git a/sdk/identity/azure-identity/test/simplified_header.cpp b/sdk/identity/azure-identity/test/simplified_header.cpp new file mode 100644 index 000000000..6549f212e --- /dev/null +++ b/sdk/identity/azure-identity/test/simplified_header.cpp @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// SPDX-License-Identifier: MIT + +/** + * @brief makes sure azure/identity.hpp can be included. + * + * @remark This file will catch any issue while trying to use/include the identity.hpp header + * + */ + +#include +#include + +class DllExportTest { + AZ_IDENTITY_DLLEXPORT static const bool DllExportHIncluded; +}; + +TEST(SimplifiedHeader, identity) +{ + EXPECT_NO_THROW(Azure::Identity::ClientSecretCredential clientSecretCredential("", "", "")); + EXPECT_NO_THROW(Azure::Identity::EnvironmentCredential environmentCredential); + EXPECT_NO_THROW(Azure::Identity::Details::Version::VersionString()); +}