Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

67 lines
1.5 KiB

  1. #include <assert.h>
  2. #include <uint16.h>
  3. #include <uint32.h>
  4. #include <uint64.h>
  5. #include <byte.h>
  6. int main() {
  7. char buf[8];
  8. {
  9. uint16 a;
  10. buf[0]=buf[1]=0;
  11. uint16_pack_big(buf,0x1234);
  12. assert(buf[0]==0x12 && buf[1]==0x34);
  13. uint16_unpack_big(buf,&a);
  14. assert(a==0x1234);
  15. assert(uint16_read_big(buf)==0x1234);
  16. buf[0]=buf[1]=0;
  17. uint16_pack(buf,0x1234);
  18. assert(buf[0]==0x34 && buf[1]==0x12);
  19. uint16_unpack(buf,&a);
  20. assert(a==0x1234);
  21. assert(uint16_read(buf)==0x1234);
  22. }
  23. {
  24. uint32 a;
  25. buf[0]=buf[1]=buf[2]=buf[3]=0;
  26. uint32_pack_big(buf,0x12345678);
  27. assert(buf[0]==0x12 && buf[1]==0x34 && buf[2]==0x56 && buf[3]==0x78);
  28. uint32_unpack_big(buf,&a);
  29. assert(a==0x12345678);
  30. assert(uint32_read_big(buf)==0x12345678);
  31. buf[0]=buf[1]=buf[2]=buf[3]=0;
  32. uint32_pack(buf,0x12345678);
  33. assert(buf[0]==0x78 && buf[1]==0x56 && buf[2]==0x34 && buf[3]==0x12);
  34. uint32_unpack(buf,&a);
  35. assert(a==0x12345678);
  36. assert(uint32_read(buf)==0x12345678);
  37. }
  38. {
  39. uint64 a;
  40. unsigned int i;
  41. byte_zero(buf,sizeof(buf));
  42. uint64_pack_big(buf,0x0102030405060708ull);
  43. for (i=0; i<8; ++i) assert(buf[i]==i+1);
  44. uint64_unpack_big(buf,&a);
  45. assert(a==0x0102030405060708ull);
  46. assert(uint64_read_big(buf)==0x0102030405060708ull);
  47. byte_zero(buf,sizeof(buf));
  48. uint64_pack(buf,0x0102030405060708ull);
  49. for (i=0; i<8; ++i) assert(buf[7-i]==i+1);
  50. uint64_unpack(buf,&a);
  51. assert(a==0x0102030405060708ull);
  52. assert(uint64_read(buf)==0x0102030405060708ull);
  53. }
  54. }