s3: Fix a typo
[Samba/gebeck_regimport.git] / libcli / echo / tests / echo.c
blob6424c8100163544c57a53c8ec2ace1ded49392a0
1 /*
2 Unix SMB/CIFS implementation.
4 Example echo torture tests
6 Copyright (C) 2010 Kai Blin <kai@samba.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "torture/smbtorture.h"
24 #include "libcli/resolve/resolve.h"
25 #include <tevent.h>
26 #include "libcli/util/ntstatus.h"
27 #include "libcli/echo/libecho.h"
29 NTSTATUS torture_libcli_echo_init(void);
31 /* Basic test function that sends an echo request and checks the reply */
32 static bool echo_udp_basic(struct torture_context *tctx, const char *address)
34 struct tevent_req *req;
35 NTSTATUS status;
36 const char *msg_send = "This is a test string\n";
37 char *msg_recv;
39 req = echo_request_send(tctx, tctx->ev, address, msg_send);
40 torture_assert(tctx, req != NULL,
41 "echo_request_send returned non-null tevent_req");
43 while(tevent_req_is_in_progress(req)) {
44 tevent_loop_once(tctx->ev);
47 status = echo_request_recv(req, tctx, &msg_recv);
48 torture_assert_ntstatus_ok(tctx, status,
49 "echo_request_recv returned ok");
51 torture_assert_str_equal(tctx, msg_recv, msg_send,
52 "Echo server echoed request string");
54 return true;
57 /*Test case to set up the environment and perform UDP-based echo tests */
58 static bool torture_echo_udp(struct torture_context *tctx)
60 const char *address;
61 struct nbt_name name;
62 NTSTATUS status;
63 bool ret = true;
65 make_nbt_name_server(&name,
66 torture_setting_string(tctx, "host", NULL));
67 status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx),
68 0, 0,
69 &name, tctx,
70 &address, tctx->ev);
71 if (!NT_STATUS_IS_OK(status)) {
72 printf("Failed to resolve %s - %s\n", name.name,
73 nt_errstr(status));
74 return false;
77 /* All tests are now called here */
78 ret &= echo_udp_basic(tctx, address);
80 return ret;
83 /* Test suite that bundles all the libecho tests */
84 NTSTATUS torture_libcli_echo_init(void)
86 struct torture_suite *suite;
88 suite = torture_suite_create(talloc_autofree_context(), "echo");
89 NT_STATUS_HAVE_NO_MEMORY(suite);
91 torture_suite_add_simple_test(suite, "udp", torture_echo_udp);
93 suite->description = talloc_strdup(suite, "libcli/echo interface tests");
94 torture_register_suite(suite);
96 return NT_STATUS_OK;