3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "network/socket.h"
26 class TestAddress : public TestBase
29 TestAddress() { TestManager::registerTestModule(this); }
31 const char *getName() { return "TestAddress"; }
33 void runTests(IGameDef *gamedef);
35 void testIsLocalhost();
38 static TestAddress g_test_instance;
40 void TestAddress::runTests(IGameDef *gamedef)
42 TEST(testIsLocalhost);
45 void TestAddress::testIsLocalhost()
48 UASSERT(Address(127, 0, 0, 1, 0).isLocalhost());
49 UASSERT(Address(127, 254, 12, 99, 0).isLocalhost());
50 UASSERT(Address(127, 188, 255, 247, 0).isLocalhost());
51 UASSERT(!Address(126, 255, 255, 255, 0).isLocalhost());
52 UASSERT(!Address(128, 0, 0, 0, 0).isLocalhost());
53 UASSERT(!Address(1, 0, 0, 0, 0).isLocalhost());
54 UASSERT(!Address(255, 255, 255, 255, 0).isLocalhost());
55 UASSERT(!Address(36, 45, 99, 158, 0).isLocalhost());
56 UASSERT(!Address(172, 45, 37, 68, 0).isLocalhost());
59 std::unique_ptr<IPv6AddressBytes> ipv6Bytes(new IPv6AddressBytes());
60 std::vector<u8> ipv6RawAddr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
61 memcpy(ipv6Bytes->bytes, &ipv6RawAddr[0], 16);
62 UASSERT(Address(ipv6Bytes.get(), 0).isLocalhost())
64 ipv6RawAddr = {16, 34, 0, 0, 0, 0, 29, 0, 0, 0, 188, 0, 0, 0, 0, 14};
65 memcpy(ipv6Bytes->bytes, &ipv6RawAddr[0], 16);
66 UASSERT(!Address(ipv6Bytes.get(), 0).isLocalhost())