~nutznboltz-deactivatedaccount/ubuntu/precise/gnutls26/fix-lp926350

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Andreas Metzler
  • Date: 2011-10-01 15:28:13 UTC
  • mfrom: (12.1.20 sid)
  • Revision ID: package-import@ubuntu.com-20111001152813-yygm1c4cxonfxhzy
Tags: 2.12.11-1
* New upstream version.
  + Allow CA importing of 0 certificates to succeed. Closes: #640639
* Add libp11-kit-dev to libgnutls-dev dependencies. (see #643811)
* [20_guiledocstring.diff] guile: Fix docstring extraction with CPP 4.5+.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Test of snprintf() function.
2
 
   Copyright (C) 2007-2010 Free Software Foundation, Inc.
 
2
   Copyright (C) 2007-2011 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
34
34
  int size;
35
35
  int retval;
36
36
 
 
37
  retval = snprintf (NULL, 0, "%d", 12345);
 
38
  ASSERT (retval == 5);
 
39
 
37
40
  for (size = 0; size <= 8; size++)
38
41
    {
39
42
      memcpy (buf, "DEADBEEF", 8);
40
43
      retval = snprintf (buf, size, "%d", 12345);
 
44
      ASSERT (retval == 5);
41
45
      if (size < 6)
42
46
        {
43
 
#if CHECK_SNPRINTF_POSIX
44
 
          ASSERT (retval < 0 || retval >= size);
45
 
#endif
46
47
          if (size > 0)
47
48
            {
48
49
              ASSERT (memcmp (buf, "12345", size - 1) == 0);
55
56
        }
56
57
      else
57
58
        {
58
 
          ASSERT (retval == 5);
59
59
          ASSERT (memcmp (buf, "12345\0EF", 8) == 0);
60
60
        }
61
61
    }
62
62
 
 
63
  /* Test the support of the POSIX/XSI format strings with positions.  */
 
64
  {
 
65
    char result[100];
 
66
    retval = snprintf (result, sizeof (result), "%2$d %1$d", 33, 55);
 
67
    ASSERT (strcmp (result, "55 33") == 0);
 
68
    ASSERT (retval == strlen (result));
 
69
  }
 
70
 
63
71
  return 0;
64
72
}