ported GoogleTests to EPICS Test Harness
This commit is contained in:
18
README
18
README
@ -5,21 +5,3 @@ PVDATA
|
||||
PVCOMMON
|
||||
|
||||
variables that points to EPICS base, pvDataCPP, and pvCommonCPP installation directory (includes and libraries) in configure/RELEASE.local
|
||||
|
||||
Google C++ Testing Framework
|
||||
----------------------------
|
||||
Download:
|
||||
http://code.google.com/p/googletest/
|
||||
|
||||
Extract, go to its root directory and in run:
|
||||
export GTEST_DIR=$PWD
|
||||
g++ -g -O3 -I${GTEST_DIR}/include -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest-all.cc
|
||||
g++ -g -O3 -I${GTEST_DIR}/include -I${GTEST_DIR} -c ${GTEST_DIR}/src/gtest_main.cc
|
||||
ar -rv libgtest_main.a gtest_main.o gtest-all.o
|
||||
|
||||
# INSTALL is where you put build artifacts
|
||||
|
||||
mkdir -p $INSTALL/gtest/lib/$EPICS_HOST_ARCH
|
||||
cp -r ${GTEST_DIR}/include $INSTALL/gtest
|
||||
cp libgtest_main.a $INSTALL/gtest/lib/$EPICS_HOST_ARCH
|
||||
|
||||
|
@ -20,41 +20,6 @@ pvAccessApp/factory/ChannelAccessFactory.cpp
|
||||
pvAccessApp/factory/CreateRequestFactory.cpp
|
||||
pvAccessApp/mb/pvAccessMB.cpp
|
||||
pvAccessApp/mb/pvAccessMB.h
|
||||
pvAccessApp/O.linux-x86_64/abstractResponseHandler.d
|
||||
pvAccessApp/O.linux-x86_64/baseChannelRequester.d
|
||||
pvAccessApp/O.linux-x86_64/beaconEmitter.d
|
||||
pvAccessApp/O.linux-x86_64/beaconHandler.d
|
||||
pvAccessApp/O.linux-x86_64/beaconServerStatusProvider.d
|
||||
pvAccessApp/O.linux-x86_64/blockingClientTCPTransport.d
|
||||
pvAccessApp/O.linux-x86_64/blockingServerTCPTransport.d
|
||||
pvAccessApp/O.linux-x86_64/blockingTCPAcceptor.d
|
||||
pvAccessApp/O.linux-x86_64/blockingTCPConnector.d
|
||||
pvAccessApp/O.linux-x86_64/blockingTCPTransport.d
|
||||
pvAccessApp/O.linux-x86_64/blockingUDPConnector.d
|
||||
pvAccessApp/O.linux-x86_64/blockingUDPTransport.d
|
||||
pvAccessApp/O.linux-x86_64/ChannelAccessFactory.d
|
||||
pvAccessApp/O.linux-x86_64/clientContextImpl.d
|
||||
pvAccessApp/O.linux-x86_64/clientFactory.d
|
||||
pvAccessApp/O.linux-x86_64/configuration.d
|
||||
pvAccessApp/O.linux-x86_64/CreateRequestFactory.d
|
||||
pvAccessApp/O.linux-x86_64/hexDump.d
|
||||
pvAccessApp/O.linux-x86_64/inetAddressUtil.d
|
||||
pvAccessApp/O.linux-x86_64/introspectionRegistry.d
|
||||
pvAccessApp/O.linux-x86_64/libpvAccess.a
|
||||
pvAccessApp/O.linux-x86_64/libpvAccess.so
|
||||
pvAccessApp/O.linux-x86_64/logger.d
|
||||
pvAccessApp/O.linux-x86_64/pvAccess.d
|
||||
pvAccessApp/O.linux-x86_64/pvAccessMB.d
|
||||
pvAccessApp/O.linux-x86_64/pvVersion.d
|
||||
pvAccessApp/O.linux-x86_64/referenceCountingLock.d
|
||||
pvAccessApp/O.linux-x86_64/responseHandlers.d
|
||||
pvAccessApp/O.linux-x86_64/rpcClient.d
|
||||
pvAccessApp/O.linux-x86_64/rpcServer.d
|
||||
pvAccessApp/O.linux-x86_64/serializationHelper.d
|
||||
pvAccessApp/O.linux-x86_64/serverChannelImpl.d
|
||||
pvAccessApp/O.linux-x86_64/serverContext.d
|
||||
pvAccessApp/O.linux-x86_64/simpleChannelSearchManagerImpl.d
|
||||
pvAccessApp/O.linux-x86_64/transportRegistry.d
|
||||
pvAccessApp/remote/abstractResponseHandler.cpp
|
||||
pvAccessApp/remote/beaconHandler.cpp
|
||||
pvAccessApp/remote/beaconHandler.h
|
||||
@ -110,43 +75,11 @@ pvAccessApp/utils/namedLockPattern.h
|
||||
pvAccessApp/utils/referenceCountingLock.cpp
|
||||
pvAccessApp/utils/referenceCountingLock.h
|
||||
scripts/gcovr
|
||||
testApp/client/O.linux-x86_64/testCreateRequest
|
||||
testApp/client/O.linux-x86_64/testCreateRequest.d
|
||||
testApp/client/O.linux-x86_64/testStartStop
|
||||
testApp/client/O.linux-x86_64/testStartStop.d
|
||||
testApp/client/MockClientImpl.cpp
|
||||
testApp/client/testChannelAccessFactory.cpp
|
||||
testApp/client/testCreateRequest.cpp
|
||||
testApp/client/testMockClient.cpp
|
||||
testApp/client/testStartStop.cpp
|
||||
testApp/remote/O.linux-x86_64/eget
|
||||
testApp/remote/O.linux-x86_64/eget.d
|
||||
testApp/remote/O.linux-x86_64/pvget
|
||||
testApp/remote/O.linux-x86_64/pvget.d
|
||||
testApp/remote/O.linux-x86_64/pvput
|
||||
testApp/remote/O.linux-x86_64/pvput.d
|
||||
testApp/remote/O.linux-x86_64/pvrpc
|
||||
testApp/remote/O.linux-x86_64/pvrpc.d
|
||||
testApp/remote/O.linux-x86_64/rpcServiceExample
|
||||
testApp/remote/O.linux-x86_64/rpcServiceExample.d
|
||||
testApp/remote/O.linux-x86_64/testBlockingTCPClnt
|
||||
testApp/remote/O.linux-x86_64/testBlockingTCPClnt.d
|
||||
testApp/remote/O.linux-x86_64/testBlockingTCPSrv
|
||||
testApp/remote/O.linux-x86_64/testBlockingTCPSrv.d
|
||||
testApp/remote/O.linux-x86_64/testBlockingUDPClnt
|
||||
testApp/remote/O.linux-x86_64/testBlockingUDPClnt.d
|
||||
testApp/remote/O.linux-x86_64/testBlockingUDPSrv
|
||||
testApp/remote/O.linux-x86_64/testBlockingUDPSrv.d
|
||||
testApp/remote/O.linux-x86_64/testChannelConnect
|
||||
testApp/remote/O.linux-x86_64/testChannelConnect.d
|
||||
testApp/remote/O.linux-x86_64/testGetPerformance
|
||||
testApp/remote/O.linux-x86_64/testGetPerformance.d
|
||||
testApp/remote/O.linux-x86_64/testRemoteClientImpl
|
||||
testApp/remote/O.linux-x86_64/testRemoteClientImpl.d
|
||||
testApp/remote/O.linux-x86_64/testServer
|
||||
testApp/remote/O.linux-x86_64/testServer.d
|
||||
testApp/remote/O.linux-x86_64/testServerContext
|
||||
testApp/remote/O.linux-x86_64/testServerContext.d
|
||||
testApp/remote/eget.cpp
|
||||
testApp/remote/epicsv4Grayscale.h
|
||||
testApp/remote/pvget.cpp
|
||||
@ -168,14 +101,10 @@ testApp/remote/testNTImage.cpp
|
||||
testApp/remote/testRemoteClientImpl.cpp
|
||||
testApp/remote/testServer.cpp
|
||||
testApp/remote/testServerContext.cpp
|
||||
testApp/utils/O.linux-x86_64/atomicBooleanTest.d
|
||||
testApp/utils/O.linux-x86_64/hexDumpTest.d
|
||||
testApp/utils/O.linux-x86_64/inetAddressUtilsTest.d
|
||||
testApp/utils/O.linux-x86_64/testUtils
|
||||
testApp/utils/atomicBooleanTest.cpp
|
||||
testApp/utils/testAtomicBoolean.cpp
|
||||
testApp/utils/configurationTest.cpp
|
||||
testApp/utils/hexDumpTest.cpp
|
||||
testApp/utils/inetAddressUtilsTest.cpp
|
||||
testApp/utils/testHexDump.cpp
|
||||
testApp/utils/testInetAddressUtils.cpp
|
||||
testApp/utils/introspectionRegistryTest.cpp
|
||||
testApp/utils/loggerTest.cpp
|
||||
testApp/utils/namedLockPatternTest.cpp
|
||||
@ -190,3 +119,4 @@ pvAccessApp/ca/caProvider.h
|
||||
pvAccessApp/ca/caProvider.cpp
|
||||
pvAccessApp/ca/caChannel.h
|
||||
pvAccessApp/ca/caChannel.cpp
|
||||
testApp/utils/Makefile
|
||||
|
@ -2,17 +2,23 @@ TOP=../..
|
||||
|
||||
include $(TOP)/configure/CONFIG
|
||||
|
||||
ifdef GTEST
|
||||
PROD_HOST += testUtils
|
||||
testUtils_SRCS += hexDumpTest.cpp
|
||||
testUtils_SRCS += inetAddressUtilsTest.cpp
|
||||
PROD_LIBS += pvAccess pvData pvMB Com
|
||||
|
||||
TESTPROD += testAtomicBoolean
|
||||
testAtomicBoolean_SRCS = testAtomicBoolean.cpp
|
||||
TESTS += testAtomicBoolean
|
||||
|
||||
TESTPROD += testHexDump
|
||||
testHexDump = testHexDump.cpp
|
||||
TESTS += testHexDump
|
||||
|
||||
TESTPROD += testInetAddressUtils
|
||||
testInetAddressUtils = testInetAddressUtils.cpp
|
||||
# Avoid errors from inlined htonl() etc. used as template argument
|
||||
inetAddressUtilsTest_CXXFLAGS = -O0
|
||||
testUtils_SRCS += atomicBooleanTest.cpp
|
||||
testUtils_LIBS += pvAccess pvData pvMB Com gtest_main
|
||||
gtest_main_DIR = $(GTEST)/lib
|
||||
testUtils_SYS_LIBS += pthread
|
||||
endif
|
||||
testInetAddressUtils_CXXFLAGS = -O0
|
||||
TESTS += testInetAddressUtils
|
||||
|
||||
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
|
||||
|
||||
#PROD_HOST += loggerTest
|
||||
#loggerTest_SRCS += loggerTest.cpp
|
||||
|
@ -1,16 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <remote.h>
|
||||
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
TEST(atomicBooleanTest, atomicBoolean)
|
||||
{
|
||||
AtomicBoolean ab;
|
||||
|
||||
EXPECT_FALSE(ab.get());
|
||||
ab.set();
|
||||
EXPECT_TRUE(ab.get());
|
||||
ab.clear();
|
||||
EXPECT_FALSE(ab.get());
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <pv/hexDump.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
TEST(hexDumpTest, hexDump)
|
||||
{
|
||||
char TO_DUMP[] = "pvAccess dump test\0\1\2\3\4\5\6\254\255\256";
|
||||
|
||||
EXPECT_NO_THROW(hexDump("test", (int8*)TO_DUMP, 18+9));
|
||||
EXPECT_NO_THROW(hexDump("only text", (int8*)TO_DUMP, 18));
|
||||
EXPECT_NO_THROW(hexDump("22 byte test", (int8*)TO_DUMP, 22));
|
||||
}
|
@ -1,137 +0,0 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <pv/inetAddressUtil.h>
|
||||
#include <pv/logger.h>
|
||||
|
||||
#include <pv/byteBuffer.h>
|
||||
#include <pv/pvType.h>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <osiSock.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
TEST(inetAddressUtils, getSocketAddressList)
|
||||
{
|
||||
auto_ptr<InetAddrVector> vec(getSocketAddressList("127.0.0.1 10.10.12.11:1234 192.168.3.4", 555));
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(3), vec->size());
|
||||
|
||||
osiSockAddr addr;
|
||||
addr = vec->at(0);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(555), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0x7F000001), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("127.0.0.1:555", inetAddressToString(addr));
|
||||
|
||||
addr = vec->at(1);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(1234), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0x0A0A0C0B), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("10.10.12.11:1234", inetAddressToString(addr));
|
||||
|
||||
addr = vec->at(2);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(555), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0xC0A80304), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("192.168.3.4:555", inetAddressToString(addr));
|
||||
|
||||
|
||||
|
||||
|
||||
auto_ptr<InetAddrVector> vec1(getSocketAddressList("172.16.55.160", 6789, vec.get()));
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(4), vec1->size());
|
||||
|
||||
addr = vec1->at(0);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(6789), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0xAC1037A0), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("172.16.55.160:6789", inetAddressToString(addr));
|
||||
|
||||
addr = vec1->at(1);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(555), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0x7F000001), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("127.0.0.1:555", inetAddressToString(addr));
|
||||
|
||||
addr = vec1->at(2);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(1234), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0x0A0A0C0B), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("10.10.12.11:1234", inetAddressToString(addr));
|
||||
|
||||
addr = vec1->at(3);
|
||||
EXPECT_EQ(AF_INET, addr.ia.sin_family);
|
||||
EXPECT_EQ(htons(555), addr.ia.sin_port);
|
||||
EXPECT_EQ(htonl(0xC0A80304), addr.ia.sin_addr.s_addr);
|
||||
EXPECT_EQ("192.168.3.4:555", inetAddressToString(addr));
|
||||
|
||||
}
|
||||
|
||||
TEST(inetAddressUtils, ipv4AddressToInt)
|
||||
{
|
||||
auto_ptr<InetAddrVector> vec(getSocketAddressList("127.0.0.1 10.10.12.11:1234 192.168.3.4", 555));
|
||||
|
||||
ASSERT_EQ(static_cast<size_t>(3), vec->size());
|
||||
|
||||
EXPECT_EQ((int32)0x7F000001, ipv4AddressToInt((vec->at(0))));
|
||||
EXPECT_EQ((int32)0x0A0A0C0B, ipv4AddressToInt((vec->at(1))));
|
||||
EXPECT_EQ((int32)0xC0A80304, ipv4AddressToInt((vec->at(2))));
|
||||
}
|
||||
|
||||
TEST(inetAddressUtils, intToIPv4Address)
|
||||
{
|
||||
auto_ptr<osiSockAddr> paddr(intToIPv4Address(0x7F000001));
|
||||
ASSERT_NE((uintptr_t)0, (uintptr_t)paddr.get());
|
||||
EXPECT_EQ(AF_INET, paddr->ia.sin_family);
|
||||
EXPECT_EQ("127.0.0.1:0", inetAddressToString(*paddr.get()));
|
||||
|
||||
paddr.reset(intToIPv4Address(0x0A0A0C0B));
|
||||
ASSERT_NE((uintptr_t)0, (uintptr_t)paddr.get());
|
||||
EXPECT_EQ(AF_INET, paddr->ia.sin_family);
|
||||
EXPECT_EQ("10.10.12.11:0", inetAddressToString(*paddr.get()));
|
||||
}
|
||||
|
||||
|
||||
TEST(inetAddressUtils, encodeAsIPv6Address)
|
||||
{
|
||||
auto_ptr<ByteBuffer> buff(new ByteBuffer(32, EPICS_ENDIAN_LITTLE));
|
||||
|
||||
char src[] = { (char)0, (char)0, (char)0, (char)0, (char)0, (char)0,
|
||||
(char)0, (char)0, (char)0, (char)0, (char)0xFF, (char)0xFF,
|
||||
(char)0x0A, (char)0x0A, (char)0x0C, (char)0x0B };
|
||||
|
||||
auto_ptr<osiSockAddr> paddr(intToIPv4Address(0x0A0A0C0B));
|
||||
ASSERT_NE((uintptr_t)0, (uintptr_t)paddr.get());
|
||||
osiSockAddr addr = *paddr;
|
||||
|
||||
encodeAsIPv6Address(buff.get(), &addr);
|
||||
ASSERT_EQ(static_cast<size_t>(16), buff->getPosition());
|
||||
|
||||
EXPECT_TRUE(strncmp(buff->getArray(), src, 16)==0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST(inetAddressUtils, getBroadcastAddresses)
|
||||
{
|
||||
osiSockAttach();
|
||||
|
||||
SOCKET socket = epicsSocketCreate(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
auto_ptr<InetAddrVector> broadcasts(getBroadcastAddresses(socket,6678));
|
||||
// at least one is expected
|
||||
ASSERT_LT(static_cast<size_t>(0), broadcasts->size());
|
||||
epicsSocketDestroy(socket);
|
||||
|
||||
// debug
|
||||
for(size_t i = 0; i<broadcasts->size(); i++) {
|
||||
cout<<"\t"<<inetAddressToString(broadcasts->at(i))<<endl;
|
||||
}
|
||||
|
||||
}
|
26
testApp/utils/testAtomicBoolean.cpp
Normal file
26
testApp/utils/testAtomicBoolean.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/remote.h>
|
||||
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
MAIN(testAtomicBoolean)
|
||||
{
|
||||
testPlan(5);
|
||||
testDiag("Tests for AtomicBoolean");
|
||||
|
||||
AtomicBoolean ab;
|
||||
|
||||
testOk(ab.get() == false, "Initial state");
|
||||
ab.set();
|
||||
testOk(ab.get() == true, "Set to true");
|
||||
ab.set();
|
||||
testOk(ab.get() == true, "Set to true (again)");
|
||||
ab.clear();
|
||||
testOk(ab.get() == false, "Set to false");
|
||||
ab.clear();
|
||||
testOk(ab.get() == false, "Set to again");
|
||||
|
||||
return testDone();
|
||||
}
|
26
testApp/utils/testHexDump.cpp
Normal file
26
testApp/utils/testHexDump.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/hexDump.h>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
|
||||
MAIN(testHexDump)
|
||||
{
|
||||
testPlan(3);
|
||||
testDiag("Tests for hexDump");
|
||||
|
||||
char TO_DUMP[] = "pvAccess dump test\0\1\2\3\4\5\6\254\255\256";
|
||||
|
||||
hexDump("test", (int8*)TO_DUMP, 18+9);
|
||||
testPass("Entire array");
|
||||
|
||||
hexDump("only text", (int8*)TO_DUMP, 18);
|
||||
testPass("Only text");
|
||||
|
||||
hexDump("22 byte test", (int8*)TO_DUMP, 22);
|
||||
testPass("22 bytes test");
|
||||
|
||||
return testDone();
|
||||
}
|
159
testApp/utils/testInetAddressUtils.cpp
Normal file
159
testApp/utils/testInetAddressUtils.cpp
Normal file
@ -0,0 +1,159 @@
|
||||
#include <epicsUnitTest.h>
|
||||
#include <testMain.h>
|
||||
|
||||
#include <pv/inetAddressUtil.h>
|
||||
#include <pv/logger.h>
|
||||
|
||||
#include <pv/byteBuffer.h>
|
||||
#include <pv/pvType.h>
|
||||
|
||||
#include <epicsAssert.h>
|
||||
#include <osiSock.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
using namespace epics::pvData;
|
||||
using namespace epics::pvAccess;
|
||||
using namespace std;
|
||||
|
||||
void test_getSocketAddressList()
|
||||
{
|
||||
testDiag("Test getSocketAddressList()");
|
||||
|
||||
auto_ptr<InetAddrVector> vec(getSocketAddressList("127.0.0.1 10.10.12.11:1234 192.168.3.4", 555));
|
||||
|
||||
testOk1(static_cast<size_t>(3) == vec->size());
|
||||
|
||||
osiSockAddr addr;
|
||||
addr = vec->at(0);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(555) == addr.ia.sin_port);
|
||||
testOk1(htonl(0x7F000001) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("127.0.0.1:555" == inetAddressToString(addr));
|
||||
|
||||
addr = vec->at(1);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(1234) == addr.ia.sin_port);
|
||||
testOk1(htonl(0x0A0A0C0B) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("10.10.12.11:1234" == inetAddressToString(addr));
|
||||
|
||||
addr = vec->at(2);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(555) == addr.ia.sin_port);
|
||||
testOk1(htonl(0xC0A80304) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("192.168.3.4:555" == inetAddressToString(addr));
|
||||
|
||||
|
||||
|
||||
|
||||
auto_ptr<InetAddrVector> vec1(getSocketAddressList("172.16.55.160", 6789, vec.get()));
|
||||
|
||||
testOk1(static_cast<size_t>(4) == vec1->size());
|
||||
|
||||
addr = vec1->at(0);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(6789) == addr.ia.sin_port);
|
||||
testOk1(htonl(0xAC1037A0) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("172.16.55.160:6789" == inetAddressToString(addr));
|
||||
|
||||
addr = vec1->at(1);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(555) == addr.ia.sin_port);
|
||||
testOk1(htonl(0x7F000001) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("127.0.0.1:555" == inetAddressToString(addr));
|
||||
|
||||
addr = vec1->at(2);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(1234) == addr.ia.sin_port);
|
||||
testOk1(htonl(0x0A0A0C0B) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("10.10.12.11:1234" == inetAddressToString(addr));
|
||||
|
||||
addr = vec1->at(3);
|
||||
testOk1(AF_INET == addr.ia.sin_family);
|
||||
testOk1(htons(555) == addr.ia.sin_port);
|
||||
testOk1(htonl(0xC0A80304) == addr.ia.sin_addr.s_addr);
|
||||
testOk1("192.168.3.4:555" == inetAddressToString(addr));
|
||||
|
||||
}
|
||||
|
||||
void test_ipv4AddressToInt()
|
||||
{
|
||||
testDiag("Test ipv4AddressToInt()");
|
||||
|
||||
auto_ptr<InetAddrVector> vec(getSocketAddressList("127.0.0.1 10.10.12.11:1234 192.168.3.4", 555));
|
||||
|
||||
testOk1(static_cast<size_t>(3) == vec->size());
|
||||
|
||||
testOk1((int32)0x7F000001 == ipv4AddressToInt((vec->at(0))));
|
||||
testOk1((int32)0x0A0A0C0B == ipv4AddressToInt((vec->at(1))));
|
||||
testOk1((int32)0xC0A80304 == ipv4AddressToInt((vec->at(2))));
|
||||
}
|
||||
|
||||
void test_intToIPv4Address()
|
||||
{
|
||||
testDiag("Test intToIPv4Address()");
|
||||
|
||||
auto_ptr<osiSockAddr> paddr(intToIPv4Address(0x7F000001));
|
||||
testOk1((uintptr_t)0 != (uintptr_t)paddr.get());
|
||||
testOk1(AF_INET == paddr->ia.sin_family);
|
||||
testOk1("127.0.0.1:0" == inetAddressToString(*paddr.get()));
|
||||
|
||||
paddr.reset(intToIPv4Address(0x0A0A0C0B));
|
||||
testOk1((uintptr_t)0 != (uintptr_t)paddr.get());
|
||||
testOk1(AF_INET == paddr->ia.sin_family);
|
||||
testOk1("10.10.12.11:0" == inetAddressToString(*paddr.get()));
|
||||
}
|
||||
|
||||
void test_encodeAsIPv6Address()
|
||||
{
|
||||
testDiag("Test encodeAsIPv6Address()");
|
||||
|
||||
auto_ptr<ByteBuffer> buff(new ByteBuffer(32, EPICS_ENDIAN_LITTLE));
|
||||
|
||||
char src[] = { (char)0, (char)0, (char)0, (char)0, (char)0, (char)0,
|
||||
(char)0, (char)0, (char)0, (char)0, (char)0xFF, (char)0xFF,
|
||||
(char)0x0A, (char)0x0A, (char)0x0C, (char)0x0B };
|
||||
|
||||
auto_ptr<osiSockAddr> paddr(intToIPv4Address(0x0A0A0C0B));
|
||||
testOk1((uintptr_t)0 != (uintptr_t)paddr.get());
|
||||
osiSockAddr addr = *paddr;
|
||||
|
||||
encodeAsIPv6Address(buff.get(), &addr);
|
||||
testOk1(static_cast<size_t>(16) == buff->getPosition());
|
||||
|
||||
testOk1(strncmp(buff->getArray(), src, 16) == 0);
|
||||
}
|
||||
|
||||
void test_getBroadcastAddresses()
|
||||
{
|
||||
testDiag("Test getBroadcastAddresses()");
|
||||
|
||||
osiSockAttach();
|
||||
|
||||
SOCKET socket = epicsSocketCreate(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
auto_ptr<InetAddrVector> broadcasts(getBroadcastAddresses(socket, 6678));
|
||||
// at least one is expected
|
||||
testOk1(static_cast<size_t>(0) < broadcasts->size());
|
||||
epicsSocketDestroy(socket);
|
||||
|
||||
// debug
|
||||
for(size_t i = 0; i<broadcasts->size(); i++) {
|
||||
testDiag(inetAddressToString(broadcasts->at(i)).c_str());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MAIN(testInetAddressUtils)
|
||||
{
|
||||
testPlan(44);
|
||||
testDiag("Tests for InetAddress utils");
|
||||
|
||||
test_getSocketAddressList();
|
||||
test_ipv4AddressToInt();
|
||||
test_intToIPv4Address();
|
||||
test_encodeAsIPv6Address();
|
||||
test_getBroadcastAddresses();
|
||||
|
||||
return testDone();
|
||||
}
|
Reference in New Issue
Block a user