1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * test-out-bzip.c:
4  *
5  * Copyright (C) 2002-2006 Jody Goldberg (jody@gnome.org)
6  *               2003-2006 Dom Lachowicz (cinamod@hotmail.com)
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of version 2.1 of the GNU Lesser General Public
10  * License as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
20  * USA
21  */
22 
23 #include <gsf/gsf-utils.h>
24 #include <gsf/gsf-output-stdio.h>
25 #include <gsf/gsf-output-bzip.h>
26 
27 #include <stdio.h>
28 
29 static int
test(int argc,char * argv[])30 test (int argc, char *argv[])
31 {
32 	GsfOutput *output;
33 	GsfOutput *bzout;
34 	GError   *err = NULL;
35 
36 	if (argc != 2) {
37 		fprintf (stderr, "Usage : %s outfile\n", argv[0]);
38 		return 1;
39 	}
40 
41 	output = gsf_output_stdio_new (argv[1], &err);
42 	if (output == NULL) {
43 		g_return_val_if_fail (err != NULL, 1);
44 
45 		g_warning ("'%s' error: %s", argv[1], err->message);
46 		g_error_free (err);
47 		return 1;
48 	}
49 
50 	bzout = gsf_output_bzip_new (output, &err);
51 	if (bzout == NULL) {
52 		g_return_val_if_fail (err != NULL, 1);
53 
54 		g_warning ("'%s' error: %s", "bzip output", err->message);
55 		g_error_free (err);
56 		return 1;
57 	}
58 
59 	if (!gsf_output_printf (bzout,
60 				"The %s sat on the %s.\n", "cat", "mat"))
61 		return 1;
62 	if (!gsf_output_printf (bzout, "%d %ss sat on the %s.\n",
63 				2, "cat", "mat"))
64 		return 1;
65 	if (!gsf_output_puts (bzout,
66 			      "The quick brown fox is afraid of the cats.\n"))
67 		return 1;
68 	if (!gsf_output_close (bzout))
69 		return 1;
70 	if (!gsf_output_close (output))
71 		return 1;
72 	g_object_unref (G_OBJECT (bzout));
73 	g_object_unref (G_OBJECT (output));
74 
75 	return 0;
76 }
77 
78 int
main(int argc,char * argv[])79 main (int argc, char *argv[])
80 {
81 	int res;
82 
83 	gsf_init ();
84 	res = test (argc, argv);
85 	gsf_shutdown ();
86 
87 	return res;
88 }
89