[2/2] wldap32: Add tests for ldap_parse_sort_control and make them pass.

Hans Leidekker hans at codeweavers.com
Mon Oct 6 08:47:28 CDT 2008


diff --git a/configure.ac b/configure.ac
index 52f5752..9bff7b2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2068,6 +2068,7 @@ WINE_CONFIG_MAKEFILE([dlls/wintab32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_D
 WINE_CONFIG_MAKEFILE([dlls/wintrust/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
 WINE_CONFIG_MAKEFILE([dlls/wintrust/tests/Makefile],[dlls/Maketest.rules],[dlls],[ALL_TEST_DIRS])
 WINE_CONFIG_MAKEFILE([dlls/wldap32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
+WINE_CONFIG_MAKEFILE([dlls/wldap32/tests/Makefile],[dlls/Maketest.rules],[dlls],[ALL_TEST_DIRS])
 WINE_CONFIG_MAKEFILE([dlls/wmi/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
 WINE_CONFIG_MAKEFILE([dlls/wnaspi32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
 WINE_CONFIG_MAKEFILE([dlls/wow32/Makefile],[dlls/Makedll.rules],[dlls],[ALL_DLL_DIRS])
diff --git a/dlls/wldap32/error.c b/dlls/wldap32/error.c
index 49e48dc..8254a1d 100644
--- a/dlls/wldap32/error.c
+++ b/dlls/wldap32/error.c
@@ -41,6 +41,32 @@ extern HINSTANCE hwldap32;
 
 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
 
+ULONG map_error( int error )
+{
+    switch (error)
+    {
+#ifdef HAVE_LDAP_H
+    case LDAP_SERVER_DOWN:              return WLDAP32_LDAP_SERVER_DOWN;
+    case LDAP_LOCAL_ERROR:              return WLDAP32_LDAP_LOCAL_ERROR;
+    case LDAP_DECODING_ERROR:           return WLDAP32_LDAP_DECODING_ERROR;
+    case LDAP_TIMEOUT:                  return WLDAP32_LDAP_TIMEOUT;
+    case LDAP_AUTH_UNKNOWN:             return WLDAP32_LDAP_AUTH_UNKNOWN;
+    case LDAP_FILTER_ERROR:             return WLDAP32_LDAP_FILTER_ERROR;
+    case LDAP_USER_CANCELLED:           return WLDAP32_LDAP_USER_CANCELLED;
+    case LDAP_PARAM_ERROR:              return WLDAP32_LDAP_PARAM_ERROR;
+    case LDAP_NO_MEMORY:                return WLDAP32_LDAP_NO_MEMORY;
+    case LDAP_CONNECT_ERROR:            return WLDAP32_LDAP_CONNECT_ERROR;
+    case LDAP_NOT_SUPPORTED:            return WLDAP32_LDAP_NOT_SUPPORTED;
+    case LDAP_CONTROL_NOT_FOUND:        return WLDAP32_LDAP_CONTROL_NOT_FOUND;
+    case LDAP_NO_RESULTS_RETURNED:      return WLDAP32_LDAP_NO_RESULTS_RETURNED;
+    case LDAP_MORE_RESULTS_TO_RETURN:   return WLDAP32_LDAP_MORE_RESULTS_TO_RETURN;
+    case LDAP_CLIENT_LOOP:              return WLDAP32_LDAP_CLIENT_LOOP;
+    case LDAP_REFERRAL_LIMIT_EXCEEDED:  return WLDAP32_LDAP_REFERRAL_LIMIT_EXCEEDED;
+#endif
+    default: return error;
+    }
+}
+
 /***********************************************************************
  *      ldap_err2stringA     (WLDAP32.@)
  *
diff --git a/dlls/wldap32/parse.c b/dlls/wldap32/parse.c
index daea812..c7aa32e 100644
--- a/dlls/wldap32/parse.c
+++ b/dlls/wldap32/parse.c
@@ -184,25 +184,25 @@ ULONG CDECL ldap_parse_resultA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
 {
     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
 #ifdef HAVE_LDAP
-    WCHAR **matchedW = NULL, **errorW = NULL, **referralsW = NULL;
+    WCHAR *matchedW = NULL, *errorW = NULL, **referralsW = NULL;
     LDAPControlW **serverctrlsW = NULL;
 
     TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
            matched, error, referrals, serverctrls, free );
 
-    if (!ld) return ~0UL;
+    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
 
-    ret = ldap_parse_resultW( ld, result, retcode, matchedW, errorW,
+    ret = ldap_parse_resultW( ld, result, retcode, &matchedW, &errorW,
                               &referralsW, &serverctrlsW, free );
 
-    matched = strarrayWtoA( matchedW );
-    error = strarrayWtoA( errorW );
+    if (matched) *matched = strWtoA( matchedW );
+    if (error) *error = strWtoA( errorW );
 
-    *referrals = strarrayWtoA( referralsW );
-    *serverctrls = controlarrayWtoA( serverctrlsW );
+    if (referrals) *referrals = strarrayWtoA( referralsW );
+    if (serverctrls) *serverctrls = controlarrayWtoA( serverctrlsW );
 
-    ldap_value_freeW( matchedW );
-    ldap_value_freeW( errorW );
+    ldap_memfreeW( matchedW );
+    ldap_memfreeW( errorW );
     ldap_value_freeW( referralsW );
     ldap_controls_freeW( serverctrlsW );
 
@@ -241,30 +241,30 @@ ULONG CDECL ldap_parse_resultW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *result,
 {
     ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
 #ifdef HAVE_LDAP
-    char **matchedU = NULL, **errorU = NULL, **referralsU = NULL;
+    char *matchedU = NULL, *errorU = NULL, **referralsU = NULL;
     LDAPControl **serverctrlsU = NULL;
 
     TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld, result, retcode,
            matched, error, referrals, serverctrls, free );
 
-    if (!ld) return ~0UL;
+    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
 
-    ret = ldap_parse_result( ld, result, (int *)retcode, matchedU, errorU,
+    ret = ldap_parse_result( ld, result, (int *)retcode, &matchedU, &errorU,
                              &referralsU, &serverctrlsU, free );
 
-    matched = strarrayUtoW( matchedU );
-    error = strarrayUtoW( errorU );
+    if (matched) *matched = strUtoW( matchedU );
+    if (error) *error = strUtoW( errorU );
 
-    *referrals = strarrayUtoW( referralsU );
-    *serverctrls = controlarrayUtoW( serverctrlsU );
+    if (referrals) *referrals = strarrayUtoW( referralsU );
+    if (serverctrls) *serverctrls = controlarrayUtoW( serverctrlsU );
 
     ldap_memfree( matchedU );
     ldap_memfree( errorU );
-    ldap_memfree( referralsU );
+    strarrayfreeU( referralsU );
     ldap_controls_free( serverctrlsU );
 
 #endif
-    return ret;
+    return map_error( ret );
 }
 
 /***********************************************************************
@@ -282,12 +282,11 @@ ULONG CDECL ldap_parse_sort_controlA( WLDAP32_LDAP *ld, PLDAPControlA *control,
 
     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
 
-    if (!ld) return ~0UL;
+    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
 
-    if (control) {
-        controlW = controlarrayAtoW( control );
-        if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
-    }
+    controlW = controlarrayAtoW( control );
+    if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
 
     ret = ldap_parse_sort_controlW( ld, controlW, result, &attrW );
 
@@ -333,7 +332,8 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
 
     TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
 
-    if (!ld || !control) return ~0UL;
+    if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
+    if (!control) return WLDAP32_LDAP_CONTROL_NOT_FOUND;
 
     controlU = controlarrayWtoU( control );
     if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
@@ -364,7 +364,7 @@ ULONG CDECL ldap_parse_sort_controlW( WLDAP32_LDAP *ld, PLDAPControlW *control,
     controlarrayfreeU( controlU );
 
 #endif
-    return ret;
+    return map_error( ret );
 }
 
 /***********************************************************************
diff --git a/dlls/wldap32/tests/Makefile.in b/dlls/wldap32/tests/Makefile.in
new file mode 100644
index 0000000..97fbc64
--- /dev/null
+++ b/dlls/wldap32/tests/Makefile.in
@@ -0,0 +1,13 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+TESTDLL   = wldap32.dll
+IMPORTS   = wldap32 kernel32
+
+CTESTS = \
+	parse.c
+
+ at MAKE_TEST_RULES@
+
+ at DEPENDENCIES@  # everything below this line is overwritten by make depend
diff --git a/dlls/wldap32/tests/parse.c b/dlls/wldap32/tests/parse.c
new file mode 100644
index 0000000..b3b6cb2
--- /dev/null
+++ b/dlls/wldap32/tests/parse.c
@@ -0,0 +1,87 @@
+/*
+ * test parsing functions
+ *
+ * Copyright 2008 Hans Leidekker for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <windef.h>
+#include <winbase.h>
+#include <winldap.h>
+
+#include "wine/test.h"
+
+static void test_ldap_parse_sort_control( LDAP *ld )
+{
+    ULONG ret, result;
+    LDAPSortKeyA *sortkeys[2], key;
+    LDAPControlA *sort, *ctrls[2], **server_ctrls;
+    LDAPMessage *res = NULL;
+    struct l_timeval timeout;
+
+    key.sk_attrtype = (char *)"cn";
+    key.sk_matchruleoid = NULL;
+    key.sk_reverseorder = FALSE;
+
+    sortkeys[0] = &key;
+    sortkeys[1] = NULL;
+    ret = ldap_create_sort_controlA( ld, sortkeys, 0, &sort );
+    ok( !ret, "ldap_create_sort_controlA failed 0x%x\n", ret );
+
+    ctrls[0] = sort;
+    ctrls[1] = NULL;
+    timeout.tv_sec = 20;
+    timeout.tv_usec = 0;
+    ret = ldap_search_ext_sA( ld, (char *)"", LDAP_SCOPE_SUBTREE, (char *)"(cn=Verisign*)", NULL, 0, ctrls, NULL, &timeout, 10, &res );
+    ok( !ret, "ldap_search_ext_sA failed 0x%x\n", ret );
+    ok( res != NULL, "expected res != NULL\n" );
+
+    ret = ldap_parse_resultA( NULL, res, &result, NULL, NULL, NULL, &server_ctrls, 1 );
+    ok( ret == LDAP_PARAM_ERROR, "ldap_parse_resultA failed 0x%x\n", ret );
+
+    result = ~0UL;
+    ret = ldap_parse_resultA( ld, res, &result, NULL, NULL, NULL, &server_ctrls, 1 );
+    ok( !ret, "ldap_parse_resultA failed 0x%x\n", ret );
+    ok( !result, "got 0x%x expected 0\n", result );
+
+    ret = ldap_parse_sort_controlA( NULL, NULL, NULL, NULL );
+    ok( ret == LDAP_PARAM_ERROR, "ldap_parse_sort_controlA failed 0x%d\n", ret );
+    
+    ret = ldap_parse_sort_controlA( ld, NULL, NULL, NULL );
+    ok( ret == LDAP_CONTROL_NOT_FOUND, "ldap_parse_sort_controlA failed 0x%x\n", ret );
+    
+    ret = ldap_parse_sort_controlA( ld, NULL, &result, NULL );
+    ok( ret == LDAP_CONTROL_NOT_FOUND, "ldap_parse_sort_controlA failed 0x%x\n", ret );
+
+    ret = ldap_parse_sort_controlA( ld, server_ctrls, &result, NULL );
+    ok( ret == LDAP_CONTROL_NOT_FOUND, "ldap_parse_sort_controlA failed 0x%x\n", ret );
+
+    ldap_control_free( sort );
+    ldap_controls_free( server_ctrls );
+}
+
+START_TEST (parse)
+{
+    LDAP *ld;
+
+    ld = ldap_initA((char *)"directory.verisign.com", 389 );
+    ok( ld != NULL, "ldap_init failed\n" );
+
+    test_ldap_parse_sort_control( ld );
+    ldap_unbind( ld );
+}
diff --git a/dlls/wldap32/wldap32.h b/dlls/wldap32/wldap32.h
index b21f24e..bf913d0 100644
--- a/dlls/wldap32/wldap32.h
+++ b/dlls/wldap32/wldap32.h
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  */
 
+ULONG map_error( int );
+
 /* A set of helper functions to convert LDAP data structures
  * to and from ansi (A), wide character (W) and utf8 (U) encodings.
  */



More information about the wine-patches mailing list