crt_test.cpp 969 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. bx::memSet(temp, 0, 0);
  11. REQUIRE(temp[0] == 1);
  12. 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. const char* orignal = "xxxxabvgd";
  23. char str[] = { 'x', 'x', 'x', 'x', 'a', 'b', 'v', 'g', 'd' };
  24. bx::memMove(&str[4], &str[4], 0);
  25. REQUIRE(0 == bx::strncmp(str, orignal) );
  26. bx::memMove(&str[4], &str[4], 5);
  27. REQUIRE(0 == bx::strncmp(str, orignal) );
  28. bx::memMove(str, &str[4], 5);
  29. REQUIRE(0 == bx::strncmp(str, "abvgd", 5) );
  30. bx::memMove(&str[4], str, 5);
  31. REQUIRE(str[4] == 'a' );
  32. bx::memSet(str, 'x', 4);
  33. REQUIRE(0 == bx::strncmp(str, orignal) );
  34. }