1+ #include <assert.h>
2+ #include <stdio.h>
3+ #include <wchar.h>
4+ #include "../src/WinDepends.Core/cmd.h"
5+ #include "../src/WinDepends.Core/mlist.h"
6+
7+ void test_cmd_entry_parsing (void ) {
8+ assert (get_command_entry (L"open" ) == ce_open );
9+ assert (get_command_entry (L"close" ) == ce_close );
10+ assert (get_command_entry (L"imports" ) == ce_imports );
11+ assert (get_command_entry (L"exports" ) == ce_exports );
12+ assert (get_command_entry (L"headers" ) == ce_headers );
13+ assert (get_command_entry (L"datadirs" ) == ce_datadirs );
14+ assert (get_command_entry (L"shutdown" ) == ce_shutdown );
15+ assert (get_command_entry (L"exit" ) == ce_exit );
16+ assert (get_command_entry (L"knowndlls" ) == ce_knowndlls );
17+ assert (get_command_entry (L"apisetresolve" ) == ce_apisetresolve );
18+ assert (get_command_entry (L"apisetmapsrc" ) == ce_apisetmapsrc );
19+ assert (get_command_entry (L"apisetnsinfo" ) == ce_apisetnsinfo );
20+ assert (get_command_entry (L"callstats" ) == ce_callstats );
21+ assert (get_command_entry (L"notacommand" ) == ce_unknown );
22+ }
23+
24+ void test_mlist_add_and_traverse (void ) {
25+ LIST_ENTRY head ;
26+ PLIST_ENTRY entry ;
27+ message_node * node ;
28+ size_t count ;
29+ const wchar_t * msg1 = L"msg1" ;
30+ const wchar_t * msg2 = L"some much longer message to check allocation" ;
31+ size_t len1 = wcslen (msg1 );
32+ size_t len2 = wcslen (msg2 );
33+
34+ InitializeListHead (& head );
35+
36+ assert (mlist_add (& head , msg1 , len1 ) == TRUE);
37+ assert (mlist_add (& head , msg2 , len2 ) == TRUE);
38+
39+ count = 0 ;
40+ for (entry = head .Flink ; entry != & head ; entry = entry -> Flink ) {
41+ node = CONTAINING_RECORD (entry , message_node , ListEntry );
42+ assert (node -> message != NULL );
43+ count ++ ;
44+ }
45+ assert (count == 2 );
46+ }
47+
48+ void test_mlist_add_empty_and_failure (void ) {
49+ LIST_ENTRY head ;
50+ InitializeListHead (& head );
51+
52+ assert (mlist_add (& head , L"" , 0 ) == TRUE);
53+ assert (mlist_add (NULL , L"test" , 4 ) == FALSE);
54+ }
55+
56+ void test_mlist_traverse_send_and_cleanup (void ) {
57+ LIST_ENTRY head ;
58+ message_node * node ;
59+ PLIST_ENTRY entry , next ;
60+ InitializeListHead (& head );
61+
62+ mlist_add (& head , L"abc" , 3 );
63+ mlist_add (& head , L"defgh" , 5 );
64+
65+ entry = head .Flink ;
66+ while (entry != & head ) {
67+ next = entry -> Flink ;
68+ node = CONTAINING_RECORD (entry , message_node , ListEntry );
69+ if (!node -> isStaticBuffer && node -> message ) {
70+ heap_free (GetProcessHeap (), node -> message );
71+ }
72+ heap_free (GetProcessHeap (), node );
73+ entry = next ;
74+ }
75+ InitializeListHead (& head );
76+ }
77+
78+ void test_cmd_unknown_command_handler (void ) {
79+ SOCKET fake_sock = 0 ;
80+ cmd_unknown_command (fake_sock );
81+ }
82+
83+ int main (void ) {
84+ test_cmd_entry_parsing ();
85+ test_mlist_add_and_traverse ();
86+ test_mlist_add_empty_and_failure ();
87+ test_mlist_traverse_send_and_cleanup ();
88+ test_cmd_unknown_command_handler ();
89+
90+ printf ("All detailed WinDepends.Core tests passed.\n" );
91+ return 0 ;
92+ }
0 commit comments