PerfProfiler: Move resource counter test creation closer to test code

Change-Id: Ie4fb52d171eabfa4440ed937ea57003a152f7338
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2024-01-19 17:03:41 +01:00
parent 295e4373fe
commit e845a551a4
3 changed files with 28 additions and 23 deletions

View File

@@ -29,7 +29,7 @@ class PerfProfilerPlugin final : public ExtensionSystem::IPlugin
#if WITH_TESTS #if WITH_TESTS
// addTest<PerfProfilerTraceFileTest>(); // FIXME these tests have to get rewritten // addTest<PerfProfilerTraceFileTest>(); // FIXME these tests have to get rewritten
addTest<PerfResourceCounterTest>(); addTestCreator(createPerfResourceCounterTest);
#endif // WITH_TESTS #endif // WITH_TESTS
} }

View File

@@ -5,8 +5,7 @@
#include <perfprofiler/perfresourcecounter.h> #include <perfprofiler/perfresourcecounter.h>
#include <QtTest> #include <QtTest>
namespace PerfProfiler { namespace PerfProfiler::Internal {
namespace Internal {
struct SizePayload : public NoPayload struct SizePayload : public NoPayload
{ {
@@ -71,6 +70,22 @@ static void fill(Counter &counter, const typename Counter::Container &container,
QCOMPARE(sum(container), 0); QCOMPARE(sum(container), 0);
} }
class PerfResourceCounterTest final : public QObject
{
Q_OBJECT
private slots:
void testMallocFree();
void testRandomFill();
void testUnitSized();
void testRandomAlternate();
void testGuesses();
void testNegative();
void testInvalidId();
void testMultiCounter();
void testMove();
};
void PerfResourceCounterTest::testMallocFree() void PerfResourceCounterTest::testMallocFree()
{ {
SizeCounter::Container intContainer; SizeCounter::Container intContainer;
@@ -345,6 +360,11 @@ void PerfResourceCounterTest::testMove()
QCOMPARE(counter.currentTotal(), 500ll); QCOMPARE(counter.currentTotal(), 500ll);
} }
} // namespace Internal QObject *createPerfResourceCounterTest()
} // namespace PerfProfiler {
return new PerfResourceCounterTest;
}
} // PerfProfiler::Internal
#include "perfresourcecounter_test.moc"

View File

@@ -5,23 +5,8 @@
#include <QObject> #include <QObject>
namespace PerfProfiler { namespace PerfProfiler::Internal {
namespace Internal {
class PerfResourceCounterTest : public QObject QObject *createPerfResourceCounterTest();
{
Q_OBJECT
private slots:
void testMallocFree();
void testRandomFill();
void testUnitSized();
void testRandomAlternate();
void testGuesses();
void testNegative();
void testInvalidId();
void testMultiCounter();
void testMove();
};
} // namespace Internal } // PerfProfiler::Internal
} // namespace PerfProfiler