r5941: Commit this patch much earlier than I would normally prefer, but metze needs...
[Samba/aatanasov.git] / source / torture / com / simple.c
blob25800896dbf0ecff08f6f1cd01d2c257aa73cc34
1 /*
2 Unix SMB/CIFS implementation.
3 run the "simple" example (D)COM program
5 Copyright (C) Jelmer Vernooij 2004
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "includes.h"
23 #include "lib/com/com.h"
24 #include "librpc/gen_ndr/com_dcom.h"
25 #include "lib/cmdline/popt_common.h"
27 #define DEFAULT_TRANS 4096
29 static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
31 BOOL ret = True;
32 struct GUID IID[2];
33 struct GUID clsid;
34 WERROR error;
35 struct IUnknown *interfaces[3];
36 WERROR results[2];
37 struct com_context *ctx;
38 char test_data[5];
39 int i;
41 com_init(&ctx);
42 dcom_client_init(ctx, cmdline_credentials);
44 GUID_from_string(COM_ISTREAM_UUID, &IID[0]);
45 GUID_from_string(COM_IUNKNOWN_UUID, &IID[1]);
46 GUID_from_string(CLSID_SIMPLE, &clsid);
48 if (host) {
49 error = dcom_create_object(ctx, &clsid,
50 host, 2, IID,
51 &interfaces,
52 results);
53 } else {
54 error = com_create_object(ctx, &clsid, 2, IID, interfaces, results);
57 if (!W_ERROR_IS_OK(error)) {
58 printf("(d)com_create_object failed - %s\n", win_errstr(error));
59 return False;
62 error = IStream_Read((struct IStream *)interfaces[0], mem_ctx, NULL, 20, 20, 30);
63 if (!W_ERROR_IS_OK(error)) {
64 printf("IStream::Read() failed - %s\n", win_errstr(error));
65 ret = False;
68 for (i = 0; i < 5; i++) {
69 test_data[i] = i+1;
72 error = IStream_Write((struct IStream *)interfaces[0], mem_ctx, &test_data, 5, NULL);
73 if (!W_ERROR_IS_OK(error)) {
74 printf("IStream::Write() failed - %s\n", win_errstr(error));
75 ret = False;
78 IUnknown_Release((struct IUnknown *)interfaces[1], mem_ctx);
80 return True;
83 BOOL torture_com_simple(void)
85 BOOL ret = True;
86 TALLOC_CTX *mem_ctx = talloc_init("torture_dcom_simple");
87 const char *host = lp_parm_string(-1, "dcom", "host");
89 ret &= test_readwrite(mem_ctx, host);
91 talloc_free(mem_ctx);
93 return ret;