mirror of
https://github.com/sbrow/zomq.git
synced 2026-08-26 10:53:32 -04:00
test: Migrated custom test to proper test.
This commit is contained in:
@@ -1,28 +0,0 @@
|
||||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import zmq "../"
|
||||
|
||||
main :: proc() {
|
||||
ctx := zmq.ctx_new()
|
||||
defer zmq.ctx_term(ctx)
|
||||
|
||||
rep1, _ := zmq.socket(ctx, .REP)
|
||||
defer zmq.close(rep1)
|
||||
zmq.bind(rep1, "tcp://*:5555")
|
||||
|
||||
rep2, _ := zmq.socket(ctx, .REP)
|
||||
defer zmq.close(rep2)
|
||||
if err := zmq.bind(rep2, "tcp://*:5555"); err != nil {
|
||||
fmt.eprintfln("bind failed: %s", zmq.strerror(err))
|
||||
switch e in err {
|
||||
case zmq.ZMQ_Error:
|
||||
fmt.eprintfln(" variant: ZMQ_Error, member: %v", e)
|
||||
case os.Platform_Error:
|
||||
fmt.eprintfln(" variant: Platform_Error, member: %v", e)
|
||||
case:
|
||||
fmt.eprintfln(" variant: nil")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ test_version :: proc(t: ^testing.T) {
|
||||
|
||||
@(test)
|
||||
test_connect_does_not_allocate_with_string_literals :: proc(t: ^testing.T) {
|
||||
context.allocator = runtime.panic_allocator()
|
||||
context.temp_allocator = runtime.panic_allocator()
|
||||
|
||||
ctx := ctx_new()
|
||||
@@ -115,3 +116,34 @@ test_simple_const_echo :: proc(t: ^testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
@(test)
|
||||
test_duplicate_bind_fails :: proc(t: ^testing.T) {
|
||||
ctx := ctx_new()
|
||||
defer ctx_term(ctx)
|
||||
|
||||
rep1, serr := socket(ctx, .REP)
|
||||
testing.expect_value(t, serr, nil)
|
||||
if serr != nil {
|
||||
testing.fail_now(t, "create first socket")
|
||||
}
|
||||
defer close(rep1)
|
||||
|
||||
if berr := bind(rep1, "inproc://duplicate"); berr != nil {
|
||||
testing.expect_value(t, berr, nil)
|
||||
testing.fail_now(t, "first bind should succeed")
|
||||
}
|
||||
|
||||
rep2, cerr := socket(ctx, .REP)
|
||||
testing.expect_value(t, cerr, nil)
|
||||
if cerr != nil {
|
||||
testing.fail_now(t, "create second socket")
|
||||
}
|
||||
defer close(rep2)
|
||||
|
||||
if berr := bind(rep2, "inproc://duplicate"); berr == nil {
|
||||
testing.fail_now(t, "second bind to same endpoint should fail with EADDRINUSE")
|
||||
} else {
|
||||
testing.expect_value(t, berr, ZMQ_Error.EADDRINUSE)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user