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-stdio.h>
25 #include <gsf/gsf-infile.h>
26 #include <gsf/gsf-output-stdio.h>
27 #include <gsf/gsf-outfile.h>
28 
29 static int
test(char * argv[])30 test (char *argv[])
31 {
32 	GsfInput   *input = NULL;
33 	GsfOutput  *output = NULL;
34 	GError     *err = NULL;
35 	int         rval = 0;
36 	GDateTime  *modtime;
37 
38 	input = gsf_input_stdio_new (argv[1], &err);
39 	if (input == NULL) {
40 
41 		g_return_val_if_fail (err != NULL, 1);
42 
43 		g_warning ("'%s' error: %s\n", argv[1], err->message);
44 		g_error_free (err);
45 		return 1;
46 	}
47 	modtime = gsf_input_get_modtime (input);
48 
49 	output = gsf_output_stdio_new_full
50 		(argv[2], &err, "modtime", modtime, NULL);
51 	if (output == NULL) {
52 		g_return_val_if_fail (err != NULL, 1);
53 
54 		g_warning ("'%s' error: %s\n", argv[2], err->message);
55 		g_error_free (err);
56 
57 		rval = 1;
58 		goto out;
59 	}
60 
61 	if (gsf_input_copy (input, output) == FALSE) {
62 		err = (GError*) gsf_output_error (output);
63 		if (err != NULL) {
64 			g_warning ("'%s' error: %s\n", argv[2], err->message);
65 		}
66 		rval = 1;
67 		goto out;
68 	}
69 
70 out:
71 	if (input)
72 		g_object_unref (input);
73 
74 	if (output) {
75 		gsf_output_close (output);
76 		g_object_unref (output);
77 	}
78 
79 	return rval;
80 }
81 
82 int
main(int argc,char * argv[])83 main (int argc, char *argv[])
84 {
85 	int res;
86 
87 	if (argc != 3) {
88 		fprintf (stderr, "%s : infile outfile\n", argv [0]);
89 		return 1;
90 	}
91 
92 	gsf_init ();
93 	res = test (argv);
94 	gsf_shutdown ();
95 
96 	return res;
97 }
98