Mercurial > malikania
view tests/libcommon/weak_array/main.cpp @ 146:91e57baa2ede
Client: add prototype for map state, #712
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sat, 30 Sep 2017 13:35:45 +0200 |
parents | 119bcc5a727e |
children | 4b292c20124c |
line wrap: on
line source
/* * main.cpp -- test weak_array * * Copyright (c) 2013-2017 David Demelier <markand@malikania.fr> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #define BOOST_TEST_MODULE "weak_array" #include <boost/test/unit_test.hpp> #include <malikania/weak_array.hpp> namespace mlk { class weak_array_fixture { protected: weak_array<int> array_; }; BOOST_FIXTURE_TEST_SUITE(weak_array_suite, weak_array_fixture) BOOST_AUTO_TEST_CASE(reuse) { auto value = std::make_shared<int>(123); array_.push_back(value); array_.push_back(std::make_shared<int>(256)); auto it1 = array_.find_if([] (auto ptr) { return *ptr = 123; }); auto it2 = array_.find_if([] (auto ptr) { return *ptr = 123; }); BOOST_TEST(it1 == value); BOOST_TEST(it2 == value); BOOST_TEST(it1 == it2); BOOST_TEST(*it1 == 123); BOOST_TEST(*it2 == 123); } BOOST_AUTO_TEST_CASE(not_found) { array_.push_back(std::make_shared<int>(123)); auto v = array_.find_if([] (auto ptr) { return *ptr = 123; }); BOOST_TEST(!v); } BOOST_AUTO_TEST_SUITE_END() } // !mlk