1 // { dg-require-profile-mode "" }
5 // Unit tests for profile/impl/profile_algos.h.
7 // Copyright (C) 2010, 2011 Free Software Foundation, Inc.
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 3, or (at your option)
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING3. If not see
22 // <http://www.gnu.org/licenses/>.
25 #include <profile/impl/profiler.h>
27 using std::_GLIBCXX_STD_C::vector;
35 INSERT_IN_THE_MIDDLE = 0x8,
47 for (int i = 0; i < 10; i++)
50 // Inserting -5 should have no effect if size is limited to 10.
51 __gnu_profile::__insert_top_n(v, -5, 10);
52 for (int i = 0; i < 10; i++)
54 return INSERT_AFTER_N;
57 __gnu_profile::__insert_top_n(v, 11, 10);
58 for (int i = 0; i < 11; i++)
60 return INSERT_AT_HEAD;
63 __gnu_profile::__insert_top_n(v, 0, 100);
64 for (int i = 0; i < 12; i++)
66 return INSERT_AT_TAIL;
68 // Insert in the middle.
69 __gnu_profile::__insert_top_n(v, 6, 11);
70 for (int i = 0; i < 6; i++)
72 return INSERT_IN_THE_MIDDLE;
73 for (int i = 6; i < 13; i++)
75 return INSERT_IN_THE_MIDDLE;
85 for (int i = 0; i < 100; i++)
91 __gnu_profile::__top_n(v, out, 10);
93 for (int i = 0; i < 10; i++)
94 if (out[i] != 199 - i)
100 struct test_for_each_helper
103 void operator ()(int i) {
108 int test_for_each_helper::sum = 0;
114 test_for_each_helper helper;
117 for (int i = 0; i < 10; i++)
123 __gnu_profile::__for_each(v.begin(), v.end(), helper);
125 return helper.sum == checksum ? NO_FAILURES : FOR_EACH;
133 for (int i = 0; i < 10; i++)
136 for (int i = 0; i < 10; i++)
140 return __gnu_profile::__remove(v.begin(), v.end(), ' ') == v.begin() + 2
141 ? NO_FAILURES : REMOVE;
146 return test_insert_top_n() | test_top_n() | test_for_each() | test_remove();