test.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* gcc -ansi -pedantic -Wall -Wextra -O3 test.c -o test */
  2. #include <stdio.h>
  3. #include "rle_opt.h"
  4. #include "rle_libc.h"
  5. int main(int argc, char **argv)
  6. {
  7. char in[] = "aaaabbccccccdefgggggghhh";
  8. unsigned char out[256], out2[256], *out3, *out4;
  9. int len, i;
  10. rle_enc8((unsigned char*)&in, 24, (unsigned char*)&out, &len);
  11. printf("rle_enc8 encoded len: %d\n", len);
  12. memset(out2, 0, sizeof(out2));
  13. rle_dec8((unsigned char*)&out, len, (unsigned char*)&out2, &len);
  14. printf("rle_dec8 decoded len: %d %s\n\n", len, !memcmp(in, out2, 24) ? "OK" : "NOT MATCH");
  15. rle_enc16((unsigned char*)&in, 24, (unsigned char*)&out, &len);
  16. printf("rle_enc16 encoded len: %d\n", len);
  17. memset(out2, 0, sizeof(out2));
  18. rle_dec16((unsigned char*)&out, len, (unsigned char*)&out2, &len);
  19. printf("rle_dec16 decoded len: %d %s\n\n", len, !memcmp(in, out2, 24) ? "OK" : "NOT MATCH");
  20. rle_enc24((unsigned char*)&in, 24, (unsigned char*)&out, &len);
  21. printf("rle_enc24 encoded len: %d\n", len);
  22. memset(out2, 0, sizeof(out2));
  23. rle_dec24((unsigned char*)&out, len, (unsigned char*)&out2, &len);
  24. printf("rle_dec24 decoded len: %d %s\n\n", len, !memcmp(in, out2, 24) ? "OK" : "NOT MATCH");
  25. rle_enc32((unsigned char*)&in, 24, (unsigned char*)&out, &len);
  26. printf("rle_enc32 encoded len: %d\n", len);
  27. memset(out2, 0, sizeof(out2));
  28. rle_dec32((unsigned char*)&out, len, (unsigned char*)&out2, &len);
  29. printf("rle_dec32 decoded len: %d %s\n\n", len, !memcmp(in, out2, 24) ? "OK" : "NOT MATCH");
  30. for(i = 1; i < 5; i++) {
  31. rle_enc((unsigned char*)&in, 24, i, (unsigned char*)&out, &len);
  32. printf("static rle_enc(%d) encoded len: %d\n", i, len);
  33. memset(out2, 0, sizeof(out2));
  34. rle_dec((unsigned char*)&out, len, i, (unsigned char*)&out2, &len);
  35. printf("static rle_dec(%d) decoded len: %d %s\n", i, len, !memcmp(in, out2, 24) ? "OK" : "NOT MATCH");
  36. out3 = rle_enc((unsigned char*)&in, 24, i, (void*)0, &len);
  37. printf("malloc rle_enc(%d) encoded len: %d\n", i, len);
  38. out4 = rle_dec(out3, len, i, (void*)0, &len);
  39. printf("malloc rle_dec(%d) decoded len: %d %s\n\n", i, len, !memcmp(in, out4, 24) ? "OK" : "NOT MATCH");
  40. free(out3);
  41. free(out4);
  42. }
  43. return 0;
  44. }