diff options
author | t3sserakt <t3ss@posteo.de> | 2021-03-04 10:41:01 +0100 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2021-03-04 10:42:39 +0100 |
commit | e5d31aa52e4983bffce3eca6ca601bbb8f4a302a (patch) | |
tree | 1878b4c6595b4b3d402988c1df772adf48908622 /src/testing/testing_api_cmd_hello_world.c | |
parent | 46111957db87028c369ea4792b9c533a9dd09a33 (diff) | |
download | gnunet-e5d31aa52e4983bffce3eca6ca601bbb8f4a302a.tar.gz gnunet-e5d31aa52e4983bffce3eca6ca601bbb8f4a302a.zip |
- first try to integrate GNU Taler command style testing
Diffstat (limited to 'src/testing/testing_api_cmd_hello_world.c')
-rw-r--r-- | src/testing/testing_api_cmd_hello_world.c | 113 |
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 | |||
29 | struct HelloWorldState | ||
30 | { | ||
31 | char *message; | ||
32 | }; | ||
33 | |||
34 | /** | ||
35 | * | ||
36 | * | ||
37 | * @param cls closure | ||
38 | * @param cmd current CMD being cleaned up. | ||
39 | */ | ||
40 | static void | ||
41 | hello_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 | */ | ||
59 | static int | ||
60 | hello_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 | */ | ||
75 | static void | ||
76 | hello_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 | */ | ||
95 | struct GNUNET_TESTING_Command | ||
96 | GNUNET_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 | } | ||