-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
119 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
*.pyc | ||
*~ | ||
test_subs | ||
test_log | ||
test_main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include <cut> | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
|
||
#include "zmq.h" | ||
#include "zmq_utils.h" | ||
|
||
#if defined( TESTSTANDALONE ) | ||
# include "test_main.C" | ||
#endif // TESTSTANDALONE | ||
|
||
namespace cut { | ||
static force force_log; | ||
CUT( root, log, "log" ) { | ||
void *sock[10]; | ||
int socknum = 0; | ||
|
||
void *ctx = zmq_init (1); | ||
assert.ISTRUE (ctx); | ||
|
||
// Create a subscriber. | ||
void *sub = zmq_socket (ctx, ZMQ_SUB); | ||
assert.ISTRUE (sub); | ||
sock[socknum++] = sub; | ||
int rc = zmq_connect (sub, "sys://log"); | ||
assert.ISEQUAL (rc, 0); | ||
|
||
// Subscribe for all messages. | ||
rc = zmq_setsockopt (sub, ZMQ_SUBSCRIBE, "", 0); | ||
assert.ISEQUAL (rc, 0); | ||
|
||
int timeout = 250; | ||
rc = zmq_setsockopt (sub, ZMQ_RCVTIMEO, &timeout, sizeof timeout); | ||
assert.ISEQUAL (rc, 0); | ||
|
||
char buff [32]; | ||
rc = zmq_recv (sub, buff, sizeof (buff), 0); | ||
assert.ISEQUAL (rc, -1); | ||
|
||
rc = zmq_log (ctx, "Hello, %s!", "World"); | ||
assert.ISEQUAL (rc, 0); | ||
|
||
rc = zmq_recv (sub, buff, sizeof (buff), 0); | ||
assert.ISEQUAL (rc, 14); | ||
if (rc >0) | ||
printf("sub sys://log received: %s\n", buff); | ||
|
||
// Clean up. | ||
for (int i = 0 | ||
; i < socknum | ||
; ++i) { | ||
rc = zmq_close (sock[i]); | ||
assert.ISEQUAL (rc, 0); | ||
} | ||
rc = zmq_term (ctx); | ||
assert.ISEQUAL (rc, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <cut> | ||
#include <stdlib.h> | ||
|
||
namespace cut { | ||
test root( "0MQ Unit Tests" ); | ||
} | ||
|
||
int | ||
main( int, char ** ) | ||
{ | ||
bool success; | ||
if ( getenv( "REQUEST_METHOD" )) { | ||
// | ||
// Lets run our tests with CGI HTML output: | ||
// | ||
// target sparse flat cgi | ||
// ------ ------ ---- --- | ||
success = cut::htmlrunner( std::cout, false, true, true ).run(); | ||
} else { | ||
// | ||
// But, here's the (simpler) textual output: | ||
// | ||
success = cut::runner( std::cout ).run(); | ||
} | ||
|
||
return ! success; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters