1 | /* |
---|
2 | * Estonian ID card plugin for web browsers |
---|
3 | * |
---|
4 | * Copyright (C) 2010-2011 Codeborne <info@codeborne.com> |
---|
5 | * |
---|
6 | * This is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Lesser General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2.1 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This software is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Lesser General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Lesser General Public |
---|
17 | * License along with this library; if not, write to the Free Software |
---|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
---|
19 | * |
---|
20 | */ |
---|
21 | |
---|
22 | #include <stdlib.h> |
---|
23 | #include <stdio.h> |
---|
24 | #include <string.h> |
---|
25 | #include "esteid_json.h" |
---|
26 | |
---|
27 | void assertStringEquals(const char *expected, char *actual) { |
---|
28 | if (strcmp(expected, actual)) { |
---|
29 | printf("assertion failed - expected: [%s], actual [%s]\n", expected, actual); |
---|
30 | free(actual); |
---|
31 | exit(1); |
---|
32 | } |
---|
33 | free(actual); |
---|
34 | } |
---|
35 | |
---|
36 | int main(void) { |
---|
37 | assertStringEquals("foo", EstEID_jsonString("foo")); |
---|
38 | assertStringEquals("foo\\\"", EstEID_jsonString("foo\"")); |
---|
39 | assertStringEquals("foo\\\\", EstEID_jsonString("foo\\")); |
---|
40 | assertStringEquals("\\n", EstEID_jsonString("\n")); |
---|
41 | assertStringEquals("foo\\\\bar\\r\\n\\\"test\\\"", EstEID_jsonString("foo\\bar\r\n\"test\"")); |
---|
42 | |
---|
43 | EstEID_Map map = NULL; |
---|
44 | assertStringEquals("{}", EstEID_mapToJson(map)); |
---|
45 | map = EstEID_mapPut(map, "foo", "bar"); |
---|
46 | assertStringEquals("{\"foo\": \"bar\"}", EstEID_mapToJson(map)); |
---|
47 | |
---|
48 | map = EstEID_mapPut(map, "a\nb", "\"123\""); |
---|
49 | assertStringEquals("{\"foo\": \"bar\", \"a\\nb\": \"\\\"123\\\"\"}", EstEID_mapToJson(map)); |
---|
50 | |
---|
51 | EstEID_mapFree(map); |
---|
52 | |
---|
53 | return 0; |
---|
54 | } |
---|
55 | |
---|