Commit 0ad8b194 authored by Olivier Gregoire's avatar Olivier Gregoire Committed by Olivier SOLDANO

test: add map_utils unit-tests

[GR: adapt for coding-rules]
[GR: adapt for map_utils.h refactoring]
Change-Id: Iaaae9a9e815321ade4dd7fc464a7d7be0c2d5fb1
Reviewed-by: default avatarOlivier Soldano <olivier.soldano@savoirfairelinux.com>
parent 482c6bb9
......@@ -19,6 +19,12 @@ ut_account_factory_SOURCES = account_factory/testAccount_factory.cpp
check_PROGRAMS += ut_base64
ut_base64_SOURCES = base64/base64.cpp
#
# map_utils
#
check_PROGRAMS += ut_map_utils
ut_map_utils_SOURCES = map_utils/testMap_utils.cpp
#
# smartools
#
......
/*
* Copyright (C) 2017 Savoir-Faire Linux Inc.
* Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include "map_utils.h"
#include <vector>
#include <map>
#include <string>
#include "../../test_runner.h"
namespace ring { namespace map_utils { namespace test {
class MapUtilsTest : public CppUnit::TestFixture {
public:
static std::string name() { return "map_utils"; }
void setUp();
private:
void test_extractKeys();
void test_extractValues();
CPPUNIT_TEST_SUITE(MapUtilsTest);
CPPUNIT_TEST(test_extractKeys);
CPPUNIT_TEST(test_extractValues);
CPPUNIT_TEST_SUITE_END();
const int NUMBERMAPVALUE = 5;
std::map<int, std::string> m;
};
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(MapUtilsTest, MapUtilsTest::name());
void
MapUtilsTest::setUp()
{
for (int i = 0; i < NUMBERMAPVALUE; i++) {
std::string string_i = std::to_string(i);
m[i] = "value " + string_i;
}
}
void
MapUtilsTest::test_extractKeys()
{
auto result = extractKeys(m);
CPPUNIT_ASSERT(result.size() == m.size());
int i = 0;
for (auto& key : result) {
CPPUNIT_ASSERT(key == i);
++i;
}
}
void
MapUtilsTest::test_extractValues()
{
auto result = extractValues(m);
CPPUNIT_ASSERT(result.size() == m.size());
int i = 0;
for (auto& value : result) {
CPPUNIT_ASSERT(value.compare("value " + std::to_string(i)) == 0);
++i;
}
}
}}} // namespace ring::map_utils::test
RING_TEST_RUNNER(ring::map_utils::test::MapUtilsTest::name());
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment