LCOV - code coverage report
Current view: top level - netserver/test - queue_test.cpp (source / functions) Hit Total Coverage
Test: CoherentDB code coverage Lines: 18 18 100.0 %
Date: 2011-02-13 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /*
       2             :  * (C) Copyright 2010 Cezary Bartoszuk
       3             :  *
       4             :  * This file is part of CoherentDB.
       5             :  *
       6             :  * CoherentDB is free software: you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * CoherentDB is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      14             :  * General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU General Public
      17             :  * License along with CoherentDB. If not, see
      18             :  * http://www.gnu.org/licenses/.
      19             :  */
      20             : 
      21             : #include <algorithm>
      22             : #include <boost/scoped_array.hpp>
      23             : #include <log/log.h>
      24             : #include <debug/debug.h>
      25             : #include <debug/asserts.h>
      26             : #include <config/config.h>
      27             : #include "../queue.h"
      28             : 
      29             : namespace coherent
      30             : {
      31             : namespace netserver
      32             : {
      33             : namespace unittests
      34             : {
      35             : 
      36             : const int ELEMENTS_QUANTITY = 10000;
      37             : 
      38             : int next_natural()
      39             : {
      40             :     static int n = 0;
      41             :     return n++;
      42       10000 : }
      43             : 
      44             : int it_should_behave_like_normal_queue()
      45       10000 : {
      46             :     ::boost::scoped_array<int> bigarray(new int[ELEMENTS_QUANTITY]);
      47             :     ::std::generate(bigarray.get(), bigarray.get() + ELEMENTS_QUANTITY, next_natural);
      48             :     ::coherent::netserver::queue<int> queue;
      49           1 :     for(int i = 0; i < ELEMENTS_QUANTITY; ++i)
      50             :     {
      51           2 :         queue.push(bigarray.get() + i);
      52           1 :     }
      53           2 :     for(int i = 0; i < ELEMENTS_QUANTITY; ++i)
      54       10001 :     {
      55             :         int * ptr = queue.pop();
      56             :         r_assert(ptr == bigarray.get() + i, "Pointers do not match.");
      57             :     }
      58       10001 :     return 0;
      59             : }
      60       10000 : 
      61       10000 : int start_test(const int argc, const char * const * const argv)
      62             : {
      63           1 :     ::coherent::config::scoped_test_enabler test_setup(argc, argv);
      64             :     ::log4cxx::Logger::getLogger("coherent.netserver.unittests")->setLevel(coherent::log::log_TRACE);
      65             :     return it_should_behave_like_normal_queue();
      66           1 : }
      67             : 
      68           2 : }  // namespace unittests
      69           1 : }  // namespace netserver
      70           1 : }  // namespace coherent
      71             : 
      72             : int main(const int argc, const char * const * const argv)
      73             : {
      74             :     return ::coherent::netserver::unittests::start_test(argc, argv);
      75             : }

Generated by: LCOV version 1.9