error: depend on stdio
[gnulib.git] / tests / test-base64.c
index 4868325..9debff0 100644 (file)
@@ -1,5 +1,5 @@
 /* Self tests for base64.
-   Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2008-2013 Free Software Foundation, Inc.
    Written by Simon Josefsson.
 
    This program is free software: you can redistribute it and/or modify
 
 #include <config.h>
 
+#include "base64.h"
+
 #include <stddef.h>
-#include <stdio.h>
 #include <stdbool.h>
 #include <stdlib.h>
 #include <string.h>
-#include <string.h>
 #include <stdint.h>
 
-#include "base64.h"
-
-#define ASSERT(expr)                                                   \
-  do                                                                   \
-    {                                                                  \
-      if (!(expr))                                                     \
-       {                                                               \
-         fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
-         fflush (stderr);                                              \
-         abort ();                                                     \
-       }                                                               \
-    }                                                                  \
-  while (0)
+#include "macros.h"
 
 int
 main (void)
@@ -51,7 +39,7 @@ main (void)
 
   memset (out, 0x42, sizeof (out));
   base64_encode (in, 0, out, 0);
-  ASSERT(out[0] == '\x42');
+  ASSERT (out[0] == '\x42');
 
   memset (out, 0x42, sizeof (out));
   base64_encode (in, 1, out, 1);
@@ -161,6 +149,7 @@ main (void)
   ASSERT (ok);
   ASSERT (len == 7);
   ASSERT (memcmp (out, "abcdefg", len) == 0);
+  free (p);
 
   {
     struct base64_decode_context ctx;
@@ -172,6 +161,7 @@ main (void)
     ASSERT (ok);
     ASSERT (len == strlen (in));
     ASSERT (memcmp (p, in, len) == 0);
+    free (p);
   }
 
   {
@@ -182,25 +172,30 @@ main (void)
     ASSERT (ok);
     ASSERT (len == 9);
     ASSERT (memcmp (p, "abcdefghi", len) == 0);
+    free (p);
 
     base64_decode_ctx_init (&ctx);
 
     ok = base64_decode_alloc_ctx (&ctx, "YW\n", 3, &p, &len);
     ASSERT (ok);
     ASSERT (len == 0);
+    free (p);
 
     ok = base64_decode_alloc_ctx (&ctx, "JjZGVmZ2", 8, &p, &len);
     ASSERT (ok);
     ASSERT (len == 6);
     ASSERT (memcmp (p, "abcdef", len) == 0);
+    free (p);
 
     ok = base64_decode_alloc_ctx (&ctx, "hp", 2, &p, &len);
     ASSERT (ok);
-    ASSERT (len == 2);
-    /* Actually this looks buggy.  Shouldn't output be 'ghi'? */
-    ASSERT (memcmp (p, "gh", len) == 0);
+    ASSERT (len == 3);
+    ASSERT (memcmp (p, "ghi", len) == 0);
+    free (p);
+
     ok = base64_decode_alloc_ctx (&ctx, "", 0, &p, &len);
     ASSERT (ok);
+    free (p);
   }
 
   {
@@ -212,6 +207,7 @@ main (void)
     ok = base64_decode_alloc_ctx (&ctx, newlineb64, strlen (newlineb64), &p, &len);
     ASSERT (ok);
     ASSERT (len == 0);
+    free (p);
   }
 
   ok = base64_decode_alloc_ctx (NULL, " ! ", 3, &p, &len);