door_test.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. package door
  2. // Need net, flag for setupSockets
  3. import (
  4. "flag"
  5. "fmt"
  6. "log"
  7. "net"
  8. "os"
  9. "strings"
  10. "testing"
  11. "time"
  12. )
  13. // Should tests not delete the logfiles?
  14. // To make use of this, set KEEP_LOGS bool = true and:
  15. // go test -c; ./door.test -test.v -test.timeout 40s
  16. // Running just one test:
  17. // go test -c; ./door.test -test.run DoorCP437 -test.v
  18. const KEEP_LOGS bool = false
  19. const VERBOSE_TEST bool = false
  20. func TestGoto(t *testing.T) {
  21. GotoMap := map[string][]int{"\x1b[10;20H": {20, 10},
  22. "\x1b[20;10H": {10, 20},
  23. "\x1b[80;120H": {120, 80},
  24. "\x1b[1;1H": {1, 1},
  25. }
  26. for text, code := range GotoMap {
  27. gt := Goto(code[0], code[1])
  28. if text != gt {
  29. t.Errorf("Goto: Expected %#v (%#v), got %#v", text, code, gt)
  30. }
  31. }
  32. }
  33. func TestLogfileFailure(t *testing.T) {
  34. tmpFile, err := os.CreateTemp("", "test-door32.sys-*")
  35. if err != nil {
  36. panic("Cannot create temporary file")
  37. }
  38. defer func() {
  39. if r := recover(); r == nil {
  40. t.Error("Init did not panic on logfile error.")
  41. }
  42. }()
  43. // Remember to clean up the file afterwards
  44. defer os.Remove(tmpFile.Name())
  45. // This test should fail before we even need sockets
  46. var fd int = 0
  47. // Create door32.sys file
  48. dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 13}
  49. err = CreateDoor32File(&dfc, tmpFile)
  50. if err != nil {
  51. t.Error("tmpFile.WriteString:", err)
  52. }
  53. err = tmpFile.Close()
  54. if err != nil {
  55. t.Error("tmpFile.Close:", err)
  56. }
  57. d := Door{}
  58. // If I call d.Init() more then once flag complains about flag redefined.
  59. // Reset flags
  60. flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
  61. // preset commandline args so door can init
  62. os.Args = []string{"door", "-d", tmpFile.Name()}
  63. uid := os.Getuid()
  64. if uid == 0 {
  65. // Running as root. Use invalid path here.
  66. d.Init("/invalid-path/badpath-test")
  67. } else {
  68. // uid == -1 (windows), this should also fail there.
  69. d.Init("/badname-test")
  70. }
  71. }
  72. func TestDetectFail(t *testing.T) {
  73. tmpFile, err := os.CreateTemp("", "test-door32.sys-*")
  74. if err != nil {
  75. panic("Cannot create temporary file")
  76. }
  77. // Remember to clean up the file afterwards
  78. defer os.Remove(tmpFile.Name())
  79. // establish network socket connection to set Comm_handle
  80. server, client := setupSockets()
  81. // We're not testing closed connections, so:
  82. defer server.Close()
  83. defer client.Close()
  84. // Send nothing
  85. var fd int = socket_to_fd(client)
  86. defer close_fd(fd)
  87. // Create door32.sys file
  88. dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, 13}
  89. err = CreateDoor32File(&dfc, tmpFile)
  90. if err != nil {
  91. t.Error("tmpFile.WriteString:", err)
  92. }
  93. err = tmpFile.Close()
  94. if err != nil {
  95. t.Error("tmpFile.Close:", err)
  96. }
  97. d := Door{ReaderCanClose: true}
  98. // Because we're not the only one calling door.Init(), the
  99. // door global variables might be from a previous test run.
  100. Unicode = false
  101. CP437 = false
  102. Full_CP437 = false
  103. Width = 0
  104. Height = 0
  105. // If I call d.Init() more then once flag complains about flag redefined.
  106. // Reset flags
  107. flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
  108. // preset commandline args so door can init
  109. os.Args = []string{"door", "-d", tmpFile.Name()}
  110. d.Init("menu-test")
  111. t.Logf("Init completed.")
  112. defer d.Close()
  113. // clean up log file
  114. // I don't need to. Tests are run in /tmp/go-buildNNNN.
  115. // defer os.Remove("menu-test-13.log")
  116. if Unicode || CP437 {
  117. t.Errorf("Expected FALSE, got Unicode %t CP437 %t", Unicode, CP437)
  118. }
  119. if Width != 0 || Height != 0 {
  120. t.Errorf("Expected 0, 0, got Width %d, Height %d", Width, Height)
  121. }
  122. t.Logf("Closing server and client...")
  123. server.Close()
  124. client.Close()
  125. // time.Sleep(time.Duration(1) * time.Second)
  126. t.Logf("Done.")
  127. }
  128. // Pass d*Door to test. Otherwise we get a copy of the object passed!
  129. // go vet (shows this error/issue)
  130. // Generic tests that will be called from CP437 and Unicode routines
  131. func InputTests(t *testing.T, server net.Conn, d *Door, mode string) {
  132. var err error
  133. var buffer string
  134. keytest := map[string][]rune{
  135. "\x1b": []rune{0x1b},
  136. "\x0d\x00": []rune{0x0d},
  137. "\x0d\x0a": []rune{0x0d},
  138. "\x0dCQ": []rune{0x0d, 'C', 'Q'},
  139. "\x0dA": []rune{0x0d, 'A'},
  140. "\x0dCAT": []rune{0x0d, 'C', 'A', 'T'},
  141. "\U0001f920\u2615": []rune{'\U0001f920', '\u2615'},
  142. }
  143. /*
  144. Test input buffer processing.
  145. Create a string with unicode that doesn't fit into the
  146. entire read buffer. And build the proper response to match.
  147. */
  148. // x = number of missing bytes (from unicode symbol).
  149. for x := 1; x <= 3; x++ {
  150. tosend := strings.Repeat(" ", READ_SIZE-x) + "\U0001f920"
  151. receive := []rune(strings.Repeat(" ", READ_SIZE-x))
  152. receive = append(receive, '\U0001f920')
  153. keytest[tosend] = receive
  154. }
  155. keyextest := map[string][]Extended{
  156. "\x00\x50\x00\x48\x00\x4b\x00\x4d": []Extended{DOWN_ARROW, UP_ARROW, LEFT_ARROW, RIGHT_ARROW},
  157. "\x00\x47\x00\x4f\x00\x49\x00\x51": []Extended{HOME, END, PAGE_UP, PAGE_DOWN},
  158. "\x00\x3b\x00\x3c\x00\x3d\x00\x3e": []Extended{F1, F2, F3, F4},
  159. "\x00\x3f\x00\x40\x00\x41\x00\x42": []Extended{F5, F6, F7, F8},
  160. "\x00\x43\x00\x44\x00\x52\x00\x53": []Extended{F9, F10, INSERT, DELETE},
  161. "\x00\x45\x00\x46": []Extended{F11, F12},
  162. "\x1b[A\x1b[B\x1b[C\x1b[D": []Extended{UP_ARROW, DOWN_ARROW, RIGHT_ARROW, LEFT_ARROW},
  163. "\x1b[H\x1b[F\x1b[K\x1b[V\x1b[U": []Extended{HOME, END, END, PAGE_UP, PAGE_DOWN},
  164. "\x1b[5~\x1b[6~": []Extended{PAGE_UP, PAGE_DOWN},
  165. "\x1b[@\x1b[2~\x1b[3~": []Extended{INSERT, INSERT, DELETE},
  166. "\x1b[1~\x1b[4~": []Extended{HOME, END},
  167. "\x1bOP\x1bOQ\x1bOR\x1bOS": []Extended{F1, F2, F3, F4},
  168. "\x1b[15~\x1b[17~\x1b[18~\x1b[19~": []Extended{F5, F6, F7, F8},
  169. "\x1b[20~\x1b[21~\x1b[23~\x1b[24~": []Extended{F9, F10, F11, F12},
  170. }
  171. // 50ms causes 3 tries (internal is 200ms, use 210ms).
  172. keyWait := time.Duration(210 * time.Millisecond)
  173. // Verify input is empty
  174. for {
  175. input, ex, err := d.WaitKey(keyWait)
  176. if err == nil {
  177. t.Errorf("Keys: %#v, %#v\n", input, ex)
  178. } else {
  179. break
  180. }
  181. }
  182. t.Logf("Starting keytest (%s)\n", mode)
  183. for send, get := range keytest {
  184. if VERBOSE_TEST {
  185. t.Logf("Sending %#v: Expect: %#v\n", send, get)
  186. }
  187. var buffer []byte = []byte(send)
  188. _, err = server.Write(buffer)
  189. if err != nil {
  190. t.Error("server.Write:", err)
  191. }
  192. time.Sleep(time.Millisecond)
  193. var recv []rune = make([]rune, 0)
  194. var retries int = 0
  195. for {
  196. input, _, err := d.WaitKey(keyWait)
  197. if VERBOSE_TEST {
  198. t.Logf(">> %#v, %#v\n", input, err)
  199. }
  200. if err == nil {
  201. recv = append(recv, input)
  202. if len(recv) != len(get) {
  203. continue
  204. }
  205. break
  206. } else {
  207. t.Logf("WaitKey Err: %#v\n", err)
  208. if len(recv) != len(get) {
  209. if retries < 5 {
  210. retries++
  211. t.Logf("Retry %d want %d got %d\n", retries, len(get), len(recv))
  212. continue
  213. }
  214. break
  215. }
  216. }
  217. }
  218. if len(recv) != len(get) {
  219. t.Errorf("FAILURE: Sent %#v, LEN expected %#v, got %#v", send, get, recv)
  220. } else {
  221. matches := true
  222. for idx, i := range get {
  223. if recv[idx] != i {
  224. matches = false
  225. break
  226. }
  227. }
  228. if !matches {
  229. t.Errorf("FAILURE: Sent %#v, MATCH expected %#v, got %#v", send, get, recv)
  230. } else {
  231. if VERBOSE_TEST {
  232. t.Logf("Success.")
  233. }
  234. }
  235. }
  236. }
  237. t.Logf("Starting keyextest (%s)\n", mode)
  238. for send, get := range keyextest {
  239. if VERBOSE_TEST {
  240. t.Logf("Sending %#v: Expect: %#v\n", send, get)
  241. }
  242. var buffer []byte = []byte(send)
  243. _, err = server.Write(buffer)
  244. if err != nil {
  245. t.Error("server.Write:", err)
  246. }
  247. time.Sleep(time.Millisecond)
  248. var recv []Extended = make([]Extended, 0)
  249. var retries int = 0
  250. for {
  251. _, ex, err := d.WaitKey(keyWait)
  252. if err == nil {
  253. recv = append(recv, ex)
  254. if len(recv) != len(get) {
  255. continue
  256. }
  257. break
  258. } else {
  259. t.Logf("WaitKey err: #%v\n", err)
  260. if len(recv) != len(get) {
  261. if retries < 5 {
  262. retries++
  263. t.Logf("Retry %d want %d got %d\n", retries, len(get), len(recv))
  264. continue
  265. }
  266. break
  267. }
  268. }
  269. }
  270. if len(recv) != len(get) {
  271. t.Errorf("Sent %#v, LEN expected %#v, got %#v", send, get, recv)
  272. } else {
  273. matches := true
  274. for idx, i := range get {
  275. if recv[idx] != i {
  276. matches = false
  277. break
  278. }
  279. }
  280. if !matches {
  281. t.Errorf("Sent %#v, MATCH expected %#v, got %#v", send, get, recv)
  282. }
  283. }
  284. }
  285. clear_socket(server, t)
  286. t.Logf("Starting WaitKey timeout (%s)...\n", mode)
  287. _, _, timeout := d.WaitKey(keyWait)
  288. if timeout == nil {
  289. t.Errorf("Expected timeout, got %d / %X", timeout, timeout)
  290. } else {
  291. t.Logf("Ok! Buffer should be empty! -1 (timeout)")
  292. }
  293. t.Logf("Starting input test (%s)\n", mode)
  294. // Input test
  295. buffer = "1234567890\r"
  296. _, err = server.Write([]byte(buffer))
  297. if err != nil {
  298. t.Error("server.Write:", err)
  299. }
  300. time.Sleep(time.Millisecond)
  301. var input string = d.Input(5)
  302. if input != "12345" {
  303. t.Errorf("Expected Input(5) = 12345, but got %#v", input)
  304. }
  305. // read everything
  306. var result string = clear_socket(server, t)
  307. expected := " \x08\x08\x08\x08\x0812345\x07\x07\x07\x07"
  308. if result != expected {
  309. expected = " \x08\x08\x08\x08\x0812345\x07\x07\x07\x07\x07"
  310. if result != expected {
  311. t.Errorf("Buffer Input(5): Expected %#v, got %#v\n", expected, result)
  312. }
  313. }
  314. err = server.SetReadDeadline(time.Time{})
  315. if err != nil {
  316. t.Error("server.SetReadDeadLine:", err)
  317. }
  318. buffer = "12345678\x08\x089\r"
  319. _, err = server.Write([]byte(buffer))
  320. if err != nil {
  321. t.Error("server.Write:", err)
  322. }
  323. time.Sleep(time.Millisecond)
  324. input = d.Input(5)
  325. if input != "1239" {
  326. t.Errorf("Expected Input(5) = 1239, but got %#v", input)
  327. }
  328. buffer = "12\x08\x08\x08987\x00\x48654321\r"
  329. _, err = server.Write([]byte(buffer))
  330. if err != nil {
  331. t.Error("server.Write:", err)
  332. }
  333. time.Sleep(time.Millisecond)
  334. input = d.Input(5)
  335. if input != "98765" {
  336. t.Errorf("Expected Input(5) = 98765, but got %#v", input)
  337. }
  338. t.Logf("Starting cursor pos test (%s)\n", mode)
  339. var cpos []CursorPos = []CursorPos{{1, 1}, {50, 5}, {4, 40}, {80, 25}, {160, 55}}
  340. for _, pos := range cpos {
  341. if VERBOSE_TEST {
  342. t.Logf("Sending CursorPos(%d,%d)\n", pos.X, pos.Y)
  343. }
  344. buffer = CursorReply(pos)
  345. _, err := server.Write([]byte(buffer))
  346. if err != nil {
  347. t.Error("server.Write:", err)
  348. }
  349. }
  350. for _, pos := range cpos {
  351. _, ex, err := d.WaitKey(keyWait)
  352. if err != nil {
  353. t.Error("WaitKey:", err)
  354. continue
  355. }
  356. if ex != CURSOR {
  357. t.Errorf("Expected Extended = CURSOR (was %s)", ex.String())
  358. continue
  359. }
  360. cp, ok := d.GetCursorPos()
  361. if !ok {
  362. t.Error("Extended sent CURSOR, but GetCursorPos failed.")
  363. continue
  364. }
  365. if (cp.X != pos.X) || (cp.Y != pos.Y) {
  366. t.Errorf("Expected (%d,%d), Got (%d,%d)", pos.X, pos.Y, cp.X, cp.Y)
  367. }
  368. }
  369. t.Logf("Starting Mouse test (%s)\n", mode)
  370. var mouse []Mouse = []Mouse{{1, 4, 5}, {4, 4, 5}, {45, 80, 25}, {2, 55, 17}}
  371. for _, m := range mouse {
  372. if VERBOSE_TEST {
  373. t.Logf("Sending Mouse(%d @ %d,%d)\n", m.Button, m.X, m.Y)
  374. }
  375. buffer = MouseReply(m)
  376. _, err = server.Write([]byte(buffer))
  377. if err != nil {
  378. t.Error("server.Write:", err)
  379. }
  380. }
  381. for _, pos := range mouse {
  382. _, ex, err := d.WaitKey(keyWait)
  383. if err != nil {
  384. t.Error("WaitKey:", err)
  385. continue
  386. }
  387. if ex != MOUSE {
  388. t.Errorf("Expected Extended = MOUSE (was %s)", ex.String())
  389. continue
  390. }
  391. mpos, ok := d.GetMouse()
  392. if !ok {
  393. t.Error("Extended sent MOUSE, but GetMouse failed.")
  394. continue
  395. }
  396. if (pos.Button != mpos.Button) || (pos.X != mpos.X) || (pos.Y != mpos.Y) {
  397. t.Errorf("Expected (%d @ %d, %d), Got (%d @ %d, %d)",
  398. pos.Button, pos.X, pos.Y, mpos.Button, mpos.X, mpos.Y)
  399. }
  400. }
  401. }
  402. func TestDoorCP437(t *testing.T) {
  403. var tmpFile *os.File
  404. var err error
  405. // Dropfile
  406. tmpFile, err = os.CreateTemp("", "test-door32.sys-*")
  407. if err != nil {
  408. panic("Cannot create temporary file")
  409. }
  410. defer os.Remove(tmpFile.Name())
  411. // establish network socket connection to set Comm_handle
  412. var server, client net.Conn
  413. server, client = setupSockets()
  414. // Ok, we have a server socket, and the client socket (that the door would talk to)
  415. // CP437 80x25 response
  416. buffer := CP437WidthHeight(80, 25)
  417. _, err = server.Write([]byte(buffer))
  418. if err != nil {
  419. t.Error("server.Write:", err)
  420. }
  421. time.Sleep(time.Millisecond)
  422. // Access Fd (File descriptor) of client for dropfile
  423. var fd int = socket_to_fd(client)
  424. defer close_fd(fd)
  425. // Create door32.sys file
  426. var node int = 10
  427. dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, node}
  428. err = CreateDoor32File(&dfc, tmpFile)
  429. if err != nil {
  430. t.Error("tmpFile.WriteString:", err)
  431. }
  432. err = tmpFile.Close()
  433. if err != nil {
  434. t.Error("tmpFile.Close:", err)
  435. }
  436. d := Door{} // Deprecated: ReaderCanClose: true}
  437. // Because we're not the only one calling door.Init(), the
  438. // door global variables might be from a previous test run.
  439. // Reset back to defaults.
  440. Unicode = false
  441. CP437 = false
  442. Full_CP437 = false
  443. Width = 0
  444. Height = 0
  445. // If I call d.Init() more then once flag complains about flag redefined.
  446. // Reset flags
  447. flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
  448. // preset commandline args so door can init
  449. os.Args = []string{"door", "-d", tmpFile.Name()}
  450. d.Init("input-test")
  451. defer d.Close()
  452. // clean up logfile - (filename is from Init name + node #)
  453. if !KEEP_LOGS {
  454. defer os.Remove(fmt.Sprintf("input-test-%d.log", node))
  455. }
  456. if VERBOSE_TEST {
  457. t.Logf("Verify Unicode %dX%d\n", 80, 25)
  458. }
  459. // Ok!
  460. if Unicode {
  461. t.Errorf("Unicode is %t", Unicode)
  462. }
  463. if !CP437 {
  464. t.Errorf("Expect CP437 true, is %t", CP437)
  465. }
  466. if Width != 80 {
  467. t.Errorf("Width not 80: %d", Width)
  468. }
  469. if Height != 25 {
  470. t.Errorf("Height not 25: %d", Height)
  471. }
  472. clear_socket(server, t)
  473. InputTests(t, server, &d, "CP437")
  474. t.Logf("server close")
  475. log.Println("server close")
  476. server.Close()
  477. time.Sleep(time.Millisecond)
  478. keyWait := time.Duration(50 * time.Millisecond)
  479. _, _, err = d.WaitKey(keyWait)
  480. if err != ErrDisconnected {
  481. t.Errorf("Expected ErrDisconnected, got %#v", err)
  482. }
  483. if !d.Disconnect() {
  484. t.Errorf("Disconnected flag shows: %t (should be true)", d.Disconnect())
  485. }
  486. _, _, err = d.WaitKey(time.Millisecond)
  487. if err != ErrDisconnected {
  488. t.Errorf("Expected ErrDisconnected, got %#v", err)
  489. }
  490. t.Logf("client close")
  491. client.Close()
  492. time.Sleep(time.Millisecond)
  493. t.Logf("Input on closed server and client")
  494. var blank string = d.Input(5)
  495. if blank != "" {
  496. t.Errorf("Input should return blank (hangup).")
  497. }
  498. _, _, err = d.WaitKey(time.Millisecond)
  499. if err != ErrDisconnected {
  500. t.Errorf("Expected ErrDisconnected, got %#v", err)
  501. }
  502. d.Write("\x00")
  503. time.Sleep(time.Millisecond)
  504. }
  505. func TestDoorUnicode(t *testing.T) {
  506. var tmpFile *os.File
  507. var err error
  508. // Dropfile
  509. tmpFile, err = os.CreateTemp("", "test-door32.sys-*")
  510. if err != nil {
  511. panic("Cannot create temporary file")
  512. }
  513. defer os.Remove(tmpFile.Name())
  514. // establish network socket connection to set Comm_handle
  515. var server, client net.Conn
  516. server, client = setupSockets()
  517. // Ok, we have a server socket, and the client socket (that the door would talk to)
  518. // unicode 190x43 response
  519. buffer := UnicodeWidthHeight(190, 43)
  520. _, err = server.Write([]byte(buffer))
  521. if err != nil {
  522. t.Error("server.Write:", err)
  523. }
  524. time.Sleep(time.Millisecond)
  525. // Access Fd (File descriptor) of client for dropfile
  526. var fd int = socket_to_fd(client)
  527. defer close_fd(fd)
  528. // Create door32.sys file
  529. var node int = 11
  530. dfc := DropfileConfig{2, fd, "Test BBSID", 1701, "Real Username", "Handle", 880, 28, node}
  531. err = CreateDoor32File(&dfc, tmpFile)
  532. if err != nil {
  533. t.Error("tmpFile.WriteString:", err)
  534. }
  535. err = tmpFile.Close()
  536. if err != nil {
  537. t.Error("tmpFile.Close:", err)
  538. }
  539. d := Door{} // Deprecated: ReaderCanClose: true}
  540. // Because we're not the only one calling door.Init(), the
  541. // door global variables might be from a previous test run.
  542. // Reset back to defaults.
  543. Unicode = false
  544. CP437 = false
  545. Full_CP437 = false
  546. Width = 0
  547. Height = 0
  548. // If I call d.Init() more then once flag complains about flag redefined.
  549. // Reset flags
  550. flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
  551. // preset commandline args so door can init
  552. os.Args = []string{"door", "-d", tmpFile.Name()}
  553. d.Init("input-test")
  554. defer d.Close()
  555. // clean up logfile - (filename is from Init name + node #)
  556. if !KEEP_LOGS {
  557. defer os.Remove(fmt.Sprintf("input-test-%d.log", node))
  558. }
  559. // Ok!
  560. if !Unicode {
  561. t.Errorf("Unicode not true %t", Unicode)
  562. }
  563. if Width != 190 {
  564. t.Errorf("Width not 190: %d", Width)
  565. }
  566. if Height != 43 {
  567. t.Errorf("Height not 43: %d", Height)
  568. }
  569. clear_socket(server, t)
  570. keyWait := time.Duration(50 * time.Millisecond)
  571. InputTests(t, server, &d, "Unicode")
  572. buffer = "\U0001f9201234\r"
  573. // double wide (2) + 4 = 6, we're inputting 5.
  574. _, err = server.Write([]byte(buffer))
  575. if err != nil {
  576. t.Error("server.Write:", err)
  577. }
  578. time.Sleep(time.Millisecond)
  579. // Unicode mode can handle unicode input. CP437 mode can't -- really.
  580. input := d.Input(5)
  581. expect := "\U0001f920123"
  582. if input != expect {
  583. t.Errorf("Expected Input(5) = %#v, but got %#v", expect, input)
  584. }
  585. clear_socket(server, t)
  586. t.Logf("server close")
  587. log.Println("server close")
  588. server.Close()
  589. time.Sleep(time.Millisecond)
  590. _, _, err = d.WaitKey(keyWait)
  591. if err != ErrDisconnected {
  592. t.Errorf("Expected ErrDisconnected, got %#v", err)
  593. }
  594. if !d.Disconnect() {
  595. t.Errorf("Disconnected flag shows: %t (should be true)", d.Disconnect())
  596. }
  597. _, _, err = d.WaitKey(time.Millisecond)
  598. if err != ErrDisconnected {
  599. t.Errorf("Expected ErrDisconnected, got %#v", err)
  600. }
  601. t.Logf("client close")
  602. client.Close()
  603. time.Sleep(time.Millisecond)
  604. t.Logf("Input on closed server and client")
  605. var blank string = d.Input(5)
  606. if blank != "" {
  607. t.Errorf("Input should return blank (hangup).")
  608. }
  609. _, _, err = d.WaitKey(time.Millisecond)
  610. if err != ErrDisconnected {
  611. t.Errorf("Expected ErrDisconnected, got %#v", err)
  612. }
  613. d.Write("\x00")
  614. time.Sleep(time.Millisecond)
  615. }