mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-04-19 10:47:13 +02:00
Switched to POCO library for unified platform/library interface. Deprecated the external module API. It was creating more problems than solving. Removed most built-in libraries in favor of system libraries for easier maintenance. Cleaned and secured code with help from static analyzers.
105 lines
1.4 KiB
C++
105 lines
1.4 KiB
C++
//
|
|
// AutoReleasePoolTest.cpp
|
|
//
|
|
// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
|
|
// and Contributors.
|
|
//
|
|
// SPDX-License-Identifier: BSL-1.0
|
|
//
|
|
|
|
|
|
#include "AutoReleasePoolTest.h"
|
|
#include "CppUnit/TestCaller.h"
|
|
#include "CppUnit/TestSuite.h"
|
|
#include "Poco/AutoReleasePool.h"
|
|
|
|
|
|
using Poco::AutoReleasePool;
|
|
|
|
|
|
namespace
|
|
{
|
|
class TestObj
|
|
{
|
|
public:
|
|
TestObj(): _rc(1)
|
|
{
|
|
++_count;
|
|
}
|
|
|
|
void duplicate()
|
|
{
|
|
++_rc;
|
|
}
|
|
|
|
void release()
|
|
{
|
|
if (--_rc == 0)
|
|
delete this;
|
|
}
|
|
|
|
int rc() const
|
|
{
|
|
return _rc;
|
|
}
|
|
|
|
static int count()
|
|
{
|
|
return _count;
|
|
}
|
|
|
|
protected:
|
|
~TestObj()
|
|
{
|
|
--_count;
|
|
}
|
|
|
|
private:
|
|
int _rc;
|
|
static int _count;
|
|
};
|
|
|
|
int TestObj::_count = 0;
|
|
}
|
|
|
|
|
|
AutoReleasePoolTest::AutoReleasePoolTest(const std::string& name): CppUnit::TestCase(name)
|
|
{
|
|
}
|
|
|
|
|
|
AutoReleasePoolTest::~AutoReleasePoolTest()
|
|
{
|
|
}
|
|
|
|
|
|
void AutoReleasePoolTest::testAutoReleasePool()
|
|
{
|
|
AutoReleasePool<TestObj> arp;
|
|
arp.add(new TestObj);
|
|
arp.add(new TestObj);
|
|
assertTrue (TestObj::count() == 2);
|
|
arp.release();
|
|
assertTrue (TestObj::count() == 0);
|
|
}
|
|
|
|
|
|
void AutoReleasePoolTest::setUp()
|
|
{
|
|
}
|
|
|
|
|
|
void AutoReleasePoolTest::tearDown()
|
|
{
|
|
}
|
|
|
|
|
|
CppUnit::Test* AutoReleasePoolTest::suite()
|
|
{
|
|
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("AutoReleasePoolTest");
|
|
|
|
CppUnit_addTest(pSuite, AutoReleasePoolTest, testAutoReleasePool);
|
|
|
|
return pSuite;
|
|
}
|