Move base64 test code into a new tests subdirectory
authorJouni Malinen <j@w1.fi>
Sat, 5 Dec 2009 18:43:07 +0000 (20:43 +0200)
committerJouni Malinen <j@w1.fi>
Sat, 5 Dec 2009 18:43:07 +0000 (20:43 +0200)
src/utils/base64.c
tests/.gitignore [new file with mode: 0644]
tests/Makefile [new file with mode: 0644]
tests/test-base64.c [new file with mode: 0644]

index 13fc511..155bfce 100644 (file)
@@ -152,38 +152,3 @@ unsigned char * base64_decode(const unsigned char *src, size_t len,
        *out_len = pos - out;
        return out;
 }
-
-
-#ifdef TEST_MAIN
-
-int main(int argc, char *argv[])
-{
-       FILE *f;
-       size_t len, elen;
-       unsigned char *buf, *e;
-
-       if (argc != 4) {
-               printf("Usage: base64 <encode|decode> <in file> <out file>\n");
-               return -1;
-       }
-
-       buf = os_readfile(argv[2], &len);
-       if (buf == NULL)
-               return -1;
-
-       if (strcmp(argv[1], "encode") == 0)
-               e = base64_encode(buf, len, &elen);
-       else
-               e = base64_decode(buf, len, &elen);
-       if (e == NULL)
-               return -2;
-       f = fopen(argv[3], "w");
-       if (f == NULL)
-               return -3;
-       fwrite(e, 1, elen, f);
-       fclose(f);
-       free(e);
-
-       return 0;
-}
-#endif /* TEST_MAIN */
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644 (file)
index 0000000..0063a1b
--- /dev/null
@@ -0,0 +1 @@
+test-base64
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644 (file)
index 0000000..9c4a428
--- /dev/null
@@ -0,0 +1,27 @@
+TESTS=test-base64
+
+all: $(TESTS)
+
+ifndef CC
+CC=gcc
+endif
+
+ifndef LDO
+LDO=$(CC)
+endif
+
+ifndef CFLAGS
+CFLAGS = -MMD -O2 -Wall -g
+endif
+
+CFLAGS += -I../src
+
+
+BASE64_OBJS=test-base64.o ../src/utils/base64.o ../src/utils/os_unix.o
+
+test-base64: $(BASE64_OBJS)
+       $(LDO) $(LDFLAGS) -o $@ $(BASE64_OBJS)
+
+clean:
+       $(MAKE) -C ../src clean
+       rm -f $(TESTS) *~ *.o
diff --git a/tests/test-base64.c b/tests/test-base64.c
new file mode 100644 (file)
index 0000000..747290e
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Base64 encoding/decoding (RFC1341) - test program
+ * Copyright (c) 2005, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include "utils/os.h"
+#include "utils/base64.h"
+
+int main(int argc, char *argv[])
+{
+       FILE *f;
+       size_t len, elen;
+       unsigned char *buf, *e;
+
+       if (argc != 4) {
+               printf("Usage: base64 <encode|decode> <in file> <out file>\n");
+               return -1;
+       }
+
+       buf = (unsigned char *) os_readfile(argv[2], &len);
+       if (buf == NULL)
+               return -1;
+
+       if (strcmp(argv[1], "encode") == 0)
+               e = base64_encode(buf, len, &elen);
+       else
+               e = base64_decode(buf, len, &elen);
+       if (e == NULL)
+               return -2;
+       f = fopen(argv[3], "w");
+       if (f == NULL)
+               return -3;
+       fwrite(e, 1, elen, f);
+       fclose(f);
+       free(e);
+
+       return 0;
+}