[RPCRT4_WINETEST] Addendum to r73006.
[reactos.git] / rostests / winetests / rpcrt4 / server.c
index a822b31..c9814d3 100644 (file)
@@ -53,6 +53,9 @@ static char *domain_and_user;
 /* type check statements generated in header file */
 fnprintf *p_printf = printf;
 
+static const WCHAR helloW[] = { 'H','e','l','l','o',0 };
+static const WCHAR worldW[] = { 'W','o','r','l','d','!',0 };
+
 static void InitFunctionPointers(void)
 {
     HMODULE hrpcrt4 = GetModuleHandleA("rpcrt4.dll");
@@ -571,6 +574,34 @@ void __cdecl s_get_name(name_t *name)
     name->name[name->size - 1] = 0;
 }
 
+void __cdecl s_get_names(int *n, str_array_t *names)
+{
+  str_array_t list;
+
+  list = MIDL_user_allocate(2 * sizeof(list[0]));
+  list[0] = MIDL_user_allocate(6);
+  strcpy(list[0], "Hello");
+  list[1] = MIDL_user_allocate(7);
+  strcpy(list[1], "World!");
+
+  *names = list;
+  *n = 2;
+}
+
+void __cdecl s_get_namesw(int *n, wstr_array_t *names)
+{
+  wstr_array_t list;
+
+  list = MIDL_user_allocate(2 * sizeof(list[0]));
+  list[0] = MIDL_user_allocate(sizeof(helloW));
+  lstrcpyW(list[0], helloW);
+  list[1] = MIDL_user_allocate(sizeof(worldW));
+  lstrcpyW(list[1], worldW);
+
+  *names = list;
+  *n = 2;
+}
+
 int __cdecl s_sum_pcarr2(int n, int **pa)
 {
   return s_sum_conf_array(*pa, n);
@@ -712,6 +743,46 @@ void __cdecl s_context_handle_test(void)
 
         pNDRSContextUnmarshall2(binding, buf, NDR_LOCAL_DATA_REPRESENTATION, &server_if2.InterfaceId, 0);
     }
+
+    binding = NULL;
+    status = RpcBindingServerFromClient(NULL, &binding);
+
+    ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
+    ok(binding != NULL, "binding is NULL\n");
+
+    if (status == RPC_S_OK && binding != NULL)
+    {
+        unsigned char* string_binding = NULL;
+        unsigned char* object_uuid = NULL;
+        unsigned char* protseq = NULL;
+        unsigned char* network_address = NULL;
+        unsigned char* endpoint = NULL;
+        unsigned char* network_options = NULL;
+
+        status = RpcBindingToStringBindingA(binding, &string_binding);
+        ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
+        ok(string_binding != NULL, "string_binding is NULL\n");
+
+        status = RpcStringBindingParseA(string_binding, &object_uuid, &protseq, &network_address, &endpoint, &network_options);
+        ok(status == RPC_S_OK, "expected RPC_S_OK got %u\n", status);
+        ok(protseq != NULL && *protseq != '\0', "protseq is %s\n", protseq);
+        ok(network_address != NULL && *network_address != '\0', "network_address is %s\n", network_address);
+
+        todo_wine
+        {
+            ok(object_uuid != NULL && *object_uuid == '\0', "object_uuid is %s\n", object_uuid);
+            ok(endpoint != NULL && *endpoint == '\0', "endpoint is %s\n", endpoint);
+            ok(network_options != NULL && *network_options == '\0', "network_options is %s\n", network_options);
+        }
+
+        RpcStringFreeA(&string_binding);
+        RpcStringFreeA(&object_uuid);
+        RpcStringFreeA(&protseq);
+        RpcStringFreeA(&network_address);
+        RpcStringFreeA(&endpoint);
+        RpcStringFreeA(&network_options);
+        RpcBindingFree(&binding);
+    }
 }
 
 void __cdecl s_get_numbers(int length, int size, pints_t n[])
@@ -1190,12 +1261,36 @@ pointer_tests(void)
 
   if (!old_windows_version)
   {
+      int n;
+      str_array_t names;
+      wstr_array_t namesw;
+
       name.size = 10;
       name.name = buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, name.size);
       get_name(&name);
       ok(name.name == buffer, "[in,out] pointer should have stayed as %p but instead changed to %p\n", name.name, buffer);
       ok(!strcmp(name.name, "Jeremy Wh"), "name didn't unmarshall properly, expected \"Jeremy Wh\", but got \"%s\"\n", name.name);
       HeapFree(GetProcessHeap(), 0, name.name);
+
+      n = -1;
+      names = NULL;
+      get_names(&n, &names);
+      ok(n == 2, "expected 2, got %d\n", n);
+      ok(!strcmp(names[0], "Hello"), "expected Hello, got %s\n", names[0]);
+      ok(!strcmp(names[1], "World!"), "expected World!, got %s\n", names[1]);
+      MIDL_user_free(names[0]);
+      MIDL_user_free(names[1]);
+      MIDL_user_free(names);
+
+      n = -1;
+      namesw = NULL;
+      get_namesw(&n, &namesw);
+      ok(n == 2, "expected 2, got %d\n", n);
+      ok(!lstrcmpW(namesw[0], helloW), "expected Hello, got %s\n", wine_dbgstr_w(namesw[0]));
+      ok(!lstrcmpW(namesw[1], worldW), "expected World!, got %s\n", wine_dbgstr_w(namesw[1]));
+      MIDL_user_free(namesw[0]);
+      MIDL_user_free(namesw[1]);
+      MIDL_user_free(namesw);
   }
 
   pa2 = a;
@@ -1476,6 +1571,26 @@ set_auth_info(RPC_BINDING_HANDLE handle)
     ok(status == RPC_S_OK, "RpcBindingSetAuthInfoExA failed %d\n", status);
 }
 
+#define test_is_server_listening(a,b) _test_is_server_listening(__LINE__,a,b)
+static void _test_is_server_listening(unsigned line, RPC_BINDING_HANDLE binding, RPC_STATUS expected_status)
+{
+    RPC_STATUS status;
+    status = RpcMgmtIsServerListening(binding);
+    ok_(__FILE__,line)(status == expected_status, "RpcMgmtIsServerListening returned %u, expected %u\n",
+                       status, expected_status);
+}
+
+#define test_is_server_listening2(a,b,c) _test_is_server_listening2(__LINE__,a,b,c)
+static void _test_is_server_listening2(unsigned line, RPC_BINDING_HANDLE binding, RPC_STATUS expected_status,
+        RPC_STATUS expected_status2)
+{
+    RPC_STATUS status;
+    status = RpcMgmtIsServerListening(binding);
+    ok_(__FILE__,line)(status == expected_status || status == expected_status2,
+                       "RpcMgmtIsServerListening returned %u, expected %u or %u\n",
+                       status, expected_status, expected_status2);
+}
+
 static void
 client(const char *test)
 {
@@ -1492,58 +1607,65 @@ client(const char *test)
 
   if (strcmp(test, "tcp_basic") == 0)
   {
-    ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
-    ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
+    ok(RPC_S_OK == RpcStringBindingComposeA(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
+    ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
 
     run_tests();
     authinfo_test(RPC_PROTSEQ_TCP, 0);
+    test_is_server_listening2(IServer_IfHandle, RPC_S_OK, RPC_S_ACCESS_DENIED);
 
-    ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
+    ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
   }
   else if (strcmp(test, "tcp_secure") == 0)
   {
-    ok(RPC_S_OK == RpcStringBindingCompose(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
-    ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
+    ok(RPC_S_OK == RpcStringBindingComposeA(NULL, iptcp, address, port, NULL, &binding), "RpcStringBindingCompose\n");
+    ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
 
     set_auth_info(IServer_IfHandle);
     authinfo_test(RPC_PROTSEQ_TCP, 1);
+    test_is_server_listening(IServer_IfHandle, RPC_S_ACCESS_DENIED);
 
-    ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
+    ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
   }
   else if (strcmp(test, "ncalrpc_basic") == 0)
   {
-    ok(RPC_S_OK == RpcStringBindingCompose(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
-    ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
+    ok(RPC_S_OK == RpcStringBindingComposeA(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
+    ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
 
     run_tests(); /* can cause RPC_X_BAD_STUB_DATA exception */
     authinfo_test(RPC_PROTSEQ_LRPC, 0);
+    test_is_server_listening(IServer_IfHandle, RPC_S_OK);
 
-    ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
+    ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
   }
   else if (strcmp(test, "ncalrpc_secure") == 0)
   {
-    ok(RPC_S_OK == RpcStringBindingCompose(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
-    ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
+    ok(RPC_S_OK == RpcStringBindingComposeA(NULL, ncalrpc, NULL, guid, NULL, &binding), "RpcStringBindingCompose\n");
+    ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
 
     set_auth_info(IServer_IfHandle);
     authinfo_test(RPC_PROTSEQ_LRPC, 1);
+    test_is_server_listening(IServer_IfHandle, RPC_S_OK);
 
-    ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
+    ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
   }
   else if (strcmp(test, "np_basic") == 0)
   {
-    ok(RPC_S_OK == RpcStringBindingCompose(NULL, np, address_np, pipe, NULL, &binding), "RpcStringBindingCompose\n");
-    ok(RPC_S_OK == RpcBindingFromStringBinding(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
+    ok(RPC_S_OK == RpcStringBindingComposeA(NULL, np, address_np, pipe, NULL, &binding), "RpcStringBindingCompose\n");
+    ok(RPC_S_OK == RpcBindingFromStringBindingA(binding, &IServer_IfHandle), "RpcBindingFromStringBinding\n");
 
+    test_is_server_listening(IServer_IfHandle, RPC_S_OK);
     run_tests();
     authinfo_test(RPC_PROTSEQ_NMP, 0);
+    test_is_server_listening(IServer_IfHandle, RPC_S_OK);
     stop();
+    test_is_server_listening(IServer_IfHandle, RPC_S_NOT_LISTENING);
 
-    ok(RPC_S_OK == RpcStringFree(&binding), "RpcStringFree\n");
+    ok(RPC_S_OK == RpcStringFreeA(&binding), "RpcStringFree\n");
     ok(RPC_S_OK == RpcBindingFree(&IServer_IfHandle), "RpcBindingFree\n");
   }
 }
@@ -1560,13 +1682,13 @@ server(void)
   RPC_STATUS status, iptcp_status, np_status, ncalrpc_status;
   DWORD ret;
 
-  iptcp_status = RpcServerUseProtseqEp(iptcp, 20, port, NULL);
+  iptcp_status = RpcServerUseProtseqEpA(iptcp, 20, port, NULL);
   ok(iptcp_status == RPC_S_OK, "RpcServerUseProtseqEp(ncacn_ip_tcp) failed with status %d\n", iptcp_status);
 
-  ncalrpc_status = RpcServerUseProtseqEp(ncalrpc, 0, guid, NULL);
+  ncalrpc_status = RpcServerUseProtseqEpA(ncalrpc, 0, guid, NULL);
   ok(ncalrpc_status == RPC_S_OK, "RpcServerUseProtseqEp(ncalrpc) failed with status %d\n", ncalrpc_status);
 
-  np_status = RpcServerUseProtseqEp(np, 0, pipe, NULL);
+  np_status = RpcServerUseProtseqEpA(np, 0, pipe, NULL);
   if (np_status == RPC_S_PROTSEQ_NOT_SUPPORTED)
     skip("Protocol sequence ncacn_np is not supported\n");
   else
@@ -1582,9 +1704,11 @@ server(void)
   else
     status = RpcServerRegisterIf(s_IServer_v0_0_s_ifspec, NULL, NULL);
   ok(status == RPC_S_OK, "RpcServerRegisterIf failed with status %d\n", status);
+  test_is_server_listening(NULL, RPC_S_NOT_LISTENING);
   status = RpcServerListen(1, 20, TRUE);
   ok(status == RPC_S_OK, "RpcServerListen failed with status %d\n", status);
-  stop_event = CreateEvent(NULL, FALSE, FALSE, NULL);
+  test_is_server_listening(NULL, RPC_S_OK);
+  stop_event = CreateEventW(NULL, FALSE, FALSE, NULL);
   ok(stop_event != NULL, "CreateEvent failed with error %d\n", GetLastError());
 
   if (iptcp_status == RPC_S_OK)