diff options
Diffstat (limited to '')
-rw-r--r-- | sal/qa/osl/socket.cxx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/sal/qa/osl/socket.cxx b/sal/qa/osl/socket.cxx new file mode 100644 index 000000000..ed31c9ede --- /dev/null +++ b/sal/qa/osl/socket.cxx @@ -0,0 +1,58 @@ +/* -*- 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_createInetSocketAddr); + CPPUNIT_TEST(test_createInetBroadcastAddr); + CPPUNIT_TEST_SUITE_END(); + + void test_createInetSocketAddr() + { + OUString const in("123.4.56.78"); + auto const addr = osl_createInetSocketAddr(in.pData, 100); + CPPUNIT_ASSERT(addr != nullptr); + CPPUNIT_ASSERT_EQUAL(osl_Socket_FamilyInet, osl_getFamilyOfSocketAddr(addr)); + OUString out; + auto const res = osl_getDottedInetAddrOfSocketAddr(addr, &out.pData); + CPPUNIT_ASSERT_EQUAL(osl_Socket_Ok, res); + CPPUNIT_ASSERT_EQUAL(in, out); + CPPUNIT_ASSERT_EQUAL(sal_Int32(100), osl_getInetPortOfSocketAddr(addr)); + osl_destroySocketAddr(addr); + } + + void test_createInetBroadcastAddr() + { + OUString const in("123.4.56.78"); + auto const addr = osl_createInetBroadcastAddr(in.pData, 100); + CPPUNIT_ASSERT(addr != nullptr); + CPPUNIT_ASSERT_EQUAL(osl_Socket_FamilyInet, osl_getFamilyOfSocketAddr(addr)); + OUString out; + auto const res = osl_getDottedInetAddrOfSocketAddr(addr, &out.pData); + CPPUNIT_ASSERT_EQUAL(osl_Socket_Ok, res); + CPPUNIT_ASSERT_EQUAL(OUString("123.255.255.255"), out); + CPPUNIT_ASSERT_EQUAL(sal_Int32(100), osl_getInetPortOfSocketAddr(addr)); + osl_destroySocketAddr(addr); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(SocketTest); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |