mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-17 12:02:36 +01:00
FIFOBuffer tidy up
This commit is contained in:
parent
84842e9eea
commit
027c8a40e2
@ -237,14 +237,14 @@ public:
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
std::size_t usedBefore = _used;
|
||||
std::size_t available = _buffer.size() - _used - _begin;
|
||||
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;
|
||||
poco_assert (_used <= _buffer.size());
|
||||
if (_notify) notify(usedBefore);
|
||||
@ -346,7 +346,7 @@ public:
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -553,14 +553,6 @@
|
||||
RelativePath=".\src\AutoReleasePoolTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BasicFIFOBufferTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BufferTestSuite.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ByteOrderTest.cpp"
|
||||
>
|
||||
@ -581,6 +573,14 @@
|
||||
RelativePath=".\src\DynamicFactoryTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\FIFOBufferTest.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\FIFOBufferTestSuite.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\FormatTest.cpp"
|
||||
>
|
||||
@ -661,14 +661,6 @@
|
||||
RelativePath=".\src\AutoReleasePoolTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BasicFIFOBufferTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\BufferTestSuite.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ByteOrderTest.h"
|
||||
>
|
||||
@ -693,6 +685,14 @@
|
||||
RelativePath=".\src\DynamicFactoryTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\FIFOBufferTest.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\FIFOBufferTestSuite.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
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.
|
||||
// and Contributors.
|
||||
@ -10,7 +10,7 @@
|
||||
//
|
||||
|
||||
|
||||
#include "BasicFIFOBufferTest.h"
|
||||
#include "FIFOBufferTest.h"
|
||||
#include "CppUnit/TestCaller.h"
|
||||
#include "CppUnit/TestSuite.h"
|
||||
#include "Poco/Buffer.h"
|
||||
@ -31,7 +31,7 @@ using Poco::delegate;
|
||||
using std::memcpy;
|
||||
|
||||
|
||||
BasicFIFOBufferTest::BasicFIFOBufferTest(const std::string& name):
|
||||
FIFOBufferTest::FIFOBufferTest(const std::string& name):
|
||||
CppUnit::TestCase(name),
|
||||
_notToReadable(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;
|
||||
else ++_readableToNot;
|
||||
};
|
||||
|
||||
|
||||
void BasicFIFOBufferTest::onWritable(bool& b)
|
||||
void FIFOBufferTest::onWritable(bool& b)
|
||||
{
|
||||
if (b) ++_notToWritable;
|
||||
else ++_writableToNot;
|
||||
}
|
||||
|
||||
void BasicFIFOBufferTest::testNextWrite()
|
||||
void FIFOBufferTest::testNextWrite()
|
||||
{
|
||||
// String length is 88 characters.
|
||||
const int BUFFER_SIZE = 128;
|
||||
@ -85,7 +85,7 @@ void BasicFIFOBufferTest::testNextWrite()
|
||||
}
|
||||
|
||||
|
||||
void BasicFIFOBufferTest::testEOFAndError()
|
||||
void FIFOBufferTest::testEOFAndError()
|
||||
{
|
||||
typedef FIFOBuffer::Type T;
|
||||
|
||||
@ -97,8 +97,8 @@ void BasicFIFOBufferTest::testEOFAndError()
|
||||
Buffer<T> b(10);
|
||||
std::vector<T> v;
|
||||
|
||||
f.readable += delegate(this, &BasicFIFOBufferTest::onReadable);
|
||||
f.writable += delegate(this, &BasicFIFOBufferTest::onWritable);
|
||||
f.readable += delegate(this, &FIFOBufferTest::onReadable);
|
||||
f.writable += delegate(this, &FIFOBufferTest::onWritable);
|
||||
|
||||
for (T c = '0'; c < '0' + 10; ++c)
|
||||
v.push_back(c);
|
||||
@ -191,7 +191,7 @@ void BasicFIFOBufferTest::testEOFAndError()
|
||||
}
|
||||
|
||||
|
||||
void BasicFIFOBufferTest::testChar()
|
||||
void FIFOBufferTest::testChar()
|
||||
{
|
||||
typedef FIFOBuffer::Type T;
|
||||
|
||||
@ -203,8 +203,8 @@ void BasicFIFOBufferTest::testChar()
|
||||
Buffer<T> b(10);
|
||||
std::vector<T> v;
|
||||
|
||||
f.readable += delegate(this, &BasicFIFOBufferTest::onReadable);
|
||||
f.writable += delegate(this, &BasicFIFOBufferTest::onWritable);
|
||||
f.readable += delegate(this, &FIFOBufferTest::onReadable);
|
||||
f.writable += delegate(this, &FIFOBufferTest::onWritable);
|
||||
|
||||
for (T c = '0'; c < '0' + 10; ++c)
|
||||
v.push_back(c);
|
||||
@ -524,12 +524,12 @@ void BasicFIFOBufferTest::testChar()
|
||||
assert(f[8] == '0');
|
||||
assert(f[9] == '1');
|
||||
|
||||
f.readable -= delegate(this, &BasicFIFOBufferTest::onReadable);
|
||||
f.writable -= delegate(this, &BasicFIFOBufferTest::onReadable);
|
||||
f.readable -= delegate(this, &FIFOBufferTest::onReadable);
|
||||
f.writable -= delegate(this, &FIFOBufferTest::onReadable);
|
||||
}
|
||||
|
||||
|
||||
void BasicFIFOBufferTest::testInt()
|
||||
void FIFOBufferTest::testInt()
|
||||
{
|
||||
typedef int T;
|
||||
|
||||
@ -671,25 +671,28 @@ void BasicFIFOBufferTest::testInt()
|
||||
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, BasicFIFOBufferTest, testChar);
|
||||
CppUnit_addTest(pSuite, BasicFIFOBufferTest, testInt);
|
||||
CppUnit_addTest(pSuite, BasicFIFOBufferTest, testEOFAndError);
|
||||
CppUnit_addTest(pSuite, FIFOBufferTest, testNextWrite);
|
||||
CppUnit_addTest(pSuite, FIFOBufferTest, testChar);
|
||||
CppUnit_addTest(pSuite, FIFOBufferTest, testInt);
|
||||
CppUnit_addTest(pSuite, FIFOBufferTest, testEOFAndError);
|
||||
|
||||
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.
|
||||
// and Contributors.
|
||||
@ -12,19 +12,19 @@
|
||||
//
|
||||
|
||||
|
||||
#ifndef BasicFIFOBufferTest_INCLUDED
|
||||
#define BasicFIFOBufferTest_INCLUDED
|
||||
#ifndef FIFOBufferTest_INCLUDED
|
||||
#define FIFOBufferTest_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Foundation.h"
|
||||
#include "CppUnit/TestCase.h"
|
||||
|
||||
|
||||
class BasicFIFOBufferTest: public CppUnit::TestCase
|
||||
class FIFOBufferTest: public CppUnit::TestCase
|
||||
{
|
||||
public:
|
||||
BasicFIFOBufferTest(const std::string& name);
|
||||
~BasicFIFOBufferTest();
|
||||
FIFOBufferTest(const std::string& name);
|
||||
~FIFOBufferTest();
|
||||
|
||||
void testNextWrite();
|
||||
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 "CacheTestSuite.h"
|
||||
#include "HashingTestSuite.h"
|
||||
#include "BufferTestSuite.h"
|
||||
#include "FIFOBufferTestSuite.h"
|
||||
|
||||
|
||||
CppUnit::Test* FoundationTestSuite::suite()
|
||||
@ -40,7 +40,7 @@ CppUnit::Test* FoundationTestSuite::suite()
|
||||
pSuite->addTest(CoreTestSuite::suite());
|
||||
pSuite->addTest(DateTimeTestSuite::suite());
|
||||
pSuite->addTest(StreamsTestSuite::suite());
|
||||
pSuite->addTest(BufferTestSuite::suite());
|
||||
pSuite->addTest(FIFOBufferTestSuite::suite());
|
||||
pSuite->addTest(CryptTestSuite::suite());
|
||||
pSuite->addTest(NotificationsTestSuite::suite());
|
||||
pSuite->addTest(ThreadingTestSuite::suite());
|
||||
|
@ -488,7 +488,7 @@ void ThreadTest::testAffinity()
|
||||
{
|
||||
threadList[i]->setAffinity(i);
|
||||
}
|
||||
catch (Poco::NotImplementedException& niex)
|
||||
catch (Poco::NotImplementedException&)
|
||||
{
|
||||
notImplemented = true;
|
||||
}
|
||||
@ -497,7 +497,7 @@ void ThreadTest::testAffinity()
|
||||
{
|
||||
usedCpu = threadList[i]->getAffinity();
|
||||
}
|
||||
catch (Poco::NotImplementedException& niex)
|
||||
catch (Poco::NotImplementedException&)
|
||||
{
|
||||
notImplemented = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user