test_vector.cpp
Go to the documentation of this file.
1 //
2 // Bareflank Hypervisor
3 //
4 // Copyright (C) 2015 Assured Information Security, Inc.
5 // Author: Rian Quinn <quinnr@ainfosec.com>
6 // Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Lesser General Public
10 // License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 #include <test.h>
23 #include <vector>
24 
25 void
26 misc_ut::test_vector_find()
27 {
28  std::vector<int> list = {1, 2, 3};
29 
30  this->expect_exception([&] { bfn::find(list, -1); }, ""_ut_ffe);
31  this->expect_exception([&] { bfn::find(list, 10); }, ""_ut_ffe);
32  this->expect_true(*bfn::find(list, 1) == 2);
33 }
34 
35 void
36 misc_ut::test_vector_cfind()
37 {
38  std::vector<int> list = {1, 2, 3};
39 
40  this->expect_exception([&] { bfn::cfind(list, -1); }, ""_ut_ffe);
41  this->expect_exception([&] { bfn::cfind(list, 10); }, ""_ut_ffe);
42  this->expect_true(*bfn::cfind(list, 1) == 2);
43 }
44 
45 void
46 misc_ut::test_vector_take()
47 {
48  std::vector<int> list = {1, 2, 3};
49 
50  this->expect_exception([&] { bfn::take(list, -1); }, ""_ut_ffe);
51  this->expect_exception([&] { bfn::take(list, 10); }, ""_ut_ffe);
52  this->expect_true(bfn::take(list, 1) == 2);
53  this->expect_true(list.size() == 2);
54 }
55 
56 void
57 misc_ut::test_vector_remove()
58 {
59  std::vector<int> list = {1, 2, 3};
60 
61  this->expect_exception([&] { bfn::remove(list, -1); }, ""_ut_ffe);
62  this->expect_exception([&] { bfn::remove(list, 10); }, ""_ut_ffe);
63  this->expect_no_exception([&] { bfn::remove(list, 1); });
64  this->expect_true(list.size() == 2);
65 }
#define expect_exception(f, e)
Definition: unittest.h:162
#define expect_no_exception(f)
Definition: unittest.h:198
bool list() override
Definition: test.cpp:41
#define expect_true(a)