|
32 | 32 | from context import unittest |
33 | 33 | import threading |
34 | 34 | import socket |
| 35 | + import socketserver |
35 | 36 | except Exception as baton: |
36 | 37 | raise ImportError("[CWE-758] Failed to import test context") from baton |
37 | 38 |
|
@@ -120,5 +121,57 @@ def run_server() -> None: |
120 | 121 | self.assertTrue(final_result) |
121 | 122 |
|
122 | 123 |
|
| 124 | +@context.markWithMetaTag("mat", "hear") |
| 125 | +class HearServerInitTestSuite(context.BasicUsageTestSuite): |
| 126 | + |
| 127 | + def test_initialization_with_valid_address(self): |
| 128 | + """ |
| 129 | + Test multicast server initialization with a valid address. |
| 130 | +
|
| 131 | + Verifies that: |
| 132 | + 1. The server instance is of the correct type (McastServer). |
| 133 | + 2. The server instance is also recognized as a UDPServer. |
| 134 | + 3. Cleanup is performed correctly after initialization. |
| 135 | + """ |
| 136 | + server = multicast.hear.McastServer(('224.0.0.1', 12345), None) |
| 137 | + self.assertIsInstance(server, multicast.hear.McastServer) |
| 138 | + self.assertIsInstance(server, socketserver.UDPServer) |
| 139 | + server.server_close() # Clean up |
| 140 | + |
| 141 | + def test_initialization_with_logger_name(self): |
| 142 | + """ |
| 143 | + Test multicast server initialization with a specific logger name. |
| 144 | +
|
| 145 | + Verifies that: |
| 146 | + 1. The logger is properly initialized. |
| 147 | + 2. The logger's name ends with the expected multicast address. |
| 148 | + 3. Cleanup is performed correctly after initialization. |
| 149 | + """ |
| 150 | + test_addr = ('239.0.0.9', 23456) |
| 151 | + server = multicast.hear.McastServer(test_addr, None) |
| 152 | + self.assertIsNotNone(server.logger) |
| 153 | + self.assertTrue(server.logger.name.endswith('239.0.0.9')) |
| 154 | + server.server_close() # Clean up |
| 155 | + |
| 156 | + def test_initialization_without_address(self): |
| 157 | + """ |
| 158 | + Test multicast server initialization without a valid address. |
| 159 | +
|
| 160 | + Verifies that: |
| 161 | + 1. The logger is initialized with the default name when server_address is None. |
| 162 | + 2. The logger is initialized with the default name when server_address is an empty tuple. |
| 163 | + 3. Cleanup is performed correctly after initialization. |
| 164 | + """ |
| 165 | + server = multicast.hear.McastServer(None, None) |
| 166 | + self.assertIsNotNone(server.logger) |
| 167 | + self.assertEqual(server.logger.name, 'multicast.hear.McastServer') |
| 168 | + server.server_close() # Clean up |
| 169 | + |
| 170 | + server = multicast.hear.McastServer((), None) |
| 171 | + self.assertIsNotNone(server.logger) |
| 172 | + self.assertEqual(server.logger.name, 'multicast.hear.McastServer') |
| 173 | + server.server_close() # Clean up |
| 174 | + |
| 175 | + |
123 | 176 | if __name__ == '__main__': |
124 | 177 | unittest.main() |
0 commit comments