"Initial commit to Gerrit"
[profile/ivi/libgsf.git] / tests / test-msvba.c
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-msvba.c:
4  *
5  * Copyright (C) 2002-2006      Jody Goldberg (jody@gnome.org)
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of version 2.1 of the GNU Lesser General Public
9  * License as published by the Free Software Foundation.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
19  * USA
20  */
21
22 #include <gsf/gsf-input-stdio.h>
23 #include <gsf/gsf-input-memory.h>
24 #include <gsf/gsf-utils.h>
25 #include <gsf/gsf-infile.h>
26 #include <gsf/gsf-infile-msole.h>
27 #include <gsf/gsf-infile-msvba.h>
28
29 #include <stdio.h>
30
31 static int
32 test (int argc, char *argv[])
33 {
34         GsfInfile *vba_wrapper;
35         GsfInput  *input;
36         GError    *err = NULL;
37         int i;
38
39         for (i = 1 ; i < argc ; i++) {
40                 input = gsf_input_mmap_new (argv[i], NULL);
41                 if (input == NULL)      /* Only report error if stdio fails too */
42                         input = gsf_input_stdio_new (argv[i], &err);
43                 if (input != NULL) {
44                         GsfInfile *infile = gsf_infile_msole_new (input, &err);
45                         if (infile != NULL) {
46                                 GsfInput *vba = gsf_infile_child_by_vname (infile, "_VBA_PROJECT_CUR", "VBA", NULL);
47                                 if (vba != NULL) {
48                                         fprintf( stderr, "%s\n",argv[i]);
49
50                                         vba_wrapper = gsf_infile_msvba_new (GSF_INFILE (vba), &err);
51                                         if (vba_wrapper != NULL) {
52                                                 g_object_unref (G_OBJECT (vba_wrapper));
53                                         }
54                                         g_object_unref (G_OBJECT (vba));
55                                 } else {
56 #if 0
57                                         g_warning ("'%s' : No VBA directory", argv[i]);
58 #endif
59                                         continue;
60                                 }
61
62                                 g_object_unref (G_OBJECT (infile));
63                         }
64                         g_object_unref (G_OBJECT (input));
65                 }
66
67                 if (err != NULL) {
68                         g_warning ("'%s' error: %s", argv[i], err->message);
69                         g_error_free (err);
70                         err = NULL;
71                 }
72         }
73
74         return 0;
75 }
76
77 int
78 main (int argc, char *argv[])
79 {
80         int res;
81
82         gsf_init ();
83         res = test (argc, argv);
84         gsf_shutdown ();
85
86         return res;
87 }