From eb222f54bb63b8cb410372ec9a05ebe7e3b49b88 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 30 Jan 2018 08:47:49 +0000 Subject: [PATCH] Containers are now deleteable through a pointer to their 'ixxxx' class. --- src/deque.h | 11 + src/flat_map.h | 11 + src/flat_multimap.h | 11 + src/flat_multiset.h | 11 + src/flat_set.h | 11 + src/forward_list.h | 11 + src/list.h | 11 + src/map.h | 10 + src/multimap.h | 10 + src/multiset.h | 10 + src/queue.h | 11 + src/set.h | 11 + src/stack.h | 11 + src/unordered_map.h | 11 + src/unordered_multimap.h | 11 + src/unordered_multiset.h | 11 + src/unordered_set.h | 11 + src/vector.h | 11 + test/codeblocks/ETL.layout | 1077 +++++++++++++------------ test/data.h | 6 +- test/test_deque.cpp | 13 + test/test_flat_map.cpp | 13 + test/test_flat_multimap.cpp | 15 +- test/test_flat_multiset.cpp | 13 + test/test_flat_set.cpp | 15 +- test/test_forward_list.cpp | 13 + test/test_instance_count.cpp | 26 +- test/test_list.cpp | 13 + test/test_map.cpp | 9 + test/test_multimap.cpp | 9 + test/test_multiset.cpp | 9 + test/test_priority_queue.cpp | 17 + test/test_queue.cpp | 15 + test/test_reference_flat_map.cpp | 11 + test/test_reference_flat_multimap.cpp | 11 + test/test_reference_flat_multiset.cpp | 11 + test/test_reference_flat_set.cpp | 11 + test/test_set.cpp | 9 + test/test_stack.cpp | 15 + test/test_unordered_map.cpp | 11 + test/test_unordered_multimap.cpp | 11 + test/test_unordered_multiset.cpp | 11 + test/test_unordered_set.cpp | 11 + test/test_vector_non_trivial.cpp | 32 +- 44 files changed, 1059 insertions(+), 543 deletions(-) diff --git a/src/deque.h b/src/deque.h index 6171131c..014ee89c 100644 --- a/src/deque.h +++ b/src/deque.h @@ -622,6 +622,17 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~ideque() + { + if (!empty()) + { + initialise(); + } + } + //************************************************************************* /// Assigns a range to the deque. //************************************************************************* diff --git a/src/flat_map.h b/src/flat_map.h index 6ca6f8ed..cdd454b2 100644 --- a/src/flat_map.h +++ b/src/flat_map.h @@ -108,6 +108,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iflat_map() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the flat_map. ///\return An iterator to the beginning of the flat_map. diff --git a/src/flat_multimap.h b/src/flat_multimap.h index 41246cb2..4d143951 100644 --- a/src/flat_multimap.h +++ b/src/flat_multimap.h @@ -110,6 +110,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iflat_multimap() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the flat_multimap. ///\return An iterator to the beginning of the flat_multimap. diff --git a/src/flat_multiset.h b/src/flat_multiset.h index ff88bb21..5c378a3c 100644 --- a/src/flat_multiset.h +++ b/src/flat_multiset.h @@ -86,6 +86,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iflat_multiset() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the flat_multiset. ///\return An iterator to the beginning of the flat_multiset. diff --git a/src/flat_set.h b/src/flat_set.h index dec75bc1..adb2de9f 100644 --- a/src/flat_set.h +++ b/src/flat_set.h @@ -86,6 +86,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iflat_set() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the flat_set. ///\return An iterator to the beginning of the flat_set. diff --git a/src/forward_list.h b/src/forward_list.h index 4be5bca8..23fa7b3f 100644 --- a/src/forward_list.h +++ b/src/forward_list.h @@ -477,6 +477,17 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iforward_list() + { + if (!empty()) + { + clear(); + } + } + //************************************************************************* /// Gets the beginning of the forward_list. //************************************************************************* diff --git a/src/list.h b/src/list.h index 97c08724..f373fd29 100644 --- a/src/list.h +++ b/src/list.h @@ -583,6 +583,17 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~ilist() + { + if (!empty()) + { + initialise(); + } + } + //************************************************************************* /// Gets the beginning of the list. //************************************************************************* diff --git a/src/map.h b/src/map.h index cd1a0e2e..4c1dea50 100644 --- a/src/map.h +++ b/src/map.h @@ -801,6 +801,16 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~imap() + { + if (!empty()) + { + clear(); + } + } //************************************************************************* /// Gets the beginning of the map. diff --git a/src/multimap.h b/src/multimap.h index 1d2e7682..4139c264 100644 --- a/src/multimap.h +++ b/src/multimap.h @@ -952,6 +952,16 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~imultimap() + { + if (!empty()) + { + clear(); + } + } //************************************************************************* /// Gets the beginning of the multimap. diff --git a/src/multiset.h b/src/multiset.h index d2911291..23e265ba 100644 --- a/src/multiset.h +++ b/src/multiset.h @@ -932,6 +932,16 @@ namespace etl typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~imultiset() + { + if (!empty()) + { + clear(); + } + } //************************************************************************* /// Gets the beginning of the multiset. diff --git a/src/queue.h b/src/queue.h index 16c3de56..757dda51 100644 --- a/src/queue.h +++ b/src/queue.h @@ -239,6 +239,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iqueue() + { + if (!empty()) + { + clear(); + } + } + //************************************************************************* /// Gets a reference to the value at the front of the queue.
/// \return A reference to the value at the front of the queue. diff --git a/src/set.h b/src/set.h index 32f58a9d..be0407c4 100644 --- a/src/set.h +++ b/src/set.h @@ -786,6 +786,17 @@ namespace etl return *this; } + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iset() + { + if (!empty()) + { + clear(); + } + } + //************************************************************************* /// Gets the beginning of the set. //************************************************************************* diff --git a/src/stack.h b/src/stack.h index 5c2b0056..3bca539e 100644 --- a/src/stack.h +++ b/src/stack.h @@ -230,6 +230,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~istack() + { + if (!empty()) + { + clear(); + } + } + //************************************************************************* /// Gets a reference to the value at the top of the stack.
/// \return A reference to the value at the top of the stack. diff --git a/src/unordered_map.h b/src/unordered_map.h index c3c03329..d90304a1 100644 --- a/src/unordered_map.h +++ b/src/unordered_map.h @@ -480,6 +480,17 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iunordered_map() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the unordered_map. ///\return An iterator to the beginning of the unordered_map. diff --git a/src/unordered_multimap.h b/src/unordered_multimap.h index 4c2bfe74..a8a8a969 100644 --- a/src/unordered_multimap.h +++ b/src/unordered_multimap.h @@ -480,6 +480,17 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iunordered_multimap() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the unordered_multimap. ///\return An iterator to the beginning of the unordered_multimap. diff --git a/src/unordered_multiset.h b/src/unordered_multiset.h index 405fe9f6..b42d3e4f 100644 --- a/src/unordered_multiset.h +++ b/src/unordered_multiset.h @@ -475,6 +475,17 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iunordered_multiset() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the unordered_multiset. ///\return An iterator to the beginning of the unordered_multiset. diff --git a/src/unordered_set.h b/src/unordered_set.h index 68bb968d..d8d6087d 100644 --- a/src/unordered_set.h +++ b/src/unordered_set.h @@ -476,6 +476,17 @@ namespace etl typedef typename std::iterator_traits::difference_type difference_type; + //************************************************************************* + /// Destructor. + //************************************************************************* + ~iunordered_set() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the unordered_set. ///\return An iterator to the beginning of the unordered_set. diff --git a/src/vector.h b/src/vector.h index 547f8fdc..2cc369df 100644 --- a/src/vector.h +++ b/src/vector.h @@ -93,6 +93,17 @@ namespace etl public: + //************************************************************************* + /// Destructor. + //************************************************************************* + ~ivector() + { + if (!empty()) + { + clear(); + } + } + //********************************************************************* /// Returns an iterator to the beginning of the vector. ///\return An iterator to the beginning of the vector. diff --git a/test/codeblocks/ETL.layout b/test/codeblocks/ETL.layout index a0ca37fb..9c71eeb5 100644 --- a/test/codeblocks/ETL.layout +++ b/test/codeblocks/ETL.layout @@ -2,484 +2,14 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -487,59 +17,14 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -547,4 +32,554 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/data.h b/test/data.h index 8bd99496..b66d2f8f 100644 --- a/test/data.h +++ b/test/data.h @@ -31,11 +31,13 @@ SOFTWARE. #include +#include "instance_count.h" + //***************************************************************************** // Default constructor. //***************************************************************************** template -class TestDataDC +class TestDataDC : public etl::instance_count> { public: @@ -88,7 +90,7 @@ std::ostream& operator << (std::ostream& s, const TestDataDC& rhs) // No default constructor. //***************************************************************************** template -class TestDataNDC +class TestDataNDC : public etl::instance_count> { public: diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 503e561d..0bd71a7e 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -107,6 +107,19 @@ namespace CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); } + //************************************************************************* + TEST(test_destruct_via_ideque) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(SIZE, N999); + CHECK_EQUAL(int(current_count + SIZE), NDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, NDC::get_instance_count()); + } + //************************************************************************* TEST(test_constructor_fill_excess) { diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index 149b2406..cc09d1da 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -238,6 +238,19 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST(test_destruct_via_iflat_map) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, NDC::get_instance_count()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index 0e573278..59c3a32d 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -197,6 +197,19 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST(test_destruct_via_iflat_multimap) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, NDC::get_instance_count()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { @@ -499,7 +512,7 @@ namespace DataNDC data(compare_data.begin(), compare_data.end()); data.clear(); CHECK_EQUAL(data.size(), size_t(0)); - + // Do it again to check that clear() didn't screw up the internals. data.assign(compare_data.begin(), compare_data.end()); CHECK_EQUAL(data.size(), compare_data.size()); diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index 882774d8..fb775560 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -154,6 +154,19 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST(test_destruct_via_iflat_multiset) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, NDC::get_instance_count()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index 35def29d..25ff5cc7 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -101,7 +101,7 @@ namespace std::vector initial_data; std::vector excess_data; std::vector different_data; - + std::vector int_data; //************************************************************************* @@ -147,6 +147,19 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST(test_destruct_via_iflat_set) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + CHECK_EQUAL(int(current_count + initial_data.size()), NDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, NDC::get_instance_count()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 11ca2e11..524150a7 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -129,6 +129,19 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST(test_destruct_via_iforward_list) + { + int current_count = ItemNDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(sorted_data.begin(), sorted_data.end()); + CHECK_EQUAL(int(current_count + sorted_data.size()), ItemNDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, ItemNDC::get_instance_count()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_instance_count.cpp b/test/test_instance_count.cpp index ea3a5816..72e5512c 100644 --- a/test/test_instance_count.cpp +++ b/test/test_instance_count.cpp @@ -35,7 +35,7 @@ SOFTWARE. #include namespace -{ +{ SUITE(test_instance_count) { //************************************************************************* @@ -47,25 +47,29 @@ namespace struct Test2 : public etl::instance_count {}; - CHECK_EQUAL(0U, Test1::get_instance_count()); - CHECK_EQUAL(0U, Test2::get_instance_count()); + CHECK_EQUAL(0, Test1::get_instance_count()); + CHECK_EQUAL(0, Test2::get_instance_count()); Test1 test1a; - CHECK_EQUAL(1U, Test1::get_instance_count()); - CHECK_EQUAL(0U, Test2::get_instance_count()); + CHECK_EQUAL(1, Test1::get_instance_count()); + CHECK_EQUAL(0, Test2::get_instance_count()); Test1 test1b; Test2 test2a; - CHECK_EQUAL(2U, Test1::get_instance_count()); - CHECK_EQUAL(1U, Test2::get_instance_count()); + CHECK_EQUAL(2, Test1::get_instance_count()); + CHECK_EQUAL(1, Test2::get_instance_count()); Test2* ptest2b = new Test2; - CHECK_EQUAL(2U, Test1::get_instance_count()); - CHECK_EQUAL(2U, Test2::get_instance_count()); + CHECK_EQUAL(2, Test1::get_instance_count()); + CHECK_EQUAL(2, Test2::get_instance_count()); + + Test2 test2c(test2a); + CHECK_EQUAL(2, Test1::get_instance_count()); + CHECK_EQUAL(3, Test2::get_instance_count()); delete ptest2b; - CHECK_EQUAL(2U, Test1::get_instance_count()); - CHECK_EQUAL(1U, Test2::get_instance_count()); + CHECK_EQUAL(2, Test1::get_instance_count()); + CHECK_EQUAL(2, Test2::get_instance_count()); } }; } diff --git a/test/test_list.cpp b/test/test_list.cpp index cef78918..c0aaf9bd 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -100,6 +100,19 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST(test_destruct_via_ilist) + { + int current_count = ItemNDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(sorted_data.begin(), sorted_data.end()); + CHECK_EQUAL(int(current_count + sorted_data.size()), ItemNDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, ItemNDC::get_instance_count()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size) { diff --git a/test/test_map.cpp b/test/test_map.cpp index bc6b1a0c..a23397b4 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -183,6 +183,15 @@ namespace CHECK_EQUAL(data.max_size(), MAX_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_destruct_via_imap) + { + Data* pdata = new Data(initial_data.begin(), initial_data.end()); + + IData* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_multimap.cpp b/test/test_multimap.cpp index 6e8a280e..d71dc01e 100644 --- a/test/test_multimap.cpp +++ b/test/test_multimap.cpp @@ -183,6 +183,15 @@ namespace CHECK_EQUAL(data.max_size(), MAX_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_destruct_via_imultimap) + { + Data* pdata = new Data(initial_data.begin(), initial_data.end()); + + IData* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index 0e443075..ab454fbd 100644 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -175,6 +175,15 @@ namespace CHECK_EQUAL(data.max_size(), MAX_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_destruct_via_imultiset) + { + Data* pdata = new Data(initial_data.begin(), initial_data.end()); + + IData* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_priority_queue.cpp b/test/test_priority_queue.cpp index 8db4ca9c..c8fd99e6 100644 --- a/test/test_priority_queue.cpp +++ b/test/test_priority_queue.cpp @@ -78,6 +78,23 @@ namespace CHECK_EQUAL(priority_queue.max_size(), SIZE); } + //************************************************************************* + TEST(test_delete_via_ipriority_queue) + { + typedef etl::priority_queue priority_queue_t; + + priority_queue_t* ppriority_queue = new etl::priority_queue; + + etl::ipriority_queue* pipriority_queue = ppriority_queue; + + pipriority_queue->push(1); + pipriority_queue->push(2); + pipriority_queue->push(3); + pipriority_queue->push(4); + + delete pipriority_queue; + } + //************************************************************************* TEST(test_copy_constructor) { diff --git a/test/test_queue.cpp b/test/test_queue.cpp index d6c3bc00..09333a5c 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -97,6 +97,21 @@ namespace } } + //************************************************************************* + TEST(test_delete_via_iqueue) + { + etl::queue* pqueue = new etl::queue; + + etl::iqueue* piqueue = pqueue; + + piqueue->push(1); + piqueue->push(2); + piqueue->push(3); + piqueue->push(4); + + delete piqueue; + } + //************************************************************************* TEST(test_size) { diff --git a/test/test_reference_flat_map.cpp b/test/test_reference_flat_map.cpp index 544686ea..976b28ea 100644 --- a/test/test_reference_flat_map.cpp +++ b/test/test_reference_flat_map.cpp @@ -227,6 +227,17 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST(test_destruct_via_ireference_flat_map) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_reference_flat_multimap.cpp b/test/test_reference_flat_multimap.cpp index 3cb25a30..f433cea2 100644 --- a/test/test_reference_flat_multimap.cpp +++ b/test/test_reference_flat_multimap.cpp @@ -185,6 +185,17 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST(test_destruct_via_ireference_flat_multimap) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_reference_flat_multiset.cpp b/test/test_reference_flat_multiset.cpp index 29d60d91..f3ad4a34 100644 --- a/test/test_reference_flat_multiset.cpp +++ b/test/test_reference_flat_multiset.cpp @@ -171,6 +171,17 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST(test_destruct_via_ireference_flat_multiset) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_reference_flat_set.cpp b/test/test_reference_flat_set.cpp index aba3e2b0..ff943446 100644 --- a/test/test_reference_flat_set.cpp +++ b/test/test_reference_flat_set.cpp @@ -167,6 +167,17 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST(test_destruct_via_ireference_flat_set) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { diff --git a/test/test_set.cpp b/test/test_set.cpp index 52735afb..06b5607a 100644 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -186,6 +186,15 @@ namespace CHECK_EQUAL(data.max_size(), MAX_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_destruct_via_iset) + { + Data* pdata = new Data(initial_data.begin(), initial_data.end()); + + IData* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_stack.cpp b/test/test_stack.cpp index 4810c410..74a1a164 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -102,6 +102,21 @@ namespace } } + //************************************************************************* + TEST(test_delete_via_istack) + { + etl::stack* pstack = new etl::stack; + + etl::istack* pistack = pstack; + + pistack->push(1); + pistack->push(2); + pistack->push(3); + pistack->push(4); + + delete pistack; + } + //************************************************************************* TEST(test_empty) { diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 36de8899..470fbecd 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -231,6 +231,17 @@ namespace CHECK(data.full()); } + //************************************************************************* + TEST(test_destruct_via_iunordered_map) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 1d72fde8..d04dc25f 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -208,6 +208,17 @@ namespace CHECK(data.full()); } + //************************************************************************* + TEST(test_destruct_via_iunordered_multimap) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 05a084a5..0fddfcee 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -142,6 +142,17 @@ namespace CHECK(data.full()); } + //************************************************************************* + TEST(test_destruct_via_iunordered_multiset) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 0bd1d20f..e658451c 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -134,6 +134,17 @@ namespace CHECK(data.full()); } + //************************************************************************* + TEST(test_destruct_via_iunordered_set) + { + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(initial_data.begin(), initial_data.end()); + + IDataNDC* pidata = pdata; + delete pidata; + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assignment) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 6d0c4c15..c7c00a8b 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -36,7 +36,7 @@ #include "data.h" namespace -{ +{ SUITE(test_vector_non_trivial) { static const size_t SIZE = 10; @@ -44,6 +44,8 @@ namespace typedef TestDataNDC NDC; typedef TestDataDC DC; + static NDC ndc("NDC"); + typedef etl::vector DataNDC; typedef etl::ivector IDataNDC; typedef std::vector CompareDataNDC; @@ -51,7 +53,7 @@ namespace typedef etl::vector DataDC; typedef etl::ivector IDataDC; typedef std::vector CompareDataDC; - + CompareDataNDC initial_data; CompareDataNDC less_data; CompareDataNDC greater_data; @@ -89,6 +91,22 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_destruct_via_ivector) + { + const size_t INITIAL_SIZE = 5; + const NDC INITIAL_VALUE("1"); + + int current_count = NDC::get_instance_count(); + + DataNDC* pdata = new DataNDC(INITIAL_SIZE, INITIAL_VALUE); + CHECK_EQUAL(int(current_count + INITIAL_SIZE), NDC::get_instance_count()); + + IDataNDC* pidata = pdata; + delete pidata; + CHECK_EQUAL(current_count, NDC::get_instance_count()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { @@ -152,7 +170,7 @@ namespace DataNDC data(initial_data.begin(), initial_data.end()); DataNDC data2(data); CHECK(data2 == data); - + data2[2] = NDC("X"); CHECK(data2 != data); } @@ -400,7 +418,7 @@ namespace CHECK(data.back() == compare_data.back()); } - + //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { @@ -676,7 +694,7 @@ namespace const size_t INITIAL_SIZE = 5; const size_t INSERT_SIZE = 3; const NDC INITIAL_VALUE("1"); - + for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { CompareDataNDC compare_data; @@ -770,7 +788,7 @@ namespace offset = 4; CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); - + offset = data.size(); CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); @@ -813,7 +831,7 @@ namespace CHECK(is_equal); } - + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) {