1//
2// MulticastSocketTest.cpp
3//
4// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "MulticastSocketTest.h"
12
13
14#ifdef POCO_NET_HAS_INTERFACE
15
16
17#include "Poco/CppUnit/TestCaller.h"
18#include "Poco/CppUnit/TestSuite.h"
19#include "MulticastEchoServer.h"
20#include "Poco/Net/MulticastSocket.h"
21#include "Poco/Net/SocketAddress.h"
22#include "Poco/Net/NetException.h"
23#include "Poco/Timespan.h"
24#include "Poco/Stopwatch.h"
25
26
27using Poco::Net::Socket;
28using Poco::Net::MulticastSocket;
29using Poco::Net::SocketAddress;
30using Poco::Net::IPAddress;
31using Poco::Timespan;
32using Poco::Stopwatch;
33using Poco::TimeoutException;
34using Poco::InvalidArgumentException;
35using Poco::IOException;
36
37
38MulticastSocketTest::MulticastSocketTest(const std::string& name): CppUnit::TestCase(name)
39{
40}
41
42
43MulticastSocketTest::~MulticastSocketTest()
44{
45}
46
47
48void MulticastSocketTest::testMulticast()
49{
50 try {
51 MulticastEchoServer echoServer;
52 MulticastSocket ms(SocketAddress::IPv4);
53 int n = ms.sendTo("hello", 5, echoServer.group());
54 assertTrue (n == 5);
55 char buffer[256];
56 n = ms.receiveBytes(buffer, sizeof(buffer));
57 assertTrue (n == 5);
58 assertTrue (std::string(buffer, n) == "hello");
59 ms.close();
60 }
61 catch(Poco::NotImplementedException e)
62 {
63#if POCO_OS != POCO_OS_ANDROID
64 throw e;
65#endif
66 }
67}
68
69
70void MulticastSocketTest::setUp()
71{
72}
73
74
75void MulticastSocketTest::tearDown()
76{
77}
78
79
80CppUnit::Test* MulticastSocketTest::suite()
81{
82 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("MulticastSocketTest");
83#if (POCO_OS != POCO_OS_FREE_BSD) // TODO
84 CppUnit_addTest(pSuite, MulticastSocketTest, testMulticast);
85#endif
86 return pSuite;
87}
88
89
90#endif // POCO_NET_HAS_INTERFACE
91