test-b64.c 849 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "utils.h"
  5. #define BUF_LEN 255
  6. static void test_b64_encode(const char *src)
  7. {
  8. char *dst = malloc(BUF_LEN+1);
  9. int r = b64_encode(src, strlen(src), dst, BUF_LEN);
  10. fprintf(stdout, "%d %s\n", r, dst);
  11. free(dst);
  12. }
  13. static void test_b64_decode(const char *src)
  14. {
  15. char *dst = malloc(BUF_LEN+1);
  16. int r = b64_decode(src, dst, BUF_LEN);
  17. fprintf(stdout, "%d %s\n", r, dst);
  18. free(dst);
  19. }
  20. int main()
  21. {
  22. test_b64_encode("");
  23. test_b64_encode("f");
  24. test_b64_encode("fo");
  25. test_b64_encode("foo");
  26. test_b64_encode("foob");
  27. test_b64_encode("fooba");
  28. test_b64_encode("foobar");
  29. test_b64_decode("");
  30. test_b64_decode("Zg==");
  31. test_b64_decode("Zm8=");
  32. test_b64_decode("Zm9v");
  33. test_b64_decode("Zm9vYg==");
  34. test_b64_decode("Zm9vYmE=");
  35. test_b64_decode("Zm9vYmFy");
  36. return 0;
  37. }