GNUnet  0.11.x
testing_api_cmd_hello_world.c
Go to the documentation of this file.
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 
26 #include "platform.h"
27 #include "gnunet_testing_ng_lib.h"
28 
30 {
31  char *message;
32  const char *birthLabel;
33 };
34 
41 static void
43  const struct GNUNET_TESTING_Command *cmd)
44 {
45  struct HelloWorldState *hs = cls;
47  "Cleaning up message %s\n",
48  hs->message);
49 }
50 
60 static int
61 hello_world_traits (void *cls,
62  const void **ret,
63  const char *trait,
64  unsigned int index)
65 {
66  return GNUNET_OK;
67 }
68 
76 static void
77 hello_world_run (void *cls,
78  const struct GNUNET_TESTING_Command *cmd,
80 {
81  struct HelloWorldState *hs = cls;
82  const struct GNUNET_TESTING_Command *birth_cmd;
83 
85  "%s\n",
86  hs->message);
90  "Now I am a %s\n",
91  hs->message);
92 }
93 
103  const char *birthLabel,
104  char *message)
105 {
106  struct HelloWorldState *hs;
107 
108  hs = GNUNET_new (struct HelloWorldState);
109  hs->message = "Hello World, I was nobody!";
110  hs->birthLabel = birthLabel;
111 
112  struct GNUNET_TESTING_Command cmd = {
113  .cls = hs,
114  .label = label,
115  .run = &hello_world_run,
116  .cleanup = &hello_world_cleanup,
117  .traits = &hello_world_traits
118  };
119 
120  return cmd;
121 }
static void hello_world_cleanup(void *cls, const struct GNUNET_TESTING_Command *cmd)
const char * label
Label for the command.
A command to be run by the interpreter.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_hello_world(const char *label, const char *birthLabel, char *message)
Create command.
Global state of the interpreter, used by a command to access information about other commands...
Definition: testing.h:34
const struct GNUNET_TESTING_Command * GNUNET_TESTING_interpreter_lookup_command(const char *label)
Lookup command by label.
struct GNUNET_TESTING_Interpreter * is
static void hello_world_run(void *cls, const struct GNUNET_TESTING_Command *cmd, struct GNUNET_TESTING_Interpreter *is)
Run the "hello world" CMD.
static int hello_world_traits(void *cls, const void **ret, const char *trait, unsigned int index)
int GNUNET_TESTING_get_trait_what_am_i(const struct GNUNET_TESTING_Command *cmd, char **what_am_i)
Offer data from trait.
#define GNUNET_log(kind,...)
void * cls
Closure for all commands with command-specific context information.