From 71d009c1c8507a02949a3925531c39ab0a7e592f Mon Sep 17 00:00:00 2001 From: monojenkins Date: Thu, 12 Dec 2019 17:56:42 +0100 Subject: [PATCH] [d16-5] [monotouch-test] Simplify NetworkReachabilityTest.CtorIPAddressPair test. (#7579) Don't assert anything about the flags, it's a never ending game to keep up with OS versions. Fixes https://github.com/xamarin/maccore/issues/2047 for good. Backport of #7546. --- .../NetworkReachabilityTest.cs | 40 +++++++------------ 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs b/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs index 19dee2b289..3815982e8c 100644 --- a/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs +++ b/tests/monotouch-test/SystemConfiguration/NetworkReachabilityTest.cs @@ -100,14 +100,7 @@ namespace MonoTouchFixtures.SystemConfiguration { NetworkReachabilityFlags flags; Assert.IsTrue (nr.TryGetFlags (out flags), "#1"); - // using Loopback iOS 10 / tvOS 10 returns no flags (0) on devices - // but only sometimes... so check for Reachable as well (as a flag). -#if !MONOMAC - if ((Runtime.Arch == Arch.DEVICE) && TestRuntime.CheckXcodeVersion (8, 0)) - Assert.That ((flags == (NetworkReachabilityFlags) 0) || ((flags & NetworkReachabilityFlags.Reachable) == NetworkReachabilityFlags.Reachable) , $"#1 Reachable: {flags.ToString ()}"); - else -#endif - Assert.That (flags, Is.EqualTo (NetworkReachabilityFlags.Reachable), "#1 Reachable"); + CheckLoopbackFlags (flags, "1", true); } using (var nr = new NetworkReachability (null, address)) @@ -123,27 +116,22 @@ namespace MonoTouchFixtures.SystemConfiguration { NetworkReachabilityFlags flags; Assert.IsTrue (nr.TryGetFlags (out flags), "#3"); - // using Loopback iOS 10 / tvOS 10 / macOS 10.12 returns no flags (0) on devices - var expected = (NetworkReachabilityFlags) 0; -#if MONOMAC - if (!TestRuntime.CheckSystemVersion (PlatformName.MacOSX, 10, 12)) { - expected = NetworkReachabilityFlags.Reachable; - if (!TestRuntime.CheckSystemVersion (PlatformName.MacOSX, 10, 11)) - expected |= NetworkReachabilityFlags.IsLocalAddress; - } -#else - if ((Runtime.Arch == Arch.DEVICE) && TestRuntime.CheckXcodeVersion (8, 0)) { - // - } else { - expected = NetworkReachabilityFlags.Reachable; - if (!TestRuntime.CheckXcodeVersion (7, 0)) - expected |= NetworkReachabilityFlags.IsLocalAddress; - } -#endif - Assert.That (flags, Is.EqualTo (expected), "#3 Reachable"); + CheckLoopbackFlags (flags, "3", false); } } + void CheckLoopbackFlags (NetworkReachabilityFlags flags, string number, bool has_address) + { + var noFlags = (NetworkReachabilityFlags) 0; + var otherFlags = (flags & ~(NetworkReachabilityFlags.Reachable | NetworkReachabilityFlags.IsLocalAddress | NetworkReachabilityFlags.IsDirect)); + + // Different versions of OSes report different flags. Trying to + // figure out which OS versions have which flags set turned out to + // be a never-ending game of whack-a-mole, so just don't assert + // that any specific flags are set. + Assert.AreEqual (noFlags, otherFlags, $"#{number} No other flags: {flags.ToString ()}"); + } + [Test] public void Ctor_Invalid () {