]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/portab/portabtest.c
portabtest: Actually test functions
[ngircd-alex.git] / src / portab / portabtest.c
index f5e4a5e7c00558b8f9993c260ca28232ea11b7f5..4f53ce76594a27fa0d70a551c6e213e66899de47 100644 (file)
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
  *
- * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
- * der GNU General Public License (GPL), wie von der Free Software Foundation
- * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
- * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
- * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
- * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
- *
- * $Id: portabtest.c,v 1.5 2002/05/30 16:52:20 alex Exp $
- *
- * portabtest.c: Testprogramm fuer portab.h
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ * Please read the file COPYING, README and AUTHORS for more information.
  */
 
-
 #include "portab.h"
 
+/**
+ * @file
+ * Test program for portab.h and friends ;-)
+ */
+
 #include "imp.h"
+#include <stdarg.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "exp.h"
 
+static void
+Panic(char *Reason)
+{
+       /* Oops, something failed!? */
+       fprintf(stderr, "Oops, test for %s failed!?\n", Reason);
+       exit(1);
+} /* Panic */
 
-LOCAL BOOLEAN portab_check_types PARAMS(( VOID ));
+static void
+Check_snprintf(void)
+{
+       char str[5];
 
+       snprintf(str, sizeof(str), "%s", "1234567890");
+       if (str[4] != '\0')
+               Panic("snprintf NULL byte");
+       if (strlen(str) != 4)
+               Panic("snprintf string length");
+}
 
-GLOBAL int
-main( VOID )
+static void
+Check_strlcpy(void)
+{
+       char str[5];
+
+       if (strlcpy(str, "1234567890", sizeof(str)) != 10)
+               Panic("strlcpy return code");
+       if (str[4] != '\0')
+               Panic("strlcpy NULL byte");
+       if (strlen(str) != 4)
+               Panic("strlcpy string length");
+}
+
+static void
+Check_strlcat(void)
 {
-       INT ret = 0;
+       char str[5];
 
-       printf( "- datatypes: ");
-       if( ! portab_check_types( ))
-       {
-               puts( "FAILED!" );
-               ret = 1;
-       }
-       else puts( "ok." );
+       if (strlcpy(str, "12", sizeof(str)) != 2)
+               Panic("strlcpy for strlcat");
+       if (strlcat(str, "1234567890", sizeof(str)) != 12)
+               Panic("strlcat return code");
+       if (str[4] != '\0')
+               Panic("strlcat NULL byte");
+       if (strlen(str) != 4)
+               Panic("strlcat string length");
+}
 
-       printf( "- system type: %s/%s/%s\n", TARGET_CPU, TARGET_VENDOR, TARGET_OS );
+#ifdef PROTOTYPES
+static void
+Check_vsnprintf(const int Len, const char *Format, ...)
+#else
+static void
+Check_vsnprintf(Len, Format, va_alist)
+const int Len;
+const char *Format;
+va_dcl
+#endif
+{
+       char str[5];
+       va_list ap;
 
-       return ret;
-} /* main */
+#ifdef PROTOTYPES
+       va_start(ap, Format);
+#else
+       va_start(ap);
+#endif
+       if (vsnprintf(str, sizeof(str), Format, ap) != Len)
+               Panic("vsnprintf return code");
+       va_end(ap);
 
+       if (str[4] != '\0')
+               Panic("vsnprintf NULL byte");
+       if (strlen(str) != 4)
+               Panic("vsnprintf string length");
+}
 
-LOCAL BOOLEAN
-portab_check_types( VOID )
+GLOBAL int
+main(void)
 {
-       if( FALSE != 0 ) return 0;
-       if( TRUE != 1 ) return 0;
-       if( sizeof( INT8 ) != 1 ) return 0;
-       if( sizeof( UINT8 ) != 1 ) return 0;
-       if( sizeof( INT16 ) != 2 ) return 0;
-       if( sizeof( UINT16 ) != 2 ) return 0;
-       if( sizeof( INT32 ) != 4 ) return 0;
-       if( sizeof( UINT32 ) != 4 ) return 0;
-       return 1;
-} /* portab_check_types */
+       /* validate datatypes */
+       if (false != 0)
+               Panic("false");
+       if (true != 1)
+               Panic("true");
+       if (sizeof(UINT8) != 1)
+               Panic("UINT8");
+       if (sizeof(UINT16) != 2)
+               Panic("UINT16");
+       if (sizeof(UINT32) != 4)
+               Panic("UINT32");
 
+       /* check functions */
+       Check_snprintf();
+       Check_strlcpy();
+       Check_strlcat();
+       Check_vsnprintf(2+10, "%s%s", "ab", "1234567890");
+       
+       return 0;
+}
 
 /* -eof- */