2017-05-31 18:52:48 +00:00
|
|
|
/* -*-comment-start: "//";comment-end:""-*-
|
|
|
|
* Mes --- Maxwell Equations of Software
|
2018-05-30 19:55:39 +00:00
|
|
|
* Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2017-05-31 18:52:48 +00:00
|
|
|
*
|
|
|
|
* This file is part of Mes.
|
|
|
|
*
|
|
|
|
* Mes is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* Mes is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-07-09 07:24:07 +00:00
|
|
|
#include "30-test.i"
|
2017-05-31 18:52:48 +00:00
|
|
|
#include <stdio.h>
|
2017-07-09 07:24:07 +00:00
|
|
|
#include <string.h>
|
2018-06-02 09:41:06 +00:00
|
|
|
#include <stdarg.h>
|
2017-05-31 18:52:48 +00:00
|
|
|
|
|
|
|
int
|
2017-07-09 07:24:07 +00:00
|
|
|
test ()
|
2017-05-31 18:52:48 +00:00
|
|
|
{
|
2017-07-09 07:24:07 +00:00
|
|
|
char *s = "mes";
|
|
|
|
char c = 'm';
|
|
|
|
int i = 3;
|
2018-05-30 19:55:39 +00:00
|
|
|
char buf[20];
|
2017-07-09 07:24:07 +00:00
|
|
|
|
|
|
|
printf ("c=%c\n", c);
|
|
|
|
sprintf (buf, "c=%c\n", c);
|
2018-05-30 19:55:39 +00:00
|
|
|
if (strcmp (buf, "c=m\n"))
|
|
|
|
return 1;
|
2017-07-09 07:24:07 +00:00
|
|
|
|
2018-05-05 10:30:06 +00:00
|
|
|
if (i != 3) return 15;
|
2017-07-09 07:24:07 +00:00
|
|
|
printf ("i=%d\n", i);
|
|
|
|
sprintf (buf, "i=%d\n", i);
|
2018-05-30 19:55:39 +00:00
|
|
|
if (strcmp (buf, "i=3\n"))
|
|
|
|
return 2;
|
2017-05-31 18:52:48 +00:00
|
|
|
|
2017-07-09 07:24:07 +00:00
|
|
|
printf ("s=%s\n", s);
|
|
|
|
sprintf (buf, "s=%s\n", s);
|
2018-05-30 19:55:39 +00:00
|
|
|
if (strcmp (buf, "s=mes\n"))
|
|
|
|
return 3;
|
|
|
|
|
|
|
|
sprintf (buf, ">%3d<", 11);
|
|
|
|
eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, "> 11<"))
|
|
|
|
return 4;
|
|
|
|
|
|
|
|
sprintf (buf, ">%03d<", 22);
|
|
|
|
eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, ">022<"))
|
|
|
|
return 5;
|
|
|
|
|
|
|
|
sprintf (buf, ">%-10d<", 33);
|
|
|
|
eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, ">33 <"))
|
|
|
|
return 6;
|
|
|
|
|
|
|
|
sprintf (buf, ">%0d<", 44);
|
|
|
|
eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, ">44<"))
|
|
|
|
return 7;
|
2017-05-31 18:52:48 +00:00
|
|
|
|
2018-06-02 09:41:06 +00:00
|
|
|
printf (">>%.*s<<\n", 5, "hello, world");
|
|
|
|
printf (">>%.*s<<\n", 20, "hello, world");
|
|
|
|
|
|
|
|
printf (">>%.*s<<\n", 10, "foo");
|
|
|
|
printf (">>%*s<<\n", 10, "bar");
|
|
|
|
printf (">>%-*s<<\n", 10, "baz");
|
|
|
|
|
|
|
|
sprintf (buf, "%ld", 42);
|
|
|
|
eputs ("buf="); eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, "42"))
|
|
|
|
return 8;
|
|
|
|
|
|
|
|
sprintf (buf, "%u", -1);
|
|
|
|
eputs ("buf="); eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, "4294967295"))
|
|
|
|
return 9;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%.5s<<\n", "hello, world");
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>hello<<\n"))
|
|
|
|
return 10;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%.*s<<\n", 5, "hello, world");
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>hello<<\n"))
|
|
|
|
return 11;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%.*s<<\n", 20, "hello, world");
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>hello, world<<\n"))
|
|
|
|
return 12;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%.*s<<\n", 10, "foo");
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>foo<<\n"))
|
|
|
|
return 13;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%*s<<\n", 10, "bar");
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">> bar<<\n"))
|
|
|
|
return 14;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%-*s<<\n", 10, "baz");
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>baz <<\n"))
|
|
|
|
return 15;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%ld<<\n", 12);
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>12<<\n"))
|
|
|
|
return 16;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%o<<\n", 12);
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>14<<\n"))
|
|
|
|
return 17;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%x<<\n", 12);
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>c<<\n"))
|
|
|
|
return 18;
|
|
|
|
|
|
|
|
sprintf (buf, ">>%X<<\n", 12);
|
|
|
|
eputs ("buf="); eputs (buf);
|
|
|
|
if (strcmp (buf, ">>C<<\n"))
|
|
|
|
return 19;
|
|
|
|
|
2018-06-06 17:29:32 +00:00
|
|
|
int n;
|
|
|
|
fprintf (stderr, "foo bar\n%n", &n);
|
|
|
|
if (n != 8)
|
|
|
|
return 20;
|
|
|
|
|
|
|
|
sprintf (buf, "foo%nbar\n", &n);
|
|
|
|
eputs ("buf="); eputs (buf); eputs ("\n");
|
|
|
|
if (strcmp (buf, "foobar\n"))
|
|
|
|
return 21;
|
|
|
|
if (n != 3)
|
|
|
|
return 22;
|
|
|
|
|
2017-05-31 18:52:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|