# One transfer between warehouses written three ways: line by line
# (basic guarantee), by copy and swap (strong), and by prepare, record,
# then commit with steps that cannot throw (strong). The tests make each
# allocation fail in turn to check which guarantee each version keeps.
add_library(adv_inventory STATIC warehouse.cpp)
target_include_directories(adv_inventory PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

lld_add_example(adv_inventory_transfer SOURCES main.cpp EXPECTED_OUTPUT expected_output.txt)
target_link_libraries(adv_inventory_transfer PRIVATE adv_inventory)

lld_add_test(adv_inventory_tests SOURCES tests/test_transfer.cpp)
target_link_libraries(adv_inventory_tests PRIVATE adv_inventory)

# Replaces the global operator new, so it is a separate test program.
# ThreadSanitizer's runtime defines operator new too, and the linker
# refuses two; this test runs one thread, so TSan has nothing to check.
if(NOT CMAKE_CXX_FLAGS MATCHES "-fsanitize=thread")
  lld_add_test(adv_inventory_fault_tests SOURCES tests/test_failing_allocation.cpp
    tests/failing_allocation.cpp)
  target_link_libraries(adv_inventory_fault_tests PRIVATE adv_inventory)
endif()
