diff options
Diffstat (limited to 'src/testing/test_testing_portreservation.c')
-rw-r--r-- | src/testing/test_testing_portreservation.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c new file mode 100644 index 000000000..40109446b --- /dev/null +++ b/src/testing/test_testing_portreservation.c | |||
@@ -0,0 +1,90 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008, 2009, 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | 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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
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-new.h" | ||
31 | |||
32 | #define LOG(kind,...) \ | ||
33 | GNUNET_log (kind, __VA_ARGS__) | ||
34 | |||
35 | /** | ||
36 | * Main point of test execution | ||
37 | */ | ||
38 | static void | ||
39 | run (void *cls, char *const *args, const char *cfgfile, | ||
40 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
41 | { | ||
42 | struct GNUNET_TESTING_System *system; | ||
43 | uint16_t new_port1; | ||
44 | uint16_t new_port2; | ||
45 | uint16_t old_port1; | ||
46 | |||
47 | system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", | ||
48 | "localhost"); | ||
49 | GNUNET_assert (NULL != system); | ||
50 | new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); | ||
51 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
52 | "Reserved TCP port %u\n", new_port1); | ||
53 | GNUNET_assert (0 != new_port1); | ||
54 | new_port2 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); | ||
55 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
56 | "Reserved TCP port %u\n", new_port2); | ||
57 | GNUNET_assert (0 != new_port2); | ||
58 | GNUNET_assert (new_port1 != new_port2); | ||
59 | GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1); | ||
60 | old_port1 = new_port1; | ||
61 | new_port1 = 0; | ||
62 | new_port1 = GNUNET_TESTING_reserve_port (system, GNUNET_YES); | ||
63 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
64 | "Reserved TCP port %u\n", new_port1); | ||
65 | GNUNET_assert (0 != new_port1); | ||
66 | GNUNET_assert (old_port1 == new_port1); | ||
67 | GNUNET_TESTING_release_port (system, GNUNET_YES, new_port1); | ||
68 | GNUNET_TESTING_release_port (system, GNUNET_YES, new_port2); | ||
69 | GNUNET_TESTING_system_destroy (system, GNUNET_NO); | ||
70 | } | ||
71 | |||
72 | int main (int argc, char *argv[]) | ||
73 | { | ||
74 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
75 | GNUNET_GETOPT_OPTION_END | ||
76 | }; | ||
77 | if (GNUNET_OK != | ||
78 | GNUNET_PROGRAM_run (argc, | ||
79 | argv, | ||
80 | "test_testing_new_portreservation", | ||
81 | "test case for testing port reservation routines" | ||
82 | " from the new testing library API", | ||
83 | options, | ||
84 | &run, | ||
85 | NULL)) | ||
86 | { | ||
87 | return 1; | ||
88 | } | ||
89 | return 0; | ||
90 | } | ||