Sha256: fec36100e99e40a428226887744c75d29c57a25c3c44e59264e41225d7ad404d

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# encoding: utf-8

require File.join(File.dirname(__FILE__), 'helper')

class TestPubSub < MosquittoTestCase
  def test_publish
    client = Mosquitto::Client.new
    client.loop_start
    assert_raises Mosquitto::Error do
      client.publish(nil, "publish", "test", Mosquitto::AT_MOST_ONCE, true)
    end
    assert client.connect(TEST_HOST, TEST_PORT, TIMEOUT)
    client.wait_readable

    assert_raises TypeError do
      client.publish(nil, :invalid, "test", Mosquitto::AT_MOST_ONCE, true)
    end
    assert client.publish(nil, "publish", "test", Mosquitto::AT_MOST_ONCE, true)
    assert client.publish(3, "publish", "test", Mosquitto::AT_MOST_ONCE, true)
  end

  def test_subscribe
    client = Mosquitto::Client.new
    client.loop_start
    assert_raises Mosquitto::Error do
      client.subscribe(nil, "subscribe", Mosquitto::AT_MOST_ONCE)
    end
    assert client.connect(TEST_HOST, TEST_PORT, TIMEOUT)
    client.wait_readable

    assert_raises TypeError do
      client.subscribe(nil, :topic, Mosquitto::AT_MOST_ONCE)
    end

    assert client.subscribe(nil, "subscribe", Mosquitto::AT_MOST_ONCE)
    assert client.subscribe(3, "subscribe", Mosquitto::AT_MOST_ONCE)
  end

  def test_unsubscribe
    client = Mosquitto::Client.new
    client.loop_start
    assert_raises Mosquitto::Error do
      client.unsubscribe(nil, "unsubscribe")
    end
    assert client.connect(TEST_HOST, TEST_PORT, TIMEOUT)
    client.wait_readable

    assert_raises TypeError do
      client.unsubscribe(nil, :topic)
    end

    assert client.unsubscribe(nil, "unsubscribe")
    assert client.unsubscribe(3, "unsubscribe")
  end

  def test_subscribe_unsubscribe
    client = Mosquitto::Client.new
    client.loop_start
    assert client.connect(TEST_HOST, TEST_PORT, TIMEOUT)
    client.wait_readable

    assert client.subscribe(nil, "subscribe_unsubscribe", Mosquitto::AT_MOST_ONCE)
    assert client.unsubscribe(nil, "subscribe_unsubscribe")
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mosquitto-0.3 test/test_pub_sub.rb