File: test-pgsql-escape.cpp

package info (click to toggle)
osm2pgsql 0.92.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,420 kB
  • ctags: 1,429
  • sloc: cpp: 11,650; python: 543; sh: 98; makefile: 14
file content (22 lines) | stat: -rw-r--r-- 540 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include "pgsql.hpp"

void test_escape(const char *in, const char *out) {
    std::string sql;
    escape(in, sql);
    if (sql.compare(out) != 0) {
        std::cerr << "Expected " << out << ", but got " << sql << " for " << in <<".\n";
        exit(1);
    }
}

int main(int argc, char *argv[]) {
    std::string sql;
    test_escape("farmland", "farmland");
    test_escape("", "");
    test_escape("\\", "\\\\");
    test_escape("foo\nbar", "foo\\\nbar");
    test_escape("\t\r\n", "\\\t\\\r\\\n");

    return 0;
}