summaryrefslogtreecommitdiffstats
path: root/sal/qa/osl/socket.cxx
blob: 4598754a22141c1f2a8986ac0d77856d974d7412 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* -*- 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 constexpr in(u"123.4.56.78"_ustr);
        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()
    {
        auto const addr = osl_createInetBroadcastAddr(u"123.4.56.78"_ustr.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: */