Zero-copy FTP/HTTP Daemon compatible with all POSIX systems
| 1 | import pytest |
| 2 | from zftpd.core import PalAlloc, EventLoop, FtpServer, HttpServer |
| 3 | |
| 4 | def test_pal_alloc(): |
| 5 | # Initialize allocator |
| 6 | assert PalAlloc.init_default() is True |
| 7 | |
| 8 | # Allocate memory |
| 9 | ptr = PalAlloc.malloc(1024) |
| 10 | assert ptr is not None |
| 11 | |
| 12 | # Check approximate free space |
| 13 | free_approx = PalAlloc.get_arena_free_approx() |
| 14 | assert free_approx > 0 |
| 15 | |
| 16 | # Free memory |
| 17 | PalAlloc.free(ptr) |
| 18 | |
| 19 | def test_ftp_server(): |
| 20 | server = FtpServer("127.0.0.1", 2121, "/tmp") |
| 21 | server.start() |
| 22 | |
| 23 | assert server.is_running() is True |
| 24 | assert server.active_sessions() == 0 |
| 25 | |
| 26 | server.stop() |
| 27 | assert server.is_running() is False |
| 28 | server.close() |
| 29 | |
| 30 | def test_http_server(): |
| 31 | # Loop and Server both implement Context Manager protocol |
| 32 | with EventLoop() as loop: |
| 33 | with HttpServer(loop, 8888) as http: |
| 34 | pass # Creating it implies it works; will auto-close on __exit__ |
| 35 |