From e17f5e33b531ea12d3f53d43520eac0c6654dfb2 Mon Sep 17 00:00:00 2001 From: abarton <Adam.Edward.Barton@cern.ch> Date: Thu, 31 Oct 2019 11:32:14 +0000 Subject: [PATCH] Add test program for IDCValue --- Event/EventContainers/CMakeLists.txt | 5 +++ Event/EventContainers/share/IDCValueTest.ref | 2 + Event/EventContainers/test/IDCValueTest.cxx | 44 ++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 Event/EventContainers/share/IDCValueTest.ref create mode 100644 Event/EventContainers/test/IDCValueTest.cxx diff --git a/Event/EventContainers/CMakeLists.txt b/Event/EventContainers/CMakeLists.txt index c65a935b9a0..a78bf3a7d82 100644 --- a/Event/EventContainers/CMakeLists.txt +++ b/Event/EventContainers/CMakeLists.txt @@ -34,3 +34,8 @@ atlas_add_test( IDStressTest SOURCES test/IDC_Realistic_Test.cxx LINK_LIBRARIES Identifier AthenaKernel GaudiKernel EventContainers EXTRA_PATTERNS "elapsed|^no lock time|^deleted|^countHit|^lock time" ) +atlas_add_test( IDCValueTest SOURCES test/IDCValueTest.cxx + INCLUDE_DIRS src test EventContainers + LINK_LIBRARIES Identifier AthenaKernel GaudiKernel EventContainers + EXTRA_PATTERNS "" + ) \ No newline at end of file diff --git a/Event/EventContainers/share/IDCValueTest.ref b/Event/EventContainers/share/IDCValueTest.ref new file mode 100644 index 00000000000..1a2c5e2c1a5 --- /dev/null +++ b/Event/EventContainers/share/IDCValueTest.ref @@ -0,0 +1,2 @@ +Threw exception correctly +Completed - no errors diff --git a/Event/EventContainers/test/IDCValueTest.cxx b/Event/EventContainers/test/IDCValueTest.cxx new file mode 100644 index 00000000000..c7b908d8f0c --- /dev/null +++ b/Event/EventContainers/test/IDCValueTest.cxx @@ -0,0 +1,44 @@ + +#include "EventContainers/IdentifiableValueContainer.h" + +#include <cstdlib> +#include <iostream> +#include <limits> + +typedef IdentifiableValueCache<int, std::numeric_limits<int>::min()> int100cache; +typedef IdentifiableValueContainer<int, std::numeric_limits<int>::min()> int100container; + +int main(){ + auto *cache = new int100cache(100); + auto *container = new int100container(cache); + auto *container2 = new int100container(cache); + static_assert(cache->emptyValue() == std::numeric_limits<int>::min()); + if(container->maxSize()!= 100) std::abort(); + if(!container->setOrDrop(50, 29)) std::abort(); + if(!container->setOrDrop(51, -29)) std::abort(); + if(!container->setOrDrop(52, -9)) std::abort(); + if(container->setOrDrop(52, 10) == true) std::abort(); //check if repeated setting passes + if(container->retrieve(52) != -9) std::abort(); + + if(container->present(50)==false || container->present(51)==false || container->present(52)==false) std::abort(); + if(container2->tryAddFromCache(50) == false) std::abort(); + if(container2->getAll().size()!= 1) std::abort(); + if(container->getAll().size()!= 3) std::abort(); + if(container2->retrieve(50) != 29) std::abort(); + if(container2->present(51) == true) std::abort(); + if(container2->retrieve(51) != container2->emptyValue()) std::abort(); + bool except =false; + try{ + container->setOrDrop(150, -29); + }catch(const std::out_of_range& ex) + { + except = true; + std::cout << "Threw exception correctly" << std::endl; + } + if(except == false) std::abort(); + delete container2; + delete container; + delete cache; + std::cout << "Completed - no errors" << std::endl; + return 0; +} \ No newline at end of file -- GitLab