2
* Copyright (C) 2004-2012 See the AUTHORS file for details.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 2 as published
6
* by the Free Software Foundation.
9
#include "znc/ZNCString.h"
10
#include "znc/ZNCDebug.h"
12
static int testEqual(const CString& a, const CString& b, const CString& what)
16
std::cout << what << " failed for '" << b << "', result is '" << a << "'\n";
20
static int testString(const CString& in, const CString& url,
21
const CString& html, const CString& sql) {
25
// Encode, then decode again and check we still got the same string
27
out = in.Escape_n(CString::EASCII, CString::EURL);
28
errors += testEqual(out, url, "EURL encode");
29
out = out.Escape_n(CString::EURL, CString::EASCII);
30
errors += testEqual(out, in, "EURL decode");
32
out = in.Escape_n(CString::EASCII, CString::EHTML);
33
errors += testEqual(out, html, "EHTML encode");
34
out = out.Escape_n(CString::EHTML, CString::EASCII);
35
errors += testEqual(out, in, "EHTML decode");
37
out = in.Escape_n(CString::EASCII, CString::ESQL);
38
errors += testEqual(out, sql, "ESQL encode");
39
out = out.Escape_n(CString::ESQL, CString::EASCII);
40
errors += testEqual(out, in, "ESQL decode");
46
unsigned int failed = 0;
49
failed += testString("abcdefg", "abcdefg", "abcdefg", "abcdefg");
50
failed += testString("\n\t\r", "%0A%09%0D", "\n\t\r", "\\n\\t\\r");
51
failed += testString("'\"", "%27%22", "'"", "\\'\\\"");
52
failed += testString("&<>", "%26%3C%3E", "&<>", "&<>");