LCOV - code coverage report
Current view: top level - test/unitTest/map_utils - testMap_utils.cpp (source / functions) Hit Total Coverage
Test: jami-coverage-filtered.info Lines: 28 28 100.0 %
Date: 2024-04-26 09:41:19 Functions: 8 8 100.0 %

          Line data    Source code
       1             : /*
       2             :  *  Copyright (C) 2004-2024 Savoir-faire Linux Inc.
       3             :  *  Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com>
       4             :  *
       5             :  *  This program is free software; you can redistribute it and/or modify
       6             :  *  it under the terms of the GNU General Public License as published by
       7             :  *  the Free Software Foundation; either version 3 of the License, or
       8             :  *  (at your option) any later version.
       9             :  *
      10             :  *  This program is distributed in the hope that it will be useful,
      11             :  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :  *  GNU General Public License for more details.
      14             :  *
      15             :  *  You should have received a copy of the GNU General Public License
      16             :  *  along with this program; if not, write to the Free Software
      17             :  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
      18             :  */
      19             : 
      20             : #include <cppunit/TestAssert.h>
      21             : #include <cppunit/TestFixture.h>
      22             : #include <cppunit/extensions/HelperMacros.h>
      23             : 
      24             : #include "map_utils.h"
      25             : 
      26             : #include <vector>
      27             : #include <map>
      28             : #include <string>
      29             : 
      30             : #include "../../test_runner.h"
      31             : 
      32             : namespace jami { namespace map_utils { namespace test {
      33             : 
      34             : class MapUtilsTest : public CppUnit::TestFixture {
      35             : public:
      36           2 :     static std::string name() { return "map_utils"; }
      37             : 
      38             :     void setUp();
      39             : 
      40             : private:
      41             :     void test_extractKeys();
      42             :     void test_extractValues();
      43             : 
      44           2 :     CPPUNIT_TEST_SUITE(MapUtilsTest);
      45           1 :     CPPUNIT_TEST(test_extractKeys);
      46           1 :     CPPUNIT_TEST(test_extractValues);
      47           4 :     CPPUNIT_TEST_SUITE_END();
      48             : 
      49             :     const int NUMBERMAPVALUE = 5;
      50             :     std::map<int, std::string> m;
      51             : };
      52             : 
      53             : CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MapUtilsTest, MapUtilsTest::name());
      54             : 
      55             : void
      56           2 : MapUtilsTest::setUp()
      57             : {
      58          12 :     for (int i = 0; i < NUMBERMAPVALUE; i++) {
      59          10 :         std::string string_i = std::to_string(i);
      60          10 :         m[i] = "value " + string_i;
      61          10 :     }
      62           2 : }
      63             : 
      64             : void
      65           1 : MapUtilsTest::test_extractKeys()
      66             : {
      67           1 :     auto result = extractKeys(m);
      68             : 
      69           1 :     CPPUNIT_ASSERT(result.size() == m.size());
      70             : 
      71           1 :     int i = 0;
      72           6 :     for (auto& key : result) {
      73           5 :         CPPUNIT_ASSERT(key == i);
      74           5 :         ++i;
      75             :     }
      76           1 : }
      77             : 
      78             : void
      79           1 : MapUtilsTest::test_extractValues()
      80             : {
      81           1 :     auto result = extractValues(m);
      82             : 
      83           1 :     CPPUNIT_ASSERT(result.size() == m.size());
      84             : 
      85           1 :     int i = 0;
      86           6 :     for (auto& value : result) {
      87           5 :         CPPUNIT_ASSERT(value.compare("value " + std::to_string(i)) == 0);
      88           5 :         ++i;
      89             :     }
      90           1 : }
      91             : 
      92             : }}} // namespace jami::map_utils::test
      93             : 
      94           1 : RING_TEST_RUNNER(jami::map_utils::test::MapUtilsTest::name());

Generated by: LCOV version 1.14