diff options
author | Neil MacIntosh <neilmac@microsoft.com> | 2016-05-30 03:06:29 +0300 |
---|---|---|
committer | Neil MacIntosh <neilmac@microsoft.com> | 2016-05-30 03:06:29 +0300 |
commit | ba8ebef509653127e74063097c1f7703b8a27185 (patch) | |
tree | 85c84017f726b38df582e089fe0a168b6987be66 /tests/span_tests.cpp | |
parent | d63c9803da102dcf87979319d6cf366ef38d5bb0 (diff) |
Added span to object rep conversions.
Diffstat (limited to 'tests/span_tests.cpp')
-rw-r--r-- | tests/span_tests.cpp | 91 |
1 files changed, 63 insertions, 28 deletions
diff --git a/tests/span_tests.cpp b/tests/span_tests.cpp index 694d9a2..ddae404 100644 --- a/tests/span_tests.cpp +++ b/tests/span_tests.cpp @@ -921,6 +921,69 @@ SUITE(span_tests) } } + TEST(as_bytes) + { + int a[] = {1, 2, 3, 4}; + + { + span<const int> s = a; + CHECK(s.length() == 4); + span<const byte> bs = as_bytes(s); + CHECK(static_cast<const void*>(bs.data()) == static_cast<const void*>(s.data())); + CHECK(bs.length() == s.length_bytes()); + } + + { + span<int> s; + auto bs = as_bytes(s); + CHECK(bs.length() == s.length()); + CHECK(bs.length() == 0); + CHECK(bs.size_bytes() == 0); + CHECK(static_cast<const void*>(bs.data()) == static_cast<const void*>(s.data())); + CHECK(bs.data() == nullptr); + } + + { + span<int> s = a; + auto bs = as_bytes(s); + CHECK(static_cast<const void*>(bs.data()) == static_cast<const void*>(s.data())); + CHECK(bs.length() == s.length_bytes()); + } + } + + TEST(as_writeable_bytes) + { + int a[] = {1, 2, 3, 4}; + + { +#ifdef CONFIRM_COMPILATION_ERRORS + // you should not be able to get writeable bytes for const objects + span<const int> s = a; + CHECK(s.length() == 4); + span<const byte> bs = as_writeable_bytes(s); + CHECK(static_cast<void*>(bs.data()) == static_cast<void*>(s.data())); + CHECK(bs.length() == s.length_bytes()); +#endif + } + + { + span<int> s; + auto bs = as_writeable_bytes(s); + CHECK(bs.length() == s.length()); + CHECK(bs.length() == 0); + CHECK(bs.size_bytes() == 0); + CHECK(static_cast<void*>(bs.data()) == static_cast<void*>(s.data())); + CHECK(bs.data() == nullptr); + } + + { + span<int> s = a; + auto bs = as_writeable_bytes(s); + CHECK(static_cast<void*>(bs.data()) == static_cast<void*>(s.data())); + CHECK(bs.length() == s.length_bytes()); + } + } + #if 0 TEST(fixed_size_conversions) { @@ -1018,34 +1081,6 @@ SUITE(span_tests) CHECK_THROW(f(), fail_fast); } - TEST(as_writeable_bytes) - { - int a[] = {1, 2, 3, 4}; - - { -#ifdef CONFIRM_COMPILATION_ERRORS - // you should not be able to get writeable bytes for const objects - span<const int, dynamic_range> av = a; - auto wav = av.as_writeable_bytes(); -#endif - } - - { - span<int, dynamic_range> av; - auto wav = as_writeable_bytes(av); - CHECK(wav.length() == av.length()); - CHECK(wav.length() == 0); - CHECK(wav.size_bytes() == 0); - } - - { - span<int, dynamic_range> av = a; - auto wav = as_writeable_bytes(av); - CHECK(wav.data() == (byte*) &a[0]); - CHECK(wav.length() == sizeof(a)); - } - } - #endif } |