Add some tests for EnumIndexedVector.
authorCarl Hetherington <cth@carlh.net>
Sun, 6 Nov 2022 20:50:34 +0000 (21:50 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 22 Dec 2022 23:12:00 +0000 (00:12 +0100)
test/enum_indexed_vector_test.cc [new file with mode: 0644]
test/wscript

diff --git a/test/enum_indexed_vector_test.cc b/test/enum_indexed_vector_test.cc
new file mode 100644 (file)
index 0000000..d3f8380
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+    Copyright (C) 2022 Carl Hetherington <cth@carlh.net>
+
+    This file is part of DCP-o-matic.
+
+    DCP-o-matic is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    DCP-o-matic is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "lib/enum_indexed_vector.h"
+#include "test.h"
+#include <boost/test/unit_test.hpp>
+
+
+BOOST_AUTO_TEST_CASE(enum_indexed_vector_referencing_test)
+{
+       enum class Foo {
+               ONE,
+               TWO,
+               THREE,
+               COUNT
+       };
+
+       EnumIndexedVector<int, Foo> vector;
+       vector[Foo::ONE] = 1;
+       vector[Foo::TWO] = 2;
+       vector[Foo::THREE] = 3;
+
+       for (auto i: vector) {
+               ++i;
+       }
+
+       BOOST_CHECK_EQUAL(vector[Foo::ONE], 1);
+       BOOST_CHECK_EQUAL(vector[Foo::TWO], 2);
+       BOOST_CHECK_EQUAL(vector[Foo::THREE], 3);
+
+       for (auto& i: vector) {
+               ++i;
+       }
+
+       BOOST_CHECK_EQUAL(vector[Foo::ONE], 2);
+       BOOST_CHECK_EQUAL(vector[Foo::TWO], 3);
+       BOOST_CHECK_EQUAL(vector[Foo::THREE], 4);
+}
+
+
+BOOST_AUTO_TEST_CASE(enum_indexed_vector_indices_test)
+{
+       enum class Foo {
+               ONE,
+               TWO,
+               THREE,
+               COUNT
+       };
+
+       EnumIndexedVector<int, Foo> vector;
+
+       auto const ref = std::vector<Foo>{Foo::ONE, Foo::TWO, Foo::THREE};
+       BOOST_CHECK(vector.indices() == ref);
+
+       // Make sure nothing funny happens on the second call to indices
+       BOOST_CHECK(vector.indices() == ref);
+}
index e54d5c9852da268687ab52837ace35bdd909ffd8..c31a37a764348e13420a020118fbbe11ee06bcd4 100644 (file)
@@ -76,6 +76,7 @@ def build(bld):
                  empty_caption_test.cc
                  empty_test.cc
                  encryption_test.cc
+                 enum_indexed_vector_test.cc
                  file_extension_test.cc
                  ffmpeg_audio_only_test.cc
                  ffmpeg_audio_test.cc