Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PingTest.cs « System.Net.NetworkInformation « Test « System « class « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6b759a06b8cf0a7e3c25659959126c14229988a0 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using NUnit.Framework;
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Threading;

namespace MonoTests.System.Net.NetworkInformation
{
	[TestFixture]
	[Category("NotWasm")]
	public partial class PingTest
	{
		partial void AndroidShouldPingWork (ref bool shouldWork);

		[Test]
		public void PingFail()
		{
#if MONOTOUCH
			Assert.Ignore ("Ping implementation is broken on MT (requires sudo access)");
#else
			var p = new Ping ().Send ("192.0.2.0");
			Assert.AreNotEqual(IPStatus.Success, p.Status);
#endif
		}

		[Test]
		public void PingSuccess()
		{
#if MONOTOUCH
			Assert.Ignore ("Ping implementation is broken on MT (requires sudo access)");
#else
			bool shouldWork = true;
			AndroidShouldPingWork (ref shouldWork);
			if (shouldWork) {
				var p = new Ping ().Send ("127.0.0.1");
				Assert.AreEqual(IPStatus.Success, p.Status);
			} else
				Assert.Ignore ("Ping will not work on this Android device");
#endif
		}		

		[Test]
#if MONOTOUCH
		[Ignore("Ping implementation is broken on MT (requires sudo access)")]
#endif
		public void SendAsyncIPV4Succeeds()
		{
			var testIp = IPAddress.Loopback;
			var ping = new Ping ();
			PingReply reply = null;

			using (var waiter = new AutoResetEvent (false)) {
				ping.PingCompleted += new PingCompletedEventHandler ( 
					(s, e) => {
						reply = e.Reply;
						(e.UserState as AutoResetEvent) ?.Set ();
					});

				ping.SendAsync (testIp, waiter);

				waiter.WaitOne (TimeSpan.FromSeconds (8));
			}

			Assert.AreEqual (IPStatus.Success, reply.Status);
		}

		[Test]
#if MONOTOUCH
		[Ignore("Ping implementation is broken on MT (requires sudo access)")]
#endif
		public void SendAsyncIPV4Fails()
		{
			var testIp = IPAddress.Parse("192.0.2.0");
			var ping = new Ping ();
			PingReply reply = null;

			using (var waiter = new AutoResetEvent (false)) {
				ping.PingCompleted += new PingCompletedEventHandler ( 
					(s, e) => {
						reply = e.Reply;
						(e.UserState as AutoResetEvent) ?.Set ();
					});

				ping.SendAsync (testIp, waiter);

				waiter.WaitOne (TimeSpan.FromSeconds (8));
			}

			Assert.AreNotEqual (IPStatus.Success, reply.Status);
		}

		[Test]
		[Category("MultiThreaded")]
#if MONOTOUCH
		[Ignore("Ping implementation is broken on MT (requires sudo access)")]
#endif
		public void SendPingAsyncIPV4Succeeds()
		{
			var testIp = IPAddress.Loopback;
			var ping = new Ping ();
			var task = ping.SendPingAsync (testIp);

			task.Wait();

			var result = task.Result;

			Assert.AreEqual (IPStatus.Success, result.Status);
		}

		[Test]
		[Category("MultiThreaded")]
#if MONOTOUCH
		[Ignore("Ping implementation is broken on MT (requires sudo access)")]
#endif
		public void SendPingAsyncIPV4Fails()
		{
			var testIp = IPAddress.Parse("192.0.2.0");
			var ping = new Ping ();
			var task = ping.SendPingAsync (testIp);

			task.Wait();

			var result = task.Result;

			Assert.AreNotEqual (IPStatus.Success, result.Status);
		}
	}
}