diff options
-rw-r--r-- | sal/CppunitTest_sal_osl.mk | 1 | ||||
-rw-r--r-- | sal/osl/unx/socket.cxx | 5 | ||||
-rw-r--r-- | sal/qa/osl/socket.cxx | 40 |
3 files changed, 45 insertions, 1 deletions
diff --git a/sal/CppunitTest_sal_osl.mk b/sal/CppunitTest_sal_osl.mk index b5e1b0658324..392da456459c 100644 --- a/sal/CppunitTest_sal_osl.mk +++ b/sal/CppunitTest_sal_osl.mk @@ -23,6 +23,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,sal_osl,\ sal/qa/osl/process/osl_Thread \ sal/qa/osl/profile/osl_old_testprofile \ sal/qa/osl/setthreadname/test-setthreadname \ + sal/qa/osl/socket \ )) $(eval $(call gb_CppunitTest_use_libraries,sal_osl,\ diff --git a/sal/osl/unx/socket.cxx b/sal/osl/unx/socket.cxx index 376d6f1412ce..c78e43a9de93 100644 --- a/sal/osl/unx/socket.cxx +++ b/sal/osl/unx/socket.cxx @@ -1092,7 +1092,10 @@ oslSocketResult SAL_CALL osl_getDottedInetAddrOfSocketAddr(oslSocketAddr Addr, r return osl_Socket_Error; } - rtl_uString_newFromAscii(ustrDottedInetAddr,inet_ntoa(pSystemInetAddr->sin_addr)); + char buf[INET_ADDRSTRLEN]; + auto const text = inet_ntop(AF_INET, &pSystemInetAddr->sin_addr, buf, INET_ADDRSTRLEN); + assert(text != nullptr); + rtl_uString_newFromAscii(ustrDottedInetAddr,text); return osl_Socket_Ok; diff --git a/sal/qa/osl/socket.cxx b/sal/qa/osl/socket.cxx new file mode 100644 index 000000000000..dab2621f2293 --- /dev/null +++ b/sal/qa/osl/socket.cxx @@ -0,0 +1,40 @@ +/* -*- 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 <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <osl/socket.h> +#include <rtl/ustring.hxx> + +namespace +{ +class SocketTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(SocketTest); + CPPUNIT_TEST(test_getDottedInetAddrOfSocketAddr); + CPPUNIT_TEST_SUITE_END(); + + void test_getDottedInetAddrOfSocketAddr() + { + OUString const in("123.4.56.78"); + auto const addr = osl_createInetSocketAddr(in.pData, 0); + CPPUNIT_ASSERT(addr != nullptr); + OUString out; + auto const res = osl_getDottedInetAddrOfSocketAddr(addr, &out.pData); + CPPUNIT_ASSERT_EQUAL(osl_Socket_Ok, res); + CPPUNIT_ASSERT_EQUAL(in, out); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SocketTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |