Imported Upstream version 2.2.37
[platform/upstream/gpg2.git] / common / t-w32-reg.c
1 /* t-w32-reg.c - Regression tests for W32 registry functions
2  * Copyright (C) 2010 Free Software Foundation, Inc.
3  *
4  * This file is part of GnuPG.
5  *
6  * GnuPG is free software; you can redistribute and/or modify this
7  * part of GnuPG under the terms of either
8  *
9  *   - the GNU Lesser General Public License as published by the Free
10  *     Software Foundation; either version 3 of the License, or (at
11  *     your option) any later version.
12  *
13  * or
14  *
15  *   - the GNU General Public License as published by the Free
16  *     Software Foundation; either version 2 of the License, or (at
17  *     your option) any later version.
18  *
19  * or both in parallel, as here.
20  *
21  * GnuPG is distributed in the hope that it will be useful, but
22  * WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * General Public License for more details.
25  *
26  * You should have received a copies of the GNU General Public License
27  * and the GNU Lesser General Public License along with this program;
28  * if not, see <https://www.gnu.org/licenses/>.
29  */
30
31 #include <config.h>
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <time.h>
37
38 #include "mischelp.h"
39
40 #include "t-support.h"
41 #include "w32help.h"
42
43
44 static void
45 test_read_registry (void)
46 {
47   char *string1, *string2;
48
49   string1 = read_w32_registry_string
50     ("HKEY_CURRENT_USER",
51      "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
52      "User Agent");
53   if (!string1)
54     fail (0);
55   fprintf (stderr, "User agent: %s\n", string1);
56
57   string2 = read_w32_reg_string
58     ("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion"
59      "\\Internet Settings:User Agent", NULL);
60   if (!string2)
61     fail (1);
62   fprintf (stderr, "User agent: %s\n", string2);
63   if (strcmp (string1, string2))
64     fail (2);
65
66
67   xfree (string1);
68   xfree (string2);
69 }
70
71
72
73
74 int
75 main (int argc, char **argv)
76 {
77   if (argc > 1)
78     {
79       char *string = read_w32_reg_string (argv[1], NULL);
80       printf ("%s -> %s\n", argv[1], string? string : "(null)");
81       xfree (string);
82     }
83   else
84     test_read_registry ();
85
86   return 0;
87 }