/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1999-2011 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#include "sftest.h"
typedef struct _coord_
{ int x;
int y;
} Coord_t;
#if __STD_C
#else
int coordprint(f, v, fe)
Sfio_t* f;
Void_t* v;
#endif
{
char* s;
return -1;
return 0;
}
typedef union Value_u
{
unsigned char c;
short h;
int i;
long l;
double d;
float f;
char *s;
int *ip;
char **p;
} Value_t;
#if __STD_C
#else
Sfio_t* f;
#endif
{
}
}
return 0;
}
static int OXcount;
#if __STD_C
#else
Sfio_t* f;
Void_t* v;
#endif
{
OXcount += 1;
{
case 'd' :
*((int*)v) = 10;
return 0;
case 'O' :
*((int*)v) = 11;
return 0;
case 'X' :
*((int*)v) = 12;
return 0;
case 's':
*((char**)v) = OXstr;
return 0;
}
return 0;
}
#if __STD_C
#else
Sfio_t* f;
Void_t* v;
#endif
{
{
case 'a' :
return 0;
case 'b' :
return 0;
case 'y' : /* test return value of extension function */
return 0;
case 'Y' : /* terminate format processing */
default :
return -1;
}
}
#if __STD_C
#else
Sfio_t* f;
#endif
{ static int i = 1;
*((int*)val) = i++;
return 0;
}
#if __STD_C
#else
Sfio_t* f;
#endif
{ static short i = -2;
*((short*)val) = i++;
return 0;
}
#if __STD_C
#else
Sfio_t* f;
#endif
{
{ case 'D' :
case 'O' :
case 'F' :
case 'S' :
case 'C' :
default : return -1;
}
}
#if __STD_C
#else
char* buf;
int n;
char* form;
#endif
#if __STD_C
#else
#endif
}
tmain()
{
double x=0.0051, y;
int i, j;
long k;
Sfio_t* f;
terror("Failed getting string");
terror("Failed formatting %%s");
terror("Failed testing $position");
terror("Failed testing $position with precision");
terror("Failed testing $position2");
if(OXcount != 4)
terror("%%f rounding wrong");
terror("%%!: Extension function failed1");
terror("%%!: Extension function failed2");
terror("%%!: Extension function failed3");
terror("%%!: Extension function failed4");
/* test extf translation */
terror("%%!: Extension function failed5");
k = 1234567890;
terror("%%I*d failed");
Coord.x = 5;
Coord.y = 7;
terror("%%Z <1,0,2,0,3> != <%o,%o,%o,%o,%o>",
terror("%%Z <1,0,2,0,3> != <%o,%o,%o,%o,%o>",
terror("%%!: Stack function failed");
terror("Failed %% +G test");
if(sizeof(int) == 4 && sizeof(short) == 2)
if(!s || strcmp(s,"ffff") != 0)
terror("Failed %%hx test");
if(!s || strcmp(s,"ffff") != 0)
terror("Failed %%I2x test");
}
if(sizeof(int) == 4 && sizeof(char) == 1)
if(!s || strcmp(s,"ff") != 0)
terror("Failed %%hhx test");
if(!s || strcmp(s,"ff") != 0)
terror("Failed %%I1x test");
}
terror("Failed %%..16d test");
terror("Failed %%..16u test");
terror("Failed %%0#4o test");
terror("Failed %%0#4x test");
terror("Failed %%c test");
terror("Failed %%.4c test");
terror("Failed %%hd test");
terror("Failed %%E test");
terror("Failed %%f test");
terror("Failed %%G test");
list[0] = "0";
list[3] = 0;
terror("Failed %%..*s test");
terror("Failed %%..*c test");
terror("Failed precision+0 test");
terror("Failed precision+1 test");
terror("Failed exceeding width test");
terror("Failed justification test");
terror("Failed zero filling test");
terror("Failed signed and zero-filled test");
terror("Failed blank and precision test");
terror("Failed +,blank and precision test");
terror("Failed floating point and zero-filled test");
terror("Failed floating point and left justification test");
terror("Failed %%-#X conversion test");
#if !_ast_intmax_long
terror("Failed conversion with I flag");
terror("Failed conversion with I64 flag");
}
}
#endif
i = (int)(~(~((unsigned int)0) >> 1));
s = sfprints("%d",i);
j = atoi(s);
if(i != j)
terror("Failed converting highbit");
for(i = -10000; i < 10000; i += 123)
{ s = sfprints("%d",i);
j = atoi(s);
if(j != i)
terror("Failed integer conversion");
}
/* test I flag for strings */
ls[0] = "0123456789";
ls[2] = 0;
if(strcmp(s, "01234abcde") != 0)
terror("Failed I flag with %%s");
}
/* test justification */
terror("Left-justification is wrong");
terror("Justification is wrong");
"%.d %.hi %.lo %.f %.e %.g %.g %.g %.g %.g %.s %.d %.hi %.lo|",
1345,
1234,
1234567890,
321.7654321,
321.7654321,
-0.01,
0.01,
1e-5,
1.4,
-1.4,
"test-string",
0,
0,
0L);
terror("Precision not set to zero as required after a dot");
/* test %#c to print C-style characters */
terror("%%#c formatting failed");
/* test printing of signed integer of length 1 */
#if defined(__STDC__)
{ signed char c = -1;
terror("%%I1d formatting failed");
}
#endif
sfsprintf(buf1, sizeof(buf1), "%05Lg %05Lg %05Lg %05Lg %05Lg %05Lg", pnanl, nnanl, pinfl, ninfl, pnill, nnill);
/* test the sfaprints() function */
terror("sfaprints() failed -- expected \"123\" [3], got \"%s\" [%d]", s, i);
free(s);
/* test 64-bit linux %g */
texit(0);
}