W5100_H_INCLUDED is defined in w5100.h but that file is not included from Ethernet.h, Dhcp.h, or Dns.h (I'm not sure why you're including the last two). You'll need to do this:
#if defined(ethernet_h) && !defined(W5500_H_INCLUDED)
#include "Ethernet.h"
#pragma message ( "W5100 network" )
#elif defined(W5500_H_INCLUDED)
#include "Ethernet2.h"
#pragma message ( "W5500 network" )
#else
#pragma message ( "no network" )
#error "No or invalid network selected"
#endif
But, as I explained in #3, then you'll still run into the problem of testlib.h being included by testlib.cpp, which is a separate translation unit from your .ino file, and thus will not have the macros defined. You could resolve that by moving the code from testlib.cpp to testlib.h.