aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_hello_world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_hello_world.c')
-rw-r--r--src/testing/testing_api_cmd_hello_world.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
new file mode 100644
index 000000000..1915f7da7
--- /dev/null
+++ b/src/testing/testing_api_cmd_hello_world.c
@@ -0,0 +1,113 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008, 2009, 2012 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_testing_ng_lib.h"
28
29struct HelloWorldState
30{
31 char *message;
32};
33
34/**
35*
36*
37* @param cls closure
38* @param cmd current CMD being cleaned up.
39*/
40static void
41hello_world_cleanup (void *cls,
42 const struct GNUNET_TESTING_Command *cmd)
43{
44 struct HelloWorldState *hs = cls;
45 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
46 "Cleaning up message %s",
47 hs->message);
48}
49
50/**
51*
52*
53* @param cls closure.
54* @param[out] ret result
55* @param trait name of the trait.
56* @param index index number of the object to offer.
57* @return #GNUNET_OK on success.
58*/
59static int
60hello_world_traits (void *cls,
61 const void **ret,
62 const char *trait,
63 unsigned int index)
64{
65 return GNUNET_OK;
66}
67
68/**
69* Run the "hello world" CMD.
70*
71* @param cls closure.
72* @param cmd CMD being run.
73* @param is interpreter state.
74*/
75static void
76hello_world_run (void *cls,
77 const struct GNUNET_TESTING_Command *cmd,
78 struct GNUNET_TESTING_Interpreter *is)
79{
80 struct HelloWorldState *hs = cls;
81 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
82 "%s",
83 hs->message);
84 GNUNET_TESTING_get_trait_what_am_i (cmd,
85 hs->message);
86}
87
88/**
89 * Create command.
90 *
91 * @param label name for command.
92 * @param message initial message.
93 * @return command.
94 */
95struct GNUNET_TESTING_Command
96GNUNET_TESTING_cmd_hello_world (const char *label,
97 char *message)
98{
99 struct HelloWorldState *hs;
100
101 hs = GNUNET_new (struct HelloWorldState);
102 hs->message = "Hello World, I am nobody!";
103
104 struct GNUNET_TESTING_Command cmd = {
105 .cls = hs,
106 .label = label,
107 .run = &hello_world_run,
108 .cleanup = &hello_world_cleanup,
109 .traits = &hello_world_traits
110 };
111
112 return cmd;
113}