diff options
Diffstat (limited to 'src/service/testing/test_testing_portreservation.c')
-rw-r--r-- | src/service/testing/test_testing_portreservation.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/service/testing/test_testing_portreservation.c b/src/service/testing/test_testing_portreservation.c new file mode 100644 index 000000000..df3d8d523 --- /dev/null +++ b/src/service/testing/test_testing_portreservation.c | |||
@@ -0,0 +1,105 @@ | |||
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/test_testing_new_portreservation.c | ||
23 | * @brief test case for testing port reservation routines from the new testing | ||
24 | * library API | ||
25 | * @author Sree Harsha Totakura | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testing_lib.h" | ||
31 | |||
32 | #define LOG(kind, ...) \ | ||
33 | GNUNET_log (kind, __VA_ARGS__) | ||
34 | |||
35 | /** | ||
36 | * The status of the test | ||
37 | */ | ||
38 | int status; | ||
39 | |||
40 | /** | ||
41 | * Main point of test execution | ||
42 | */ | ||
43 | static void | ||
44 | run (void *cls, char *const *args, const char *cfgfile, | ||
45 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
46 | { | ||
47 | struct GNUNET_TESTING_System *system; | ||
48 | uint16_t new_port1; | ||
49 | uint16_t new_port2; | ||
50 | uint16_t old_port1; | ||
51 | |||
52 | system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", | ||
53 | "localhost", NULL, NULL); | ||
54 | GNUNET_assert (NULL != system); | ||
55 | new_port1 = GNUNET_TESTING_reserve_port (system); | ||
56 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
57 | "Reserved TCP port %u\n", new_port1); | ||
58 | if (0 == new_port1) | ||
59 | goto end; | ||
60 | new_port2 = GNUNET_TESTING_reserve_port (system); | ||
61 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
62 | "Reserved TCP port %u\n", new_port2); | ||
63 | if (0 == new_port2) | ||
64 | goto end; | ||
65 | GNUNET_assert (new_port1 != new_port2); | ||
66 | GNUNET_TESTING_release_port (system, new_port1); | ||
67 | old_port1 = new_port1; | ||
68 | new_port1 = 0; | ||
69 | new_port1 = GNUNET_TESTING_reserve_port (system); | ||
70 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
71 | "Reserved TCP port %u\n", new_port1); | ||
72 | GNUNET_assert (0 != new_port1); | ||
73 | GNUNET_assert (old_port1 == new_port1); | ||
74 | GNUNET_TESTING_release_port (system, new_port1); | ||
75 | GNUNET_TESTING_release_port (system, new_port2); | ||
76 | status = GNUNET_OK; | ||
77 | |||
78 | end: | ||
79 | GNUNET_TESTING_system_destroy (system, GNUNET_YES); | ||
80 | } | ||
81 | |||
82 | |||
83 | int | ||
84 | main (int argc, char *argv[]) | ||
85 | { | ||
86 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
87 | GNUNET_GETOPT_OPTION_END | ||
88 | }; | ||
89 | |||
90 | status = GNUNET_SYSERR; | ||
91 | if (GNUNET_OK != | ||
92 | GNUNET_PROGRAM_run (argc, | ||
93 | argv, | ||
94 | "test_testing_new_portreservation", | ||
95 | "test case for testing port reservation routines" | ||
96 | " from the new testing library API", | ||
97 | options, | ||
98 | &run, | ||
99 | NULL)) | ||
100 | return 1; | ||
101 | return (GNUNET_OK == status) ? 0 : 1; | ||
102 | } | ||
103 | |||
104 | |||
105 | /* end of test_testing_portreservation.c */ | ||