"Initial commit to Gerrit"
[profile/ivi/libgsf.git] / tests / test-gio.c
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-cp-zip.c: Test gsf_input_copy
4  *
5  * Copyright (C) 2002-2006      Dom Lachowicz <cinamod@hotmail.com>
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 <stdio.h>
23 #include <gsf/gsf-utils.h>
24 #include <gsf/gsf-input-gio.h>
25 #include <gsf/gsf-infile.h>
26 #include <gsf/gsf-output-gio.h>
27 #include <gsf/gsf-outfile.h>
28
29 static int
30 test (char *argv[])
31 {
32         GsfInput   *input;
33         GsfOutput  *output;
34         GError     *err = NULL;
35         int         rval = 0;
36
37         input = gsf_input_gio_new_for_path (argv[1], &err);
38         if (input == NULL) {
39
40                 g_return_val_if_fail (err != NULL, 1);
41
42                 g_warning ("'%s' error: %s\n", argv[1], err->message);
43                 g_error_free (err);
44                 return 1;
45         }
46
47         output = gsf_output_gio_new_for_path (argv[2], &err);
48         if (output == NULL) {
49
50                 g_return_val_if_fail (err != NULL, 1);
51
52                 g_warning ("'%s' error: %s\n", argv[2], err->message);
53                 g_error_free (err);
54
55                 g_object_unref (G_OBJECT (input));
56                 return 1;
57         }
58
59         if (gsf_input_copy (input, output) == FALSE) {
60                 rval = 1;
61                 err = (GError*) gsf_output_error (output);
62                 if (err != NULL) {
63                         g_warning ("'%s' error: %s\n", argv[2], err->message);  
64                 }
65         }
66
67         g_object_unref (G_OBJECT (input));
68
69         gsf_output_close (output);
70         g_object_unref (G_OBJECT (output));
71
72         return rval;
73 }
74
75 int
76 main (int argc, char *argv[])
77 {
78         int res;
79
80         if (argc != 3) {
81                 fprintf (stderr, "%s : infile outfile\n", argv [0]);
82                 return 1;
83         }
84
85         gsf_init ();
86         res = test (argv);
87         gsf_shutdown ();
88
89         return res;
90 }