mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
FIFOBuffer tidy up
This commit is contained in:
@@ -237,14 +237,14 @@ public:
|
|||||||
|
|
||||||
if (_buffer.size() - (_begin + _used) < length)
|
if (_buffer.size() - (_begin + _used) < length)
|
||||||
{
|
{
|
||||||
std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T));
|
std::memmove(_buffer.begin(), begin(), _used * sizeof(T));
|
||||||
_begin = 0;
|
_begin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t usedBefore = _used;
|
std::size_t usedBefore = _used;
|
||||||
std::size_t available = _buffer.size() - _used - _begin;
|
std::size_t available = _buffer.size() - _used - _begin;
|
||||||
std::size_t len = length > available ? available : length;
|
std::size_t len = length > available ? available : length;
|
||||||
std::memcpy(_buffer.begin() + _begin + _used, pBuffer, len * sizeof(T));
|
std::memcpy(begin() + _used, pBuffer, len * sizeof(T));
|
||||||
_used += len;
|
_used += len;
|
||||||
poco_assert (_used <= _buffer.size());
|
poco_assert (_used <= _buffer.size());
|
||||||
if (_notify) notify(usedBefore);
|
if (_notify) notify(usedBefore);
|
||||||
@@ -346,7 +346,7 @@ public:
|
|||||||
|
|
||||||
if (_buffer.size() - (_begin + _used) < length)
|
if (_buffer.size() - (_begin + _used) < length)
|
||||||
{
|
{
|
||||||
std::memmove(_buffer.begin(), _buffer.begin() + _begin, _used * sizeof(T));
|
std::memmove(_buffer.begin(), begin(), _used * sizeof(T));
|
||||||
_begin = 0;
|
_begin = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -553,14 +553,6 @@
|
|||||||
RelativePath=".\src\AutoReleasePoolTest.cpp"
|
RelativePath=".\src\AutoReleasePoolTest.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\src\BasicFIFOBufferTest.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\BufferTestSuite.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\ByteOrderTest.cpp"
|
RelativePath=".\src\ByteOrderTest.cpp"
|
||||||
>
|
>
|
||||||
@@ -581,6 +573,14 @@
|
|||||||
RelativePath=".\src\DynamicFactoryTest.cpp"
|
RelativePath=".\src\DynamicFactoryTest.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\FIFOBufferTest.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\FIFOBufferTestSuite.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\FormatTest.cpp"
|
RelativePath=".\src\FormatTest.cpp"
|
||||||
>
|
>
|
||||||
@@ -661,14 +661,6 @@
|
|||||||
RelativePath=".\src\AutoReleasePoolTest.h"
|
RelativePath=".\src\AutoReleasePoolTest.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\src\BasicFIFOBufferTest.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\BufferTestSuite.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\ByteOrderTest.h"
|
RelativePath=".\src\ByteOrderTest.h"
|
||||||
>
|
>
|
||||||
@@ -693,6 +685,14 @@
|
|||||||
RelativePath=".\src\DynamicFactoryTest.h"
|
RelativePath=".\src\DynamicFactoryTest.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\FIFOBufferTest.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\FIFOBufferTestSuite.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\FormatTest.h"
|
RelativePath=".\src\FormatTest.h"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
//
|
|
||||||
// BufferTestSuite.cpp
|
|
||||||
//
|
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/BufferTestSuite.cpp#1 $
|
|
||||||
//
|
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
||||||
// and Contributors.
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "BufferTestSuite.h"
|
|
||||||
#include "BasicFIFOBufferTest.h"
|
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* BufferTestSuite::suite()
|
|
||||||
{
|
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("BufferTestSuite");
|
|
||||||
|
|
||||||
pSuite->addTest(BasicFIFOBufferTest::suite());
|
|
||||||
|
|
||||||
return pSuite;
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
//
|
|
||||||
// BufferTestSuite.h
|
|
||||||
//
|
|
||||||
// $Id: //poco/1.6/Foundation/testsuite/src/BufferTestSuite.h#1 $
|
|
||||||
//
|
|
||||||
// Definition of the BufferTestSuite class.
|
|
||||||
//
|
|
||||||
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
||||||
// and Contributors.
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: BSL-1.0
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef BufferTestSuite_INCLUDED
|
|
||||||
#define BufferTestSuite_INCLUDED
|
|
||||||
|
|
||||||
|
|
||||||
#include "CppUnit/TestSuite.h"
|
|
||||||
|
|
||||||
|
|
||||||
class BufferTestSuite
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static CppUnit::Test* suite();
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif // BufferTestSuite_INCLUDED
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// BasicFIFOBufferTest.cpp
|
// FIFOBufferTest.cpp
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.4/Foundation/testsuite/src/BasicFIFOBufferTest.cpp#1 $
|
// $Id: //poco/1.4/Foundation/testsuite/src/FIFOBufferTest.cpp#1 $
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#include "BasicFIFOBufferTest.h"
|
#include "FIFOBufferTest.h"
|
||||||
#include "CppUnit/TestCaller.h"
|
#include "CppUnit/TestCaller.h"
|
||||||
#include "CppUnit/TestSuite.h"
|
#include "CppUnit/TestSuite.h"
|
||||||
#include "Poco/Buffer.h"
|
#include "Poco/Buffer.h"
|
||||||
@@ -31,7 +31,7 @@ using Poco::delegate;
|
|||||||
using std::memcpy;
|
using std::memcpy;
|
||||||
|
|
||||||
|
|
||||||
BasicFIFOBufferTest::BasicFIFOBufferTest(const std::string& name):
|
FIFOBufferTest::FIFOBufferTest(const std::string& name):
|
||||||
CppUnit::TestCase(name),
|
CppUnit::TestCase(name),
|
||||||
_notToReadable(0),
|
_notToReadable(0),
|
||||||
_notToWritable(0),
|
_notToWritable(0),
|
||||||
@@ -41,24 +41,24 @@ BasicFIFOBufferTest::BasicFIFOBufferTest(const std::string& name):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BasicFIFOBufferTest::~BasicFIFOBufferTest()
|
FIFOBufferTest::~FIFOBufferTest()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicFIFOBufferTest::onReadable(bool& b)
|
void FIFOBufferTest::onReadable(bool& b)
|
||||||
{
|
{
|
||||||
if (b) ++_notToReadable;
|
if (b) ++_notToReadable;
|
||||||
else ++_readableToNot;
|
else ++_readableToNot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void BasicFIFOBufferTest::onWritable(bool& b)
|
void FIFOBufferTest::onWritable(bool& b)
|
||||||
{
|
{
|
||||||
if (b) ++_notToWritable;
|
if (b) ++_notToWritable;
|
||||||
else ++_writableToNot;
|
else ++_writableToNot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicFIFOBufferTest::testNextWrite()
|
void FIFOBufferTest::testNextWrite()
|
||||||
{
|
{
|
||||||
// String length is 88 characters.
|
// String length is 88 characters.
|
||||||
const int BUFFER_SIZE = 128;
|
const int BUFFER_SIZE = 128;
|
||||||
@@ -85,7 +85,7 @@ void BasicFIFOBufferTest::testNextWrite()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BasicFIFOBufferTest::testEOFAndError()
|
void FIFOBufferTest::testEOFAndError()
|
||||||
{
|
{
|
||||||
typedef FIFOBuffer::Type T;
|
typedef FIFOBuffer::Type T;
|
||||||
|
|
||||||
@@ -97,8 +97,8 @@ void BasicFIFOBufferTest::testEOFAndError()
|
|||||||
Buffer<T> b(10);
|
Buffer<T> b(10);
|
||||||
std::vector<T> v;
|
std::vector<T> v;
|
||||||
|
|
||||||
f.readable += delegate(this, &BasicFIFOBufferTest::onReadable);
|
f.readable += delegate(this, &FIFOBufferTest::onReadable);
|
||||||
f.writable += delegate(this, &BasicFIFOBufferTest::onWritable);
|
f.writable += delegate(this, &FIFOBufferTest::onWritable);
|
||||||
|
|
||||||
for (T c = '0'; c < '0' + 10; ++c)
|
for (T c = '0'; c < '0' + 10; ++c)
|
||||||
v.push_back(c);
|
v.push_back(c);
|
||||||
@@ -191,7 +191,7 @@ void BasicFIFOBufferTest::testEOFAndError()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BasicFIFOBufferTest::testChar()
|
void FIFOBufferTest::testChar()
|
||||||
{
|
{
|
||||||
typedef FIFOBuffer::Type T;
|
typedef FIFOBuffer::Type T;
|
||||||
|
|
||||||
@@ -203,8 +203,8 @@ void BasicFIFOBufferTest::testChar()
|
|||||||
Buffer<T> b(10);
|
Buffer<T> b(10);
|
||||||
std::vector<T> v;
|
std::vector<T> v;
|
||||||
|
|
||||||
f.readable += delegate(this, &BasicFIFOBufferTest::onReadable);
|
f.readable += delegate(this, &FIFOBufferTest::onReadable);
|
||||||
f.writable += delegate(this, &BasicFIFOBufferTest::onWritable);
|
f.writable += delegate(this, &FIFOBufferTest::onWritable);
|
||||||
|
|
||||||
for (T c = '0'; c < '0' + 10; ++c)
|
for (T c = '0'; c < '0' + 10; ++c)
|
||||||
v.push_back(c);
|
v.push_back(c);
|
||||||
@@ -524,12 +524,12 @@ void BasicFIFOBufferTest::testChar()
|
|||||||
assert(f[8] == '0');
|
assert(f[8] == '0');
|
||||||
assert(f[9] == '1');
|
assert(f[9] == '1');
|
||||||
|
|
||||||
f.readable -= delegate(this, &BasicFIFOBufferTest::onReadable);
|
f.readable -= delegate(this, &FIFOBufferTest::onReadable);
|
||||||
f.writable -= delegate(this, &BasicFIFOBufferTest::onReadable);
|
f.writable -= delegate(this, &FIFOBufferTest::onReadable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BasicFIFOBufferTest::testInt()
|
void FIFOBufferTest::testInt()
|
||||||
{
|
{
|
||||||
typedef int T;
|
typedef int T;
|
||||||
|
|
||||||
@@ -671,25 +671,28 @@ void BasicFIFOBufferTest::testInt()
|
|||||||
assert (f.isEmpty());
|
assert (f.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasicFIFOBufferTest::setUp()
|
void FIFOBufferTest::setUp()
|
||||||
{
|
{
|
||||||
|
_notToReadable = 0;
|
||||||
|
_notToWritable = 0;
|
||||||
|
_readableToNot = 0;
|
||||||
|
_writableToNot = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BasicFIFOBufferTest::tearDown()
|
void FIFOBufferTest::tearDown()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* BasicFIFOBufferTest::suite()
|
CppUnit::Test* FIFOBufferTest::suite()
|
||||||
{
|
{
|
||||||
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("BasicFIFOBufferTest");
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FIFOBufferTest");
|
||||||
|
|
||||||
CppUnit_addTest(pSuite, BasicFIFOBufferTest, testNextWrite);
|
CppUnit_addTest(pSuite, FIFOBufferTest, testNextWrite);
|
||||||
CppUnit_addTest(pSuite, BasicFIFOBufferTest, testChar);
|
CppUnit_addTest(pSuite, FIFOBufferTest, testChar);
|
||||||
CppUnit_addTest(pSuite, BasicFIFOBufferTest, testInt);
|
CppUnit_addTest(pSuite, FIFOBufferTest, testInt);
|
||||||
CppUnit_addTest(pSuite, BasicFIFOBufferTest, testEOFAndError);
|
CppUnit_addTest(pSuite, FIFOBufferTest, testEOFAndError);
|
||||||
|
|
||||||
return pSuite;
|
return pSuite;
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
//
|
//
|
||||||
// BasicFIFOBufferTest.h
|
// FIFOBufferTest.h
|
||||||
//
|
//
|
||||||
// $Id: //poco/1.6/Foundation/testsuite/src/BasicFIFOBufferTest.h#1 $
|
// $Id: //poco/1.6/Foundation/testsuite/src/FIFOBufferTest.h#1 $
|
||||||
//
|
//
|
||||||
// Definition of the BasicFIFOBufferTest class.
|
// Definition of the FIFOBufferTest class.
|
||||||
//
|
//
|
||||||
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
|
||||||
// and Contributors.
|
// and Contributors.
|
||||||
@@ -12,19 +12,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
#ifndef BasicFIFOBufferTest_INCLUDED
|
#ifndef FIFOBufferTest_INCLUDED
|
||||||
#define BasicFIFOBufferTest_INCLUDED
|
#define FIFOBufferTest_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
#include "Poco/Foundation.h"
|
#include "Poco/Foundation.h"
|
||||||
#include "CppUnit/TestCase.h"
|
#include "CppUnit/TestCase.h"
|
||||||
|
|
||||||
|
|
||||||
class BasicFIFOBufferTest: public CppUnit::TestCase
|
class FIFOBufferTest: public CppUnit::TestCase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BasicFIFOBufferTest(const std::string& name);
|
FIFOBufferTest(const std::string& name);
|
||||||
~BasicFIFOBufferTest();
|
~FIFOBufferTest();
|
||||||
|
|
||||||
void testNextWrite();
|
void testNextWrite();
|
||||||
void testChar();
|
void testChar();
|
||||||
@@ -48,4 +48,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // BasicFIFOBufferTest_INCLUDED
|
#endif // FIFOBufferTest_INCLUDED
|
||||||
24
Foundation/testsuite/src/FIFOBufferTestSuite.cpp
Normal file
24
Foundation/testsuite/src/FIFOBufferTestSuite.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// FIFOBufferTestSuite.cpp
|
||||||
|
//
|
||||||
|
// $Id: //poco/1.4/Foundation/testsuite/src/FIFOBufferTestSuite.cpp#1 $
|
||||||
|
//
|
||||||
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
|
// and Contributors.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#include "FIFOBufferTestSuite.h"
|
||||||
|
#include "FIFOBufferTest.h"
|
||||||
|
|
||||||
|
|
||||||
|
CppUnit::Test* FIFOBufferTestSuite::suite()
|
||||||
|
{
|
||||||
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("FIFOBufferTestSuite");
|
||||||
|
|
||||||
|
pSuite->addTest(FIFOBufferTest::suite());
|
||||||
|
|
||||||
|
return pSuite;
|
||||||
|
}
|
||||||
29
Foundation/testsuite/src/FIFOBufferTestSuite.h
Normal file
29
Foundation/testsuite/src/FIFOBufferTestSuite.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// FIFOBufferTestSuite.h
|
||||||
|
//
|
||||||
|
// $Id: //poco/1.6/Foundation/testsuite/src/FIFOBufferTestSuite.h#1 $
|
||||||
|
//
|
||||||
|
// Definition of the FIFOBufferTestSuite class.
|
||||||
|
//
|
||||||
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
||||||
|
// and Contributors.
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: BSL-1.0
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef FIFOBufferTestSuite_INCLUDED
|
||||||
|
#define FIFOBufferTestSuite_INCLUDED
|
||||||
|
|
||||||
|
|
||||||
|
#include "CppUnit/TestSuite.h"
|
||||||
|
|
||||||
|
|
||||||
|
class FIFOBufferTestSuite
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static CppUnit::Test* suite();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // FIFOBufferTestSuite_INCLUDED
|
||||||
@@ -30,7 +30,7 @@
|
|||||||
#include "EventTestSuite.h"
|
#include "EventTestSuite.h"
|
||||||
#include "CacheTestSuite.h"
|
#include "CacheTestSuite.h"
|
||||||
#include "HashingTestSuite.h"
|
#include "HashingTestSuite.h"
|
||||||
#include "BufferTestSuite.h"
|
#include "FIFOBufferTestSuite.h"
|
||||||
|
|
||||||
|
|
||||||
CppUnit::Test* FoundationTestSuite::suite()
|
CppUnit::Test* FoundationTestSuite::suite()
|
||||||
@@ -40,7 +40,7 @@ CppUnit::Test* FoundationTestSuite::suite()
|
|||||||
pSuite->addTest(CoreTestSuite::suite());
|
pSuite->addTest(CoreTestSuite::suite());
|
||||||
pSuite->addTest(DateTimeTestSuite::suite());
|
pSuite->addTest(DateTimeTestSuite::suite());
|
||||||
pSuite->addTest(StreamsTestSuite::suite());
|
pSuite->addTest(StreamsTestSuite::suite());
|
||||||
pSuite->addTest(BufferTestSuite::suite());
|
pSuite->addTest(FIFOBufferTestSuite::suite());
|
||||||
pSuite->addTest(CryptTestSuite::suite());
|
pSuite->addTest(CryptTestSuite::suite());
|
||||||
pSuite->addTest(NotificationsTestSuite::suite());
|
pSuite->addTest(NotificationsTestSuite::suite());
|
||||||
pSuite->addTest(ThreadingTestSuite::suite());
|
pSuite->addTest(ThreadingTestSuite::suite());
|
||||||
|
|||||||
@@ -488,7 +488,7 @@ void ThreadTest::testAffinity()
|
|||||||
{
|
{
|
||||||
threadList[i]->setAffinity(i);
|
threadList[i]->setAffinity(i);
|
||||||
}
|
}
|
||||||
catch (Poco::NotImplementedException& niex)
|
catch (Poco::NotImplementedException&)
|
||||||
{
|
{
|
||||||
notImplemented = true;
|
notImplemented = true;
|
||||||
}
|
}
|
||||||
@@ -497,7 +497,7 @@ void ThreadTest::testAffinity()
|
|||||||
{
|
{
|
||||||
usedCpu = threadList[i]->getAffinity();
|
usedCpu = threadList[i]->getAffinity();
|
||||||
}
|
}
|
||||||
catch (Poco::NotImplementedException& niex)
|
catch (Poco::NotImplementedException&)
|
||||||
{
|
{
|
||||||
notImplemented = true;
|
notImplemented = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user