/* token-test.c - Test program for error routines.
* © Copyright 1999 by John Halleck
* All rights reserved.
*/
/* Version of August 30th, 1999 */
#include <stdio.h>
#include "errors.h"
/* The standard errors package. */
#include "reportframe.h"
/* Lets make reporting easier */
#include "token.h"
/* The routines we are planning to test.*/
/* static int someplace; */ /* Just a place */
#define SIZE 8
static char buffer[SIZE];
int size; /* Place for returned size */
/* -------------------------------------------------------------------------- */
/* Diddly character source */
static char *currentinput = 0;
/* Diddly source of characters */
static error setstring (char *given) {
currentinput = 0;
if (!given) return ERRnil;
currentinput = given;
return NoError;
}
static error nextfromstring (int *place) {
if(!place) return ERRnil;
if(!currentinput) return ERRuninitialized;
*place = *currentinput;
if (*currentinput) currentinput++;
else *place = -1;
return NoError;
}
/* ------------------------- Housekeeping ---------------------------------- */
static error initcheck (char *name, error result) {
if (result == ERRuninitialized) return NoError;
if (!name) name = "NO NAME GIVEN";
printf ("%s failed to properly notice uninitialized status\n", name);
if (!result) return ERRfalse;
printerror (result);
return result;
}
static error checkinitstat () {
error good = 1;
if(initcheck ("skipnoneolwhite", skipnoneolwhite()) ) good = 0;
if(initcheck ("finalize", tokfinalize()) ) good = 0;
if(initcheck ("skipwhite", skipwhite()) ) good = 0;
if(initcheck ("skipnonwhite", skipnonwhite()) ) good = 0;
if(initcheck ("nextchar", nextchar()) ) good = 0;
if(initcheck ("prefetch", prefetch()) ) good = 0;
if(initcheck ("skipeol", skipeol()) ) good = 0;
if(initcheck ("skiptoeol", skiptoeol()) ) good = 0;
if(initcheck ("skipto", skipto("x")) ) good = 0;
if(initcheck ("nonwhitetok", nonwhitetok (SIZE, buffer, &size))) good = 0;
if(initcheck ("inttok", inttok (SIZE, buffer, &size))) good = 0;
if(initcheck ("flttok", flttok (SIZE, buffer, &size))) good = 0;
if(initcheck ("alphatok", alphatok (SIZE, buffer, &size))) good = 0;
if(initcheck ("alphanumtok", alphanumtok (SIZE, buffer, &size))) good = 0;
if(initcheck ("varnamtok", varnamtok (SIZE, buffer, &size))) good = 0;
if(initcheck ("puncttok", puncttok (SIZE, buffer, &size))) good = 0;
if(initcheck ("sinttok", sinttok (SIZE, buffer, &size))) good = 0;
if(initcheck ("sflttok", sflttok (SIZE, buffer, &size))) good = 0;
if (!good) return ERRfalse;
return NoError;
}
static error haveerrorstat (char *text, char *shouldbe, error theerror) {
goterrorstat (text, theerror);
if (shouldbe) {
printf ("Token should have been \"%s\"\n", shouldbe);
}
/* make it string like. */
buffer[SIZE-1] = 0;
/* And dump it. */
printf ("Token was: (Size = %d) \"%s\"\n", size, buffer);
if (thischaracter == EOF)
printf ("thischaracter = EOF\n");
else {
printf ("thischaracter (%d) '%c'", thischaracter, thischaracter);
if (validnextcharacter && nextcharacter != EOF)
printf (", nextcharacter (%d) '%c'", nextcharacter, nextcharacter);
else if (validnextcharacter) printf(", nextcharacter = EOF");
printf ("\n");
}
if (currentinput && *currentinput != 0)
printf ("Remaining unprocessed input is: \"%s\"\n", currentinput);
return theerror;
}
static error haveerror (char *text, char *shouldbe) {
return haveerrorstat(text, shouldbe, NoError);
}
static error havewrongstat (char *text, error theerror) {
return haveerrorstat(text, 0, theerror);
}
static error havewrong (char *text) {
return haveerrorstat (text, 0, NoError);
}
/* ------------------------- Housekeeping ---------------------------------- */
int main() {
error problem;
int i; /* Default loop index */
int outchar; /* Default character output */
inittests("token");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
newsection ("Internal character fetch test routines");
newtest ("setstring");
if ((problem = setstring(0))!=ERRnil)
goterrorstat ("Nil pointer accepted?", problem);
if ((problem = setstring ("Junk")))
goterrorstat ("Valid call failed", problem);
currentinput = 0; /* Pretend uninitialized */
endtest();
newtest ("nextfromstring");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = nextfromstring (0)) != ERRnil)
goterrorstat ("nextfromstring accepted nil pointer?", problem);
if (ERRuninitialized != (problem = nextfromstring (&outchar)))
goterrorstat ("Uninitialized call worked?", problem);
if ((problem = setstring ("AB")))
goterrorstat ("setstring call failed???", problem);
if ((problem = nextfromstring (&outchar)))
havewrongstat ("valid call failed", problem);
if (outchar != 'A') {
goterror ("Got wrong answer");
printf ("Should have been 'A' was '%c' (%d)\n", outchar, outchar);
}
if ((problem = nextfromstring (&outchar)))
havewrongstat ("valid 2nd call failed", problem);
if (outchar != 'B') {
goterror ("Got wrong answer");
printf ("Should have been 'B' was '%c' (%d)\n", outchar, outchar);
}
if ((problem = nextfromstring (&outchar)))
goterrorstat ("valid 3rd call failed", problem);
if (outchar != EOF) {
goterror ("Didn't understand end of string");
printf ("Got %d instead\n", outchar);
}
currentinput = 0; /* No longer initialized */
endtest();
endsection ();
newtest ("Calls preceding initialization");
checkinitstat();
endtest();
newsection ("Package Housekeeping");
newtest ("tokinitialize");
if ((problem = tokinitialize(0))!=ERRnil)
goterrorstat ("Nil pointer accepted?", problem);
if (ERRuninitialized != (problem = tokinitialize (&nextfromstring)))
goterrorstat ("Didn't notice support routine failed.", problem);
if ((problem = setstring("xyz")))
goterrorstat ("setstring failed valid call?", problem);
if ((problem = tokinitialize(&nextfromstring)))
goterrorstat ("Valid initialization call failed", problem);
if (thischaracter != 'x')
haveerror("Set up thischaracter incorrectly", "x");
if (validnextcharacter)
haveerror ("Set up nextcharacter incorrectly", 0);
endtest();
newtest("tokfinalize");
if ((problem = tokfinalize()))
goterrorstat ("Failed valid call", problem);
if (ERRuninitialized != (problem = tokfinalize()))
goterrorstat ("Failed to notice not initialized", problem);
endtest();
endsection ();
newsection ("Scanning");
newtest("nextchar");
for (i=0; i<SIZE; i++) buffer[i] = 0; size = 0;
if ((problem = setstring("ABC")))
goterrorstat ("setstring failed valid call?", problem);
if ((problem = tokinitialize(&nextfromstring)))
goterrorstat ("Valid initialization call failed", problem);
if (thischaracter != 'A')
haveerror ("initialization produced wrong answer going in.", "A");
if ((problem = nextchar()))
havewrongstat ("First valid call failed", problem);
if (thischaracter != 'B')
haveerror ("First call returned wrong answer", "B");
if ((problem = nextchar()))
havewrongstat ("Second valid call failed", problem);
if (thischaracter != 'C')
haveerror ("Second call returned wrong answer", "C");
if ((problem = nextchar()))
havewrongstat ("Third valid call failed", problem);
if (thischaracter != EOF)
havewrong ("failed to produce EOF");
if (ERRendoffile != (problem = nextchar()))
havewrongstat ("Failed to notice EOF", problem);
if (thischaracter != EOF)
havewrong ("Failed to produce EOF answer");
if ((problem = tokfinalize()))
havewrongstat ("tokfinalize call failed???", problem);
endtest();
newtest("prefetch");
for (i=0; i<SIZE; i++) buffer[i] = 0; size = 0;
if ((problem = setstring("AB")))
goterrorstat ("setstring failed valid call?", problem);
if ((problem = tokinitialize(&nextfromstring)))
goterrorstat ("Valid initialization call failed", problem);
if (thischaracter != 'A')
haveerror ("initialization produced wrong answer going in.", "A");
if ((problem = prefetch()))
havewrongstat ("First valid call failed", problem);
if (!validnextcharacter)
haveerror ("Prefetch failed to get character", "B");
if (nextcharacter != 'B')
haveerror ("Prefetch produced wrong character", "B");
if ((problem = nextchar()))
havewrongstat ("Call to nextchar failed.", problem);
if (validnextcharacter)
havewrong ("Prefetched next character not used in nextchar");
if (thischaracter != 'B')
havewrong ("Next character got wrong result after prefetch?");
if ((problem = prefetch()))
havewrongstat ("Second valid call failed", problem);
if (!validnextcharacter)
havewrong ("Prefetch failed to get character");
if (nextcharacter != EOF)
havewrong ("Prefetch failed to produce end of file");
if ((problem = nextchar()))
havewrongstat ("Call to nextchar failed.", problem);
if (validnextcharacter)
havewrong ("Prefetched next character not used in nextchar");
if (thischaracter != EOF)
havewrong ("Prefetched EOF not correct after nextchar");
if (ERRendoffile != (problem = prefetch()))
havewrong ("failed to notice EOF");
if (thischaracter != EOF)
havewrong ("failed to produce EOF");
if (ERRendoffile != (problem = nextchar()))
havewrongstat ("Failed to notice EOF", problem);
if ((problem = tokfinalize()))
havewrongstat ("tokfinalize call failed???", problem);
endtest();
newtest("skipwhite");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring(" xyz 123 ====")))
goterrorstat ("setstring failed valid call?", problem);
if ((problem = tokinitialize(&nextfromstring)))
goterrorstat ("Valid initialization call failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Failed to skip white", problem);
if (thischaracter != 'x')
havewrong ("Ended in the wrong place");
if ((problem = skipwhite()) != ERRnotfound)
havewrongstat ("Failed to notice non-white", problem);
endtest();
newtest("skipnonwhite");
if ((problem = skipnonwhite()))
havewrongstat ("Didn't skip", problem);
if (thischaracter != ' ')
havewrong ("Ended in the wrong place.");
if (ERRnotfound != (problem = skipnonwhite()))
haveerrorstat ("Didn't notice whitespace", 0, problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest ("skipeol");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("abc define\nOK")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ((problem = skipeol())) havewrongstat ("Failed valid call?", problem);
if (thischaracter != 'O')
haveerror ("Ended up in the wrong place.", "O");
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest ();
newtest ("skiptoeol");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("abc define\nOK")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ((problem = skiptoeol())) havewrongstat ("Failed valid call?", problem);
if (thischaracter != '\n')
haveerror ("Ended up in the wrong place.", "End of line");
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest ();
newtest ("skipnoneolwhite");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring (" \nOK")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ((problem = skipnoneolwhite()))
havewrongstat ("Failed valid call?", problem);
if (thischaracter != '\n')
haveerror ("Ended up in the wrong place.", "\\nOK");
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest ();
newtest ("skipto");
for (i=0;i<SIZE;i++) buffer[i] = 0;
if ((problem = setstring ("abc x abc y and stuff")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if (ERRnil != (problem = skipto(0)))
goterrorstat ("Failed to notice nil", problem);
if (ERRempty != (problem = skipto("")))
goterrorstat ("Failed to notice empty list.", problem);
if ((problem = skipto("xy"))) goterrorstat ("Failed valid call?", problem);
if (thischaracter != 'x')
havewrong ("Ended up in the wrong place");
if ((problem = nextchar())) goterror ("nextchar call failed???");
if ((problem = skipto("xy"))) goterrorstat ("Failed valid call?", problem);
if (thischaracter != 'y')
haveerror ("Ended up in the wrong place", "y");
if ((problem = nextchar())) goterror ("Second nextchar call failed???");
if (ERRnotfound != (problem = skipto("xy")))
havewrongstat ("Failed to notice failure", problem);
if (ERRendoffile != (problem = skipto("xy")))
havewrongstat ("Failed to notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest ();
endsection ();
newsection ("Tokenizing");
newtest("nonwhitetok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("First Second Third")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = nonwhitetok (SIZE, buffer, 0))
|| ERRnil != (problem = nonwhitetok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = nonwhitetok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if ((problem = nonwhitetok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if ( size != 5 || buffer[0] != 'F' || buffer[1] != 'i' || buffer[2] != 'r'
|| buffer[3] != 's' || buffer[4] != 't')
havewrong ("Wrong First result");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = nonwhitetok (SIZE, buffer, &size)) )
havewrongstat ("Failed 2nd valid call", problem);
if (size != 6 || buffer[0] != 'S')
havewrong ("Wrong Second result");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip second white", problem);
if ((problem = nonwhitetok (SIZE, buffer, &size)) )
havewrongstat ("Failed 3rd valid call", problem);
if (size != 5 || buffer[0] != 'T' || buffer[4] != 'd')
haveerror ("Wrong Third result", "Third");
if (ERRendoffile != (problem = nonwhitetok (SIZE, buffer, &size)) )
havewrongstat ("Failed to notice call at EOF", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("puncttok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("N +- O")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = puncttok (SIZE, buffer, 0))
|| ERRnil != (problem = puncttok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = puncttok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = puncttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non punctuation", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = puncttok (SIZE, buffer, &size)))
havewrongstat ("Failed valid call", problem);
if (size != 1 || buffer[0] != '+')
haveerror ("Wrong result", "+");
if ((problem = puncttok (SIZE, buffer, &size)))
havewrongstat ("Failed valid call", problem);
if (size != 1 || buffer[0] != '-')
haveerror ("Wrong result", "-");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip second white", problem);
if (ERRnotfound != (problem = puncttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non punctuation on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = puncttok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("inttok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("Non 123 bad")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = inttok (SIZE, buffer, 0))
|| ERRnil != (problem = inttok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = inttok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = inttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non integer", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = inttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 3 || buffer[0] != '1' || buffer[1] != '2' || buffer[2] != '3')
haveerror ("Wrong result", "123");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if (ERRnotfound != (problem = inttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non integer on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = inttok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("sinttok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("Non 123 -1 +2 bad")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = sinttok (SIZE, buffer, 0))
|| ERRnil != (problem = sinttok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = sinttok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = sinttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non integer", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = sinttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 3 || buffer[0] != '1' || buffer[1] != '2' || buffer[2] != '3')
haveerror ("Wrong result", "123");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = sinttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 2 || buffer[0] != '-' || buffer[1] != '1')
haveerror ("Wrong result", "-1");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = sinttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 1 || buffer[0] != '2')
haveerror ("Wrong result", "2");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if (ERRnotfound != (problem = sinttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non integer on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = sinttok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("flttok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("junk 1 2. 3.4 bad")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = flttok (SIZE, buffer, 0))
|| ERRnil != (problem = flttok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = flttok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = flttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non float", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = flttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 1 || buffer[0] != '1')
haveerror ("Wrong result", "1");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = flttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid second call", problem);
if (size != 2 || buffer[0] != '2' || buffer[1] != '.')
haveerror ("Wrong second result", "2.");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = flttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid third call", problem);
if (size != 3 || buffer[0] != '3' || buffer[1] != '.' || buffer[2] != '4')
haveerror ("Wrong result", "3.4");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if (ERRnotfound != (problem = flttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non integer on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = flttok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("ssflttok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("junk 1 2. 3.4 -1 -2. -3.4 +1 +2. +3.4 bad")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = sflttok (SIZE, buffer, 0))
|| ERRnil != (problem = sflttok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = sflttok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non float", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 1 || buffer[0] != '1')
haveerror ("Wrong result", "1");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip second white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid second call", problem);
if (size != 2 || buffer[0] != '2' || buffer[1] != '.')
haveerror ("Wrong second result", "2.");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip third white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid third call", problem);
if (size != 3 || buffer[0] != '3' || buffer[1] != '.' || buffer[2] != '4')
haveerror ("Wrong result", "3.4");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip fourth white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid fourth call", problem);
if (size != 2 || buffer[0] != '-' || buffer[1] != '1')
haveerror ("Wrong result", "-1");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip 5th white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid 5th call", problem);
if (size != 3 || buffer[0] != '-' || buffer[1] != '2' || buffer[2] != '.')
haveerror ("Wrong result", "-2.");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip 6th white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid 6th call", problem);
if (size != 4 || buffer[0] != '-' || buffer[1] != '3' || buffer[2] != '.'
|| buffer[3] != '4')
haveerror ("Wrong result", "-3.4");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip 7th white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid 7th call", problem);
if (size != 1 || buffer[0] != '1')
haveerror ("Wrong positive result", "1");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip 8th white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid 8th call", problem);
if (size != 2 || buffer[0] != '2' || buffer[1] != '.')
haveerror ("Wrong positive result", "2.");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip 9th white", problem);
if ((problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid 9th call", problem);
if (size != 3 || buffer[0] != '3' || buffer[1] != '.' || buffer[2] != '4')
haveerror ("Wrong positive result", "3.4");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip 10th white", problem);
if (ERRnotfound != (problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non integer on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = sflttok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("alphatok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("123 Non 456")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = alphatok (SIZE, buffer, 0))
|| ERRnil != (problem = alphatok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = alphatok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = alphatok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non-alpha token", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = alphatok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 3 || buffer[0] != 'N' || buffer[1] != 'o' || buffer[2] != 'n')
haveerror ("Wrong result", "123");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if (ERRnotfound != (problem = alphatok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non alphanumeric on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = alphatok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest("alphanumtok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("+1= 1a *")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = alphanumtok (SIZE, buffer, 0))
|| ERRnil != (problem = alphanumtok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = alphanumtok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = alphanumtok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non alphanumeric token", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = alphanumtok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 2 || buffer[0] != '1' || buffer[1] != 'a')
haveerror ("Wrong result", "1a");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip second white", problem);
if (ERRnotfound != (problem = alphanumtok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non alphanumeric on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = alphanumtok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest ("varnamtok");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("123 N34 567")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = varnamtok (SIZE, buffer, 0))
|| ERRnil != (problem = varnamtok (SIZE, 0, &size))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRsize != (problem = varnamtok (0, buffer, &size)) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = varnamtok (SIZE, buffer, &size)) )
havewrongstat ("non-varnametok", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = varnamtok (SIZE, buffer, &size)) )
havewrongstat ("Failed valid call", problem);
if (size != 3 || buffer[0] != 'N' || buffer[1] != '3' || buffer[2] != '4')
haveerror ("Wrong result", "N34");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if (ERRnotfound != (problem = varnamtok (SIZE, buffer, &size)) )
havewrongstat ("Accepted non name on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = varnamtok (SIZE, buffer, &size)) )
havewrongstat ("Didn't notice end of file;", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest();
newtest ("tokfrom");
for (i=0;i<SIZE;i++) buffer[i] = 0; size = 0;
if ((problem = setstring ("123 xy+ 567")))
goterrorstat ("Set string failed?", problem);
if ((problem = tokinitialize (&nextfromstring)))
goterrorstat ("initialize call failed?", problem);
if ( ERRnil != (problem = tokfrom (SIZE, buffer, 0, "x"))
|| ERRnil != (problem = tokfrom (SIZE, 0, &size, "x"))
|| ERRnil != (problem = tokfrom (SIZE, 0, &size, 0 ))
) goterrorstat ("Didn't notice NIL arguments", problem);
if ( ERRempty != (problem = tokfrom (SIZE, 0, &size, "")) )
goterrorstat ("Didn't notice empty list.", problem);
if ( ERRsize != (problem = tokfrom (0, buffer, &size, "x")) )
goterrorstat ("Didn't notice bad buffer size.", problem);
if (ERRnotfound != (problem = tokfrom (SIZE, buffer, &size, "xy+")) )
havewrongstat ("didn't notice non-list", problem);
if ((problem = skipnonwhite()))
havewrongstat ("skip nonwhite routine failed", problem);
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip first white", problem);
if ((problem = tokfrom (SIZE, buffer, &size,"+xy")) )
havewrongstat ("Failed valid call", problem);
if (size != 3 || buffer[0] != 'x' || buffer[1] != 'y' || buffer[2] != '+')
haveerror ("Wrong result", "xy+");
if ((problem = skipwhite()))
havewrongstat ("Couldn't skip second white", problem);
if (ERRnotfound != (problem = tokfrom (SIZE, buffer, &size,"xy+")) )
havewrongstat ("Accepted list on second try", problem);
if ((problem = skipnonwhite()))
goterrorstat ("skipnonwhite routine failed", problem);
if (ERRendoffile != (problem = tokfrom (SIZE, buffer, &size, "xy+")) )
havewrongstat ("Didn't notice end of file;", problem);
if ((problem = tokfinalize()))
goterrorstat ("finalize call failed?", problem);
endtest ();
endsection ();
newtest("Calls after finalization");
checkinitstat();
endtest();
finalizetests();
return progerrors;
}
This page is http://www.cc.utah.edu/~nahaj/cave/survey/code/c/token-test.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 11th, 2000