wldap32/tests: Don't crash if ldap_search_ext_sA fails.
[wine] / dlls / wldap32 / tests / parse.c
1 /*
2  * test parsing functions
3  *
4  * Copyright 2008 Hans Leidekker for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <stdarg.h>
22 #include <stdlib.h>
23 #include <windef.h>
24 #include <winbase.h>
25 #include <winldap.h>
26
27 #include "wine/test.h"
28
29 static void test_ldap_parse_sort_control( LDAP *ld )
30 {
31     ULONG ret, result;
32     LDAPSortKeyA *sortkeys[2], key;
33     LDAPControlA *sort, *ctrls[2], **server_ctrls;
34     LDAPMessage *res = NULL;
35     struct l_timeval timeout;
36
37     key.sk_attrtype = (char *)"cn";
38     key.sk_matchruleoid = NULL;
39     key.sk_reverseorder = FALSE;
40
41     sortkeys[0] = &key;
42     sortkeys[1] = NULL;
43     ret = ldap_create_sort_controlA( ld, sortkeys, 0, &sort );
44     ok( !ret, "ldap_create_sort_controlA failed 0x%x\n", ret );
45
46     ctrls[0] = sort;
47     ctrls[1] = NULL;
48     timeout.tv_sec = 20;
49     timeout.tv_usec = 0;
50     ret = ldap_search_ext_sA( ld, (char *)"", LDAP_SCOPE_SUBTREE, (char *)"(cn=Verisign*)", NULL, 0, ctrls, NULL, &timeout, 10, &res );
51     ok( !ret, "ldap_search_ext_sA failed 0x%x\n", ret );
52     if (ret)
53     {
54         ldap_control_free( sort );
55         return;
56     }
57     ok( res != NULL, "expected res != NULL\n" );
58
59     ret = ldap_parse_resultA( NULL, res, &result, NULL, NULL, NULL, &server_ctrls, 1 );
60     ok( ret == LDAP_PARAM_ERROR, "ldap_parse_resultA failed 0x%x\n", ret );
61
62     result = ~0UL;
63     ret = ldap_parse_resultA( ld, res, &result, NULL, NULL, NULL, &server_ctrls, 1 );
64     ok( !ret, "ldap_parse_resultA failed 0x%x\n", ret );
65     ok( !result, "got 0x%x expected 0\n", result );
66
67     ret = ldap_parse_sort_controlA( NULL, NULL, NULL, NULL );
68     ok( ret == LDAP_PARAM_ERROR, "ldap_parse_sort_controlA failed 0x%d\n", ret );
69
70     ret = ldap_parse_sort_controlA( ld, NULL, NULL, NULL );
71     ok( ret == LDAP_CONTROL_NOT_FOUND, "ldap_parse_sort_controlA failed 0x%x\n", ret );
72
73     ret = ldap_parse_sort_controlA( ld, NULL, &result, NULL );
74     ok( ret == LDAP_CONTROL_NOT_FOUND, "ldap_parse_sort_controlA failed 0x%x\n", ret );
75
76     ret = ldap_parse_sort_controlA( ld, server_ctrls, &result, NULL );
77     ok( ret == LDAP_CONTROL_NOT_FOUND, "ldap_parse_sort_controlA failed 0x%x\n", ret );
78
79     ldap_control_free( sort );
80     ldap_controls_free( server_ctrls );
81 }
82
83 START_TEST (parse)
84 {
85     LDAP *ld;
86
87     ld = ldap_initA((char *)"directory.verisign.com", 389 );
88     ok( ld != NULL, "ldap_init failed\n" );
89
90     test_ldap_parse_sort_control( ld );
91     ldap_unbind( ld );
92 }