dfc3beff4ef7c3e819c9c94c2b29495dc9cff333
[gd/samba-autobuild/.git] / source4 / torture / com / simple.c
1 /* 
2    Unix SMB/CIFS implementation.
3    run the "simple" example (D)COM program 
4
5    Copyright (C) Jelmer Vernooij 2004
6    
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.
11    
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.
16    
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.
20 */
21
22 #include "includes.h"
23 #include "lib/com/com.h"
24 #include "librpc/gen_ndr/com_dcom.h"
25
26 #define DEFAULT_TRANS 4096
27
28 static BOOL test_readwrite(TALLOC_CTX *mem_ctx, const char *host)
29 {
30         struct dcerpc_pipe *p = NULL;
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;
40
41         com_init(&ctx);
42         dcom_client_init(ctx, lp_parm_string(-1, "torture", "userdomain"), lp_parm_string(-1, "torture", "username"), lp_parm_string(-1, "torture", "password"));
43
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);
47
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);
55         }
56
57         if (!W_ERROR_IS_OK(error)) {
58                 printf("(d)com_create_object failed - %s\n", win_errstr(error));
59                 return False;
60         }
61         
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;
66         }
67
68         for (i = 0; i < 5; i++) {
69                 test_data[i] = i+1;
70         }
71
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;
76         }
77
78         IUnknown_Release((struct IUnknown *)interfaces[1], mem_ctx);
79
80         torture_rpc_close(p);
81
82         return True;
83 }
84
85 BOOL torture_com_simple(void)
86 {
87         BOOL ret = True;
88         TALLOC_CTX *mem_ctx = talloc_init("torture_dcom_simple");
89         const char *host = lp_parm_string(-1, "dcom", "host");
90
91         ret &= test_readwrite(mem_ctx, host);
92
93         talloc_free(mem_ctx);
94
95         return ret;
96 }