~behda/+junk/udisks2.original

« back to all changes in this revision

Viewing changes to src/tests/helper.c

  • Committer: behda
  • Date: 2014-05-24 15:15:11 UTC
  • Revision ID: pauvitk@gmail.com-20140524151511-3vtr0uubjewx3z2j
Initial commit of source code and Debian packaging.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
 
2
 *
 
3
 * Copyright (C) 2007-2010 David Zeuthen <david@fubar.dk>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 *
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
 
 
26
#include <udisks/udisks.h>
 
27
 
 
28
#include "testutil.h"
 
29
 
 
30
int
 
31
main (int argc, char *argv[])
 
32
{
 
33
  gint ret;
 
34
 
 
35
  g_type_init ();
 
36
 
 
37
  ret = 1;
 
38
 
 
39
  g_assert_cmpint (argc, ==, 2);
 
40
  switch (strtol (argv[1], NULL, 10))
 
41
    {
 
42
    case 0:
 
43
      g_print ("Hello Stdout\n"
 
44
               "Line 2\n");
 
45
      ret = 0;
 
46
      break;
 
47
 
 
48
    case 1:
 
49
      g_printerr ("Hello Stderr\n"
 
50
                  "Line 2\n");
 
51
      ret = 0;
 
52
      break;
 
53
 
 
54
    case 2:
 
55
      ret = 1;
 
56
      break;
 
57
 
 
58
    case 3:
 
59
      ret = 2;
 
60
      break;
 
61
 
 
62
    case 4:
 
63
      /* cause abnormal termination, segfault */
 
64
      g_print ("OK, deliberately causing a segfault\n");
 
65
      {
 
66
        const gchar **p = NULL;
 
67
        *p = "fail";
 
68
      }
 
69
      g_assert_not_reached ();
 
70
      break;
 
71
 
 
72
    case 5:
 
73
      /* abort */
 
74
      g_print ("OK, deliberately abort()'ing\n");
 
75
      abort ();
 
76
      g_assert_not_reached ();
 
77
      break;
 
78
 
 
79
    case 6:
 
80
      /* write binary output to stdout (including NUL bytes) */
 
81
      {
 
82
        guint n;
 
83
        for (n = 0; n < 100; n++)
 
84
          {
 
85
            g_assert_cmpint (fputc (n, stdout), !=, EOF);
 
86
            g_assert_cmpint (fputc (0, stdout), !=, EOF);
 
87
          }
 
88
        ret = 0;
 
89
      }
 
90
      break;
 
91
 
 
92
    case 7:
 
93
      /* read from stdin.. echo that back */
 
94
      {
 
95
        GString *s;
 
96
        gint c;
 
97
 
 
98
        s = g_string_new (NULL);
 
99
        while ((c = fgetc (stdin)) != EOF)
 
100
          g_string_append_c (s, c);
 
101
        g_print ("Woah, you said `%s', partner!\n", s->str);
 
102
        g_string_free (s, TRUE);
 
103
        ret = 0;
 
104
      }
 
105
      break;
 
106
 
 
107
    default:
 
108
      g_assert_not_reached ();
 
109
      break;
 
110
    }
 
111
 
 
112
  /* stderr is not buffered so force a flush */
 
113
  if (fflush (stdout) != 0)
 
114
    abort ();
 
115
  if (fflush (stderr) != 0)
 
116
    abort ();
 
117
 
 
118
  return ret;
 
119
}