Keep track of per-column information inside the listview.
[wine] / dlls / wininet / tests / http.c
1 #include "wine/test.h"
2 #include <stdio.h>
3 #include "winbase.h"
4 #include "wininet.h"
5
6 int goon = 0;
7
8 VOID WINAPI callback(
9      HINTERNET hInternet,
10      DWORD dwContext,
11      DWORD dwInternetStatus,
12      LPVOID lpvStatusInformation,
13      DWORD dwStatusInformationLength
14 )
15 {
16     char name[124];
17
18     switch (dwInternetStatus)
19     {
20         case INTERNET_STATUS_RESOLVING_NAME:
21             strcpy(name,"INTERNET_STATUS_RESOLVING_NAME");
22             break;
23         case INTERNET_STATUS_NAME_RESOLVED:
24             strcpy(name,"INTERNET_STATUS_NAME_RESOLVED");
25             break;
26         case INTERNET_STATUS_CONNECTING_TO_SERVER:
27             strcpy(name,"INTERNET_STATUS_CONNECTING_TO_SERVER");
28             break;
29         case INTERNET_STATUS_CONNECTED_TO_SERVER:
30             strcpy(name,"INTERNET_STATUS_CONNECTED_TO_SERVER");
31             break;
32         case INTERNET_STATUS_SENDING_REQUEST:
33             strcpy(name,"INTERNET_STATUS_SENDING_REQUEST");
34             break;
35         case INTERNET_STATUS_REQUEST_SENT:
36             strcpy(name,"INTERNET_STATUS_REQUEST_SENT");
37             break;
38         case INTERNET_STATUS_RECEIVING_RESPONSE:
39             strcpy(name,"INTERNET_STATUS_RECEIVING_RESPONSE");
40             break;
41         case INTERNET_STATUS_RESPONSE_RECEIVED:
42             strcpy(name,"INTERNET_STATUS_RESPONSE_RECEIVED");
43             break;
44         case INTERNET_STATUS_CTL_RESPONSE_RECEIVED:
45             strcpy(name,"INTERNET_STATUS_CTL_RESPONSE_RECEIVED");
46             break;
47         case INTERNET_STATUS_PREFETCH:
48             strcpy(name,"INTERNET_STATUS_PREFETCH");
49             break;
50         case INTERNET_STATUS_CLOSING_CONNECTION:
51             strcpy(name,"INTERNET_STATUS_CLOSING_CONNECTION");
52             break;
53         case INTERNET_STATUS_CONNECTION_CLOSED:
54             strcpy(name,"INTERNET_STATUS_CONNECTION_CLOSED");
55             break;
56         case INTERNET_STATUS_HANDLE_CREATED:
57             strcpy(name,"INTERNET_STATUS_HANDLE_CREATED");
58             break;
59         case INTERNET_STATUS_HANDLE_CLOSING:
60             strcpy(name,"INTERNET_STATUS_HANDLE_CLOSING");
61             break;
62         case INTERNET_STATUS_REQUEST_COMPLETE:
63             strcpy(name,"INTERNET_STATUS_REQUEST_COMPLETE");
64             goon = 1;
65             break;
66         case INTERNET_STATUS_REDIRECT:
67             strcpy(name,"INTERNET_STATUS_REDIRECT");
68             break;
69         case INTERNET_STATUS_INTERMEDIATE_RESPONSE:
70             strcpy(name,"INTERNET_STATUS_INTERMEDIATE_RESPONSE");
71             break;
72     }
73
74     trace("Callback %p 0x%lx %s(%li) %p %ld\n",hInternet,dwContext,name,dwInternetStatus,lpvStatusInformation,dwStatusInformationLength);
75 }
76
77 void winapi_test(int flags)
78 {
79     DWORD rc;
80     CHAR buffer[4000];
81     DWORD length;
82     DWORD out;
83     char *types;
84     HINTERNET hi,hic,hor;
85
86     trace("Starting with flags 0x%x\n",flags);
87
88     trace("InternetOpenA <--\n");
89     hi = InternetOpenA("",0x0,0x0,0x0,flags);
90     ok((hi != 0x0),"InternetOpen Failed");
91     trace("InternetOpenA -->\n");
92
93     if (hi == 0x0) goto abort;
94
95     InternetSetStatusCallback(hi,&callback);
96
97     trace("InternetConnectA <--\n");
98     hic=InternetConnectA(hi,"www.winehq.com",0x0,0x0,0x0,0x3,0x0,0xdeadbeef);
99     ok((hic != 0x0),"InternetConnect Failed");
100     trace("InternetConnectA -->\n");
101
102     if (hic == 0x0) goto abort;
103
104     types = (char*)malloc(100);
105     strcpy(types,"*");
106
107     trace("HttpOpenRequestA <--\n");
108     hor = HttpOpenRequestA(hic, "GET",
109                           "/about/",
110                           0x0,0x0,(const char**)&types,0x00400800,0xdeadbead);
111     if (hor == 0x0 && GetLastError() == 12007 /* ERROR_INTERNET_NAME_NOT_RESOLVED */) {
112         /*
113          * If the internet name can't be resolved we are probably behind
114          * a firewall or in some other way not directly connected to the
115          * Internet. Not enough reason to fail the test. Just ignore and
116          * abort.
117          */
118     } else  {
119         ok((hor != 0x0),"HttpOpenRequest Failed");
120     }
121     trace("HttpOpenRequestA -->\n");
122
123     if (hor == 0x0) goto abort;
124
125     trace("HttpSendRequestA -->\n");
126     rc = HttpSendRequestA(hor, "", 0xffffffff,0x0,0x0);
127     if (flags)
128         ok(((rc == 0)&&(GetLastError()==997)),
129             "Asyncronous HttpSendRequest NOT returning 0 with error 997");
130     else
131         ok((rc != 0), "Syncronous HttpSendRequest returning 0");
132     trace("HttpSendRequestA <--\n");
133
134     while ((flags)&&(!goon))
135         Sleep(100);
136
137     length = 4;
138     rc = InternetQueryOptionA(hor,0x17,&out,&length);
139     trace("Option 0x17 -> %li  %li\n",rc,out);
140
141     length = 100;
142     rc = InternetQueryOptionA(hor,0x22,buffer,&length);
143     trace("Option 0x22 -> %li  %s\n",rc,buffer);
144
145     length = 4000;
146     rc = HttpQueryInfoA(hor,0x16,buffer,&length,0x0);
147     buffer[length]=0;
148     trace("Option 0x16 -> %li  %s\n",rc,buffer);
149
150     length = 4000;
151     rc = InternetQueryOptionA(hor,0x22,buffer,&length);
152     buffer[length]=0;
153     trace("Option 0x22 -> %li  %s\n",rc,buffer);
154
155     length = 16;
156     rc = HttpQueryInfoA(hor,0x5,&buffer,&length,0x0);
157     trace("Option 0x5 -> %li  %s  (%li)\n",rc,buffer,GetLastError());
158
159     length = 100;
160     rc = HttpQueryInfoA(hor,0x1,buffer,&length,0x0);
161     buffer[length]=0;
162     trace("Option 0x1 -> %li  %s\n",rc,buffer);
163
164     length = 100;
165     trace("Entery Query loop\n");
166
167     while (length)
168     {
169
170         rc = InternetQueryDataAvailable(hor,&length,0x0,0x0);
171         ok((rc != 0),"InternetQueryDataAvailable failed");
172
173         if (length)
174         {
175             char *buffer;
176             buffer = (char*)HeapAlloc(GetProcessHeap(),0,length+1);
177
178             rc = InternetReadFile(hor,buffer,length,&length);
179
180             buffer[length]=0;
181
182             trace("ReadFile -> %li %li\n",rc,length);
183
184             HeapFree(GetProcessHeap(),0,buffer);
185         }
186     }
187 abort:
188     if (hor != 0x0) {
189         rc = InternetCloseHandle(hor);
190         ok ((rc != 0), "InternetCloseHandle of handle opened by HttpOpenRequestA failed");
191     }
192     if (hor != 0x0) {
193         rc = InternetCloseHandle(hic);
194         ok ((rc != 0), "InternetCloseHandle of handle opened by InternetConnectA failed");
195     }
196     if (hi != 0x0) {
197       rc = InternetCloseHandle(hi);
198       ok ((rc != 0), "InternetCloseHandle of handle opened by InternetOpenA failed");
199       if (flags)
200           Sleep(100);
201     }
202 }
203
204
205 START_TEST(http)
206 {
207     winapi_test(0x10000000);
208     winapi_test(0x00000000);
209 }