aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_hello_world_birth.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_hello_world_birth.c')
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c159
1 files changed, 0 insertions, 159 deletions
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
deleted file mode 100644
index 9d60059a5..000000000
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ /dev/null
@@ -1,159 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 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 testing/testing_api_cmd_hello_world.c
23 * @brief implementation of a hello world command.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30struct HelloWorldBirthState
31{
32 struct GNUNET_TIME_Absolute *date;
33 char *what_am_i;
34};
35
36/**
37*
38*
39* @param cls closure
40* @param cmd current CMD being cleaned up.
41*/
42static void
43hello_world_birth_cleanup (void *cls,
44 const struct GNUNET_TESTING_Command *cmd)
45{
46 struct HelloWorldBirthState *hbs = cls;
47 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
48 "Finished birth of %s\n",
49 hbs->what_am_i);
50}
51
52/**
53*
54*
55* @param cls closure.
56* @param[out] ret result
57* @param trait name of the trait.
58* @param index index number of the object to offer.
59* @return #GNUNET_OK on success.
60*/
61static int
62hello_world_birth_traits (void *cls,
63 const void **ret,
64 const char *trait,
65 unsigned int index)
66{
67 struct HelloWorldBirthState *hbs = cls;
68 const char *what_am_i = hbs->what_am_i;
69
70 struct GNUNET_TESTING_Trait traits[] = {
71 {
72 .index = 0,
73 .trait_name = "what_am_i",
74 .ptr = (const void *) what_am_i,
75 },
76 GNUNET_TESTING_trait_end ()
77 };
78
79 return GNUNET_TESTING_get_trait (traits,
80 ret,
81 trait,
82 index);
83}
84
85/**
86* Run the "hello world" CMD.
87*
88* @param cls closure.
89* @param cmd CMD being run.
90* @param is interpreter state.
91*/
92static void
93hello_world_birth_run (void *cls,
94 const struct GNUNET_TESTING_Command *cmd,
95 struct GNUNET_TESTING_Interpreter *is)
96{
97 struct HelloWorldBirthState *hbs = cls;
98 struct GNUNET_TIME_Relative relative;
99
100 relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
101 GNUNET_TIME_absolute_get ());
102
103 if (0 == relative.rel_value_us % 10)
104 {
105 hbs->what_am_i = "creature!";
106 }
107 else if (0 == relative.rel_value_us % 2)
108 {
109 hbs->what_am_i = "girl!";
110 }
111 else
112 {
113 hbs->what_am_i = "boy!";
114 }
115}
116
117/**
118 * Offer data from trait
119 *
120 * @param cmd command to extract the message from.
121 * @param pt pointer to message.
122 * @return #GNUNET_OK on success.
123 */
124int
125GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
126 char **what_am_i)
127{
128 return cmd->traits (cmd->cls,
129 (const void **) what_am_i,
130 "what_am_i",
131 (unsigned int) 0);
132}
133
134/**
135 * Create command.
136 *
137 * @param label name for command.
138 * @param now when the command was started.
139 * @return command.
140 */
141struct GNUNET_TESTING_Command
142GNUNET_TESTING_cmd_hello_world_birth (const char *label,
143 struct GNUNET_TIME_Absolute *now)
144{
145 struct HelloWorldBirthState *hbs;
146
147 hbs = GNUNET_new (struct HelloWorldBirthState);
148 hbs->date = now;
149
150 struct GNUNET_TESTING_Command cmd = {
151 .cls = hbs,
152 .label = label,
153 .run = &hello_world_birth_run,
154 .cleanup = &hello_world_birth_cleanup,
155 .traits = &hello_world_birth_traits
156 };
157
158 return cmd;
159}