1
0
mirror of https://github.com/codership/wsrep-lib.git synced 2025-07-24 10:42:31 +03:00
Files
wsrep-lib/test/view_test.cpp
Teemu Ollakka 36dbb37645 codership/wsrep-lib#35 Rewrote member_index() to use iterators
Use iterators for scanning members vector in order to avoid
issues with integer signedness and range checks. The vector is
usually rather small and not in hot codepath, so performance
is here not an issue.

Added unit test for member_index() method.
2018-12-15 13:46:42 +00:00

42 lines
1.5 KiB
C++

/*
* Copyright (C) 2018 Codership Oy <info@codership.com>
*
* This file is part of wsrep-lib.
*
* Wsrep-lib 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.
*
* Wsrep-lib 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 wsrep-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#include "wsrep/view.hpp"
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(view_test_member_index)
{
std::vector<wsrep::view::member> members;
members.push_back(wsrep::view::member(wsrep::id("1"), "", ""));
members.push_back(wsrep::view::member(wsrep::id("2"), "", ""));
members.push_back(wsrep::view::member(wsrep::id("3"), "", ""));
wsrep::view view(wsrep::gtid(wsrep::id("cluster"), wsrep::seqno(1)),
wsrep::seqno(1),
wsrep::view::primary,
0,
1,
0,
members);
BOOST_REQUIRE(view.member_index(wsrep::id("1")) == 0);
BOOST_REQUIRE(view.member_index(wsrep::id("2")) == 1);
BOOST_REQUIRE(view.member_index(wsrep::id("3")) == 2);
BOOST_REQUIRE(view.member_index(wsrep::id("4")) == -1);
}