Skip to content

Commit

Permalink
Add tests for deprecated usage of utils
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjseitz authored and jdorn-gt committed Aug 23, 2024
1 parent 13f35d9 commit 0e73b66
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 3 deletions.
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,6 @@ option(
# === C++ ===
set(CXX_API ${GTIRB_CXX_API})

# Disable using GTIRB utilities from the global namespace
add_definitions(-DGTIRB_WRAP_UTILS_IN_NAMESPACE)

# === Python ===
set(PY_API ${GTIRB_PY_API})
if(GTIRB_PY_API)
Expand Down
9 changes: 9 additions & 0 deletions doc/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,29 @@ if(CXX_API)

add_executable(ex-api-walkthrough api-walkthrough.cpp)
target_link_libraries(ex-api-walkthrough gtirb)
target_compile_definitions(
ex-api-walkthrough PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE
)

add_executable(ex-data-symbols data-symbols.cpp)
target_link_libraries(ex-data-symbols gtirb)
target_compile_definitions(
ex-data-symbols PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE
)

add_executable(ex-cfg-paths cfg-paths.cpp)
target_link_libraries(ex-cfg-paths gtirb)
target_compile_definitions(ex-cfg-paths PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE)

add_executable(ex-functions functions.cpp)
target_link_libraries(ex-functions gtirb)
target_compile_definitions(ex-functions PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE)

find_library(CAPSTONE NAMES capstone)
if(CAPSTONE)
add_executable(ex-jumps jumps.cpp)
target_link_libraries(ex-jumps gtirb ${CAPSTONE})
target_compile_definitions(ex-jumps PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE)
endif()

list(
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ target_link_libraries(
)
target_compile_definitions(
${PROJECT_NAME} PRIVATE GTIRB_${PROJECT_NAME}_EXPORTS
GTIRB_WRAP_UTILS_IN_NAMESPACE
)
target_include_directories(${PROJECT_NAME} PUBLIC "${PROTOBUF_INCLUDE_DIRS}")

Expand Down
31 changes: 31 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ endif()

add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_H} ${${PROJECT_NAME}_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "gtirb/test")
target_compile_definitions(
${PROJECT_NAME} PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE
)

target_link_libraries(
${PROJECT_NAME} ${SYSLIBS} ${Boost_LIBRARIES} gtest gtest_main gtirb
Expand All @@ -84,6 +87,9 @@ set(${PROJECT_NAME}_SRC PrepTestGTIRB.cpp)

add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_H} ${${PROJECT_NAME}_SRC})
set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER "gtirb/test")
target_compile_definitions(
${PROJECT_NAME} PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE
)

target_link_libraries(${PROJECT_NAME} ${SYSLIBS} ${Boost_LIBRARIES} gtirb)

Expand All @@ -110,6 +116,31 @@ set(${PROJECT_NAME}_SRC AuxDataSchemaRegistration.test.cpp)

# Add this test to ctest
gtirb_add_executable_gtest()
target_compile_definitions(
${PROJECT_NAME} PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE
)

target_link_libraries(
${PROJECT_NAME} ${SYSLIBS} ${Boost_LIBRARIES} gtest gtest_main gtirb
)

# testgtirb_deprecated_utils
#
# This separate test executable does NOT define GTIRB_WRAP_UTILS_IN_NAMESPACE
set(PROJECT_NAME testgtirb_deprecated_utils)

set(${PROJECT_NAME}_SRC UtilsUsingGtirbNamespace.test.cpp
UtilsDeprecatedGlobals.test.cpp
)

gtirb_add_executable_gtest()

if((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL
Clang)
)
# Disable deprecation warnings
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-deprecated-declarations)
endif()

target_link_libraries(
${PROJECT_NAME} ${SYSLIBS} ${Boost_LIBRARIES} gtest gtest_main gtirb
Expand Down
22 changes: 22 additions & 0 deletions src/test/UtilsDeprecatedGlobals.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===- UtilsDeprecatedGlobals.test.cpp --------------------------*- C++ -*-===//
//
// Copyright (C) 2024 GrammaTech, Inc.
//
// This code is licensed under the MIT license. See the LICENSE file in the
// project root for license terms.
//
// This project is sponsored by the Office of Naval Research, One Liberty
// Center, 875 N. Randolph Street, Arlington, VA 22203 under contract #
// N68335-17-C-0700. The content of the information does not necessarily
// reflect the position or policy of the Government and no official
// endorsement should be inferred.
//
//===----------------------------------------------------------------------===//
#include <gtirb/Allocator.hpp>
#include <gtest/gtest.h>

/*
Ensure it is possible to use utility functions with no namespace if
GTIRB_WRAP_UTILS_IN_NAMESPACE is not defined.
*/
TEST(Unit_IR, globalNextPowerOfTwo) { EXPECT_EQ(NextPowerOf2(5), 8U); }
24 changes: 24 additions & 0 deletions src/test/UtilsUsingGtirbNamespace.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//===- UtilsUsingGtirbNamespace.test.cpp ------------------------*- C++ -*-===//
//
// Copyright (C) 2024 GrammaTech, Inc.
//
// This code is licensed under the MIT license. See the LICENSE file in the
// project root for license terms.
//
// This project is sponsored by the Office of Naval Research, One Liberty
// Center, 875 N. Randolph Street, Arlington, VA 22203 under contract #
// N68335-17-C-0700. The content of the information does not necessarily
// reflect the position or policy of the Government and no official
// endorsement should be inferred.
//
//===----------------------------------------------------------------------===//
#define GTIRB_WRAP_UTILS_IN_NAMESPACE
#include <gtirb/Allocator.hpp>
#include <gtest/gtest.h>

/*
Ensure it is possible to use utility functions by using the gtirb namesapce when
GTIRB_WRAP_UTILS_IN_NAMESPACE is defined.
*/
using namespace gtirb;
TEST(Unit_IR, namespacedNextPowerOfTwo) { EXPECT_EQ(NextPowerOf2(5), 8U); }
3 changes: 3 additions & 0 deletions src/test/testInterop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ set_target_properties(test_variants PROPERTIES FOLDER "gtirb/test/testInterop")
target_link_libraries(test_floats gtirb)
target_link_libraries(test_variants gtirb)

target_compile_definitions(test_floats PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE)
target_compile_definitions(test_variants PRIVATE GTIRB_WRAP_UTILS_IN_NAMESPACE)

set(${PROJECT_NAME}_SCRIPTS test_floats.py test_variants.py)
set(test_floats ${CMAKE_BINARY_DIR}/bin/test_floats)

Expand Down

0 comments on commit 0e73b66

Please sign in to comment.