1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <cppunit/TestAssert.h>
11 #include <cppunit/TestFixture.h>
12 #include <cppunit/extensions/HelperMacros.h>
14 #include <osl/socket.h>
15 #include <rtl/ustring.hxx>
19 class SocketTest
: public CppUnit::TestFixture
21 CPPUNIT_TEST_SUITE(SocketTest
);
22 CPPUNIT_TEST(test_createInetSocketAddr
);
23 CPPUNIT_TEST(test_createInetBroadcastAddr
);
24 CPPUNIT_TEST_SUITE_END();
26 void test_createInetSocketAddr()
28 OUString
constexpr in(u
"123.4.56.78"_ustr
);
29 auto const addr
= osl_createInetSocketAddr(in
.pData
, 100);
30 CPPUNIT_ASSERT(addr
!= nullptr);
31 CPPUNIT_ASSERT_EQUAL(osl_Socket_FamilyInet
, osl_getFamilyOfSocketAddr(addr
));
33 auto const res
= osl_getDottedInetAddrOfSocketAddr(addr
, &out
.pData
);
34 CPPUNIT_ASSERT_EQUAL(osl_Socket_Ok
, res
);
35 CPPUNIT_ASSERT_EQUAL(in
, out
);
36 CPPUNIT_ASSERT_EQUAL(sal_Int32(100), osl_getInetPortOfSocketAddr(addr
));
37 osl_destroySocketAddr(addr
);
40 void test_createInetBroadcastAddr()
42 auto const addr
= osl_createInetBroadcastAddr(u
"123.4.56.78"_ustr
.pData
, 100);
43 CPPUNIT_ASSERT(addr
!= nullptr);
44 CPPUNIT_ASSERT_EQUAL(osl_Socket_FamilyInet
, osl_getFamilyOfSocketAddr(addr
));
46 auto const res
= osl_getDottedInetAddrOfSocketAddr(addr
, &out
.pData
);
47 CPPUNIT_ASSERT_EQUAL(osl_Socket_Ok
, res
);
48 CPPUNIT_ASSERT_EQUAL(OUString("123.255.255.255"), out
);
49 CPPUNIT_ASSERT_EQUAL(sal_Int32(100), osl_getInetPortOfSocketAddr(addr
));
50 osl_destroySocketAddr(addr
);
54 CPPUNIT_TEST_SUITE_REGISTRATION(SocketTest
);
57 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */