From: Carl Hetherington Date: Sun, 6 Nov 2022 20:50:34 +0000 (+0100) Subject: Add some tests for EnumIndexedVector. X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=81eda546d9defa3b58516acfb689060f61dff044 Add some tests for EnumIndexedVector. --- diff --git a/test/enum_indexed_vector_test.cc b/test/enum_indexed_vector_test.cc new file mode 100644 index 000000000..d3f83805e --- /dev/null +++ b/test/enum_indexed_vector_test.cc @@ -0,0 +1,75 @@ +/* + Copyright (C) 2022 Carl Hetherington + + 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 . + +*/ + + +#include "lib/enum_indexed_vector.h" +#include "test.h" +#include + + +BOOST_AUTO_TEST_CASE(enum_indexed_vector_referencing_test) +{ + enum class Foo { + ONE, + TWO, + THREE, + COUNT + }; + + EnumIndexedVector 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 vector; + + auto const ref = std::vector{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); +} diff --git a/test/wscript b/test/wscript index e54d5c985..c31a37a76 100644 --- a/test/wscript +++ b/test/wscript @@ -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