LCOV - code coverage report
Current view: top level - tests - catch_cache.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.8 % 24 23
Test Date: 2026-10-09 15:00:44 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : // Copyright (c) 2026  Made to Order Software Corp.  All Rights Reserved
       2              : //
       3              : // https://snapwebsites.org/project/magpie
       4              : // contact@m2osw.com
       5              : //
       6              : // This program is free software: you can redistribute it and/or modify
       7              : // it 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              : // This program 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
      14              : // GNU General Public License for more details.
      15              : //
      16              : // You should have received a copy of the GNU General Public License
      17              : // along with this program.  If not, see <https://www.gnu.org/licenses/>.
      18              : 
      19              : // self
      20              : //
      21              : #include    "catch_main.h"
      22              : 
      23              : 
      24              : // magpie
      25              : //
      26              : #include    <magpie/cache.h>
      27              : 
      28              : #include    <magpie/exception.h>
      29              : 
      30              : 
      31              : // last include
      32              : //
      33              : #include    <snapdev/poison.h>
      34              : 
      35              : 
      36              : 
      37            1 : CATCH_TEST_CASE("cache", "[cache]")
      38              : {
      39            1 :     CATCH_START_SECTION("cache: basic cache with keys & values as int (construct, add 3 values, get 3 values, destruct)")
      40              :     {
      41            1 :         magpie::options opts;
      42              : 
      43              :         // construct
      44              :         //
      45            1 :         magpie::cache<int, int> cache(opts);
      46              : 
      47              :         // set a few values
      48              :         //
      49            1 :         int k1(rand());
      50            1 :         int v1(rand());
      51            1 :         cache.set(k1, v1);
      52              : 
      53            1 :         int k2(rand());
      54            1 :         int v2(rand());
      55            1 :         cache.set(k2, v2);
      56              : 
      57            1 :         int k3(rand());
      58            1 :         int v3(rand());
      59            1 :         cache.set(k3, v3);
      60              : 
      61              :         // verify the values
      62              :         //
      63            1 :         CATCH_REQUIRE(cache.get(k1) == v1);
      64            1 :         CATCH_REQUIRE(cache.get(k2) == v2);
      65            1 :         CATCH_REQUIRE(cache.get(k3) == v3);
      66              : 
      67              :         // make sure a key that's not set returns a null
      68              :         //
      69            1 :         int k4(rand());
      70            1 :         while(k4 == k1 || k4 == k2 || k4 == k3)
      71              :         {
      72            0 :             k4 = rand();
      73              :         }
      74            1 :         std::optional<int> v(cache.get(k4));
      75            1 :         CATCH_REQUIRE_FALSE(v.has_value());
      76              : 
      77              :         // done, everything gets destroyed
      78            1 :     }
      79            1 :     CATCH_END_SECTION()
      80            1 : }
      81              : 
      82              : 
      83              : //CATCH_TEST_CASE("options_error", "[options][error]")
      84              : //{
      85              : //    CATCH_START_SECTION("options_error: verify that the TTL cannot be a negative number")
      86              : //    {
      87              : //        magpie::options opts;
      88              : //
      89              : //        for(magpie::duration_t duration(-2); duration > -100; --duration)
      90              : //        {
      91              : //            CATCH_REQUIRE_THROWS_MATCHES(
      92              : //                      opts.set_default_ttl(duration)
      93              : //                    , magpie::out_of_range
      94              : //                    , Catch::Matchers::ExceptionMessage(
      95              : //                              "out_of_range: options::set_default_ttl(): ttl must be a positive number, magpie::NO_TTL, or magpie::DEFAULT_TTL."));
      96              : //        }
      97              : //    }
      98              : //    CATCH_END_SECTION()
      99              : //}
     100              : 
     101              : 
     102              : // vim: ts=4 sw=4 et
        

Generated by: LCOV version 2.0-1

Snap C++ | List of projects | List of versions