From 482c6bb9d56933424b739a574126efd31818256c Mon Sep 17 00:00:00 2001 From: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com> Date: Fri, 18 Aug 2017 17:06:54 +0200 Subject: [PATCH] test: add utf8_utils unit-tests [GR: adapted for coding-rules] Change-Id: I531d1c742704ed9b577aa09131200a1a66be83be Reviewed-by: Olivier Soldano <olivier.soldano@savoirfairelinux.com> --- test/unitTest/Makefile.am | 6 ++ test/unitTest/utf8_utils/testUtf8_utils.cpp | 71 +++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/unitTest/utf8_utils/testUtf8_utils.cpp diff --git a/test/unitTest/Makefile.am b/test/unitTest/Makefile.am index 2a956563e0..13a41022ee 100644 --- a/test/unitTest/Makefile.am +++ b/test/unitTest/Makefile.am @@ -25,6 +25,12 @@ ut_base64_SOURCES = base64/base64.cpp check_PROGRAMS += ut_smartools ut_smartools_SOURCES = smartools/testSmartools.cpp +# +# utf8_utils +# +check_PROGRAMS += ut_utf8_utils +ut_utf8_utils_SOURCES = utf8_utils/testUtf8_utils.cpp + # # video_input # diff --git a/test/unitTest/utf8_utils/testUtf8_utils.cpp b/test/unitTest/utf8_utils/testUtf8_utils.cpp new file mode 100644 index 0000000000..baa4744989 --- /dev/null +++ b/test/unitTest/utf8_utils/testUtf8_utils.cpp @@ -0,0 +1,71 @@ +/* + * 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 <string> + +#include "utf8_utils.h" +#include "../../test_runner.h" + + +namespace ring { namespace test { + +class Utf8UtilsTest : public CppUnit::TestFixture { +public: + static std::string name() { return "utf8_utils"; } + +private: + void utf8_validate_test(); + void utf8_make_valid_test(); + + CPPUNIT_TEST_SUITE(Utf8UtilsTest); + CPPUNIT_TEST(utf8_validate_test); + CPPUNIT_TEST(utf8_make_valid_test); + CPPUNIT_TEST_SUITE_END(); + + const std::string VALIDE_UTF8 = "çèềé{}()/\\*"; + const std::string INVALID_UTF8 = "\xc3\x28"; +}; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Utf8UtilsTest, Utf8UtilsTest::name()); + +void +Utf8UtilsTest::utf8_validate_test() +{ + CPPUNIT_ASSERT(!utf8_validate(INVALID_UTF8)); + CPPUNIT_ASSERT(utf8_validate(VALIDE_UTF8)); +} + +void +Utf8UtilsTest::utf8_make_valid_test() +{ + // valide utf8 string in input + CPPUNIT_ASSERT(utf8_make_valid(VALIDE_UTF8).compare(VALIDE_UTF8) == 0); + + // invalid utf8 string in input + std::string str = utf8_make_valid(INVALID_UTF8); + CPPUNIT_ASSERT(utf8_validate(str)); +} + +}} // namespace ring::test + +RING_TEST_RUNNER(ring::test::Utf8UtilsTest::name()); -- GitLab