readerwriter_test.cpp 1009 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright 2010-2025 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
  4. */
  5. #include "test.h"
  6. #include <bx/readerwriter.h>
  7. TEST_CASE("writeLE", "")
  8. {
  9. bx::SizerWriter writer;
  10. bx::Error err;
  11. int32_t total = bx::writeLE(&writer, 1.0f, &err);
  12. REQUIRE(err.isOk() );
  13. REQUIRE(total == 4);
  14. }
  15. TEST_CASE("writeBE", "")
  16. {
  17. bx::SizerWriter writer;
  18. bx::Error err;
  19. int32_t total = bx::writeBE(&writer, 1.0f, &err);
  20. REQUIRE(err.isOk() );
  21. REQUIRE(total == 4);
  22. }
  23. TEST_CASE("writeRep", "")
  24. {
  25. uint8_t tmp[1389];
  26. bx::StaticMemoryBlock mb(tmp, sizeof(tmp) );
  27. bx::MemoryWriter writer(&mb);
  28. bx::Error err;
  29. int32_t total = 0;
  30. total += bx::writeRep(&writer, 0xfb, BX_COUNTOF(tmp)-1, &err);
  31. REQUIRE(err.isOk() );
  32. REQUIRE(BX_COUNTOF(tmp)-1 == total);
  33. total += bx::writeRep(&writer, 0xfb, 2, &err);
  34. REQUIRE(!err.isOk() );
  35. REQUIRE(BX_COUNTOF(tmp) == total);
  36. for (uint32_t ii = 0; ii < BX_COUNTOF(tmp); ++ii)
  37. {
  38. REQUIRE(0xfb == tmp[ii]);
  39. }
  40. }