string_test.cpp 796 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*
  2. * Copyright 2010-2016 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. #include <bx/crtimpl.h>
  8. #include <bx/handlealloc.h>
  9. bx::AllocatorI* g_allocator;
  10. TEST_CASE("strnlen", "")
  11. {
  12. const char* test = "test";
  13. REQUIRE(0 == bx::strnlen(test, 0) );
  14. REQUIRE(2 == bx::strnlen(test, 2) );
  15. REQUIRE(4 == bx::strnlen(test, UINT32_MAX) );
  16. }
  17. TEST_CASE("StringView", "")
  18. {
  19. bx::StringView sv("test");
  20. REQUIRE(4 == sv.getLength() );
  21. bx::CrtAllocator crt;
  22. g_allocator = &crt;
  23. typedef bx::StringT<&g_allocator> String;
  24. String st(sv);
  25. REQUIRE(4 == st.getLength() );
  26. st.clear();
  27. REQUIRE(0 == st.getLength() );
  28. REQUIRE(4 == sv.getLength() );
  29. sv.clear();
  30. REQUIRE(0 == sv.getLength() );
  31. }