crt_test.cpp 958 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright 2010-2017 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx#license-bsd-2-clause
  4. */
  5. #include "test.h"
  6. #include <bx/string.h>
  7. TEST_CASE("memSet", "")
  8. {
  9. char temp[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
  10. REQUIRE(temp == bx::memSet(temp, 0, 0) );
  11. REQUIRE(temp[0] == 1);
  12. REQUIRE(temp == bx::memSet(temp, 0, 5) );
  13. REQUIRE(temp[0] == 0);
  14. REQUIRE(temp[1] == 0);
  15. REQUIRE(temp[2] == 0);
  16. REQUIRE(temp[3] == 0);
  17. REQUIRE(temp[4] == 0);
  18. REQUIRE(temp[5] == 6);
  19. }
  20. TEST_CASE("memMove", "")
  21. {
  22. char str[] = { 'x', 'x', 'x', 'x', 'a', 'b', 'v', 'g', 'd' };
  23. REQUIRE(bx::memMove(&str[4], &str[4], 0) );
  24. REQUIRE(bx::memMove(&str[4], &str[4], 5) );
  25. REQUIRE(&str[0] == bx::memMove(str, &str[4], 5) );
  26. REQUIRE( 0 == bx::strncmp(str, "abvgd", 5) );
  27. REQUIRE(&str[4] == bx::memMove(&str[4], str, 5) );
  28. REQUIRE( str[4] == 'a' );
  29. bx::memSet(str, 'x', 4);
  30. REQUIRE(0 == bx::strncmp(str, "xxxxabvgd", 9) );
  31. }