root/examples/cache.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. BOOST_AUTO_TEST_SUITE
  2. BOOST_AUTO_TEST_CASE_TEMPLATE
  3. BOOST_AUTO_TEST_CASE_TEMPLATE
  4. BOOST_AUTO_TEST_CASE_TEMPLATE
  5. BOOST_AUTO_TEST_CASE_TEMPLATE
  6. BOOST_AUTO_TEST_CASE_TEMPLATE
  7. BOOST_AUTO_TEST_CASE_TEMPLATE
  8. BOOST_AUTO_TEST_CASE_TEMPLATE

   1 /******************************************************************************
   2 ** $Header: svn+ssh://jmmcg@svn.code.sf.net/p/libjmmcg/code/trunk/libjmmcg/examples/cache.cpp 2353 2018-10-21 20:22:18Z jmmcg $
   3 **
   4 ** Copyright (C) 2002 by J.M.a_cacheGuiness, coder@hussar.me.uk
   5 **
   6 ** This library is free software; you can redistribute it and/or
   7 ** modify it under the terms of the GNU Lesser General Public
   8 ** License as published by the Free Software Foundation; either
   9 ** version 2.1 of the License, or (at your option) any later version.
  10 **
  11 ** This library is distributed in the hope that it will be useful,
  12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14 ** Lesser General Public License for more details.
  15 **
  16 ** You should have received a copy of the GNU Lesser General Public
  17 ** License along with this library; if not, write to the Free Software
  18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19 */
  20 
  21 #include "stdafx.h"
  22 
  23 #define BOOST_TEST_MODULE libjmmcg_tests
  24 #include <boost/test/included/unit_test.hpp>
  25 #include <boost/test/test_case_template.hpp>
  26 #include <boost/mpl/list.hpp>
  27 
  28 #include "core/cache.hpp"
  29 
  30 struct my_factory final : public jmmcg::cache::factory_base<int,int> {
  31         inline value_type __fastcall make(const key_type &i) const {
  32                 return i<<2;
  33         }
  34 };
  35 
  36 typedef boost::mpl::list<
  37         jmmcg::cache::ro<my_factory>,
  38         jmmcg::cache::ro<my_factory, jmmcg::cache::lru<my_factory::value_type>, jmmcg::cache::threading<my_factory::key_type, jmmcg::cache::lru<my_factory::value_type> >::multi<jmmcg::ppd::platform_api, jmmcg::ppd::sequential_mode>, jmmcg::cache::basic_statistics>,
  39         jmmcg::cache::ro<my_factory, jmmcg::cache::lru<my_factory::value_type>, jmmcg::cache::threading<my_factory::key_type, jmmcg::cache::lru<my_factory::value_type> >::multi<jmmcg::ppd::platform_api, jmmcg::ppd::heavyweight_threading>, jmmcg::cache::basic_statistics>
  40 > test_types;
  41 
  42 BOOST_AUTO_TEST_SUITE(cache_tests)
  43 
  44 BOOST_AUTO_TEST_CASE_TEMPLATE(ctor, T, test_types) {
  45         typedef T cache_t;
  46 
  47         cache_t cache(2,4,2,my_factory());
  48         BOOST_CHECK_EQUAL(cache.empty(), true);
  49         BOOST_CHECK_EQUAL(cache.size(), 0U);
  50 }
  51 
  52 BOOST_AUTO_TEST_CASE_TEMPLATE(clear_empty, T, test_types) {
  53         typedef T cache_t;
  54 
  55         cache_t cache(2,4,2,my_factory());
  56         cache.clear();
  57         BOOST_CHECK_EQUAL(cache.empty(), true);
  58         BOOST_CHECK_EQUAL(cache.size(), 0U);
  59 }
  60 
  61 BOOST_AUTO_TEST_CASE_TEMPLATE(flush_empty, T, test_types) {
  62         typedef T cache_t;
  63 
  64         cache_t cache(2,4,2,my_factory());
  65         cache.flush();
  66         BOOST_CHECK_EQUAL(cache.empty(), true);
  67         BOOST_CHECK_EQUAL(cache.size(), 0U);
  68 }
  69 
  70 BOOST_AUTO_TEST_CASE_TEMPLATE(create_one_item, T, test_types) {
  71         typedef T cache_t;
  72 
  73         cache_t cache(2,4,2,my_factory());
  74         BOOST_CHECK_EQUAL(cache[1].value(), 4);
  75         BOOST_CHECK_EQUAL(cache.empty(), false);
  76         BOOST_CHECK_EQUAL(cache.size(), 1U);
  77 }
  78 
  79 BOOST_AUTO_TEST_CASE_TEMPLATE(create_two_items, T, test_types) {
  80         typedef T cache_t;
  81 
  82         cache_t cache(2,4,2,my_factory());
  83         BOOST_CHECK_EQUAL(cache[1].value(), 4);
  84         BOOST_CHECK_EQUAL(cache[2].value(), 8);
  85         BOOST_CHECK_EQUAL(cache.empty(), false);
  86         BOOST_CHECK_EQUAL(cache.size(), 2U);
  87 }
  88 
  89 BOOST_AUTO_TEST_CASE_TEMPLATE(flush_small, T, test_types) {
  90         typedef T cache_t;
  91 
  92         cache_t cache(2,4,2,my_factory());
  93         cache[1].value();
  94         cache[2].value();
  95         cache[3].value();
  96         cache.flush();
  97         BOOST_CHECK_EQUAL(cache.empty(), false);
  98         BOOST_CHECK_EQUAL(cache.size(), 3U);
  99 }
 100 
 101 BOOST_AUTO_TEST_CASE_TEMPLATE(flush_full, T, test_types) {
 102         typedef T cache_t;
 103 
 104         cache_t cache(2,4,2,my_factory());
 105         cache[1].value();
 106         cache[2].value();
 107         cache[3].value();
 108         cache[4].value();
 109         cache[5].value();
 110         cache.flush();
 111         BOOST_CHECK_EQUAL(cache.empty(), false);
 112         BOOST_CHECK_EQUAL(cache.size(), 2U);
 113 }
 114 
 115 BOOST_AUTO_TEST_CASE_TEMPLATE(clear_small, T, test_types) {
 116         typedef T cache_t;
 117 
 118         cache_t cache(2,4,2,my_factory());
 119         cache[1].value();
 120         cache[2].value();
 121         cache.clear();
 122         BOOST_CHECK_EQUAL(cache.empty(), true);
 123         BOOST_CHECK_EQUAL(cache.size(), 0U);
 124 }
 125 
 126 BOOST_AUTO_TEST_SUITE_END()

/* [<][>][^][v][top][bottom][index][help] */