diff options
author | Gabor X Toth <*@tg-x.net> | 2016-01-12 23:26:47 +0000 |
---|---|---|
committer | Gabor X Toth <*@tg-x.net> | 2016-01-12 23:26:47 +0000 |
commit | 50eaf8d7de763d25b7dae7ffdee8d7c6b5fe71ea (patch) | |
tree | a8023bdb9c9446a45792d7100303265c78713a50 /src/env/test_env.c | |
parent | 3cbdbe18dbd56def00c0014381ff90b4ee664904 (diff) | |
download | gnunet-50eaf8d7de763d25b7dae7ffdee8d7c6b5fe71ea.tar.gz gnunet-50eaf8d7de763d25b7dae7ffdee8d7c6b5fe71ea.zip |
psycutil reorg: message, env, slicer
Diffstat (limited to 'src/env/test_env.c')
-rw-r--r-- | src/env/test_env.c | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/src/env/test_env.c b/src/env/test_env.c deleted file mode 100644 index 3af9e26f0..000000000 --- a/src/env/test_env.c +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | /* | ||
2 | * This file is part of GNUnet. | ||
3 | * Copyright (C) 2013 Christian Grothoff (and other contributing authors) | ||
4 | * | ||
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. | ||
9 | * | ||
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. | ||
14 | * | ||
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., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file env/test_env.c | ||
23 | * @brief Tests for the environment library. | ||
24 | * @author Gabor X Toth | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testing_lib.h" | ||
30 | #include "gnunet_env_lib.h" | ||
31 | |||
32 | struct GNUNET_ENV_Modifier mods[] = { | ||
33 | { .oper = GNUNET_ENV_OP_SET, | ||
34 | .name = "_foo", .value = "foo", .value_size = 3 }, | ||
35 | |||
36 | { .oper = GNUNET_ENV_OP_ASSIGN, | ||
37 | .name = "_foo_bar", .value = "foo bar", .value_size = 7 }, | ||
38 | |||
39 | { .oper = GNUNET_ENV_OP_AUGMENT, | ||
40 | .name = "_foo_bar_baz", .value = "foo bar baz", .value_size = 11 } | ||
41 | }; | ||
42 | |||
43 | struct ItCls | ||
44 | { | ||
45 | size_t n; | ||
46 | }; | ||
47 | |||
48 | int | ||
49 | iterator (void *cls, enum GNUNET_ENV_Operator oper, | ||
50 | const char *name, const char *value, uint32_t value_size) | ||
51 | { | ||
52 | struct ItCls *it_cls = cls; | ||
53 | struct GNUNET_ENV_Modifier *m = &mods[it_cls->n++]; | ||
54 | |||
55 | GNUNET_assert (oper == m->oper); | ||
56 | GNUNET_assert (value_size == m->value_size); | ||
57 | GNUNET_assert (0 == memcmp (name, m->name, strlen (m->name))); | ||
58 | GNUNET_assert (0 == memcmp (value, m->value, m->value_size)); | ||
59 | |||
60 | return GNUNET_YES; | ||
61 | } | ||
62 | |||
63 | int | ||
64 | main (int argc, char *argv[]) | ||
65 | { | ||
66 | GNUNET_log_setup ("test-env", "WARNING", NULL); | ||
67 | |||
68 | struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create (); | ||
69 | GNUNET_assert (NULL != env); | ||
70 | int i, len = 3; | ||
71 | |||
72 | for (i = 0; i < len; i++) | ||
73 | { | ||
74 | GNUNET_ENV_environment_add (env, mods[i].oper, mods[i].name, | ||
75 | mods[i].value, mods[i].value_size); | ||
76 | } | ||
77 | |||
78 | struct ItCls it_cls = { .n = 0 }; | ||
79 | GNUNET_ENV_environment_iterate (env, iterator, &it_cls); | ||
80 | GNUNET_assert (len == it_cls.n); | ||
81 | |||
82 | for (i = 0; i < len; i++) | ||
83 | { | ||
84 | enum GNUNET_ENV_Operator oper; | ||
85 | const char *name; | ||
86 | const void *value; | ||
87 | size_t value_size; | ||
88 | GNUNET_ENV_environment_shift (env, &oper, &name, &value, &value_size); | ||
89 | GNUNET_assert (len - i - 1 == GNUNET_ENV_environment_get_count (env)); | ||
90 | } | ||
91 | |||
92 | GNUNET_ENV_environment_destroy (env); | ||
93 | |||
94 | return 0; | ||
95 | } | ||