Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

t_event_attrs.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2005 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 **
00018 ** @(#)$Id: t_event_attrs.c,v 1.6 2005/06/05 03:56:33 klmitch Exp $
00019 */
00027 #include "event-test.h"
00028 
00029 #include <string.h>
00030 
00031 RCSTAG("@(#)$Id: t_event_attrs.c,v 1.6 2005/06/05 03:56:33 klmitch Exp $");
00032 
00033 TEST_PROG(t_event_attrs, "Test operation of event_attr_* functions")
00034      TEST_DEP(t_event_attrs, t_event_log)
00035 
00042 int
00043 main(int argc, char **argv)
00044 {
00045   const char *newpath = "~/.event", *tmp;
00046   ev_err_t err;
00047   ev_attr_t attrs;
00048   ev_varlist_t *vlist;
00049   ev_overvars_t *ovlist;
00050   char namebuf[] = "test.a";
00051 
00052   ev_test_init(t_event_attrs); /* initialize test program */
00053 
00054   /* OK, test that event_attr_init() works... */
00055   TEST(t_event_attrs, ea_init, "Test that event_attr_init() initializes "
00056        "the attribute set",
00057        (!(err = event_attr_init(&attrs)) && attrs && ea_verify(&attrs)),
00058        FATAL(0),
00059        ("event_attr_init() properly initialized attribute set"),
00060        ("event_attr_init() failed to initialize attribute set; error %u",
00061         err));
00062 
00063   /* Test that event_attr_confpath() does what it's supposed to... */
00064   tmp = 0; /* first, try no change... */
00065   TEST(t_event_attrs, ea_confpath_nochange, "Test that event_attr_confpath() "
00066        "doesn't change confpath when *path is a NULL pointer",
00067        (!(err = event_attr_confpath(&attrs, &tmp)) &&
00068         ea_confpath(&attrs) == ea_confpath(&_ev_defattr) &&
00069         tmp == ea_confpath(&_ev_defattr)), 0,
00070        ("event_attr_confpath() returned default confpath (\"%s\") without "
00071         "changing it", tmp),
00072        ("event_attr_confpath() unexpectedly failed; error %u, confpath "
00073         "\"%s\", default \"%s\", returned \"%s\"", err, ea_confpath(&attrs),
00074         ea_confpath(&_ev_defattr), tmp));
00075 
00076   /* OK, change it... */
00077   tmp = newpath;
00078   TEST(t_event_attrs, ea_confpath_change, "Test that event_attr_confpath() "
00079        "can change confpath",
00080        (!(err = event_attr_confpath(&attrs, &tmp)) &&
00081         ea_confpath(&attrs) == newpath && tmp == ea_confpath(&_ev_defattr)), 0,
00082        ("event_attr_confpath() successfully changed confpath"),
00083        ("event_attr_confpath() unexpectedly failed; error %u, confpath "
00084         "\"%s\", default \"%s\", returned \"%s\"", err, ea_confpath(&attrs),
00085         ea_confpath(&_ev_defattr), tmp));
00086 
00087   /* Test that event_attr_libpath() does what it's supposed to... */
00088   tmp = 0; /* first, try no change... */
00089   TEST(t_event_attrs, ea_libpath_nochange, "Test that event_attr_libpath() "
00090        "doesn't change libpath when *path is a NULL pointer",
00091        (!(err = event_attr_libpath(&attrs, &tmp)) &&
00092         ea_libpath(&attrs) == ea_libpath(&_ev_defattr) &&
00093         tmp == ea_libpath(&_ev_defattr)), 0,
00094        ("event_attr_libpath() returned default libpath (\"%s\") without "
00095         "changing it", tmp),
00096        ("event_attr_libpath() unexpectedly failed; error %u, libpath "
00097         "\"%s\", default \"%s\", returned \"%s\"", err, ea_libpath(&attrs),
00098         ea_libpath(&_ev_defattr), tmp));
00099 
00100   /* OK, change it... */
00101   tmp = newpath;
00102   TEST(t_event_attrs, ea_libpath_change, "Test that event_attr_libpath() "
00103        "can change libpath",
00104        (!(err = event_attr_libpath(&attrs, &tmp)) &&
00105         ea_libpath(&attrs) == newpath && tmp == ea_libpath(&_ev_defattr)), 0,
00106        ("event_attr_libpath() successfully changed libpath"),
00107        ("event_attr_libpath() unexpectedly failed; error %u, libpath "
00108         "\"%s\", default \"%s\", returned \"%s\"", err, ea_libpath(&attrs),
00109         ea_libpath(&_ev_defattr), tmp));
00110 
00111   /* Test that event_attr_modlist() does what it's supposed to... */
00112   tmp = 0; /* first, try no change... */
00113   TEST(t_event_attrs, ea_modlist_nochange, "Test that event_attr_modlist() "
00114        "doesn't change modlist when *list is a NULL pointer",
00115        (!(err = event_attr_modlist(&attrs, &tmp)) &&
00116         ea_modlist(&attrs) == ea_modlist(&_ev_defattr) &&
00117         tmp == ea_modlist(&_ev_defattr)), 0,
00118        ("event_attr_modlist() returned default modlist (\"%s\") without "
00119         "changing it", tmp),
00120        ("event_attr_modlist() unexpectedly failed; error %u, modlist "
00121         "\"%s\", default \"%s\", returned \"%s\"", err, ea_modlist(&attrs),
00122         ea_modlist(&_ev_defattr), tmp));
00123 
00124   /* OK, change it... */
00125   tmp = newpath;
00126   TEST(t_event_attrs, ea_modlist_change, "Test that event_attr_modlist() "
00127        "can change modlist",
00128        (!(err = event_attr_modlist(&attrs, &tmp)) &&
00129         ea_modlist(&attrs) == newpath && tmp == ea_modlist(&_ev_defattr)), 0,
00130        ("event_attr_modlist() successfully changed modlist"),
00131        ("event_attr_modlist() unexpectedly failed; error %u, modlist "
00132         "\"%s\", default \"%s\", returned \"%s\"", err, ea_modlist(&attrs),
00133         ea_modlist(&_ev_defattr), tmp));
00134 
00135   /* Next, let's test event_attr_confreg() and see if it does what it's
00136    * supposed to do...
00137    */
00138   TEST(t_event_attrs, ea_confreg_event, "Test that event_attr_confreg() "
00139        "rejects attempts to register variables beginning with \"event.\"",
00140        ((err = event_attr_confreg(&attrs, "event.foo", 0, 0, 0, 0)) == EINVAL),
00141        FATAL(0),
00142        ("event_attr_confreg() rejected registration of \"event.foo\""),
00143        ("event_attr_confreg() failed to reject registration of \"event.foo\"; "
00144         "error code %u", err));
00145 
00146   /* Now, add a couple of variables at different places... */
00147   TEST(t_event_attrs, ea_confreg_b, "Test that event_attr_confreg() can add "
00148        "a variable to an empty variable list",
00149        (!(err = event_attr_confreg(&attrs, "test.b", 0, 0, 0, 0))), FATAL(0),
00150        ("event_attr_confreg() successfully registered variable \"test.b\""),
00151        ("event_attr_confreg() failed to register variable \"test.b\"; error "
00152         "code %u", err));
00153 
00154   TEST(t_event_attrs, ea_confreg_a, "Test that event_attr_confreg() can add "
00155        "a predecessor variable in a variable list",
00156        (!(err = event_attr_confreg(&attrs, "test.a", 0, 0, 0, 0))), FATAL(0),
00157        ("event_attr_confreg() successfully registered variable \"test.a\""),
00158        ("event_attr_confreg() failed to register variable \"test.a\"; error "
00159         "code %u", err));
00160 
00161   TEST(t_event_attrs, ea_confreg_c, "Test that event_attr_confreg() can add "
00162        "a successor variable in a variable list",
00163        (!(err = event_attr_confreg(&attrs, "test.c", 0, 0, 0, 0))), FATAL(0),
00164        ("event_attr_confreg() successfully registered variable \"test.c\""),
00165        ("event_attr_confreg() failed to register variable \"test.c\"; error "
00166         "code %u", err));
00167 
00168   /* Try registering an already registered variable... */
00169   TEST(t_event_attrs, ea_confreg_mult, "Test that event_attr_confreg() "
00170        "rejects previously registered variables",
00171        ((err = event_attr_confreg(&attrs, "test.b",
00172                                   0, 0, 0, 0)) == TC_ERR_MULTREG), FATAL(0),
00173        ("event_attr_confreg() rejected multiple registration of \"test.b\""),
00174        ("event_attr_confreg() failed to reject multiple registration of "
00175         "\"test.b\"; error code %u", err));
00176 
00177   /* Now, verify the order of the variables... */
00178   TEST_DECL(t_event_attrs, ea_confreg_order, "Test that event_attr_confreg() "
00179             "put the variables in the correct order")
00180     for (vlist = ea_varlist(&attrs); vlist;
00181          vlist = vlist->vl_next, namebuf[sizeof(namebuf) - 2]++)
00182       if (strcmp(vlist->vl_name, namebuf))
00183         FAIL(TEST_NAME(ea_confreg_order), FATAL(0), "List order problem; "
00184              "expecting %s, got %s", namebuf, vlist->vl_name);
00185   PASS(TEST_NAME(ea_confreg_order), "Variable list order verified");
00186 
00187   /* Now, let's see if event_attr_confvar() does what it's supposed to do... */
00188   TEST(t_event_attrs, ea_confvar_e, "Test that event_attr_confvar() can add "
00189        "a variable to an empty variable list",
00190        (!(err = event_attr_confvar(&attrs, "test.e", "bah"))), FATAL(0),
00191        ("event_attr_confvar() successfully overrode variable \"test.e\""),
00192        ("event_attr_confvar() failed to register variable \"test.e\"; error "
00193         "code %u", err));
00194 
00195   TEST(t_event_attrs, ea_confvar_d, "Test that event_attr_confvar() can add "
00196        "a predecessor variable in a variable list",
00197        (!(err = event_attr_confvar(&attrs, "test.d", "test.d"))), FATAL(0),
00198        ("event_attr_confvar() successfully overrode variable \"test.d\""),
00199        ("event_attr_confvar() failed to register variable \"test.d\"; error "
00200         "code %u", err));
00201 
00202   TEST(t_event_attrs, ea_confvar_f, "Test that event_attr_confvar() can add "
00203        "a successor variable in a variable list",
00204        (!(err = event_attr_confvar(&attrs, "test.f", "test.f"))), FATAL(0),
00205        ("event_attr_confvar() successfully overrode variable \"test.f\""),
00206        ("event_attr_confvar() failed to register variable \"test.f\"; error "
00207         "code %u", err));
00208 
00209   /* Try changing one of the names... */
00210   TEST(t_event_attrs, ea_confvar_change, "Test that event_attr_confvar() can "
00211        "change the value of an existing variable",
00212        (!(err = event_attr_confvar(&attrs, "test.e", "test.e"))), FATAL(0),
00213        ("event_attr_confvar() successfully changed value of variable "
00214         "\"test.e\""),
00215        ("event_attr_confvar() failed to change value of variable \"test.e\"; "
00216         "error code %u", err));
00217 
00218   /* Let's verify the order of the variables... */
00219   TEST_DECL(t_event_attrs, ea_confvar_order, "Test that event_attr_confvar() "
00220             "put the variables in the correct order with the correct value")
00221     for (ovlist = ea_ovars(&attrs); ovlist;
00222          ovlist = ovlist->ov_next, namebuf[sizeof(namebuf) - 2]++)
00223       if (strcmp(ovlist->ov_name, namebuf) || !ovlist->ov_value ||
00224           strcmp(ovlist->ov_value, namebuf))
00225         FAIL(TEST_NAME(ea_confvar_order), FATAL(0), "List order problem; "
00226              "expecting %s, got %s (value %s)", namebuf, ovlist->ov_name,
00227              ovlist->ov_value ? ovlist->ov_value : "(null)");
00228   PASS(TEST_NAME(ea_confvar_order), "Variable list order verified");
00229 
00230   /* What happens if we try to add a variable at its default value? */
00231   TEST(t_event_attrs, ea_confvar_default, "Test that event_attr_confvar() "
00232        "ignores a variable reset to its default",
00233        (!(err = event_attr_confvar(&attrs, "test.c", 0)) &&
00234         strcmp(ea_ovars(&attrs)->ov_name, "test.c")), FATAL(0),
00235        ("event_attr_confvar() properly ignored un-added variable \"test.c\" "
00236         "being set to its default value"),
00237        ("event_attr_confvar() failed to ignore un-added variable \"test.c\" "
00238         "being set to its default value"));
00239 
00240   /* Try resetting a variable to its default... */
00241   TEST(t_event_attrs, ea_confvar_delete, "Test that event_attr_confvar() "
00242        "removes a variable which is reset to default",
00243        (!(err = event_attr_confvar(&attrs, "test.d", 0)) &&
00244         strcmp(ea_ovars(&attrs)->ov_name, "test.d")), FATAL(0),
00245        ("event_attr_confvar() successfully deleted variable \"test.d\" reset "
00246         "to its default value"),
00247        ("event_attr_confvar() failed to properly delete variable \"test.d\" "
00248         "reset to its default value; error code %u", err));
00249 
00250   /* Finally, test that an attribute set may be destroyed */
00251   TEST(t_event_attrs, ea_destroy, "Test that event_attr_destroy() can destroy "
00252        "an attribute set",
00253        (!(err = event_attr_destroy(&attrs)) && !attrs), 0,
00254        ("event_attr_destroy() successfully destroyed attribute set"),
00255        ("event_attr_destroy() failed to destroy attribute set; error %u",
00256         err));
00257 
00258   return 0;
00259 }

Generated on Wed Dec 28 23:36:56 2005 for event by  doxygen 1.4.4