Move tests from QueryTest to IpAddressTest.
Include validity as criterion for loopback.
Rewrite for readability.