diff options
Diffstat (limited to 'src/service/messenger/messenger-testing.c')
-rw-r--r-- | src/service/messenger/messenger-testing.c | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/src/service/messenger/messenger-testing.c b/src/service/messenger/messenger-testing.c new file mode 100644 index 000000000..b3f7e3137 --- /dev/null +++ b/src/service/messenger/messenger-testing.c | |||
@@ -0,0 +1,114 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2023 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file messenger-testing.c | ||
23 | * @brief testing lib for messenger service | ||
24 | * @author Tobias Frisch | ||
25 | */ | ||
26 | |||
27 | #include "messenger-testing.h" | ||
28 | |||
29 | #include "gnunet_util_lib.h" | ||
30 | |||
31 | struct GNUNET_MESSENGER_TestStage | ||
32 | GNUNET_MESSENGER_create_stage_skip () | ||
33 | { | ||
34 | struct GNUNET_MESSENGER_TestStage stage; | ||
35 | stage.door_id = 0; | ||
36 | stage.join = GNUNET_MESSENGER_STAGE_JOIN_NONE; | ||
37 | return stage; | ||
38 | } | ||
39 | |||
40 | |||
41 | struct GNUNET_MESSENGER_TestStage | ||
42 | GNUNET_MESSENGER_create_stage_open_room () | ||
43 | { | ||
44 | struct GNUNET_MESSENGER_TestStage stage; | ||
45 | stage.door_id = 0; | ||
46 | stage.join = GNUNET_MESSENGER_STAGE_JOIN_OPEN_ROOM; | ||
47 | return stage; | ||
48 | } | ||
49 | |||
50 | |||
51 | struct GNUNET_MESSENGER_TestStage | ||
52 | GNUNET_MESSENGER_create_stage_enter_room (uint32_t door_id) | ||
53 | { | ||
54 | struct GNUNET_MESSENGER_TestStage stage; | ||
55 | stage.door_id = door_id; | ||
56 | stage.join = GNUNET_MESSENGER_STAGE_JOIN_ENTER_ROOM; | ||
57 | return stage; | ||
58 | } | ||
59 | |||
60 | |||
61 | struct GNUNET_MESSENGER_TestStageTopology * | ||
62 | GNUNET_MESSENGER_create_topo (unsigned int peer_amount, | ||
63 | unsigned int stage_amount, | ||
64 | const struct GNUNET_MESSENGER_TestStage | ||
65 | peer_stages[static peer_amount * stage_amount]) | ||
66 | { | ||
67 | GNUNET_assert ((peer_amount) && (stage_amount) && (peer_stages)); | ||
68 | |||
69 | struct GNUNET_MESSENGER_TestStageTopology *tp; | ||
70 | tp = GNUNET_new (struct GNUNET_MESSENGER_TestStageTopology); | ||
71 | tp->peer_amount = peer_amount; | ||
72 | tp->stage_amount = stage_amount; | ||
73 | |||
74 | const unsigned int size = tp->peer_amount * tp->stage_amount; | ||
75 | tp->peer_stages = GNUNET_new_array (size, struct GNUNET_MESSENGER_TestStage); | ||
76 | |||
77 | for (unsigned int i = 0; i < size; i++) | ||
78 | tp->peer_stages[i] = peer_stages[i]; | ||
79 | |||
80 | return tp; | ||
81 | } | ||
82 | |||
83 | |||
84 | void | ||
85 | GNUNET_MESSENGER_destroy_topo (struct | ||
86 | GNUNET_MESSENGER_TestStageTopology *topology) | ||
87 | { | ||
88 | GNUNET_assert ((topology) && (topology->peer_stages)); | ||
89 | GNUNET_free (topology->peer_stages); | ||
90 | GNUNET_free (topology); | ||
91 | } | ||
92 | |||
93 | |||
94 | struct GNUNET_MESSENGER_RoomState * | ||
95 | GNUNET_MESSENGER_create_room_state (struct | ||
96 | GNUNET_MESSENGER_TestStageTopology *topology) | ||
97 | { | ||
98 | struct GNUNET_MESSENGER_RoomState *rs; | ||
99 | rs = GNUNET_new (struct GNUNET_MESSENGER_RoomState); | ||
100 | rs->doors = GNUNET_CONTAINER_multipeermap_create (topology->peer_amount, | ||
101 | GNUNET_NO); | ||
102 | rs->required_doors = 0; | ||
103 | return rs; | ||
104 | } | ||
105 | |||
106 | |||
107 | void | ||
108 | GNUNET_MESSENGER_destroy_room_state (struct | ||
109 | GNUNET_MESSENGER_RoomState *room_state) | ||
110 | { | ||
111 | GNUNET_assert ((room_state) && (room_state->doors)); | ||
112 | GNUNET_CONTAINER_multipeermap_destroy (room_state->doors); | ||
113 | GNUNET_free (room_state); | ||
114 | } | ||