Debian Codegraph @

tests/TEST_README.md

raw
1 # resolve_host() Test Suite
2
3 This directory contains comprehensive tests for the `resolve_host()` function in `pacparser.c`.
4
5 ## Test Files
6
7 ### 1. test_resolve_host.c
8 Basic functional testing with various hostnames and configurations.
9
10 **Compile & Run:**
11 ```bash
12 gcc -g -Wall -o test_resolve_host test_resolve_host.c
13 ./test_resolve_host
14 ```
15
16 **Tests:**
17 - IPv4/IPv6 resolution
18 - localhost resolution
19 - Invalid/empty hostnames
20 - Numeric IP addresses
21 - max_results limiting
22
23 ### 2. test_multi_ip.c
24 Specific tests for multiple IP address handling.
25
26 **Compile & Run:**
27 ```bash
28 gcc -g -Wall -o test_multi_ip test_multi_ip.c
29 ./test_multi_ip
30 ```
31
32 **Tests:**
33 - Multiple IP resolution with semicolon separation
34 - Format validation (no leading/trailing/double semicolons)
35 - max_results limiting with multiple IPs
36
37 ### 3. test_buffer_safety.c
38 Memory safety and buffer overflow detection.
39
40 **Compile & Run:**
41 ```bash
42 gcc -g -Wall -o test_buffer_safety test_buffer_safety.c
43 ./test_buffer_safety
44 ```
45
46 **Tests:**
47 - Canary-based overflow detection
48 - Edge case: max_results = 0
49 - Long IPv6 addresses
50 - Buffer utilization metrics
51
52 ### 4. test_edge_cases.c
53 Comprehensive edge case and boundary condition testing.
54
55 **Compile & Run:**
56 ```bash
57 gcc -g -Wall -o test_edge_cases test_edge_cases.c
58 ./test_edge_cases
59 ```
60
61 **Tests:**
62 - max_results boundaries (0, 1, MAX)
63 - IPv4-only, IPv6-only, and mixed resolution
64 - Numeric IPs (including IPv4-mapped IPv6)
65 - Null termination verification
66 - Write-beyond-buffer detection
67
68 ## Running All Tests
69
70 ```bash
71 # Compile all
72 for test in test_resolve_host test_multi_ip test_buffer_safety test_edge_cases; do
73 gcc -g -Wall -o $test ${test}.c
74 done
75
76 # Run all
77 for test in test_resolve_host test_multi_ip test_buffer_safety test_edge_cases; do
78 echo "=== Running $test ==="
79 ./$test
80 echo
81 done
82 ```
83
84 ## Clean Up
85
86 ```bash
87 rm -f test_resolve_host test_multi_ip test_buffer_safety test_edge_cases
88 ```
89
90 ## Test Coverage
91
92 These tests verify:
93 - ✅ Single and multiple IP resolution
94 - ✅ IPv4 and IPv6 handling
95 - ✅ Semicolon separation formatting
96 - ✅ Buffer safety (no overruns)
97 - ✅ Null termination
98 - ✅ Error handling for invalid hostnames
99 - ✅ max_results limiting
100 - ✅ Edge cases (empty results, max boundaries)
101 - ✅ All address families (AF_INET, AF_INET6, AF_UNSPEC)
102
103 ## Notes
104
105 - Some tests (google.com, IPv6) require network connectivity
106 - IPv6 tests may fail on IPv4-only systems (this is expected)
107 - The tests use the same `resolve_host()` implementation from `pacparser.c`
108 - All tests include validation to detect memory corruption and format errors