Files
odfstudio/basic/qa/cppunit/test_util.cxx
T
Neil Roberts af830cc577 Move searchEOL from basicide to a general basic utility
Moves the searchEOL function from basicide to a general purpose utility
function in the basic module. This also adds some unit tests for it.

Change-Id: I8f446990654415a994b7964dd62706f3204d817a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/207060
Tested-by: Jenkins
Reviewed-by: Neil Roberts <nroberts@libreoffice.org>
2026-07-22 15:58:49 +02:00

59 lines
1.8 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <basic/sbutil.hxx>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
#include <cppunit/TestFixture.h>
namespace
{
class TestUtil : public CppUnit::TestFixture
{
private:
void testSearchEOL();
CPPUNIT_TEST_SUITE(TestUtil);
CPPUNIT_TEST(testSearchEOL);
CPPUNIT_TEST_SUITE_END();
};
void TestUtil::testSearchEOL()
{
// Find the ending when \n is the first one
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), sb::searchEOL(u"one\ntwo\r\three\r\n"));
// Find the ending when \r\n is the first one
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), sb::searchEOL(u"one\r\ntwo\r\three\n"));
// The three types of ending at at the end of the string
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), sb::searchEOL(u"one\n"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), sb::searchEOL(u"one\r"));
CPPUNIT_ASSERT_EQUAL(sal_Int32(4), sb::searchEOL(u"one\r\n"));
// No ending
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), sb::searchEOL(u""));
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1), sb::searchEOL(u"unending string"));
// Skip an ending
CPPUNIT_ASSERT_EQUAL(sal_Int32(7), sb::searchEOL(u"one\ntwo\n", 4));
// Start at an ending
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), sb::searchEOL(u"one\ntwo\n", 3));
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(TestUtil);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */