Fix several problems in tests under MSW (mostly with MinGW) and enable building and running them on AppVeyor CI.