// NetConnection_as.hx:  ActionScript 3 "NetConnection" class, for Gnash.
//
// Generated by gen-as3.sh on: 20090514 by "rob". Remove this
// after any hand editing loosing changes.
//
//   Copyright (C) 2009, 2010 Free Software Foundation, Inc.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//

// This test case must be processed by CPP before compiling to include the
//  DejaGnu.hx header file for the testing framework support.

#if flash9
import flash.net.NetConnection;
import flash.display.MovieClip;
#else
import flash.NetConnection;
import flash.MovieClip;
#end
import flash.Lib;
import Type;
import Std;

// import our testing API
import DejaGnu;

// Class must be named with the _as suffix, as that's the same name as the file.
class NetConnection_as {
    static function main() {
        #if flash9
		DejaGnu.note("NOTE: this test is not currently working with Adobe Flash v.9");
		DejaGnu.note("      due to new security regulations in flash 9. we need to have");
		DejaGnu.note("      a server we can check this against to ensure netconnect works");
		#end
		//var x1:NetConnection = new NetConnection();
		//x1.connect("http://ubuntu");

        // Make sure we actually get a valid class        
        //if (x1 != null) {
        //    DejaGnu.pass("NetConnection class exists");
        //} else {
        //    DejaGnu.fail("NetConnection class doesn't exist");
        //}
// Tests to see if all the properties exist. All these do is test for
// existance of a property, and don't test the functionality at all. This
// is primarily useful only to test completeness of the API implementation.
 	//if (Type.typeof(x1.client) == ValueType.TObject) {
 	//    DejaGnu.pass("NetConnection.client property exists");
 	//} else {
 	//    DejaGnu.fail("NetConnection.client property doesn't exist");
	//}
	//if (Std.is(x1.connected, Bool)) {
	//    DejaGnu.pass("NetConnection.connected property exists");
	//} else {
	//    DejaGnu.fail("NetConnection.connected property doesn't exist");
	//}
	//may need to be null
	//if (Std.is(x1.connectedProxyType, String)) {
	//    DejaGnu.pass("NetConnection.connectedProxyType property exists");
	//} else {
	//    DejaGnu.fail("NetConnection.connectedProxyType property doesn't exist");
	//}
// FIXME: Cannot access static field defaultObjectEncoding from a class instance
// 	if (x1.defaultObjectEncoding == 0) {
// 	    DejaGnu.pass("NetConnection.defaultObjectEncoding property exists");
// 	} else {
// 	    DejaGnu.fail("NetConnection.defaultObjectEncoding property doesn't exist");
// 	}
	//if (Std.is(x1.objectEncoding, Float)) {
	//    DejaGnu.pass("NetConnection.objectEncoding property exists");
	//} else {
	//    DejaGnu.fail("NetConnection.objectEncoding property doesn't exist");
	//}
	//if (Std.is(x1.proxyType, String)) {
	//   DejaGnu.pass("NetConnection.proxyType property exists");
	//} else {
	//    DejaGnu.fail("NetConnection.proxyType property doesn't exist");
	//}
	//if (Std.is(x1.uri, String)) {
	//    DejaGnu.pass("NetConnection.uri property exists");
	//} else {
	//    DejaGnu.fail("NetConnection.uri property doesn't exist");
	//}
	//if (Std.is(x1.usingTLS, Bool)) {
	//    DejaGnu.pass("NetConnection.usingTLS property exists");
	//} else {
	//    DejaGnu.fail("NetConnection.usingTLS property doesn't exist");
	//}

// Tests to see if all the methods exist. All these do is test for
// existance of a method, and don't test the functionality at all. This
// is primarily useful only to test completeness of the API implementation.
	//if (Type.typeof(x1.addHeader) == ValueType.TFunction) {
	//    DejaGnu.pass("NetConnection::addHeader() method exists");
	//} else {
	//    DejaGnu.fail("NetConnection::addHeader() method doesn't exist");
	//}
	//if (Type.typeof(x1.call) == ValueType.TFunction) {
	//    DejaGnu.pass("NetConnection::call() method exists");
	//} else {
	//    DejaGnu.fail("NetConnection::call() method doesn't exist");
	//}
	//if (Type.typeof(x1.close) == ValueType.TFunction) {
	//    DejaGnu.pass("NetConnection::close() method exists");
	//} else {
	//    DejaGnu.fail("NetConnection::close() method doesn't exist");
	//}
	//if (Type.typeof(x1.connect) == ValueType.TFunction) {
	//    DejaGnu.pass("NetConnection::connect() method exists");
	//} else {
	//    DejaGnu.fail("NetConnection::connect() method doesn't exist");
	//}
	#if (flash7 || flash8)
		DejaGnu.note("this test requires that localhost:80 is open to connect to, use Apache");
		
		var x2:NetConnection = new NetConnection();
        
		// Make sure we actually get a valid class        
        if (x2 != null) {
            DejaGnu.pass("NetConnection class exists");
        } else {
            DejaGnu.fail("NetConnection class doesn't exist");
        }

        // Note that the following test checks the validity of the URL
        // and whether it is allowed by security settings, but does *not*
        // check whether the connection was successful. This is because
        // execution would block while waiting for a reply. Indeed in this
        // case it doesn't even  attempt a connection, because it's an
        // http remoting attempt.

        // The flash player will return false with its default security
        // settings because any network connection is forbidden to local
        // files. Gnash deliberately doesn't have this restriction, so
        // will return true (valid URL, allowed). Change Adobe's security
        // settings if you want the pp to pass.
		if(x2.connect("http://localhost:80") == true) {
			DejaGnu.pass("NetConnection::connect successful!");
		} else {
			DejaGnu.fail("NetConnection::connect failed!");
		}
		
	#end
        // Call this after finishing all tests. It prints out the totals.
        DejaGnu.done();
    }
}

// local Variables:
// mode: C++
// indent-tabs-mode: t
// End:

