Seregon/zftpd

Zero-copy FTP/HTTP Daemon compatible with all POSIX systems

C/11.0 KB/No license
ffi/python/tests/test_ffi.py
zftpd / ffi / python / tests / test_ffi.py
1import pytest
2from zftpd.core import PalAlloc, EventLoop, FtpServer, HttpServer
3 
4def 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 
19def 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 
30def 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