| 
					
				 | 
			
			
				@@ -0,0 +1,77 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+package door 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import ( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"flag" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"fmt" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"io/ioutil" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"net" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"os" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"testing" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	"time" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+func TestMenuConnection(t *testing.T) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	tmpFile, err := ioutil.TempFile(os.TempDir(), "test-") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if err != nil { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		panic("Cannot create temporary file") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// Remember to clean up the file afterwards 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	defer os.Remove(tmpFile.Name()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// establish network socket connection to set Comm_handle 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	server, client := setupSockets() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// We're not testing closed connections, so: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	defer server.Close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	defer client.Close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// unicode 90x40 response 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	buffer := []byte("\x1b[1;1R\x1b[2;3R\x1b[40;90R") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	server.Write(buffer) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// Access Fd (File descriptor) of client for dropfile 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	client_conn := client.(*net.TCPConn) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	client_file, err := client_conn.File() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var fd int = int(client_file.Fd()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// Create door32.sys file 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	dfc := DropfileConfig{2, fd, 1800, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 0, 12} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	tmpFile.WriteString(fmt.Sprintf("%d\n%d\n%d\n%s\n%d\n%s\n%s\n%d\n%d\n%d\n%d\n", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		dfc.Comm_type, dfc.Comm_handle, dfc.Baudrate, dfc.BBSID, dfc.User_number, dfc.Real_name, dfc.Handle, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		dfc.Security_level, dfc.Time_left, dfc.Emulation, dfc.Node)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	tmpFile.Close() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	d := Door{} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// If I call d.Init() more then once flag complains about flag redefined. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// Reset flags 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// preset commandline args so door can init 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	os.Args = []string{"door", "-d", tmpFile.Name()} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	d.Init() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// Ok! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if !Unicode { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		t.Errorf("Unicode not true %t", Unicode) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if Width != 90 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		t.Errorf("Width not 90: %d", Width) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if Height != 40 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		t.Errorf("Height not 40: %d", Height) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// These are the commands sent to detect ... throw this all away. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	buffer = make([]byte, 128) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	server.SetReadDeadline(time.Now().Add(time.Millisecond * 20)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	_, err = server.Read(buffer) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// t.Errorf("Buffer : %#v\n", buffer[:r]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	server.SetReadDeadline(time.Time{}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// Ready to test! 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |