t_dict.c revision 1.1.1.1
1279264Sdelphij/* $Id: t_dict.c,v 1.1.1.1 2010/11/27 21:23:59 agc Exp $ */ 296593Smarkm 396593Smarkm/* Copyright (c) 2010 The NetBSD Foundation, Inc. 4142429Snectar * All rights reserved. 596593Smarkm * 696593Smarkm * This code is derived from software contributed to The NetBSD Foundation 796593Smarkm * by Mateusz Kocielski. 896593Smarkm * 996593Smarkm * Redistribution and use in source and binary forms, with or without 1096593Smarkm * modification, are permitted provided that the following conditions 1196593Smarkm * are met: 1296593Smarkm * 1. Redistributions of source code must retain the above copyright 1396593Smarkm * notice, this list of conditions and the following disclaimer. 1496593Smarkm * 2. Redistributions in binary form must reproduce the above copyright 1596593Smarkm * notice, this list of conditions and the following disclaimer in the 1696593Smarkm * documentation and/or other materials provided with the distribution. 1796593Smarkm * 3. All advertising materials mentioning features or use of this software 1896593Smarkm * must display the following acknowledgement: 1996593Smarkm * This product includes software developed by the NetBSD 20215698Ssimon * Foundation, Inc. and its contributors. 21215698Ssimon * 4. Neither the name of The NetBSD Foundation nor the names of its 22215698Ssimon * contributors may be used to endorse or promote products derived 23215698Ssimon * from this software without specific prior written permission. 24215698Ssimon * 2596593Smarkm * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 2696593Smarkm * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2796593Smarkm * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2896593Smarkm * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 2996593Smarkm * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 3096593Smarkm * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3196593Smarkm * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3296593Smarkm * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3396593Smarkm * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3496593Smarkm * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3596593Smarkm * POSSIBILITY OF SUCH DAMAGE. 3696593Smarkm */ 3796593Smarkm 3896593Smarkm#include <atf-c.h> 3996593Smarkm#include <stdio.h> 4096593Smarkm#include <dict.h> 41279264Sdelphij 42279264Sdelphij/* src/dict.c test cases */ 4396593Smarkm 4496593Smarkm/* saslc__dict_create() */ 45215698SsimonATF_TC(t_saslc__dict_create); 46215698SsimonATF_TC_HEAD(t_saslc__dict_create, tc) 47215698Ssimon{ 48215698Ssimon atf_tc_set_md_var(tc, "descr", "saslc__dict_create() tests"); 49142429Snectar} 50215698SsimonATF_TC_BODY(t_saslc__dict_create, tc) 51142429Snectar{ 52142429Snectar saslc__dict_t *dict; 53279264Sdelphij ATF_REQUIRE(dict = saslc__dict_create()); 54279264Sdelphij saslc__dict_destroy(dict); 55279264Sdelphij} 5696593Smarkm 57279264Sdelphij/* saslc__dict_insert() */ 58279264SdelphijATF_TC(t_saslc__dict_insert); 59279264SdelphijATF_TC_HEAD(t_saslc__dict_insert, tc) 60279264Sdelphij{ 61279264Sdelphij atf_tc_set_md_var(tc, "descr", "saslc__dict_insert() tests"); 62279264Sdelphij} 63215698SsimonATF_TC_BODY(t_saslc__dict_insert, tc) 64279264Sdelphij{ 65279264Sdelphij saslc__dict_t *dict; 66279264Sdelphij ATF_REQUIRE(dict = saslc__dict_create()); 67279264Sdelphij ATF_CHECK_EQ(saslc__dict_insert(dict, "foo", "bar"), DICT_OK); 68279264Sdelphij ATF_CHECK_EQ(saslc__dict_insert(dict, "bar", "blah"), DICT_OK); 69215698Ssimon ATF_CHECK_EQ(saslc__dict_insert(dict, " ", "bar"), DICT_KEYINVALID); 70279264Sdelphij ATF_CHECK_EQ(saslc__dict_insert(dict, NULL, NULL), DICT_KEYINVALID); 7196593Smarkm ATF_CHECK_EQ(saslc__dict_insert(dict, "a", NULL), DICT_VALBAD); 7296593Smarkm ATF_CHECK_EQ(saslc__dict_insert(dict, 7396593Smarkm "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890", 7496593Smarkm "zero"), DICT_OK); 7596593Smarkm ATF_CHECK_EQ(saslc__dict_insert(dict, "a", "b"), DICT_OK); 7696593Smarkm ATF_CHECK_EQ(saslc__dict_insert(dict, "a", "c"), DICT_KEYEXISTS); 7796593Smarkm ATF_CHECK_EQ(saslc__dict_insert(dict, "foo", "bar"), DICT_KEYEXISTS); 7896593Smarkm ATF_CHECK_EQ(saslc__dict_insert(dict, "&^#%$#", "bad"), DICT_KEYINVALID); 7996593Smarkm saslc__dict_destroy(dict); 8096593Smarkm} 8196593Smarkm 8296593Smarkm/* saslc__dict_remove() */ 8396593SmarkmATF_TC(t_saslc__dict_remove); 8496593SmarkmATF_TC_HEAD(t_saslc__dict_remove, tc) 8596593Smarkm{ 8696593Smarkm atf_tc_set_md_var(tc, "descr", "saslc__dict_remove() tests"); 8796593Smarkm} 8896593SmarkmATF_TC_BODY(t_saslc__dict_remove, tc) 8996593Smarkm{ 9096593Smarkm saslc__dict_t *dict; 9196593Smarkm ATF_REQUIRE(dict = saslc__dict_create()); 9296593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "BAR"), DICT_KEYNOTFOUND); 9396593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo", "bar"), DICT_OK); 9496593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "BAR"), DICT_KEYNOTFOUND); 9596593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "BAR", "bar"), DICT_OK); 9696593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "BAR"), DICT_OK); 9796593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "BAR"), DICT_KEYNOTFOUND); 9896593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "BAR", "bar"), DICT_OK); 9996593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "foo"), DICT_OK); 10096593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "BAR"), DICT_OK); 10196593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo", "bar"), DICT_OK); 10296593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "foo"), DICT_OK); 10396593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo1", "bar"), DICT_OK); 10496593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo2", "bar"), DICT_OK); 10596593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo3", "bar"), DICT_OK); 10696593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "foo2"), DICT_OK); 10796593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "foo1"), DICT_OK); 10896593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "foo3"), DICT_OK); 10996593Smarkm ATF_CHECK_EQ(saslc__dict_remove(dict, "foo3"), DICT_KEYNOTFOUND); 11096593Smarkm saslc__dict_destroy(dict); 11196593Smarkm} 11296593Smarkm 11396593Smarkm/* saslc__dict_get() */ 11496593SmarkmATF_TC(t_saslc__dict_get); 11596593SmarkmATF_TC_HEAD(t_saslc__dict_get, tc) 11696593Smarkm{ 11796593Smarkm atf_tc_set_md_var(tc, "descr", "saslc__dict_get() tests"); 11896593Smarkm} 11996593SmarkmATF_TC_BODY(t_saslc__dict_get, tc) 12096593Smarkm{ 12196593Smarkm saslc__dict_t *dict; 12296593Smarkm ATF_REQUIRE(dict = saslc__dict_create()); 12396593Smarkm ATF_CHECK_EQ(saslc__dict_get(dict, "BAR"), NULL); 12496593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo1", "bar1"), DICT_OK); 12596593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo2", "bar2"), DICT_OK); 12696593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo3", "bar3"), DICT_OK); 12796593Smarkm ATF_CHECK_STREQ(saslc__dict_get(dict, "foo1"), "bar1"); 12896593Smarkm ATF_CHECK_STREQ(saslc__dict_get(dict, "foo2"), "bar2"); 12996593Smarkm ATF_CHECK_STREQ(saslc__dict_get(dict, "foo3"), "bar3"); 13096593Smarkm ATF_CHECK_EQ(saslc__dict_get(dict, "foo4"), NULL); 13196593Smarkm ATF_REQUIRE_EQ(saslc__dict_remove(dict, "foo2"), DICT_OK); 13296593Smarkm ATF_CHECK_STREQ(saslc__dict_get(dict, "foo1"), "bar1"); 133142429Snectar ATF_CHECK_EQ(saslc__dict_get(dict, "foo2"), NULL); 13496593Smarkm ATF_CHECK_STREQ(saslc__dict_get(dict, "foo3"), "bar3"); 135100946Snectar ATF_REQUIRE_EQ(saslc__dict_remove(dict, "foo1"), DICT_OK); 136279264Sdelphij ATF_REQUIRE_EQ(saslc__dict_remove(dict, "foo3"), DICT_OK); 137215698Ssimon ATF_CHECK_EQ(saslc__dict_get(dict, "foo2"), NULL); 138215698Ssimon saslc__dict_destroy(dict); 139215698Ssimon} 140215698Ssimon 14196593Smarkm/* saslc__dict_get_len() */ 142110010SmarkmATF_TC(t_saslc__dict_get_len); 143110010SmarkmATF_TC_HEAD(t_saslc__dict_get_len, tc) 144110010Smarkm{ 145110010Smarkm atf_tc_set_md_var(tc, "descr", "saslc__dict_get_len() tests"); 146110010Smarkm} 147110010SmarkmATF_TC_BODY(t_saslc__dict_get_len, tc) 148110010Smarkm{ 149110010Smarkm saslc__dict_t *dict; 150142429Snectar ATF_REQUIRE(dict = saslc__dict_create()); 15196593Smarkm ATF_CHECK_EQ(saslc__dict_get_len(dict, "BAR"), 0); 15296593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo1", "1"), DICT_OK); 15396593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo2", "1234567890"), DICT_OK); 15496593Smarkm ATF_REQUIRE_EQ(saslc__dict_insert(dict, "foo3", "12345678901234567890"), DICT_OK); 155215698Ssimon ATF_CHECK_EQ(saslc__dict_get_len(dict, "foo4"), 0); 156110010Smarkm ATF_CHECK_EQ(saslc__dict_get_len(dict, "foo1"), 1); 157215698Ssimon ATF_CHECK_EQ(saslc__dict_get_len(dict, "foo2"), 10); 158110010Smarkm ATF_CHECK_EQ(saslc__dict_get_len(dict, "foo3"), 20); 159110010Smarkm saslc__dict_destroy(dict); 160110010Smarkm} 161110010Smarkm 162110010SmarkmATF_TP_ADD_TCS(tp) 163110010Smarkm{ 164215698Ssimon /* constructors and destructors */ 165110010Smarkm ATF_TP_ADD_TC(tp, t_saslc__dict_create); 166110010Smarkm 167215698Ssimon /* modifiers */ 168110010Smarkm ATF_TP_ADD_TC(tp, t_saslc__dict_insert); 169110010Smarkm ATF_TP_ADD_TC(tp, t_saslc__dict_remove); 170110010Smarkm 171110010Smarkm /* getters */ 172110010Smarkm ATF_TP_ADD_TC(tp, t_saslc__dict_get); 173110010Smarkm ATF_TP_ADD_TC(tp, t_saslc__dict_get_len); 174110010Smarkm 175215698Ssimon return atf_no_error(); 176110010Smarkm} 177110010Smarkm