/***********************************************************************
* *
* 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"
#if _hdr_values
#include <values.h>
#endif
#if _hdr_math
#include <math.h>
#endif
#if _hdr_float
#include <float.h>
#endif
#if defined(MAXDOUBLE)
#endif
#endif
#if !defined(MAXD)
#define MAXD (double)(~((unsigned long)0))
#endif
typedef struct Fmt_s
{
int arg;
} Fmt_t;
static int
#if __STD_C
#else
#endif
{
return 0;
}
tmain()
{
int i, j, k, n;
float f;
double d;
char* s;
if(n != 0)
terror("Bad %%[ scanning1");
terror("Bad %%[ scanning2");
c[0] = c[1] = c[2] = c[3] = 'x';
i = -1;
terror("Bad %%d scanning");
if(i != 1234)
terror("Expected 1234, got %d", i);
i = -1;
terror("Bad %%i scanning1");
i = -1;
terror("Bad %%i scanning2");
i = -1;
terror("Bad %%i scanning3");
i = -1;
terror("Bad %%i scanning4");
i = -1;
terror("Bad %%i scanning5");
terror("Bad s");
terror("str overwritten");
terror("Bad c");
if(c[2] != 'x')
terror("c overwritten");
terror("Bad class");
terror("cl overwritten");
terror("Bad return value");
terror("Bad character class scanning");
terror("Bad integer scanning");
if(i != 123 || j != 456 || n != 7)
terror("Bad return values");
terror("Bad scanning2");
if(i != 1 || j != 2 || n != 3)
terror("Bad return values 2");
terror("Bad scanning3");
if(i != 12 || j != 34 || n != 4)
terror("Bad return values 3");
terror("Bad scanning4");
if(i != 9 || j != 2 || k != 3 || n != 5)
terror("Bad return values 4");
terror("Bad scanning5");
if(f != 4 || d != 6)
terror("Bad return values f=%f d=%f", f, d);
s = ".1234 .1234";
terror("Bad scanning6");
if(f <= .1233 || f >= .1235 || d <= .1233 || d >= .1235)
terror("Bad return values: f=%.4f d=%.4lf",f,d);
/* test for scanning max double value */
if(!s || s[0] < '0' || s[0] > '9')
terror("sfprints failed");
for(i = 0; s[i]; ++i)
if(s[i] == 'e')
break;
if(s[i-1] > '0' && s[i-1] <= '9')
s[i-1] -= 1;
sfsscanf(s,"%le",&d);
terror("sfscanf of MAXDOUBLE failed");
terror("Opening temp file");
for(k = 2; k <= 64; ++k)
for(i = 0; i < 1000; ++i)
for(i = 0; i < 1000; ++i)
terror("Scanf failed");
if(i != j)
terror("Wrong scanned value");
}
}
/* test %p */
terror("Wrong pointer scan");
terror("Bad %%i scanning");
terror("Bad %%#i scanning");
n = -1;
terror("Bad scanning results");
n = -1;
terror("Bad scanning results");
n = -1;
terror("Bad scanning results");
n = -1;
terror("Bad scanning results");
if (!s)
terror("sfprints failed");
if (strcmp(s, "3 46036 46036 985781544"))
terror("Base 36 scan failed");
terror("Scanning NaN failed");
if(i != 2 || n != 123 || f <= 3.1414 || f >= 3.1416)
terror("%%! failed i=%d n=%d d=%g", i, n, f);
k = 0;
terror("%%%% failed");
k = 0;
terror("%%%% does not skip leading space");
k = 0;
terror("%%*%% failed");
k = 0;
terror("%%*%% skips leading space");
texit(0);
}