everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
blob 7e99b9eae084eafd06476f9fc700e38abaf053ed 1228 bytes (raw)
name: test/test_unixserver.rb 	 # note: path name is non-authoritative(*)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 
# Copyright (C) 2013-2020 all contributors <dtas-all@nongnu.org>
# License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
# frozen_string_literal: true
require './test/helper'
require 'tempfile'
require 'dtas/unix_server'
require 'stringio'

class TestUNIXServer < Testcase
  def setup
    @tmp = Tempfile.new(%w(dtas-unix_server-test .sock))
    File.unlink(@tmp.path)
    @clients = []
    @srv = DTAS::UNIXServer.new(@tmp.path)
  end

  def test_close
    assert File.exist?(@tmp.path)
    assert_nil @srv.close
    refute File.exist?(@tmp.path)
  end

  def teardown
    @clients.each(&:close)
    if File.exist?(@tmp.path)
      @tmp.close!
    else
      @tmp.close
    end
  end

  def new_client
    c = Socket.new(:AF_UNIX, :SEQPACKET, 0)
    @clients << c
    c.connect(Socket.pack_sockaddr_un(@tmp.path))
    c
  end

  def test_server_loop
    client = new_client
    @srv.run_once # nothing
    msgs = []
    clients = []
    client.send("HELLO", Socket::MSG_EOR)
    @srv.run_once do |c, msg|
      clients << c
      msgs << msg
    end
    assert_equal %w(HELLO), msgs, clients.inspect
    assert_equal 1, clients.size
    c = clients[0]
    c.emit "HIHI"
    assert_equal "HIHI", client.recv(4)
  end
end

debug log:

solving 7e99b9e ...
found 7e99b9e in https://80x24.org/dtas.git/

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://80x24.org/dtas.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).