~ubuntu-branches/ubuntu/trusty/znc/trusty

« back to all changes in this revision

Viewing changes to test/EscapeTest.cpp

  • Committer: Package Import Robot
  • Author(s): Patrick Matthäi
  • Date: 2013-11-08 13:13:58 UTC
  • mfrom: (34.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20131108131358-o90mlo1evvu27z8h
Tags: 1.2-1
* New upstream release.
  Closes: #728786
  - Remove merged patch 01-spelling-error.
  - Remove merged patch 02-CVE-2013-2130.
  - License has been changed to Apache-2.0.
  - Disable new tests, because they require an internet connection.
  - Add new znc-extra module modules_online.
  - Remove AUTHORS file.
* Bump Standards-Version to 3.9.5 (no changes needed).
* Don't explicitly request xz compression - dpkg 1.17 does this by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2004-2012  See the AUTHORS file for details.
3
 
 *
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.
7
 
 */
8
 
 
9
 
#include "znc/ZNCString.h"
10
 
#include "znc/ZNCDebug.h"
11
 
 
12
 
static int testEqual(const CString& a, const CString& b, const CString& what)
13
 
{
14
 
        if (a == b)
15
 
                return 0;
16
 
        std::cout << what << " failed for '" << b << "', result is '" << a << "'\n";
17
 
        return 1;
18
 
}
19
 
 
20
 
static int testString(const CString& in, const CString& url,
21
 
                const CString& html, const CString& sql) {
22
 
        CString out;
23
 
        int errors = 0;
24
 
 
25
 
        // Encode, then decode again and check we still got the same string
26
 
 
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");
31
 
 
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");
36
 
 
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");
41
 
 
42
 
        return errors;
43
 
}
44
 
 
45
 
int main() {
46
 
        unsigned int failed = 0;
47
 
 
48
 
        //                    input      url          html             sql
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",    "'&quot;",       "\\'\\\"");
52
 
        failed += testString("&<>",     "%26%3C%3E", "&amp;&lt;&gt;", "&<>");
53
 
 
54
 
        return failed;
55
 
}