-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from trilogy-libraries/add-connection-check2
Add connection check to Trilogy
- Loading branch information
Showing
6 changed files
with
133 additions
and
0 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
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
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
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,68 @@ | ||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "test.h" | ||
|
||
#include "trilogy/client.h" | ||
#include "trilogy/error.h" | ||
|
||
#define do_connect(CONN) \ | ||
do { \ | ||
int err = trilogy_init(CONN); \ | ||
ASSERT_OK(err); \ | ||
err = trilogy_connect(CONN, get_connopt()); \ | ||
ASSERT_OK(err); \ | ||
} while (0) | ||
|
||
TEST test_check_connected() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
|
||
int err = trilogy_sock_check(conn.socket); | ||
ASSERT_OK(err); | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
|
||
TEST test_check_disconnected() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
shutdown(trilogy_sock_fd(conn.socket), SHUT_RD); | ||
|
||
int err = trilogy_sock_check(conn.socket); | ||
ASSERT_ERR(TRILOGY_CLOSED_CONNECTION, err); | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
TEST test_check_closed() | ||
{ | ||
trilogy_conn_t conn; | ||
|
||
do_connect(&conn); | ||
close_socket(&conn); | ||
|
||
int err = trilogy_sock_check(conn.socket); | ||
ASSERT_ERR(TRILOGY_SYSERR, err); | ||
|
||
trilogy_free(&conn); | ||
PASS(); | ||
} | ||
|
||
int socket_test() | ||
{ | ||
RUN_TEST(test_check_connected); | ||
RUN_TEST(test_check_disconnected); | ||
RUN_TEST(test_check_closed); | ||
|
||
return 0; | ||
} |