/*!
* \file test_ostream_dev.cpp
*
* Copyright (C) 2018 Christos Choutouridis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*/
#include
#include
#include
namespace test_ostream_dev {
using namespace utl;
// Device base data types
// MUST be DefaultConstructible, Copyable
using test_data_t = uint8_t;
// Test data
static const size_t SIZE = 10;
test_data_t Idata = 42;
test_data_t& IdataR = Idata;
test_data_t&& IdataRR = 0xAA;
test_data_t Ibuffer[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
// ostream device implementer (Mocks)
class Ostream_dev_impl : public ostream_dev {
friend ostream_dev;
public:
// virtual device
static constexpr size_t N =SIZE;
std::array v {}; // more than one so we can remember N-1 previous values
size_t c {0};
protected:
// ostream_dev requirements
size_t put_ (const test_data_t& data) {
v[c++] = data;
if (c >= N)
c = 0;
return 1;
}
size_t put_ (const test_data_t* data, size_t n) {
for (size_t i=0 ; i {
public:
// virtual device
static constexpr size_t N =SIZE;
std::array v {};
size_t c {0};
protected:
// ostream_dev requirements
size_t put_ (const test_data_t& data) {
v[c++] = data;
if (c >= N)
c = 0;
return 1;
}
size_t put_ (const test_data_t* data, size_t n) {
for (size_t i=0 ; i osVdev {};
ostream_dev *basePointer = nullptr;
};
//ToDo: Must add Concept test for ostream_dev
// TEST_F(Tostream_Idev, TestConcept) {
// EXPECT_EQ(true, Ostream_dev);
// }
TEST_F(Tostream_Idev, Construction) {
EXPECT_LT(0UL, sizeof(osIdev));
}
TEST_F (Tostream_Idev, Api) {
EXPECT_EQ(1UL, osIdev.put(Idata)); // single write from var
EXPECT_EQ(Idata, osIdev.getLastV ());
EXPECT_EQ(1UL, osIdev.put(IdataR));// single write from lvalue ref
EXPECT_EQ(IdataR, osIdev.getLastV ());
EXPECT_EQ(1UL, osIdev.put(IdataRR));// single write from rvalue ref
EXPECT_EQ(IdataRR, osIdev.getLastV ());
EXPECT_EQ(1UL, osIdev.put(42));// single write from rvalue
EXPECT_EQ(42U, osIdev.getLastV ());
EXPECT_EQ(7U, osIdev.put(Ibuffer, 7)); // batch write some data
for (size_t i =0 ; i<7 ; ++i) {
EXPECT_EQ(Ibuffer[i], osIdev.v[i]);
}
EXPECT_EQ(0, osIdev.v[7]);
EXPECT_EQ(SIZE, osIdev.put(Ibuffer, SIZE)); // batch write all data
for (size_t i =0 ; iput(Idata);
EXPECT_EQ(Idata, dev.v[0]);
EXPECT_EQ(SIZE, basePointer->put(Ibuffer, SIZE)); // batch write all data
for (size_t i =0 ; ibegin();
std::fill_n(it, SIZE, Idata);
for (size_t i=0 ;i