~ubuntu-branches/ubuntu/oneiric/gnutls26/oneiric

« back to all changes in this revision

Viewing changes to gl/tests/test-snprintf.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-05-20 13:07:18 UTC
  • mfrom: (12.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110520130718-db41dybbanzfvlji
Tags: 2.10.5-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Fix build failure with --no-add-needed.
  - Build for multiarch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Test of snprintf() function.
2
 
   Copyright (C) 2007-2008 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 <stdlib.h>
 
23
#include "signature.h"
 
24
SIGNATURE_CHECK (snprintf, int, (char *, size_t, char const *, ...));
 
25
 
24
26
#include <string.h>
25
27
 
26
 
#define ASSERT(expr) \
27
 
  do                                                                         \
28
 
    {                                                                        \
29
 
      if (!(expr))                                                           \
30
 
        {                                                                    \
31
 
          fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
32
 
          fflush (stderr);                                                   \
33
 
          abort ();                                                          \
34
 
        }                                                                    \
35
 
    }                                                                        \
36
 
  while (0)
 
28
#include "macros.h"
37
29
 
38
30
int
39
31
main (int argc, char *argv[])
47
39
      memcpy (buf, "DEADBEEF", 8);
48
40
      retval = snprintf (buf, size, "%d", 12345);
49
41
      if (size < 6)
50
 
        {
 
42
        {
51
43
#if CHECK_SNPRINTF_POSIX
52
 
          ASSERT (retval < 0 || retval >= size);
 
44
          ASSERT (retval < 0 || retval >= size);
53
45
#endif
54
 
          if (size > 0)
55
 
            {
56
 
              ASSERT (memcmp (buf, "12345", size - 1) == 0);
57
 
              ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size);
58
 
            }
 
46
          if (size > 0)
 
47
            {
 
48
              ASSERT (memcmp (buf, "12345", size - 1) == 0);
 
49
              ASSERT (buf[size - 1] == '\0' || buf[size - 1] == '0' + size);
 
50
            }
59
51
#if !CHECK_SNPRINTF_POSIX
60
 
          if (size > 0)
 
52
          if (size > 0)
61
53
#endif
62
 
            ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
63
 
        }
 
54
            ASSERT (memcmp (buf + size, "DEADBEEF" + size, 8 - size) == 0);
 
55
        }
64
56
      else
65
 
        {
66
 
          ASSERT (retval == 5);
67
 
          ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
68
 
        }
 
57
        {
 
58
          ASSERT (retval == 5);
 
59
          ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
 
60
        }
69
61
    }
70
62
 
71
63
  return 0;