image: add simple offset test

This commit is contained in:
Danny Robson 2015-07-23 21:19:15 +10:00
parent d388e6543f
commit 86b36afc49
2 changed files with 34 additions and 0 deletions

View File

@ -327,6 +327,7 @@ TEST_BIN = \
test/hmac \
test/hotp \
test/hton \
test/image \
test/introspection \
test/ip \
test/json_types \

33
test/image.cpp Normal file
View File

@ -0,0 +1,33 @@
#include "image.hpp"
#include "tap.hpp"
#include <cstdint>
int
main (void)
{
util::TAP::logger tap;
constexpr size_t W = 64;
constexpr size_t H = 128;
util::image::buffer<uint16_t> img (W, H);
if (!img.is_packed ())
tap.skip ("linear position probe requires packed image allocation");
else {
// write out sequential values at each pixel, row-major
size_t i = 0;
for (size_t y = 0; y < H; ++y)
for (size_t x = 0; x < W; ++x)
img[{x,y}] = i++;
// check pixel values are sequential in row-major order
bool success = true;
for (size_t j = 0; j < i; ++j)
success = success && img[j] == j;
tap.expect (success, "linear position probe");
}
return tap.status ();
}