/*
   <p>Test harness for the trim function.</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program 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 Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include <stdio.h>
#include <stdlib.h>
#include "environ.h"

#ifdef OS9
#include <strings.h>
#else
#include <string.h>
#endif

static int diffonly = TRUE;

void test(int n, char *s, char *e)
{
   char *r = "unset";
   char bs[MAXLINE];
   char br[MAXLINE];
   char be[MAXLINE];

   r = strhex(s);
   if (!diffonly || strcmp(r, e) != 0)
      printf("%2d: '%s' should give '%s': got '%s'\n", n, s, e, r);
}

main(int argc, char **argv)
{
   if (argc > 1)
   {
      if (strcmp(argv[1], "-?") == 0)
      {
         printf("Usage: teststrhex -d\n");
         printf("  -d shows test results.\n");
         printf("     default is to just show unexpected results\n");
         exit (1); 
      }
      else
      if (strcmp(argv[1], "-d") == 0)
         diffonly = FALSE;
      else
      {
         printf("Error: unknown option %s\n", argv[1]);
         exit(1);
      }
   }

   if (diffonly)
      printf("No output expected from correct operation\n");

   test(1, "", "");
   test(2, " ", " ");
   test(3, "  ", "  ");
   test(4, "x", "x");
   test(5, "xs", "xs");    
   test(6, "\Esx", "<1b>sx");
   test(7, "\E\f\E", "<1b><0c><1b>");
   test(8, "\ttxt\t", "<09>txt<09>");
   test(9, "\nnxn\n", "<0a>nxn<0a>");
   test(10, "\rrxr\r", "<0d>rxr<0d>");
   test(11, "\ffxf\f", "<0c>fxf<0c>");
   test(12, "   A short sentence.\n", "   A short sentence.<0a>");
   test(13, "\E[21~", "<1b>[21~");
   printf("Test ended\n");
   return(0);
}
