File indexing completed on 2024-04-06 12:03:55
0001 #include "cppunit/extensions/HelperMacros.h"
0002 #include "DataFormats/Common/interface/AtomicPtrCache.h"
0003
0004 #include <vector>
0005
0006 class testAtomicPtrCache : public CppUnit::TestFixture {
0007 CPPUNIT_TEST_SUITE(testAtomicPtrCache);
0008 CPPUNIT_TEST(check);
0009 CPPUNIT_TEST_SUITE_END();
0010 public:
0011 void setUp() {}
0012 void tearDown() {}
0013 void check();
0014 };
0015
0016 CPPUNIT_TEST_SUITE_REGISTRATION(testAtomicPtrCache);
0017
0018 typedef std::vector<int> Vec;
0019 void
0020 testAtomicPtrCache::check()
0021 {
0022 using namespace edm;
0023
0024 const Vec values = {1,2,3};
0025
0026 {
0027 AtomicPtrCache<Vec> cache;
0028 CPPUNIT_ASSERT(false == cache.isSet());
0029 CPPUNIT_ASSERT(nullptr == cache.operator->());
0030 CPPUNIT_ASSERT(nullptr == cache.load());
0031
0032 cache.set(std::make_unique<Vec>(values));
0033 CPPUNIT_ASSERT(true == cache.isSet());
0034 CPPUNIT_ASSERT(cache->size() == values.size());
0035 CPPUNIT_ASSERT((*cache).size() == values.size());
0036 CPPUNIT_ASSERT(cache.load()->size() == values.size());
0037
0038 {
0039
0040 const AtomicPtrCache<Vec> & constCache = cache;
0041
0042 CPPUNIT_ASSERT(true == constCache.isSet());
0043 CPPUNIT_ASSERT(constCache->size() == values.size());
0044 CPPUNIT_ASSERT((*constCache).size() == values.size());
0045 CPPUNIT_ASSERT(constCache.load()->size() == values.size());
0046 }
0047
0048 cache.reset();
0049 CPPUNIT_ASSERT(false == cache.isSet());
0050 }
0051
0052 {
0053 AtomicPtrCache<Vec> cache{new Vec{values}};
0054 CPPUNIT_ASSERT(true == cache.isSet());
0055 CPPUNIT_ASSERT(cache->size() == values.size());
0056 }
0057
0058 {
0059 AtomicPtrCache<Vec> cache;
0060 CPPUNIT_ASSERT(false == cache.isSet());
0061
0062 AtomicPtrCache<Vec> cache2{new Vec{values}};
0063
0064 cache = cache2;
0065
0066 CPPUNIT_ASSERT(true == cache.isSet());
0067 CPPUNIT_ASSERT(cache->size() == values.size());
0068 CPPUNIT_ASSERT(true == cache2.isSet());
0069 CPPUNIT_ASSERT(cache2->size() == values.size());
0070 CPPUNIT_ASSERT(cache.load() != cache2.load());
0071 }
0072
0073 {
0074 AtomicPtrCache<Vec> cache2{new Vec{values}};
0075 AtomicPtrCache<Vec> cache{ cache2 };
0076 CPPUNIT_ASSERT(true == cache.isSet());
0077 CPPUNIT_ASSERT(cache->size() == values.size());
0078 CPPUNIT_ASSERT(true == cache2.isSet());
0079 CPPUNIT_ASSERT(cache2->size() == values.size());
0080 CPPUNIT_ASSERT(cache.load() != cache2.load());
0081 }
0082
0083 }