align_up_test.cpp 865 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. Copyright 2015 Glen Joseph Fernandes
  3. (glenjofe@gmail.com)
  4. Distributed under the Boost Software License, Version 1.0.
  5. (http://www.boost.org/LICENSE_1_0.txt)
  6. */
  7. #include <boost/align/align_up.hpp>
  8. #include <boost/align/is_aligned.hpp>
  9. #include <boost/core/lightweight_test.hpp>
  10. template<std::size_t Alignment>
  11. void test()
  12. {
  13. char s[Alignment << 1];
  14. char* b = s;
  15. while (!boost::alignment::is_aligned(b, Alignment)) {
  16. ++b;
  17. }
  18. {
  19. void* p = b;
  20. BOOST_TEST(boost::alignment::align_up(p, Alignment) == p);
  21. }
  22. {
  23. void* p = &b[Alignment];
  24. void* q = &b[1];
  25. BOOST_TEST(boost::alignment::align_up(q, Alignment) == p);
  26. }
  27. }
  28. int main()
  29. {
  30. test<1>();
  31. test<2>();
  32. test<4>();
  33. test<8>();
  34. test<16>();
  35. test<32>();
  36. test<64>();
  37. test<128>();
  38. return boost::report_errors();
  39. }