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/>.
19 * @file transport-testing-filenames.c
20 * @brief convenience string manipulation functions for tests
21 * @author Matthias Wachs
22 * @author Christian Grothoff
24 #include "transport-testing.h"
28 * Removes all directory separators from absolute filename
30 * @param file the absolute file name, e.g. as found in argv[0]
31 * @return extracted file name, has to be freed by caller
34 extract_filename (const char *file)
36 char *pch = GNUNET_strdup (file);
38 char *filename = NULL;
42 if ((strlen (pch) >= 3) && pch[1] == ':')
44 if (NULL != strstr (pch, "\\"))
46 pch = strtok (pch, "\\");
49 pch = strtok (NULL, "\\");
56 pch = filename; /* If we miss the next condition, filename = pch will
60 if (NULL != strstr (pch, "/"))
62 pch = strtok (pch, "/");
65 pch = strtok (NULL, "/");
75 res = GNUNET_strdup (filename);
82 * Extracts the test filename from an absolute file name and removes
85 * @param file absolute file name
89 GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
91 char *backup = extract_filename (file);
92 char *filename = backup;
100 filename = strstr (filename, "test");
101 if (NULL == filename)
103 GNUNET_free (backup);
108 if (NULL != (dotexe = strstr (filename, ".exe")))
110 ret = GNUNET_strdup (filename);
111 GNUNET_free (backup);
117 * Extracts the filename from an absolute file name and removes the extension
119 * @param file absolute file name
123 GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
125 char *src = extract_filename (file);
128 split = strstr (src, ".");
136 * Extracts the plugin name from an absolute file name and the test name
138 * @param file absolute file name
139 * @param test test name
143 GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file,
148 char *e = extract_filename (file);
149 char *t = extract_filename (test);
155 filename = strstr (e, "tes");
156 if (NULL == filename)
159 if (NULL != (dotexe = strstr (filename, ".exe")))
163 filename = strstr (filename, t);
164 if (NULL == filename)
167 filename += strlen (t);
168 if ('\0' != *filename)
170 ret = GNUNET_strdup (filename);
182 * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and
183 * if existing ".exe"-prefix and adds the peer-number
185 * @param file filename of the test, e.g. argv[0]
186 * @param count peer number
190 GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
193 char *filename = extract_filename (file);
194 char *backup = filename;
198 if (NULL == filename)
201 filename = strstr (filename, "test");
202 if (NULL == filename)
205 if (NULL != (dotexe = strstr (filename, ".exe")))
207 GNUNET_asprintf (&ret,
211 GNUNET_free (backup);
214 GNUNET_free (backup);
219 /* end of transport-testing-filenames.c */