summaryrefslogtreecommitdiffstats
path: root/testprogs/win32/midltests
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2008-02-06 16:34:36 +0100
committerStefan Metzmacher <metze@samba.org>2008-02-06 16:34:36 +0100
commitc6a6fa184125f94a0891b613daffb44d93d0e803 (patch)
tree84b7297e648a8f538d56bc944e5d52b0fb88565e /testprogs/win32/midltests
parent3a0cfad2238ce5701102587c6b50ef088c7c55ba (diff)
downloadsamba-c6a6fa184125f94a0891b613daffb44d93d0e803.tar.gz
samba-c6a6fa184125f94a0891b613daffb44d93d0e803.tar.xz
samba-c6a6fa184125f94a0891b613daffb44d93d0e803.zip
win32-tests: add a very usefull w32 programm to explore midl features
You have to define idl, call the client function and add a server implementation. Then you need to compile midltests.exe and run it, it will dump the generated NDR on the screen. metze (This used to be commit dc15c8833599a1cb8f51c2b5390925410cbf4e12)
Diffstat (limited to 'testprogs/win32/midltests')
-rw-r--r--testprogs/win32/midltests/midltests.acf6
-rw-r--r--testprogs/win32/midltests/midltests.c42
-rw-r--r--testprogs/win32/midltests/midltests.idl27
-rw-r--r--testprogs/win32/midltests/midltests_c_m.c2
-rw-r--r--testprogs/win32/midltests/midltests_marshall.c121
-rw-r--r--testprogs/win32/midltests/midltests_marshall.h16
-rw-r--r--testprogs/win32/midltests/midltests_s_m.c2
-rw-r--r--testprogs/win32/midltests/utils.c32
8 files changed, 248 insertions, 0 deletions
diff --git a/testprogs/win32/midltests/midltests.acf b/testprogs/win32/midltests/midltests.acf
new file mode 100644
index 0000000000..a04bb5dcd9
--- /dev/null
+++ b/testprogs/win32/midltests/midltests.acf
@@ -0,0 +1,6 @@
+[
+ implicit_handle (handle_t midltests_IfHandle)
+]
+interface midltests
+{
+}
diff --git a/testprogs/win32/midltests/midltests.c b/testprogs/win32/midltests/midltests.c
new file mode 100644
index 0000000000..61d4ce0812
--- /dev/null
+++ b/testprogs/win32/midltests/midltests.c
@@ -0,0 +1,42 @@
+/*
+ MIDLTESTS client.
+
+ Copyright (C) Stefan Metzmacher 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "midltests.h"
+
+#define MIDLTESTS_C_CODE 1
+#include "midltests.idl"
+
+int main(int argc, char **argv)
+{
+ int ret;
+
+ midltests_IfHandle = NULL;
+
+ RpcTryExcept {
+ midltests();
+ } RpcExcept(1) {
+ ret = RpcExceptionCode();
+ printf("Runtime error 0x%x\n", ret);
+ } RpcEndExcept
+
+ return ret;
+}
diff --git a/testprogs/win32/midltests/midltests.idl b/testprogs/win32/midltests/midltests.idl
new file mode 100644
index 0000000000..1932549c56
--- /dev/null
+++ b/testprogs/win32/midltests/midltests.idl
@@ -0,0 +1,27 @@
+#ifndef MIDLTESTS_C_CODE
+
+[
+ uuid("225b9fcb-eb3d-497b-8b0b-591f049a2507"),
+ pointer_default(unique)
+]
+interface midltests
+{
+ long midltests_fn(
+ );
+}
+
+#elif MIDLTESTS_C_CODE
+
+static void midltests(void)
+{
+ cli_midltests_fn();
+}
+
+long srv_midltests_fn(void)
+{
+ printf("srv_midltests_fn: Start\n");
+ printf("srv_midltests_fn: End\n");
+ return 0x65757254;
+}
+
+#endif \ No newline at end of file
diff --git a/testprogs/win32/midltests/midltests_c_m.c b/testprogs/win32/midltests/midltests_c_m.c
new file mode 100644
index 0000000000..facf735304
--- /dev/null
+++ b/testprogs/win32/midltests/midltests_c_m.c
@@ -0,0 +1,2 @@
+#include "midltests_marshall.h"
+#include "midltests_c.c"
diff --git a/testprogs/win32/midltests/midltests_marshall.c b/testprogs/win32/midltests/midltests_marshall.c
new file mode 100644
index 0000000000..e772afd03d
--- /dev/null
+++ b/testprogs/win32/midltests/midltests_marshall.c
@@ -0,0 +1,121 @@
+/*
+ MIDLTESTS client.
+
+ Copyright (C) Stefan Metzmacher 2008
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include "midltests.h"
+
+#define MIN(a,b) ((a)<(b)?(a):(b))
+static void print_asc(const unsigned char *buf,int len)
+{
+ int i;
+ for (i=0;i<len;i++)
+ printf("%c", isprint(buf[i])?buf[i]:'.');
+}
+
+static void dump_data(const unsigned char *buf1,int len)
+{
+ const unsigned char *buf = (const unsigned char *)buf1;
+ int i=0;
+ if (len<=0) return;
+
+ printf("[%03X] ",i);
+ for (i=0;i<len;) {
+ printf("%02X ",(int)buf[i]);
+ i++;
+ if (i%8 == 0) printf(" ");
+ if (i%16 == 0) {
+ print_asc(&buf[i-16],8); printf(" ");
+ print_asc(&buf[i-8],8); printf("\n");
+ if (i<len) printf("[%03X] ",i);
+ }
+ }
+ if (i%16) {
+ int n;
+ n = 16 - (i%16);
+ printf(" ");
+ if (n>8) printf(" ");
+ while (n--) printf(" ");
+ n = MIN(8,i%16);
+ print_asc(&buf[i-(i%16)],n); printf( " " );
+ n = (i%16) - n;
+ if (n>0) print_asc(&buf[i-n],n);
+ printf("\n");
+ }
+}
+
+void NdrGetBufferMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned long len, RPC_BINDING_HANDLE hnd)
+{
+ stubmsg->RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, len);
+ memset(stubmsg->RpcMsg->Buffer, 0xef, len);
+ stubmsg->RpcMsg->BufferLength = len;
+ stubmsg->Buffer = stubmsg->RpcMsg->Buffer;
+ stubmsg->BufferLength = stubmsg->RpcMsg->BufferLength;
+ stubmsg->fBufferValid = TRUE;
+}
+
+void __RPC_STUB midltests_midltests_fn(PRPC_MESSAGE _pRpcMessage);
+
+void NdrSendReceiveMarshall(PMIDL_STUB_MESSAGE StubMsg, unsigned char *buffer)
+{
+ unsigned long DataRepresentation;
+
+ StubMsg->RpcMsg->BufferLength = buffer - (unsigned char *)StubMsg->RpcMsg->Buffer;
+
+ printf("[in] Buffer[%d/%d]\n",
+ StubMsg->RpcMsg->BufferLength, StubMsg->BufferLength);
+ dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength);
+
+ DataRepresentation = StubMsg->RpcMsg->DataRepresentation;
+ StubMsg->RpcMsg->DataRepresentation = NDR_LOCAL_DATA_REPRESENTATION;
+ midltests_midltests_fn(StubMsg->RpcMsg);
+ StubMsg->RpcMsg->DataRepresentation = DataRepresentation;
+
+ StubMsg->BufferLength = StubMsg->RpcMsg->BufferLength;
+ StubMsg->BufferStart = StubMsg->RpcMsg->Buffer;
+ StubMsg->BufferEnd = StubMsg->BufferStart + StubMsg->BufferLength;
+ StubMsg->Buffer = StubMsg->BufferStart;
+
+ printf("[out] Buffer[%d]\n",
+ StubMsg->RpcMsg->BufferLength);
+ dump_data(StubMsg->RpcMsg->Buffer, StubMsg->RpcMsg->BufferLength);
+}
+
+void NdrServerInitializeNewMarshall(PRPC_MESSAGE pRpcMsg,
+ PMIDL_STUB_MESSAGE pStubMsg,
+ PMIDL_STUB_DESC pStubDesc)
+{
+ memset(pStubMsg, 0, sizeof(*pStubMsg));
+ pStubMsg->RpcMsg = pRpcMsg;
+ pStubMsg->Buffer = pStubMsg->BufferStart = pRpcMsg->Buffer;
+ pStubMsg->BufferEnd = pStubMsg->Buffer + pRpcMsg->BufferLength;
+ pStubMsg->BufferLength = pRpcMsg->BufferLength;
+ pStubMsg->pfnAllocate = pStubDesc->pfnAllocate;
+ pStubMsg->pfnFree = pStubDesc->pfnFree;
+ pStubMsg->StubDesc = pStubDesc;
+ pStubMsg->dwDestContext = MSHCTX_DIFFERENTMACHINE;
+}
+
+RPC_STATUS WINAPI I_RpcGetBufferMarshall(PRPC_MESSAGE RpcMsg)
+{
+ RpcMsg->Buffer = HeapAlloc(GetProcessHeap(), 0, RpcMsg->BufferLength);
+ memset(RpcMsg->Buffer, 0xcd, RpcMsg->BufferLength);
+ return 0;
+}
diff --git a/testprogs/win32/midltests/midltests_marshall.h b/testprogs/win32/midltests/midltests_marshall.h
new file mode 100644
index 0000000000..0c6aed2721
--- /dev/null
+++ b/testprogs/win32/midltests/midltests_marshall.h
@@ -0,0 +1,16 @@
+#include "rpc.h"
+#include "rpcndr.h"
+#define NdrSendReceive NdrSendReceiveMarshall
+void NdrSendReceiveMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned char *buffer);
+#define NdrGetBuffer NdrGetBufferMarshall
+void NdrGetBufferMarshall(PMIDL_STUB_MESSAGE stubmsg, unsigned long len, RPC_BINDING_HANDLE hnd);
+#define NdrServerInitializeNew NdrServerInitializeNewMarshall
+void NdrServerInitializeNewMarshall(PRPC_MESSAGE pRpcMsg,
+ PMIDL_STUB_MESSAGE pStubMsg,
+ PMIDL_STUB_DESC pStubDesc);
+#define I_RpcGetBuffer I_RpcGetBufferMarshall
+RPC_STATUS WINAPI I_RpcGetBufferMarshall(PRPC_MESSAGE pMsg);
+
+
+
+
diff --git a/testprogs/win32/midltests/midltests_s_m.c b/testprogs/win32/midltests/midltests_s_m.c
new file mode 100644
index 0000000000..7e0862dc69
--- /dev/null
+++ b/testprogs/win32/midltests/midltests_s_m.c
@@ -0,0 +1,2 @@
+#include "midltests_marshall.h"
+#include "midltests_s.c"
diff --git a/testprogs/win32/midltests/utils.c b/testprogs/win32/midltests/utils.c
new file mode 100644
index 0000000000..8c4833ddb4
--- /dev/null
+++ b/testprogs/win32/midltests/utils.c
@@ -0,0 +1,32 @@
+/*
+ MIDLTESTS utility functions.
+
+ Copyright (C) Tim Potter 2003
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "midltests.h"
+
+/* MIDL allocate and free functions */
+
+void __RPC_FAR *__RPC_USER midl_user_allocate(size_t len)
+{
+ return(malloc(len));
+}
+
+void __RPC_USER midl_user_free(void __RPC_FAR *ptr)
+{
+ free(ptr);
+}