first commit

This commit is contained in:
2023-03-14 11:29:44 +07:00
commit b215f1a3ac
19 changed files with 1061 additions and 0 deletions

49
test/runtests.jl Normal file
View File

@@ -0,0 +1,49 @@
using Mosquitto, Test, Random
topic = "jltest"*randstring(5)
message = [1, 2, 3]
client = Client("test.mosquitto.org", 1883)
@testset "General" begin
Threads.nthreads()>1 && @test client.status.loop_status == 1
Threads.nthreads()==1 && @test client.status.loop_status == 0
@test loop_stop(client) == 0
end
@testset "Unauthenticated" begin
@test subscribe(client, topic) == 0
@test loop(client) == 0
while !isempty(Mosquitto.messages_channel)
# empty channel
take!(Mosquitto.messages_channel)
end
@test publish(client, topic, message; retain = false) == 0
loop(client, ntimes = 10)
@test Base.n_avail(Mosquitto.messages_channel) == 1
if Base.n_avail(Mosquitto.messages_channel) >= 1
@test Array(reinterpret(Int, take!(Mosquitto.messages_channel).payload)) == message
end
@test disconnect(client) == 0
end
client = Client("", 0; connectme = false)
@testset "Authenticated" begin
@test connect(client, "test.mosquitto.org", 1884; username = "rw", password = "readwrite") == 0
@test subscribe(client, topic) == 0
@test loop(client) == 0
while !isempty(Mosquitto.messages_channel)
# empty channel
take!(Mosquitto.messages_channel)
end
@test publish(client, topic, message; retain = false) == 0
loop(client, ntimes = 5)
loop(client; ntimes = 2, timeout = 5000)
@test Base.n_avail(Mosquitto.messages_channel) == 1
if Base.n_avail(Mosquitto.messages_channel) >= 1
@test Array(reinterpret(Int, take!(Mosquitto.messages_channel).payload)) == message
end
@test disconnect(client) == 0
end