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-11-15 09:04:49 Functions: 8 8 100.0 %

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

Generated by: LCOV version 1.14