2 This file is part of GNUnet.
3 Copyright (C) 2006, 2009, 2015, 2016 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
21 * @file transport-testing-filenames.c
22 * @brief convenience string manipulation functions for tests
23 * @author Matthias Wachs
24 * @author Christian Grothoff
26 #include "transport-testing.h"
30 * Removes all directory separators from absolute filename
32 * @param file the absolute file name, e.g. as found in argv[0]
33 * @return extracted file name, has to be freed by caller
36 extract_filename (const char *file)
38 char *pch = GNUNET_strdup (file);
40 char *filename = NULL;
43 if (NULL != strstr (pch, "/"))
45 pch = strtok (pch, "/");
48 pch = strtok (NULL, "/");
58 res = GNUNET_strdup (filename);
65 * Extracts the test filename from an absolute file name and removes
68 * @param file absolute file name
72 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
74 char *backup = extract_filename (file);
75 char *filename = backup;
83 filename = strstr (filename, "test");
91 if (NULL != (dotexe = strstr (filename, ".exe")))
93 ret = GNUNET_strdup (filename);
100 * Extracts the filename from an absolute file name and removes the extension
102 * @param file absolute file name
106 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
108 char *src = extract_filename (file);
111 split = strstr (src, ".");
119 * Extracts the plugin name from an absolute file name and the test name
121 * @param file absolute file name
122 * @param test test name
126 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
131 char *e = extract_filename (file);
132 char *t = extract_filename (test);
138 filename = strstr (e, "tes");
139 if (NULL == filename)
142 if (NULL != (dotexe = strstr (filename, ".exe")))
146 filename = strstr (filename, t);
147 if (NULL == filename)
150 filename += strlen (t);
151 if ('\0' != *filename)
153 ret = GNUNET_strdup (filename);
165 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
166 * if existing ".exe"-prefix and adds the peer-number
168 * @param file filename of the test, e.g. argv[0]
169 * @param count peer number
173 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
176 char *filename = extract_filename (file);
177 char *backup = filename;
181 if (NULL == filename)
184 filename = strstr (filename, "test");
185 if (NULL == filename)
188 if (NULL != (dotexe = strstr (filename, ".exe")))
190 GNUNET_asprintf (&ret,
194 GNUNET_free (backup);
197 GNUNET_free (backup);
202 /* end of transport-testing-filenames.c */