Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2009-12-13 11:27:33 +0100
committerArthur de Jong <arthur@arthurdejong.org>2009-12-13 11:27:33 +0100
commitef8cc767b201e4798a060282d4a6f280094bb8cc (patch)
tree4f19eae6870321f280959be4b7b24cd0e38d4c2a /tests
parent7dd703c9af5f8b4a50f056c47588a9e51d4ea681 (diff)
change dict and set API to perform loops with a list of strings instead of loop_first() and loop_next() functions
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1028 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'tests')
-rw-r--r--tests/test_dict.c51
-rw-r--r--tests/test_set.c17
2 files changed, 37 insertions, 31 deletions
diff --git a/tests/test_dict.c b/tests/test_dict.c
index 905d916..4e0adf9 100644
--- a/tests/test_dict.c
+++ b/tests/test_dict.c
@@ -2,7 +2,7 @@
test_dict.c - simple test for the dict module
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2007, 2008 Arthur de Jong
+ Copyright (C) 2007, 2008, 2009 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -35,11 +35,12 @@
static void test_simple(void)
{
DICT *dict;
- const char *key;
void *val;
static char *value1="value1";
static char *value2="value2";
static char *replace2="replace2";
+ const char **keys;
+ int i;
/* initialize */
dict=dict_new();
/* store some entries */
@@ -61,13 +62,15 @@ static void test_simple(void)
val=dict_get(dict,"keY3");
assert(val==NULL);
/* loop over dictionary contents */
- dict_loop_first(dict);
- while (dict_loop_next(dict,&key,&val)!=NULL)
+ keys=dict_keys(dict);
+ for (i=0;keys[i]!=NULL;i++)
{
+ val=dict_get(dict,keys[i]);
assert(((val==value1)||(val==replace2)));
}
- /* free dictionary */
+ /* free stuff */
dict_free(dict);
+ free(keys);
}
/* Test to insert a large number of elements in the dict. */
@@ -76,8 +79,8 @@ static void test_lotsofelements(void)
DICT *dict;
char buf[80];
int i,r;
- const char *key;
void *val;
+ const char **keys;
/* initialize */
dict=dict_new();
/* insert a number of entries */
@@ -102,13 +105,15 @@ static void test_lotsofelements(void)
dict_put(dict,buf,&buf);
}
/* loop over dictionary contents */
- dict_loop_first(dict);
- while (dict_loop_next(dict,&key,&val)!=NULL)
+ keys=dict_keys(dict);
+ for (i=0;keys[i]!=NULL;i++)
{
+ val=dict_get(dict,keys[i]);
assert(val==buf);
}
- /* free dictionary */
+ /* free stuff */
dict_free(dict);
+ free(keys);
}
/* Test to insert a large number of elements in the dict. */
@@ -117,8 +122,9 @@ static void test_readelements(const char *fname)
DICT *dict;
char buf[80];
FILE *fp;
- const char *key;
void *val;
+ const char **keys;
+ int i;
/* initialize */
dict=dict_new();
/* read file and insert all entries */
@@ -132,22 +138,23 @@ static void test_readelements(const char *fname)
}
fclose(fp);
/* loop over dictionary contents */
- dict_loop_first(dict);
- while (dict_loop_next(dict,&key,&val)!=NULL)
+ keys=dict_keys(dict);
+ for (i=0;keys[i]!=NULL;i++)
{
+ val=dict_get(dict,keys[i]);
assert(val==buf);
}
- /* free dictionary */
+ /* free stuff */
dict_free(dict);
+ free(keys);
}
static void test_countelements(int num)
{
DICT *dict;
char buf[80];
- int i,j,r;
- const char *key;
- void *val;
+ int i,r;
+ const char **keys;
/* initialize */
dict=dict_new();
/* insert a number of entries */
@@ -158,17 +165,13 @@ static void test_countelements(int num)
dict_put(dict,buf,&buf);
}
/* loop over dictionary contents */
- dict_loop_first(dict);
- i=0;
- while (dict_loop_next(dict,&key,&val)!=NULL)
- {
- assert(val==buf);
- i++;
- }
+ keys=dict_keys(dict);
+ for (i=0;keys[i]!=NULL;i++);
/* we should have num elements */
assert(i==num);
- /* free dictionary */
+ /* free stuff */
dict_free(dict);
+ free(keys);
}
/* the main program... */
diff --git a/tests/test_set.c b/tests/test_set.c
index 7ebfe4e..2623906 100644
--- a/tests/test_set.c
+++ b/tests/test_set.c
@@ -2,7 +2,7 @@
test_set.c - simple test for the set module
This file is part of the nss-pam-ldapd library.
- Copyright (C) 2008 Arthur de Jong
+ Copyright (C) 2008, 2009 Arthur de Jong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <string.h>
#include <assert.h>
+#include <stdlib.h>
#include "common/set.h"
#include "compat/attrs.h"
@@ -33,7 +34,8 @@
int main(int UNUSED(argc),char UNUSED(*argv[]))
{
SET *set;
- const char *val;
+ const char **list;
+ int i;
/* initialize */
set=set_new();
@@ -51,16 +53,17 @@ int main(int UNUSED(argc),char UNUSED(*argv[]))
assert(!set_contains(set,"key4"));
/* loop over set contents */
- set_loop_first(set);
- while ((val=set_loop_next(set))!=NULL)
+ list=set_tolist(set);
+ for (i=0;list[i]!=NULL;i++)
{
- assert( (strcasecmp(val,"key1")==0) ||
- (strcasecmp(val,"key2")==0) ||
- (strcasecmp(val,"key3")==0) );
+ assert( (strcasecmp(list[i],"key1")==0) ||
+ (strcasecmp(list[i],"key2")==0) ||
+ (strcasecmp(list[i],"key3")==0) );
}
/* free set */
set_free(set);
+ free(list);
return 0;
}