Skip to content

Commit 208cf71

Browse files
committed
C++: Add tests with tests for remote flow sources from the Win32 API and from the Azure SDK.
1 parent 5204255 commit 208cf71

File tree

3 files changed

+461
-0
lines changed

3 files changed

+461
-0
lines changed
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
using uint16_t = unsigned short;
2+
using int64_t = long long;
3+
using size_t = unsigned long;
4+
using uint8_t = unsigned char;
5+
using int32_t = int;
6+
using uint32_t = unsigned int;
7+
8+
namespace std
9+
{
10+
class string
11+
{
12+
public:
13+
string();
14+
string(const char *);
15+
~string();
16+
};
17+
18+
template <typename K, typename V>
19+
class map
20+
{
21+
public:
22+
map();
23+
~map();
24+
25+
V& operator[](const K& key);
26+
};
27+
28+
template <typename T>
29+
class vector
30+
{
31+
public:
32+
vector();
33+
~vector();
34+
35+
T& operator[](size_t);
36+
};
37+
38+
template<typename T>
39+
class unique_ptr {
40+
public:
41+
unique_ptr();
42+
~unique_ptr();
43+
44+
T* get();
45+
};
46+
}
47+
48+
namespace Azure
49+
{
50+
template <typename T>
51+
class Nullable
52+
{
53+
public:
54+
Nullable();
55+
Nullable(const T);
56+
Nullable(const Nullable &);
57+
~Nullable();
58+
Nullable (Nullable &&);
59+
Nullable & operator= (const Nullable &);
60+
bool HasValue() const;
61+
const T & Value () const;
62+
T& Value ();
63+
const T * operator-> () const;
64+
T * operator-> ();
65+
const T & operator* () const;
66+
T & operator* ();
67+
};
68+
69+
namespace Core
70+
{
71+
class Url
72+
{
73+
public:
74+
Url();
75+
Url(const std::string &);
76+
void AppendPath(const std::string &encodedPath);
77+
void AppendQueryParameter(const std::string &encodedKey,
78+
const std::string &encodedValue);
79+
80+
static std::string Url::Decode(const std::string &value);
81+
static std::string Url::Encode(const std::string &value,
82+
const std::string &doNotEncodeSymbols = "");
83+
84+
std::string Url::GetAbsoluteUrl() const;
85+
const std::string &GetHost() const;
86+
const std::string &GetPath() const;
87+
uint16_t GetPort() const;
88+
std::map<std::string, std::string> GetQueryParameters() const;
89+
std::string Url::GetRelativeUrl() const;
90+
const std::string &GetScheme() const;
91+
void RemoveQueryParameter(const std::string &encodedKey);
92+
void SetHost(const std::string &encodedHost);
93+
void SetPath(const std::string &encodedPath);
94+
void SetPort(uint16_t port);
95+
void SetQueryParameters(std::map<std::string, std::string> queryParameters);
96+
void SetScheme(const std::string &scheme);
97+
};
98+
99+
class Context
100+
{
101+
public:
102+
Context();
103+
};
104+
105+
namespace IO
106+
{
107+
class BodyStream
108+
{
109+
public:
110+
virtual ~BodyStream();
111+
virtual int64_t Length() const = 0;
112+
virtual void Rewind();
113+
size_t Read(uint8_t *buffer, size_t count, Azure::Core::Context const &context = Azure::Core::Context());
114+
size_t ReadToCount(uint8_t *buffer, size_t count, Azure::Core::Context const &context = Azure::Core::Context());
115+
std::vector<uint8_t> ReadToEnd(Azure::Core::Context const &context = Azure::Core::Context());
116+
};
117+
}
118+
119+
enum class HttpStatusCode {
120+
None = 0,
121+
Continue = 100,
122+
SwitchingProtocols = 101,
123+
Processing = 102,
124+
EarlyHints = 103,
125+
OK = 200,
126+
Created = 201,
127+
Accepted = 202,
128+
NonAuthoritativeInformation = 203,
129+
NoContent = 204,
130+
ResetContent = 205,
131+
PartialContent = 206,
132+
MultiStatus = 207,
133+
AlreadyReported = 208,
134+
IMUsed = 226,
135+
MultipleChoices = 300,
136+
MovedPermanently = 301,
137+
Found = 302,
138+
SeeOther = 303,
139+
NotModified = 304,
140+
UseProxy = 305,
141+
TemporaryRedirect = 307,
142+
PermanentRedirect = 308,
143+
BadRequest = 400,
144+
Unauthorized = 401,
145+
PaymentRequired = 402,
146+
Forbidden = 403,
147+
NotFound = 404,
148+
MethodNotAllowed = 405,
149+
NotAcceptable = 406,
150+
ProxyAuthenticationRequired = 407,
151+
RequestTimeout = 408,
152+
Conflict = 409,
153+
Gone = 410,
154+
LengthRequired = 411,
155+
PreconditionFailed = 412,
156+
PayloadTooLarge = 413,
157+
URITooLong = 414,
158+
UnsupportedMediaType = 415,
159+
RangeNotSatisfiable = 416,
160+
ExpectationFailed = 417,
161+
MisdirectedRequest = 421,
162+
UnprocessableEntity = 422,
163+
Locked = 423,
164+
FailedDependency = 424,
165+
TooEarly = 425,
166+
UpgradeRequired = 426,
167+
PreconditionRequired = 428,
168+
TooManyRequests = 429,
169+
RequestHeaderFieldsTooLarge = 431,
170+
UnavailableForLegalReasons = 451,
171+
InternalServerError = 500,
172+
NotImplemented = 501,
173+
BadGateway = 502,
174+
ServiceUnavailable = 503,
175+
GatewayTimeout = 504,
176+
HTTPVersionNotSupported = 505,
177+
VariantAlsoNegotiates = 506,
178+
InsufficientStorage = 507,
179+
LoopDetected = 508,
180+
NotExtended = 510,
181+
NetworkAuthenticationRequired = 511
182+
};
183+
184+
namespace Http
185+
{
186+
class HttpMethod
187+
{
188+
public:
189+
HttpMethod(std::string value);
190+
bool operator==(const HttpMethod &other) const;
191+
bool operator!=(const HttpMethod &other) const;
192+
const std::string &ToString() const;
193+
};
194+
195+
extern const HttpMethod Get;
196+
extern const HttpMethod Head;
197+
extern const HttpMethod Post;
198+
extern const HttpMethod Put;
199+
extern const HttpMethod Delete;
200+
extern const HttpMethod Patch;
201+
extern const HttpMethod Options;
202+
203+
class Request
204+
{
205+
public:
206+
explicit Request(HttpMethod httpMethod,
207+
Url url);
208+
explicit Request(HttpMethod httpMethod,
209+
Url url,
210+
bool shouldBufferResponse);
211+
explicit Request(HttpMethod httpMethod,
212+
Url url,
213+
IO::BodyStream *bodyStream);
214+
explicit Request(HttpMethod httpMethod,
215+
Url url,
216+
IO::BodyStream *bodyStream,
217+
bool shouldBufferResponse);
218+
std::map<std::string, std::string> GetHeaders () const;
219+
Azure::Nullable<std::string> GetHeader(std::string const &name);
220+
IO::BodyStream * GetBodyStream();
221+
Azure::Core::IO::BodyStream const* GetBodyStream () const;
222+
};
223+
224+
class RawResponse {
225+
public:
226+
RawResponse (int32_t majorVersion, int32_t minorVersion, HttpStatusCode statusCode, std::string const &reasonPhrase);
227+
RawResponse (RawResponse const &response);
228+
RawResponse (RawResponse &&response);
229+
~RawResponse ();
230+
void SetHeader (std::string const &name, std::string const &value);
231+
void SetBodyStream (std::unique_ptr< Azure::Core::IO::BodyStream > stream);
232+
void SetBody (std::vector< uint8_t > body);
233+
uint32_t GetMajorVersion () const;
234+
uint32_t GetMinorVersion () const;
235+
HttpStatusCode GetStatusCode () const;
236+
std::string const & GetReasonPhrase () const;
237+
std::map<std::string, std::string>& GetHeaders () const;
238+
std::unique_ptr<Azure::Core::IO::BodyStream> ExtractBodyStream ();
239+
std::vector<uint8_t> & GetBody ();
240+
std::vector<uint8_t> const& GetBody() const;
241+
};
242+
}
243+
}
244+
}
245+
246+
void sink(char);
247+
void sink(std::string);
248+
void sink(std::vector<uint8_t>);
249+
void sink(Azure::Nullable<std::string>);
250+
251+
void test_BodyStream() {
252+
Azure::Core::Http::Request request(Azure::Core::Http::Get, Azure::Core::Url("http://example.com"));
253+
Azure::Core::IO::BodyStream * resp = request.GetBodyStream();
254+
255+
{
256+
unsigned char buffer[1024];
257+
resp->Read(buffer, sizeof(buffer));
258+
sink(*buffer); // $ MISSING: ir
259+
}
260+
{
261+
unsigned char buffer[1024];
262+
resp->ReadToCount(buffer, sizeof(buffer));
263+
sink(*buffer); // $ MISSING: ir
264+
}
265+
{
266+
std::vector<unsigned char> vec = resp->ReadToEnd();
267+
sink(vec); // $ MISSING: ir
268+
}
269+
}
270+
271+
void test_RawResponse(Azure::Core::Http::RawResponse& resp) {
272+
{
273+
std::map<std::string, std::string> body = resp.GetHeaders();
274+
sink(body["Content-Type"]); // $ MISSING: ir
275+
}
276+
{
277+
std::vector<uint8_t> body = resp.GetBody();
278+
sink(body); // $ MISSING: ir
279+
}
280+
{
281+
std::unique_ptr<Azure::Core::IO::BodyStream> bodyStream = resp.ExtractBodyStream();
282+
sink(bodyStream.get()->ReadToEnd()); // $ MISSING: ir
283+
}
284+
}
285+
286+
void test_GetHeader() {
287+
Azure::Core::Http::Request request(Azure::Core::Http::Get, Azure::Core::Url("http://example.com"));
288+
{
289+
auto headerValue = request.GetHeader("Content-Type").Value();
290+
sink(headerValue); // $ MISSING: ir
291+
}
292+
{
293+
std::map<std::string, std::string> headers = request.GetHeaders();
294+
std::string contentType = headers["Content-Type"];
295+
sink(contentType); // $ MISSING: ir
296+
}
297+
}

cpp/ql/test/library-tests/dataflow/external-models/validatemodels.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,3 +5586,6 @@
55865586
| Unrecognized output specification "Field[***hEvent]" in summary model. |
55875587
| Unrecognized output specification "Parameter[***0]" in summary model. |
55885588
| Unrecognized output specification "Parameter[****0]" in summary model. |
5589+
| Unrecognized output specification "ReturnValue[*****]" in summary model. |
5590+
| Unrecognized output specification "ReturnValue[****]" in summary model. |
5591+
| Unrecognized output specification "ReturnValue[***]" in summary model. |

0 commit comments

Comments
 (0)