2 * This file is part of GNUnet.
3 * (C) 2013 Christian Grothoff (and other contributing authors)
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
10 * GNUnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * @file env/test_env.c
23 * @brief Tests for the environment library.
24 * @author Gabor X Toth
28 #include "gnunet_crypto_lib.h"
29 #include "gnunet_common.h"
30 #include "gnunet_util_lib.h"
31 #include "gnunet_testing_lib.h"
32 #include "gnunet_env_lib.h"
34 struct GNUNET_ENV_Modifier mods[] = {
35 { .oper = GNUNET_ENV_OP_SET,
36 .name = "_foo", .value = "foo", .value_size = 3 },
38 { .oper = GNUNET_ENV_OP_ASSIGN,
39 .name = "_foo_bar", .value = "foo bar", .value_size = 7 },
41 { .oper = GNUNET_ENV_OP_AUGMENT,
42 .name = "_foo_bar_baz", .value = "foo bar baz", .value_size = 11 }
51 iterator (void *cls, struct GNUNET_ENV_Modifier *mod)
53 struct ItCls *it_cls = cls;
54 struct GNUNET_ENV_Modifier *m = &mods[it_cls->n++];
56 GNUNET_assert (mod->oper == m->oper);
57 GNUNET_assert (mod->value_size == m->value_size);
58 GNUNET_assert (0 == memcmp (mod->name, m->name, strlen (m->name)));
59 GNUNET_assert (0 == memcmp (mod->value, m->value, m->value_size));
65 main (int argc, char *argv[])
67 GNUNET_log_setup ("test-env", "WARNING", NULL);
69 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
70 GNUNET_assert (NULL != env);
73 for (i = 0; i < len; i++)
75 GNUNET_ENV_environment_add_mod (env, mods[i].oper, mods[i].name,
76 mods[i].value, mods[i].value_size);
79 struct ItCls it_cls = { .n = 0 };
80 GNUNET_ENV_environment_iterate (env, iterator, &it_cls);
81 GNUNET_assert (len == it_cls.n);
83 GNUNET_ENV_environment_destroy (env);