source: murachi/esteidfirefoxplugin/common/esteid_map_test.c @ f346e17

Last change on this file since f346e17 was 7d3ae3e, checked in by antonioaraujob <aaraujo@…>, 9 years ago

Agregados archivos fuentes del complemento esteidfirefoxplugin de Estonia para firmar electrónicamente un hash.

  • Property mode set to 100644
File size: 2.3 KB
Line 
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_map.h"
26
27void assertIntEquals(int expected, int actual) {
28        if (expected != actual) {
29                printf("assertion failed - expected: %i, actual %i", expected, actual);
30                exit(1);
31        }
32}
33
34void assertStringEquals(const char *expected, const char *actual) {
35        if (strcmp(expected, actual)) {
36                printf("assertion failed - expected: [%s], actual [%s]", expected, actual);
37                exit(1);
38        }
39}
40
41void assertNull(const void *ptr) {
42        if (ptr) {
43                printf("assertion failed - expected: NULL, actual [%p]", ptr);
44                exit(1);
45        }
46}
47
48void assertNotNull(const void *ptr) {
49        if (!ptr) {
50                printf("assertion failed - expected: !NULL, actual NULL");
51                exit(1);
52        }
53}
54
55int main(void) {
56
57        EstEID_Map map = NULL;
58        assertIntEquals(0, EstEID_mapSize(map));
59
60        map = EstEID_mapPut(map, "foo", "bar");
61        assertNotNull(map);
62        assertIntEquals(1, EstEID_mapSize(map));
63
64        map = EstEID_mapPut(map, "foo", "FOO");
65        assertIntEquals(1, EstEID_mapSize(map));
66
67        char *k = strdup("key");
68        char *v = strdup("value");
69        map = EstEID_mapPut(map, k, v);
70        free(k);
71        free(v);
72        assertIntEquals(2, EstEID_mapSize(map));
73        assertStringEquals("value", EstEID_mapGet(map, "key"));
74
75        assertNull(EstEID_mapGet(map, "xyz"));
76
77        EstEID_mapFree(map);
78
79
80        EstEID_Map m = EstEID_mapPut(NULL, "a", "A");
81        EstEID_mapPut(m, "b", "B");
82        EstEID_mapPut(m, "c", "C");
83
84        printf("map:\n");
85        EstEID_mapPrint(stdout, m);
86
87        EstEID_Map c = EstEID_mapClone(m);
88        EstEID_mapFree(m);
89
90        printf("clone:\n");
91        EstEID_mapPrint(stdout, c);
92        EstEID_mapFree(c);
93
94}
95
Note: See TracBrowser for help on using the repository browser.