Update is_aligned unit test
This commit is contained in:
parent
6e72b6adf7
commit
f001ed1d5c
@ -207,11 +207,11 @@ void test_pointer()
|
||||
void test_member_pointer()
|
||||
{
|
||||
test<int X::*>();
|
||||
test<int (X::*)()>();
|
||||
test<int(X::*)()>();
|
||||
}
|
||||
|
||||
enum E {
|
||||
v = 1
|
||||
V = 1
|
||||
};
|
||||
|
||||
void test_enum()
|
||||
|
@ -1,44 +1,66 @@
|
||||
/*
|
||||
(c) 2014 Glen Joseph Fernandes
|
||||
(c) 2014-2015 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software
|
||||
License, Version 1.0.
|
||||
http://boost.org/LICENSE_1_0.txt
|
||||
*/
|
||||
#include <boost/align/alignment_of.hpp>
|
||||
#include <boost/align/is_aligned.hpp>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
template<std::size_t Alignment>
|
||||
template<std::size_t N>
|
||||
struct A { };
|
||||
|
||||
template<std::size_t N>
|
||||
void test(char* p, A<N>)
|
||||
{
|
||||
BOOST_TEST(boost::alignment::is_aligned(p, N));
|
||||
BOOST_TEST(!boost::alignment::is_aligned(&p[1], N));
|
||||
}
|
||||
|
||||
void test(char* p, A<1>)
|
||||
{
|
||||
BOOST_TEST(boost::alignment::is_aligned(p, 1));
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void test()
|
||||
{
|
||||
char s[Alignment << 1];
|
||||
char* b = s;
|
||||
while (!boost::alignment::is_aligned(b, Alignment)) {
|
||||
b++;
|
||||
}
|
||||
std::size_t n = Alignment;
|
||||
{
|
||||
void* p = &b[n];
|
||||
BOOST_TEST(boost::alignment::is_aligned(p, n));
|
||||
}
|
||||
if (n > 1) {
|
||||
void* p = &b[1];
|
||||
BOOST_TEST(!boost::alignment::is_aligned(p, n));
|
||||
}
|
||||
T o;
|
||||
test(reinterpret_cast<char*>(&o),
|
||||
A<boost::alignment::alignment_of<T>::value>());
|
||||
}
|
||||
|
||||
class X;
|
||||
|
||||
int main()
|
||||
{
|
||||
test<1>();
|
||||
test<2>();
|
||||
test<4>();
|
||||
test<8>();
|
||||
test<16>();
|
||||
test<32>();
|
||||
test<64>();
|
||||
test<128>();
|
||||
test<bool>();
|
||||
test<char>();
|
||||
test<wchar_t>();
|
||||
#if !defined(BOOST_NO_CXX11_CHAR16_T)
|
||||
test<char16_t>();
|
||||
#endif
|
||||
#if !defined(BOOST_NO_CXX11_CHAR32_T)
|
||||
test<char32_t>();
|
||||
#endif
|
||||
test<short>();
|
||||
test<int>();
|
||||
test<long>();
|
||||
#if !defined(BOOST_NO_LONG_LONG)
|
||||
test<long long>();
|
||||
#endif
|
||||
test<void*>();
|
||||
test<char*>();
|
||||
test<int*>();
|
||||
test<X*>();
|
||||
test<void(*)()>();
|
||||
test<int X::*>();
|
||||
test<int(X::*)()>();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user