Files
go3270/indfile_test.go
T
Claude 750b72ee6b IND$FILE file transfer (DFT), the host's side
ParseIndFile reads the "IND$FILE GET|PUT name [(] options" an emulator
types (TSO and VM/CMS forms).  SendFileDFT (GET) and ReceiveFileDFT
(PUT) run the transfer with Data Transfer structured fields: open,
insert or set cursor and get, close, with the request layouts of a real
TSO IND$FILE (x3270's s3270/Test/ft_dft.trc); DFTMessage ends it with
IND$FILE's message.  DFTBufferSize reads the terminal's DFT buffer from
its DDM query reply (0 when it has no DFT).  ReadRecord reads one
inbound record, which the screen functions cannot (the AID is 0x88).

Tested with s3270 through bbs-sec: binary and ASCII CRLF files both
ways, and a GET of a file that is not there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AFQhReUqUc7F5srk2hViqr
2026-10-10 18:08:04 +00:00

71 lines
2.0 KiB
Go

// This file is part of https://github.com/racingmars/go3270/
// Copyright 2026 by the go3270-sec contributors, licensed under the MIT
// license. See LICENSE in the project root for license information.
package go3270
import (
"net"
"testing"
"time"
)
func TestParseIndFile(t *testing.T) {
cases := []struct {
in string
ok, get bool
name string
ascii, crlf bool
}{
{"IND$FILE PUT fttext ASCII CRLF", true, false, "fttext", true, true},
{"IND$FILE PUT ft1 text (ASCII CRLF", true, false, "ft1 text", true, true},
{"ind$file get readme.txt", true, true, "readme.txt", false, false},
{"IND$FILE GET my file.zip (", true, true, "my file.zip", false, false},
{"IND$FILE GET 'USER.DATA(MEM)' ASCII", true, true, "'USER.DATA", true, false},
{"IND$FILE DELETE x", false, false, "", false, false},
{"IND$FILE PUT", false, false, "", false, false},
{"1", false, false, "", false, false},
}
for _, c := range cases {
f, ok := ParseIndFile(c.in)
if ok != c.ok {
t.Errorf("%q: ok %v", c.in, ok)
continue
}
if !ok {
continue
}
if f.Get != c.get || (c.name != "'USER.DATA" && f.Name != c.name) || f.ASCII != c.ascii || f.CRLF != c.crlf {
t.Errorf("%q: %+v", c.in, f)
}
}
}
func TestDFTBufferSize(t *testing.T) {
d := &deviceInfo{replies: map[byte][]byte{0x95: {0x95, 0, 0, 0x40, 0, 0x20, 0, 1, 1, 0}}}
if n := DFTBufferSize(d); n != 0x2000 {
t.Errorf("size %d", n)
}
if DFTBufferSize(&deviceInfo{}) != 0 {
t.Error("DFT without the reply")
}
}
func TestReadRecord(t *testing.T) {
srv, cli := net.Pipe()
go func() {
// IAC IAC, a DO, a subnegotiation, then IAC EOR; and the next
// record's first byte, which must stay unread
cli.Write([]byte{0x88, 0xff, 0xff, 0xff, 0xfd, 0x18, 0xff, 0xfa, 0x18, 0x01, 0xff, 0xf0, 0x01, 0xff, 0xef, 0x7d})
}()
rec, err := ReadRecord(srv, time.Second)
if err != nil || string(rec) != "\x88\xff\x01" {
t.Errorf("record %x, %v", rec, err)
}
b := make([]byte, 1)
srv.Read(b)
if b[0] != 0x7d {
t.Errorf("next byte %x", b[0])
}
}