widl/rpcrt4: Add more basic tests for RPC stub code

Dan Hipschman dsh at linux.ucla.edu
Thu Apr 19 20:21:11 CDT 2007


This patch only applies on top of the previous two patches I sent today.
It adds a few basic tests for the stub code generated by widl.  They all
pass under wine and XP SP1 (I don't have access to an SP2 box I can test
on).  A lot of more advanced things I tried to put in widl couldn't com-
pile.  Having these kinds of tests should make fixing widl a lot easier,
though.

---
 dlls/rpcrt4/tests/server.c      |   65 ++++++++++++++++++++++++++++++++++++++-
 dlls/rpcrt4/tests/server.idl    |   16 +++++++++
 dlls/rpcrt4/tests/server_test.c |   38 ++++++++++++++++++++++
 3 files changed, 118 insertions(+), 1 deletions(-)

diff --git a/dlls/rpcrt4/tests/server.c b/dlls/rpcrt4/tests/server.c
index 8f8bf93..395c5a8 100644
--- a/dlls/rpcrt4/tests/server.c
+++ b/dlls/rpcrt4/tests/server.c
@@ -21,12 +21,71 @@
 #include "wine/test.h"
 #include "server.h"
 
+#include <string.h>
+
 int
 Test(void)
 {
   return TESTCODE;
 }
 
+int
+Square(int x)
+{
+  return x * x;
+}
+
+int
+Sum(int x, int y)
+{
+  return x + y;
+}
+
+void
+SquareOut(int x, int *y)
+{
+  *y = Square(x);
+}
+
+void
+SquareRef(int *x)
+{
+  *x = Square(*x);
+}
+
+int
+StrLen(const char *s)
+{
+  return strlen(s);
+}
+
+int
+DotSelf(SERVER_VECTOR *v)
+{
+  return Square(v->x) + Square(v->y) + Square(v->z);
+}
+
+double
+SquareHalf(double x, double *y)
+{
+  *y = x / 2.0;
+  return x * x;
+}
+
+float
+SquareHalfFloat(float x, float *y)
+{
+  *y = x / 2.0f;
+  return x * x;
+}
+
+long
+SquareHalfLong(long x, long *y)
+{
+  *y = x / 2;
+  return x * x;
+}
+
 HANDLE event;
 
 void
@@ -43,6 +102,7 @@ START_TEST(server)
 {
   static unsigned char protseq[] = PROTSEQ;
   static unsigned char endpoint[] = ENDPOINT;
+  int client_ok;
 
   ok(RPC_S_OK == RpcServerUseProtseqEp(protseq, 20, endpoint, NULL),
      "RpcServerUseProtseqEp failed\n");
@@ -54,7 +114,10 @@ START_TEST(server)
   event = CreateEvent(NULL, FALSE, FALSE, NULL);
   ok(event != NULL, "CreateEvent failed\n");
 
-  ok(winetest_run_testclient("server_test"), "client process failed\n");
+  client_ok = winetest_run_testclient("server_test");
+  ok(client_ok, "client process failed\n");
+  if (!client_ok)
+    Stop();
 
   ok(WAIT_OBJECT_0 == WaitForSingleObject(event, INFINITE),
      "WaitForSingleObject failed\n");
diff --git a/dlls/rpcrt4/tests/server.idl b/dlls/rpcrt4/tests/server.idl
index aa63edf..01927e5 100644
--- a/dlls/rpcrt4/tests/server.idl
+++ b/dlls/rpcrt4/tests/server.idl
@@ -23,6 +23,13 @@ cpp_quote("#define PROTSEQ \"ncacn_ip_tcp\"")
 cpp_quote("#define ENDPOINT \"4114\"")
 cpp_quote("#define TESTCODE 4114")
 
+typedef struct tagSERVER_VECTOR
+{
+  int x;
+  int y;
+  int z;
+} SERVER_VECTOR;
+
 [
   uuid(00000000-4114-0704-1701-000000000000),
   implicit_handle(handle_t IServer_IfHandle)
@@ -30,5 +37,14 @@ cpp_quote("#define TESTCODE 4114")
 interface IServer
 {
   int Test(void);
+  int Square(int x);
+  int Sum(int x, int y);
+  void SquareOut(int x, [out] int *y);
+  void SquareRef([in, out] int *x);
+  int StrLen([string] const char *s);
+  int DotSelf(SERVER_VECTOR *v);
+  double SquareHalf(double x, [out] double *y);
+  float SquareHalfFloat(float x, [out] float *y);
+  long SquareHalfLong(long x, [out] long *y);
   void Stop(void);
 }
diff --git a/dlls/rpcrt4/tests/server_test.c b/dlls/rpcrt4/tests/server_test.c
index d5f36c7..5f2a19e 100644
--- a/dlls/rpcrt4/tests/server_test.c
+++ b/dlls/rpcrt4/tests/server_test.c
@@ -21,12 +21,20 @@
 #include "wine/test.h"
 #include "server.h"
 
+#include <string.h>
+
 START_TEST(server_test)
 {
   static unsigned char protseq[] = PROTSEQ;
   static unsigned char endpoint[] = ENDPOINT;
   static unsigned char address[] = "127.0.0.1";
+  static char string[] = "I am a string";
+  static SERVER_VECTOR a = {1, 3, 7};
   unsigned char *binding;
+  double u, v;
+  float s, t;
+  long q, r;
+  int x;
 
   ok(RPC_S_OK == RpcStringBindingCompose(NULL, protseq, address,
                                          endpoint, NULL, &binding),
@@ -35,6 +43,36 @@ START_TEST(server_test)
      "RpcBindingFromStringBinding failed\n");
 
   ok(Test() == TESTCODE, "RPC `Test' returned the wrong result\n");
+  ok(Square(7) == 49, "RPC `Square' returned the wrong result\n");
+  ok(Sum(23, -4) == 19, "RPC `Sum' returned the wrong result\n");
+
+  x = 0;
+  SquareOut(11, &x);
+  ok(x == 121, "RPC `SquareOut' returned the wrong result\n");
+
+  x = 5;
+  SquareRef(&x);
+  ok(x == 25, "RPC `SquareRef' returned the wrong result\n");
+
+  ok(StrLen(string) == strlen(string),
+     "RPC `StrLen' returned the wrong result\n");
+  ok(DotSelf(&a) == 59, "RPC `DotSelf' returned the wrong result\n");
+
+  v = 0.0;
+  u = SquareHalf(3.0, &v);
+  ok(u == 9.0, "RPC `SquareHalf' returned the wrong result\n");
+  ok(v == 1.5, "RPC `SquareHalf' returned the wrong result\n");
+
+  t = 0.0f;
+  s = SquareHalfFloat(3.0f, &t);
+  ok(s == 9.0f, "RPC `SquareHalfFloat' returned the wrong result\n");
+  ok(t == 1.5f, "RPC `SquareHalfFloat' returned the wrong result\n");
+
+  r = 0;
+  q = SquareHalfLong(3, &r);
+  ok(q == 9, "RPC `SquareHalfLong' returned the wrong result\n");
+  ok(r == 1, "RPC `SquareHalfLong' returned the wrong result\n");
+
   Stop();
 
   ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree failed\n");



More information about the wine-patches mailing list