1 /** 2 * Tests all Network implementations. 3 * 4 * License: 5 * This Source Code Form is subject to the terms of 6 * the Mozilla Public License, v. 2.0. If a copy of 7 * the MPL was not distributed with this file, You 8 * can obtain one at http://mozilla.org/MPL/2.0/. 9 * 10 * Authors: 11 * Vladimir Panteleev <vladimir@thecybershadow.net> 12 */ 13 14 module ae.sys.net.test; 15 16 import std.file; 17 18 static import ae.sys.net.ae; 19 static import ae.sys.net.curl; 20 version(Windows) 21 static import ae.sys.net.wininet; 22 23 debug static import std.stdio; 24 25 void test(string moduleName, string className)() 26 { 27 debug std.stdio.stderr.writeln("Testing " ~ className); 28 29 mixin("import ae.sys.net." ~ moduleName ~ ";"); 30 mixin("alias Net = " ~ className ~ ";"); 31 auto net = new Net(); 32 33 debug std.stdio.stderr.writeln(" - getFile"); 34 { 35 assert(net.getFile("http://d-lang.appspot.com/testUrl1") == "Hello world\n"); 36 } 37 38 debug std.stdio.stderr.writeln(" - downloadFile"); 39 { 40 enum fn = "test.txt"; 41 if (fn.exists) fn.remove(); 42 scope(exit) if (fn.exists) fn.remove(); 43 44 net.downloadFile("http://d-lang.appspot.com/testUrl1", fn); 45 assert(fn.readText() == "Hello world\n"); 46 } 47 48 debug std.stdio.stderr.writeln(" - urlOK"); 49 { 50 assert( net.urlOK("http://d-lang.appspot.com/testUrl1")); 51 assert(!net.urlOK("http://d-lang.appspot.com/testUrlNX")); 52 static if (moduleName == "wininet") 53 assert( net.urlOK("https://d-lang.appspot.com/testUrl1")); 54 } 55 56 debug std.stdio.stderr.writeln(" - resolveRedirect"); 57 { 58 auto result = net.resolveRedirect("http://d-lang.appspot.com/testUrl3"); 59 assert(result == "http://d-lang.appspot.com/testUrl2", result); 60 } 61 } 62 63 unittest 64 { 65 test!("ae", "AENetwork"); 66 test!("curl", "CurlNetwork"); 67 version(Windows) 68 test!("wininet", "WinINetNetwork"); 69 }