1
0
mirror of https://github.com/haiwen/libsearpc.git synced 2025-04-27 18:25:06 +00:00

named pipe transport: Added tests.

This commit is contained in:
Shuai Lin 2016-05-19 11:31:11 +08:00
parent b9234ae5dc
commit 1b6b5b8d9f
2 changed files with 38 additions and 5 deletions

7
.gitignore vendored
View File

@ -8,6 +8,7 @@
.deps .deps
*.db *.db
*.gz *.gz
compile
config.* config.*
autom4te.cache/* autom4te.cache/*
aclocal.m4 aclocal.m4
@ -51,6 +52,6 @@ tests/searpc-signature.h
tests/rpc_table.stamp tests/rpc_table.stamp
tests/rpc_table.tmp tests/rpc_table.tmp
tests/clar.suite tests/clar.suite
tests/.clarcache
tests/*.trs
test-driver

View File

@ -139,17 +139,19 @@ maman_bar_class_init (MamanBarClass *klass)
static void static void
maman_bar_init (MamanBar *self) maman_bar_init (MamanBar *self)
{ {
} }
/* sample client */ /* sample client */
static SearpcClient *client; static SearpcClient *client;
/* sample client with named pipe as transport */
static SearpcClient *client_with_pipe_transport;
char * char *
sample_send(void *arg, const gchar *fcall_str, sample_send(void *arg, const gchar *fcall_str,
size_t fcall_len, size_t *ret_len) size_t fcall_len, size_t *ret_len)
{ {
cl_assert (strcmp(arg, "test") == 0); cl_assert_ (strcmp(arg, "test") == 0, arg);
char *ret; char *ret;
/* directly call in memory, instead of send via network */ /* directly call in memory, instead of send via network */
@ -321,6 +323,26 @@ test_searpc__simple_call_async (void)
2, "string", "hello", "int", 10); 2, "string", "hello", "int", 10);
} }
void
test_searpc__pipe_simple_call (void)
{
gchar* result;
GError *error = NULL;
result = searpc_client_call__string (client_with_pipe_transport, "get_substring", &error,
2, "string", "hello", "int", 2);
cl_assert_ (error == NULL, error ? error->message : "");
cl_assert (strcmp(result, "he") == 0);
g_free (result);
/* error should return */
result = NULL;
result = searpc_client_call__string (client_with_pipe_transport, "get_substring", &error,
2, "string", "hello", "int", 10);
cl_assert (error->message);
g_free (result);
}
#include "searpc-signature.h" #include "searpc-signature.h"
#include "searpc-marshal.h" #include "searpc-marshal.h"
@ -346,6 +368,16 @@ test_searpc__initialize (void)
client->async_send = sample_async_send; client->async_send = sample_async_send;
client->async_arg = "test_async"; client->async_arg = "test_async";
const char *pipe_path = "/tmp/.searpc-test";
SearpcNamedPipeServer *pipe_server = searpc_create_named_pipe_server(pipe_path);
SearpcNamedPipeClient *pipe_client = searpc_create_named_pipe_client(pipe_path);
cl_must_pass_(searpc_named_pipe_server_start(pipe_server), "named pipe server failed to start");
cl_must_pass_(searpc_named_pipe_client_connect(pipe_client), "named pipe client failed to connect");
client_with_pipe_transport = searpc_client_with_named_pipe_transport(pipe_client, "test");
} }
void void