~ubuntu-branches/ubuntu/utopic/gettext/utopic

« back to all changes in this revision

Viewing changes to gettext-tools/gnulib-tests/test-vasprintf.c

  • Committer: Colin Watson
  • Date: 2010-08-01 21:36:08 UTC
  • mfrom: (2.1.10 sid)
  • Revision ID: cjwatson@canonical.com-20100801213608-yy7vkm8lpatep3ci
merge from Debian 0.18.1.1-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Test of vasprintf() and asprintf() functions.
2
 
   Copyright (C) 2007 Free Software Foundation, Inc.
 
2
   Copyright (C) 2007-2010 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software: you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
20
20
 
21
21
#include <stdio.h>
22
22
 
 
23
#include "signature.h"
 
24
SIGNATURE_CHECK (asprintf, int, (char **, char const *, ...));
 
25
SIGNATURE_CHECK (vasprintf, int, (char **, char const *, va_list));
 
26
 
23
27
#include <stdarg.h>
24
28
#include <stdlib.h>
25
29
#include <string.h>
26
30
 
27
 
#define ASSERT(expr) \
28
 
  do                                                                         \
29
 
    {                                                                        \
30
 
      if (!(expr))                                                           \
31
 
        {                                                                    \
32
 
          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
33
 
          abort ();                                                          \
34
 
        }                                                                    \
35
 
    }                                                                        \
36
 
  while (0)
 
31
#include "macros.h"
37
32
 
38
33
static int
39
34
my_asprintf (char **result, const char *format, ...)
61
56
      ASSERT (strcmp (result, "12345") == 0);
62
57
      free (result);
63
58
    }
 
59
 
 
60
  for (repeat = 0; repeat <= 8; repeat++)
 
61
    {
 
62
      char *result;
 
63
      int retval = my_asprintf (&result, "%08lx", 12345UL);
 
64
      ASSERT (retval == 8);
 
65
      ASSERT (result != NULL);
 
66
      ASSERT (strcmp (result, "00003039") == 0);
 
67
      free (result);
 
68
    }
64
69
}
65
70
 
66
71
static void
77
82
      ASSERT (strcmp (result, "12345") == 0);
78
83
      free (result);
79
84
    }
 
85
 
 
86
  for (repeat = 0; repeat <= 8; repeat++)
 
87
    {
 
88
      char *result;
 
89
      int retval = asprintf (&result, "%08lx", 12345UL);
 
90
      ASSERT (retval == 8);
 
91
      ASSERT (result != NULL);
 
92
      ASSERT (strcmp (result, "00003039") == 0);
 
93
      free (result);
 
94
    }
80
95
}
81
96
 
82
97
int