1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * test-msole-printf.c: Create a simple msole file.
4 *
5 * Copyright (C) 2002-2006 Jon K Hellan (hellan@acm.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-utils.h>
23 #include <gsf/gsf-output-stdio.h>
24 #include <gsf/gsf-outfile.h>
25 #include <gsf/gsf-outfile-msole.h>
26
27 #include <stdio.h>
28
29 static gboolean
test_write_once(GsfOutput * output)30 test_write_once (GsfOutput *output)
31 {
32 if (!gsf_output_printf (output,
33 "The %s sat on the %s.\n", "cat", "mat"))
34 return FALSE;
35 if (!gsf_output_printf (output, "%d %ss sat on the %s.\n",
36 2, "cat", "mat"))
37 return FALSE;
38 if (!gsf_output_puts (output,
39 "The quick brown fox is afraid of the cats.\n"))
40 return FALSE;
41
42 return TRUE;
43 }
44
45 static int
test(int argc,char * argv[])46 test (int argc, char *argv[])
47 {
48 GsfOutput *output;
49 GsfOutfile *outfile;
50 GsfOutput *small;
51 GsfOutput *large;
52 GError *err = NULL;
53 int i;
54
55 if (argc != 2) {
56 fprintf (stderr, "Usage : %s outfile\n", argv[0]);
57 return 1;
58 }
59
60 output = gsf_output_stdio_new (argv[1], &err);
61 if (output == NULL) {
62 g_return_val_if_fail (err != NULL, 1);
63
64 g_warning ("'%s' error: %s", argv[1], err->message);
65 g_error_free (err);
66 return 1;
67 }
68 outfile = gsf_outfile_msole_new (output);
69 g_object_unref (G_OBJECT (output));
70
71 small = gsf_outfile_new_child (outfile, "small", FALSE);
72 if (!test_write_once (small))
73 return 1;
74 if (!gsf_output_close (small))
75 return 1;
76 g_object_unref (G_OBJECT(small));
77
78 large = gsf_outfile_new_child (outfile, "large", FALSE);
79 for (i = 1; i <= 100; i++) {
80 if (!gsf_output_printf (large, "=== Round %d ===\n", i))
81 return 1;
82 if (!test_write_once (large))
83 return 1;
84 }
85 if (!gsf_output_close (large))
86 return 1;
87 g_object_unref (G_OBJECT(large));
88
89 if (!gsf_output_close (GSF_OUTPUT (outfile)))
90 return 1;
91 g_object_unref (G_OBJECT (outfile));
92
93 return 0;
94 }
95
96 int
main(int argc,char * argv[])97 main (int argc, char *argv[])
98 {
99 int res;
100
101 gsf_init ();
102 res = test (argc, argv);
103 gsf_shutdown ();
104
105 return res;
106 }
107