2
test_nslcd_group.c - simple tests of developed lookup code
4
Copyright (C) 2008 Arthur de Jong
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.
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.
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 Street, Fifth Floor, Boston, MA
24
#include <sys/types.h>
30
#include "common/tio.h"
31
#include "nslcd/myldap.h"
33
/* include group code because we want to test static methods */
34
#include "nslcd/group.c"
36
static void test_isvalidgroupname(void)
38
assert(isvalidgroupname("foo"));
39
assert(!isvalidgroupname("foo^"));
40
assert(!isvalidgroupname("-foo"));
41
assert(isvalidgroupname("foo-bar"));
44
static void test_group_all(MYLDAP_SESSION *session,TFILE *fp)
46
MYLDAP_SEARCH *search;
49
/* build the list of attributes */
51
/* do the LDAP search */
52
search=myldap_search(session,group_base,group_scope,group_filter,group_attrs);
55
while ((entry=myldap_get_entry(search,&rc))!=NULL)
57
if (write_group(fp,entry,NULL,NULL,1,session))
62
static void test_group_byname(MYLDAP_SESSION *session,TFILE *fp,const char *name)
64
MYLDAP_SEARCH *search;
68
/* build the list of attributes */
70
/* build the filter */
71
mkfilter_group_byname(name,filter,sizeof(filter));
72
/* do the LDAP search */
73
search=myldap_search(session,group_base,group_scope,filter,group_attrs);
76
while ((entry=myldap_get_entry(search,&rc))!=NULL)
78
if (write_group(fp,entry,NULL,NULL,1,session))
83
static void initconfig(void)
87
/* build the name of the file to read */
88
srcdir=getenv("srcdir");
90
strcpy(fname,"nslcd-test.conf");
92
snprintf(fname,sizeof(fname),"%s/nslcd-test.conf",srcdir);
93
fname[sizeof(fname)-1]='\0';
94
/* load config file */
96
/* partially initialize logging */
97
log_setdefaultloglevel(LOG_DEBUG);
100
static TFILE *opendummyfile(void)
103
struct timeval timeout;
104
/* set the timeout */
107
/* open the file for writing the result data */
108
fd=open("/dev/null",O_RDWR,0);
110
return tio_fdopen(fd,&timeout,&timeout,1024,2*1024,1024,2*1024);
113
/* the main program... */
114
int main(int UNUSED(argc),char UNUSED(*argv[]))
116
MYLDAP_SESSION *session;
118
/* initialize configuration */
120
/* initialize session */
121
session=myldap_create_session();
122
assert(session!=NULL);
127
test_isvalidgroupname();
128
test_group_byname(session,fp,"testgroup");
129
test_group_byname(session,fp,"testgroup2");
130
test_group_all(session,fp);
132
myldap_session_close(session);