summaryrefslogtreecommitdiff
path: root/libproxy/test/url-encode.cpp
blob: ef386a35a4ce836542831b36c8e4560ff210300e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <cassert>
#include <iostream>
#include <string>


#include "url.hpp"

using namespace libproxy;

#define test(cond,rtv) _test(#cond, (cond), (rtv))
void _test (const string &exp, bool condition, bool &rtv)
{
	if (!condition) {
		cerr << "Failed: " << exp << endl;
		rtv = false;
	}
}

int main()
{
	bool rtv = true;
	string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._~";

	test(url::encode(valid) == valid, rtv);
	test(url::encode("é") == "%c3%a9", rtv);
	test(url::encode("+!@#$^\r%", "!#^") == "%2b!%40#%24^%0d%25", rtv);

	return !rtv;
}