2015-11-11 16:56:35 +11:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2015-11-11 16:56:35 +11:00
|
|
|
*
|
|
|
|
* Copyright 2015 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
2018-12-19 20:22:18 +11:00
|
|
|
#include "std.hpp"
|
|
|
|
#include "buffer/circular.hpp"
|
2015-11-11 16:56:35 +11:00
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-11-11 16:56:35 +11:00
|
|
|
|
|
|
|
// provoke usage of the smallest size buffer we can get away with so we
|
|
|
|
// might detect caching issues or similar.
|
|
|
|
constexpr size_t CAPACITY = 1;
|
2018-12-19 20:22:18 +11:00
|
|
|
cruft::buffer::circular<u08> data (CAPACITY);
|
2015-11-11 16:56:35 +11:00
|
|
|
|
|
|
|
// zero fill to ensure our value setting tests don't accidentall succeed
|
2018-12-19 20:22:18 +11:00
|
|
|
std::fill_n (data.begin (), data.size () * 2, 0);
|
2015-11-11 16:56:35 +11:00
|
|
|
|
|
|
|
// sanity check we haven't accidentally mapped an empty region
|
2018-12-19 20:22:18 +11:00
|
|
|
tap.expect_neq (data.begin (), data.end (), "non-zero sized region");
|
2015-11-11 16:56:35 +11:00
|
|
|
|
|
|
|
// check a near overrun is replicated
|
2018-12-19 20:22:18 +11:00
|
|
|
data.end ()[0] = 1;
|
|
|
|
tap.expect_eq (data.begin ()[0], data.end ()[0], "near overrun is replicated");
|
2015-11-11 16:56:35 +11:00
|
|
|
|
|
|
|
// check a far overrun is replicated
|
2018-12-19 20:22:18 +11:00
|
|
|
data.end ()[data.size () - 1] = 2;
|
|
|
|
tap.expect_eq (data.begin ()[data.size () - 1],
|
|
|
|
data.end ()[data.size () - 1],
|
2015-11-11 16:56:35 +11:00
|
|
|
"far overrun is replicated");
|
|
|
|
|
|
|
|
return tap.status ();
|
|
|
|
}
|