From cd467d5ffc6eaaa7da089ab4acc5284cd11d1109 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 6 Sep 2017 13:17:54 +0200 Subject: Get rid of the AllocationPolicy template argument in the ResourceManager We always use the same policy anyway. Change-Id: I3349b8c19ce0e6239b140dfac7ba66f8dda1b9be Reviewed-by: Sean Harmer --- src/animation/backend/managers_p.h | 15 +- src/core/resources/qresourcemanager_p.h | 16 +- src/input/backend/inputmanagers_p.h | 48 +-- src/logic/managers_p.h | 3 +- src/plugins/renderplugins/scene2d/scene2dplugin.h | 1 - src/render/backend/managers_p.h | 28 -- src/render/geometry/buffermanager_p.h | 1 - src/render/geometry/geometryrenderermanager_p.h | 1 - src/render/io/scenemanager.cpp | 1 - src/render/io/scenemanager_p.h | 1 - src/render/materialsystem/techniquemanager_p.h | 1 - .../arrayresourcesmanager.pro | 4 - .../dynamicarraypolicy/dynamicarraypolicy.pro | 7 - .../dynamicarraypolicy/tst_dynamicarraypolicy.cpp | 438 --------------------- tests/auto/core/core.pro | 2 +- .../core/qresourcemanager/qresourcemanager.pro | 7 + .../core/qresourcemanager/tst_qresourcemanager.cpp | 436 ++++++++++++++++++++ 17 files changed, 472 insertions(+), 538 deletions(-) delete mode 100644 tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro delete mode 100644 tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro delete mode 100644 tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp create mode 100644 tests/auto/core/qresourcemanager/qresourcemanager.pro create mode 100644 tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp diff --git a/src/animation/backend/managers_p.h b/src/animation/backend/managers_p.h index f99ed0698..3c670a8d2 100644 --- a/src/animation/backend/managers_p.h +++ b/src/animation/backend/managers_p.h @@ -70,8 +70,7 @@ class ClipBlendNode; class AnimationClipLoaderManager : public Qt3DCore::QResourceManager< AnimationClip, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: AnimationClipLoaderManager() {} @@ -80,8 +79,7 @@ public: class ClipAnimatorManager : public Qt3DCore::QResourceManager< ClipAnimator, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: ClipAnimatorManager() {} @@ -90,8 +88,7 @@ public: class BlendedClipAnimatorManager : public Qt3DCore::QResourceManager< BlendedClipAnimator, Qt3DCore::QNodeId, - 12, - Qt3DCore::ArrayAllocatingPolicy> + 12> { public: BlendedClipAnimatorManager() {} @@ -100,8 +97,7 @@ public: class ChannelMappingManager : public Qt3DCore::QResourceManager< ChannelMapping, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: ChannelMappingManager() {} @@ -110,8 +106,7 @@ public: class ChannelMapperManager : public Qt3DCore::QResourceManager< ChannelMapper, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: ChannelMapperManager() {} diff --git a/src/core/resources/qresourcemanager_p.h b/src/core/resources/qresourcemanager_p.h index 85233c97f..4cb2a38af 100644 --- a/src/core/resources/qresourcemanager_p.h +++ b/src/core/resources/qresourcemanager_p.h @@ -346,28 +346,25 @@ private: #ifndef QT_NO_DEBUG_STREAM template class AllocatingPolicy, template class LockingPolicy > class QResourceManager; template class AllocatingPolicy = ArrayAllocatingPolicy, template class LockingPolicy = NonLockingPolicy > -QDebug operator<<(QDebug dbg, const QResourceManager &manager); +QDebug operator<<(QDebug dbg, const QResourceManager &manager); #endif template class AllocatingPolicy = ArrayAllocatingPolicy, template class LockingPolicy = NonLockingPolicy > class QResourceManager - : public AllocatingPolicy - , public LockingPolicy< QResourceManager > + : public ArrayAllocatingPolicy + , public LockingPolicy< QResourceManager > { public: - typedef AllocatingPolicy Allocator; + typedef ArrayAllocatingPolicy Allocator; typedef QHandle Handle; QResourceManager() : @@ -474,15 +471,14 @@ private: Allocator::releaseResource(handle); } - friend QDebug operator<< <>(QDebug dbg, const QResourceManager &manager); + friend QDebug operator<< <>(QDebug dbg, const QResourceManager &manager); }; #ifndef QT_NO_DEBUG_STREAM template class AllocatingPolicy, template class LockingPolicy > -QDebug operator<<(QDebug dbg, const QResourceManager &manager) +QDebug operator<<(QDebug dbg, const QResourceManager &manager) { QDebugStateSaver saver(dbg); dbg << "Contains" << manager.count() << "items" << "of a maximum" << manager.maximumSize() << endl; diff --git a/src/input/backend/inputmanagers_p.h b/src/input/backend/inputmanagers_p.h index a0cb127b1..956b0ab8b 100644 --- a/src/input/backend/inputmanagers_p.h +++ b/src/input/backend/inputmanagers_p.h @@ -80,8 +80,7 @@ namespace Input { class KeyboardInputManager : public Qt3DCore::QResourceManager< KeyboardHandler, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: KeyboardInputManager() {} @@ -90,8 +89,7 @@ public: class KeyboardDeviceManager : public Qt3DCore::QResourceManager< KeyboardDevice, Qt3DCore::QNodeId, - 8, - Qt3DCore::ArrayAllocatingPolicy> + 8> { public: KeyboardDeviceManager() {} @@ -100,8 +98,7 @@ public: class MouseDeviceManager : public Qt3DCore::QResourceManager< MouseDevice, Qt3DCore::QNodeId, - 8, - Qt3DCore::ArrayAllocatingPolicy> + 8> { public: MouseDeviceManager() {} @@ -110,8 +107,7 @@ public: class MouseInputManager : public Qt3DCore::QResourceManager< MouseHandler, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: MouseInputManager() {} @@ -120,8 +116,7 @@ public: class AxisManager : public Qt3DCore::QResourceManager< Axis, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: AxisManager() {} @@ -130,8 +125,7 @@ public: class AxisSettingManager : public Qt3DCore::QResourceManager< AxisSetting, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: AxisSettingManager() {} @@ -140,8 +134,7 @@ public: class ActionManager : public Qt3DCore::QResourceManager< Action, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: ActionManager() {} @@ -150,8 +143,7 @@ public: class ActionInputManager : public Qt3DCore::QResourceManager< ActionInput, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: ActionInputManager() {} @@ -160,8 +152,7 @@ public: class AnalogAxisInputManager : public Qt3DCore::QResourceManager< AnalogAxisInput, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: AnalogAxisInputManager() {} @@ -170,8 +161,7 @@ public: class ButtonAxisInputManager : public Qt3DCore::QResourceManager< ButtonAxisInput, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: ButtonAxisInputManager() {} @@ -180,8 +170,7 @@ public: class InputChordManager : public Qt3DCore::QResourceManager< InputChord, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: InputChordManager() {} @@ -190,8 +179,7 @@ public: class InputSequenceManager : public Qt3DCore::QResourceManager< InputSequence, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: InputSequenceManager() {} @@ -200,8 +188,7 @@ public: class LogicalDeviceManager : public Qt3DCore::QResourceManager< LogicalDevice, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: LogicalDeviceManager() {} @@ -217,8 +204,7 @@ private: class GenericDeviceBackendNodeManager : public Qt3DCore::QResourceManager< GenericDeviceBackendNode, Qt3DCore::QNodeId, - 8, - Qt3DCore::ArrayAllocatingPolicy> + 8> { public: GenericDeviceBackendNodeManager() {} @@ -227,8 +213,7 @@ public: class Q_AUTOTEST_EXPORT PhysicalDeviceProxyManager : public Qt3DCore::QResourceManager< PhysicalDeviceProxy, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: PhysicalDeviceProxyManager() {} @@ -243,8 +228,7 @@ private: class AxisAccumulatorManager : public Qt3DCore::QResourceManager< AxisAccumulator, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: AxisAccumulatorManager() {} diff --git a/src/logic/managers_p.h b/src/logic/managers_p.h index 6194d260a..3d48aab24 100644 --- a/src/logic/managers_p.h +++ b/src/logic/managers_p.h @@ -65,8 +65,7 @@ namespace Logic { class HandlerManager : public Qt3DCore::QResourceManager< Handler, Qt3DCore::QNodeId, - 16, - Qt3DCore::ArrayAllocatingPolicy> + 16> { public: HandlerManager() {} diff --git a/src/plugins/renderplugins/scene2d/scene2dplugin.h b/src/plugins/renderplugins/scene2d/scene2dplugin.h index f19093c7e..3b4471d55 100644 --- a/src/plugins/renderplugins/scene2d/scene2dplugin.h +++ b/src/plugins/renderplugins/scene2d/scene2dplugin.h @@ -68,7 +68,6 @@ class Scene2DNodeManager : public Qt3DCore::QResourceManager< Render::Quick::Scene2D, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> { }; diff --git a/src/render/backend/managers_p.h b/src/render/backend/managers_p.h index 53d5e61c0..c5af93b8d 100644 --- a/src/render/backend/managers_p.h +++ b/src/render/backend/managers_p.h @@ -90,7 +90,6 @@ class AttachmentManager : public Qt3DCore::QResourceManager< RenderTargetOutput, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -101,7 +100,6 @@ class CameraManager : public Qt3DCore::QResourceManager< CameraLens, Qt3DCore::QNodeId, 8, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -112,7 +110,6 @@ class FilterKeyManager : public Qt3DCore::QResourceManager< FilterKey, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { @@ -124,7 +121,6 @@ class EffectManager : public Qt3DCore::QResourceManager< Effect, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -135,7 +131,6 @@ class Q_AUTOTEST_EXPORT EntityManager : public Qt3DCore::QResourceManager< Entity, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -170,7 +165,6 @@ class LayerManager : public Qt3DCore::QResourceManager< Layer, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -181,7 +175,6 @@ class LevelOfDetailManager : public Qt3DCore::QResourceManager< LevelOfDetail, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -192,7 +185,6 @@ class MaterialManager : public Qt3DCore::QResourceManager< Material, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -203,7 +195,6 @@ class MatrixManager : public Qt3DCore::QResourceManager< QMatrix4x4, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -214,7 +205,6 @@ class ShaderManager : public Qt3DCore::QResourceManager< Shader, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -225,7 +215,6 @@ class TextureManager : public Qt3DCore::QResourceManager< Texture, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -251,7 +240,6 @@ class TransformManager : public Qt3DCore::QResourceManager< Transform, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -262,7 +250,6 @@ class VAOManager : public Qt3DCore::QResourceManager< OpenGLVertexArrayObject, VAOIdentifier, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -273,7 +260,6 @@ class RenderTargetManager : public Qt3DCore::QResourceManager< RenderTarget, Qt3DCore::QNodeId, 8, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -284,7 +270,6 @@ class RenderPassManager : public Qt3DCore::QResourceManager< RenderPass, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -296,7 +281,6 @@ class ParameterManager : public Qt3DCore::QResourceManager< Parameter, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -307,7 +291,6 @@ class ShaderDataManager : public Qt3DCore::QResourceManager< ShaderData, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -318,7 +301,6 @@ class GLBufferManager : public Qt3DCore::QResourceManager< GLBuffer, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { }; @@ -327,7 +309,6 @@ class TextureImageManager : public Qt3DCore::QResourceManager< TextureImage, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { }; @@ -336,7 +317,6 @@ class AttributeManager : public Qt3DCore::QResourceManager< Attribute, Qt3DCore::QNodeId, 20, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { }; @@ -345,7 +325,6 @@ class GeometryManager : public Qt3DCore::QResourceManager< Geometry, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { }; @@ -354,7 +333,6 @@ class ObjectPickerManager : public Qt3DCore::QResourceManager< ObjectPicker, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { }; @@ -364,7 +342,6 @@ class BoundingVolumeDebugManager : public Qt3DCore::QResourceManager< BoundingVolumeDebug, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> { }; @@ -374,7 +351,6 @@ class LightManager : public Qt3DCore::QResourceManager< Light, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -385,7 +361,6 @@ class EnvironmentLightManager : public Qt3DCore::QResourceManager< EnvironmentLight, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -396,7 +371,6 @@ class ComputeCommandManager : public Qt3DCore::QResourceManager< ComputeCommand, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: @@ -407,12 +381,10 @@ class RenderStateManager : public Qt3DCore::QResourceManager< RenderStateNode, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { }; - } // namespace Render } // namespace Qt3DRender diff --git a/src/render/geometry/buffermanager_p.h b/src/render/geometry/buffermanager_p.h index 3eecb3664..ed3563876 100644 --- a/src/render/geometry/buffermanager_p.h +++ b/src/render/geometry/buffermanager_p.h @@ -64,7 +64,6 @@ class Q_AUTOTEST_EXPORT BufferManager : public Qt3DCore::QResourceManager< Buffer, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> { public: diff --git a/src/render/geometry/geometryrenderermanager_p.h b/src/render/geometry/geometryrenderermanager_p.h index 4dea63862..e3b313569 100644 --- a/src/render/geometry/geometryrenderermanager_p.h +++ b/src/render/geometry/geometryrenderermanager_p.h @@ -64,7 +64,6 @@ class Q_AUTOTEST_EXPORT GeometryRendererManager : public Qt3DCore::QResourceMana GeometryRenderer, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> { public: diff --git a/src/render/io/scenemanager.cpp b/src/render/io/scenemanager.cpp index d59391a87..8e6af8c40 100644 --- a/src/render/io/scenemanager.cpp +++ b/src/render/io/scenemanager.cpp @@ -47,7 +47,6 @@ namespace Render { SceneManager::SceneManager() : Qt3DCore::QResourceManager() { } diff --git a/src/render/io/scenemanager_p.h b/src/render/io/scenemanager_p.h index 164f82590..941b90a4d 100644 --- a/src/render/io/scenemanager_p.h +++ b/src/render/io/scenemanager_p.h @@ -69,7 +69,6 @@ class Q_AUTOTEST_EXPORT SceneManager : public Qt3DCore::QResourceManager< Scene, Qt3DCore::QNodeId, 8, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::ObjectLevelLockingPolicy> { public: diff --git a/src/render/materialsystem/techniquemanager_p.h b/src/render/materialsystem/techniquemanager_p.h index 5c86741c3..5b390f94b 100644 --- a/src/render/materialsystem/techniquemanager_p.h +++ b/src/render/materialsystem/techniquemanager_p.h @@ -64,7 +64,6 @@ class Q_AUTOTEST_EXPORT TechniqueManager : public Qt3DCore::QResourceManager< Technique, Qt3DCore::QNodeId, 16, - Qt3DCore::ArrayAllocatingPolicy, Qt3DCore::NonLockingPolicy> { public: diff --git a/tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro b/tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro deleted file mode 100644 index a23a04f3c..000000000 --- a/tests/auto/core/arrayresourcesmanager/arrayresourcesmanager.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs - -SUBDIRS = \ - dynamicarraypolicy diff --git a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro deleted file mode 100644 index ee2a73e03..000000000 --- a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/dynamicarraypolicy.pro +++ /dev/null @@ -1,7 +0,0 @@ -TARGET = tst_dynamicarraypolicy -CONFIG += testcase -TEMPLATE = app - -SOURCES += tst_dynamicarraypolicy.cpp - -QT += testlib 3dcore 3dcore-private diff --git a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp b/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp deleted file mode 100644 index 5c193ec90..000000000 --- a/tests/auto/core/arrayresourcesmanager/dynamicarraypolicy/tst_dynamicarraypolicy.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include - -class tst_DynamicArrayPolicy : public QObject -{ - Q_OBJECT -public: - tst_DynamicArrayPolicy() {} - ~tst_DynamicArrayPolicy() {} - -private slots: - void createResourcesManager(); - void acquireResources(); - void getResources(); - void registerResourcesResize(); - void removeResource(); - void lookupResource(); - void releaseResource(); - void heavyDutyMultiThreadedAccess(); - void heavyDutyMultiThreadedAccessRelease(); - void maximumNumberOfResources(); - void activeHandles(); -}; - -class tst_ArrayResource -{ -public: - tst_ArrayResource() : m_value(0) - {} - - void cleanup() { m_value = 0; } - - QAtomicInt m_value; -}; - -QT_BEGIN_NAMESPACE -Q_DECLARE_RESOURCE_INFO(tst_ArrayResource, Q_REQUIRES_CLEANUP) -QT_END_NAMESPACE - -typedef Qt3DCore::QHandle tHandle; -typedef Qt3DCore::QHandle tHandle4; -typedef Qt3DCore::QHandle tHandle8; -typedef Qt3DCore::QHandle tHandle16; - -void tst_DynamicArrayPolicy::createResourcesManager() -{ - Qt3DCore::QResourceManager manager16; - Qt3DCore::QResourceManager manager4; - Qt3DCore::QResourceManager manager8; - QVERIFY(manager16.maximumSize() == 65535); - QVERIFY(manager8.maximumSize() == 255); - QVERIFY(manager4.maximumSize() == 15); -} - -/*! - * Check that the handles returned when a registering resources - * have a correct index and counter. - */ -void tst_DynamicArrayPolicy::acquireResources() -{ - Qt3DCore::QResourceManager manager; - - QList handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - } - - for (uint i = 0; i < 5; i++) { - QVERIFY(handles.at(i).index() == i); - QVERIFY(handles.at(i).counter() == 1); - } -} - -/*! - * Test that values can be properly retrieved. - */ -void tst_DynamicArrayPolicy::getResources() -{ - - Qt3DCore::QResourceManager manager; - QList resources; - QList handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - } - - for (uint i = 0; i < 5; i++) { - QVERIFY(handles.at(i).index() == i); - QVERIFY(handles.at(i).counter() == 1); - resources << manager.data(handles.at(i)); - QVERIFY(resources.at(i) != nullptr); - resources.at(i)->m_value = i; - } - - for (int i = 0; i < 5; i++) - QVERIFY(manager.data(handles.at(i))->m_value == i); - - // Check that an invalid resource returns NULL - tHandle8 iHandle; - QVERIFY(manager.data(iHandle) == nullptr); - -} - -/*! - * Test that when a resize of the data vectors in the manager occurs, - * everything behaves correctly. - */ -void tst_DynamicArrayPolicy::registerResourcesResize() -{ - Qt3DCore::QResourceManager manager; - QList handles; - - for (uint i = 0; i < 2; i++) { - handles << manager.acquire(); - manager.data(handles.at(i))->m_value = i + 2; - } - - for (uint i = 0; i < 5; i++) { - handles << manager.acquire(); - manager.data(handles.at(i + 2))->m_value = i + 2 + 5; - } - - for (int i = 0; i < 7; i++) { - QVERIFY(handles.at(i).index() == static_cast(i)); - QVERIFY(handles.at(i).counter() == 1); - if (i < 2) - QVERIFY(manager.data(handles.at(i))->m_value == i + 2); - else - QVERIFY(manager.data(handles.at(i))->m_value == i + 5); - } -} - -/*! - * Checks for the removal of resources. - */ -void tst_DynamicArrayPolicy::removeResource() -{ - Qt3DCore::QResourceManager manager; - - QList resources; - QList handles; - - for (int i = 0; i < 32; i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - } - - manager.release(handles.at(2)); - QVERIFY(manager.data(handles.at(2)) == nullptr); - // Triggers QASSERT so commented - // manager.release(handles.at(2)); - - tHandle nHandle = manager.acquire(); - QVERIFY(manager.data(nHandle) != nullptr); -} - -void tst_DynamicArrayPolicy::lookupResource() -{ - Qt3DCore::QResourceManager manager; - - QList resources; - QList handles; - - for (int i = 0; i < 5; i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - resources.at(i)->m_value = 4; - } - - tHandle16 t = manager.lookupHandle(2); - QVERIFY(t.handle() == 0); - QVERIFY(manager.data(t) == nullptr); - tst_ArrayResource *resource = manager.getOrCreateResource(2); - QVERIFY(resource != nullptr); - t = manager.lookupHandle(2); - QVERIFY(manager.data(t) == manager.lookupResource(2)); - QVERIFY(t == manager.getOrAcquireHandle(2)); - QVERIFY(resource == manager.getOrCreateResource(2)); - QVERIFY(manager.data(t) == resource); -} - -void tst_DynamicArrayPolicy::releaseResource() -{ - Qt3DCore::QResourceManager manager; - QList resources; - - for (int i = 0; i < 5; i++) { - resources << manager.getOrCreateResource(i); - } - - for (int i = 0; i < 5; i++) { - QVERIFY(resources.at(i) == manager.lookupResource(i)); - } - - for (int i = 0; i < 5; i++) { - manager.releaseResource(i); - QVERIFY(manager.lookupResource(i) == nullptr); - } -} - -class tst_Thread : public QThread -{ - Q_OBJECT -public: - - typedef Qt3DCore::QResourceManager Manager; - - tst_Thread() - : QThread() - { - } - - void setManager(Manager *manager) - { - m_manager = manager; - } - - // QThread interface -protected: - void run() - { - int i = 0; - int max = tHandle::maxIndex(); - while (i < max) { - tst_ArrayResource *r = m_manager->getOrCreateResource(i); - i++; - QVERIFY(r != nullptr); - r->m_value.fetchAndAddOrdered(+1); - } - qDebug() << QThread::currentThread() << "Done"; - } - - Manager *m_manager; -}; - -void tst_DynamicArrayPolicy::heavyDutyMultiThreadedAccess() -{ - tst_Thread::Manager *manager = new tst_Thread::Manager(); - - QList threads; - - int iterations = 8; - int max = tHandle16::maxIndex(); - - for (int i = 0; i < iterations; i++) { - tst_Thread *thread = new tst_Thread(); - thread->setManager(manager); - threads << thread; - } - - for (int i = 0; i < iterations; i++) { - threads[i]->start(); - } - - for (int i = 0; i < iterations; i++) { - threads[i]->wait(); - } - - for (int i = 0; i < max; i++) { - QVERIFY(manager->lookupResource(i) != nullptr); - QVERIFY(manager->lookupResource(i)->m_value = iterations); - } - - qDeleteAll(threads); - delete manager; -} - -class tst_Thread2 : public QThread -{ - Q_OBJECT -public: - - typedef Qt3DCore::QResourceManager Manager; - - tst_Thread2(int releaseAbove = 7) - : QThread() - , m_releaseAbove(releaseAbove) - { - } - - void setManager(Manager *manager) - { - m_manager = manager; - } - - // QThread interface -protected: - void run() - { - int i = 0; - int max = tHandle::maxIndex(); - while (i < max) { - tst_ArrayResource *r = m_manager->getOrCreateResource(i); - QVERIFY(r != nullptr); - int oldValue = r->m_value.fetchAndAddOrdered(+1); - if (oldValue == m_releaseAbove) - m_manager->releaseResource(i); - i++; - } - qDebug() << QThread::currentThread() << "Done"; - } - - Manager *m_manager; - int m_releaseAbove; -}; - -void tst_DynamicArrayPolicy::heavyDutyMultiThreadedAccessRelease() -{ - tst_Thread2::Manager *manager = new tst_Thread2::Manager(); - - QList threads; - - int iterations = 8; - int max = tHandle16::maxIndex(); - - for (int u = 0; u < 2; u++) { - - for (int i = 0; i < iterations; i++) { - tst_Thread2 *thread = new tst_Thread2(); - thread->setManager(manager); - threads << thread; - } - - for (int i = 0; i < iterations; i++) { - threads[i]->start(); - } - - for (int i = 0; i < iterations; i++) { - threads[i]->wait(); - } - - for (int i = 0; i < max; i++) { - QVERIFY(manager->lookupResource(i) == nullptr); - } - - qDeleteAll(threads); - threads.clear(); - } - - delete manager; -} - -void tst_DynamicArrayPolicy::maximumNumberOfResources() -{ - Qt3DCore::QResourceManager manager; - - QList resources; - QList handles; - - QCOMPARE(tHandle16::maxIndex(), (uint)manager.maximumSize()); - - for (int i = 0; i < manager.maximumSize(); i++) { - handles << manager.acquire(); - resources << manager.data(handles.at(i)); - resources.at(i)->m_value = 4; - } -} - -void tst_DynamicArrayPolicy::activeHandles() -{ - // GIVEN - Qt3DCore::QResourceManager manager; - - { - // WHEN - const tHandle newHandle = manager.getOrAcquireHandle(883U); - // THEN - QCOMPARE(manager.activeHandles().size(), 1); - QCOMPARE(manager.activeHandles().first(), newHandle); - } - - { - // WHEN - manager.releaseResource(883U); - // THEN - QVERIFY(manager.activeHandles().empty()); - } - - { - // WHEN - const tHandle newHandle = manager.acquire(); - // THEN - QCOMPARE(manager.activeHandles().size(), 1); - QCOMPARE(manager.activeHandles().first(), newHandle); - - // WHEN - manager.release(newHandle); - // THEN - QVERIFY(manager.activeHandles().empty()); - } -} - - - - -QTEST_APPLESS_MAIN(tst_DynamicArrayPolicy) - -#include "tst_dynamicarraypolicy.moc" diff --git a/tests/auto/core/core.pro b/tests/auto/core/core.pro index 088940b7d..3595755d6 100644 --- a/tests/auto/core/core.pro +++ b/tests/auto/core/core.pro @@ -2,7 +2,7 @@ TEMPLATE = subdirs SUBDIRS = \ handle \ - arrayresourcesmanager \ + qresourcemanager \ qcircularbuffer \ qboundedcircularbuffer \ nodes \ diff --git a/tests/auto/core/qresourcemanager/qresourcemanager.pro b/tests/auto/core/qresourcemanager/qresourcemanager.pro new file mode 100644 index 000000000..8fdf9b569 --- /dev/null +++ b/tests/auto/core/qresourcemanager/qresourcemanager.pro @@ -0,0 +1,7 @@ +TARGET = tst_qresourcemanager +CONFIG += testcase +TEMPLATE = app + +SOURCES += tst_qresourcemanager.cpp + +QT += testlib 3dcore 3dcore-private diff --git a/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp new file mode 100644 index 000000000..c3238fc8f --- /dev/null +++ b/tests/auto/core/qresourcemanager/tst_qresourcemanager.cpp @@ -0,0 +1,436 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include + +class tst_DynamicArrayPolicy : public QObject +{ + Q_OBJECT +public: + tst_DynamicArrayPolicy() {} + ~tst_DynamicArrayPolicy() {} + +private slots: + void createResourcesManager(); + void acquireResources(); + void getResources(); + void registerResourcesResize(); + void removeResource(); + void lookupResource(); + void releaseResource(); + void heavyDutyMultiThreadedAccess(); + void heavyDutyMultiThreadedAccessRelease(); + void maximumNumberOfResources(); + void activeHandles(); +}; + +class tst_ArrayResource +{ +public: + tst_ArrayResource() : m_value(0) + {} + + void cleanup() { m_value = 0; } + + QAtomicInt m_value; +}; + +QT_BEGIN_NAMESPACE +Q_DECLARE_RESOURCE_INFO(tst_ArrayResource, Q_REQUIRES_CLEANUP) +QT_END_NAMESPACE + +typedef Qt3DCore::QHandle tHandle; +typedef Qt3DCore::QHandle tHandle4; +typedef Qt3DCore::QHandle tHandle8; +typedef Qt3DCore::QHandle tHandle16; + +void tst_DynamicArrayPolicy::createResourcesManager() +{ + Qt3DCore::QResourceManager manager16; + Qt3DCore::QResourceManager manager4; + Qt3DCore::QResourceManager manager8; + QVERIFY(manager16.maximumSize() == 65535); + QVERIFY(manager8.maximumSize() == 255); + QVERIFY(manager4.maximumSize() == 15); +} + +/*! + * Check that the handles returned when a registering resources + * have a correct index and counter. + */ +void tst_DynamicArrayPolicy::acquireResources() +{ + Qt3DCore::QResourceManager manager; + + QList handles; + + for (int i = 0; i < 5; i++) { + handles << manager.acquire(); + } + + for (uint i = 0; i < 5; i++) { + QVERIFY(handles.at(i).index() == i); + QVERIFY(handles.at(i).counter() == 1); + } +} + +/*! + * Test that values can be properly retrieved. + */ +void tst_DynamicArrayPolicy::getResources() +{ + + Qt3DCore::QResourceManager manager; + QList resources; + QList handles; + + for (int i = 0; i < 5; i++) { + handles << manager.acquire(); + } + + for (uint i = 0; i < 5; i++) { + QVERIFY(handles.at(i).index() == i); + QVERIFY(handles.at(i).counter() == 1); + resources << manager.data(handles.at(i)); + QVERIFY(resources.at(i) != nullptr); + resources.at(i)->m_value = i; + } + + for (int i = 0; i < 5; i++) + QVERIFY(manager.data(handles.at(i))->m_value == i); + + // Check that an invalid resource returns NULL + tHandle8 iHandle; + QVERIFY(manager.data(iHandle) == nullptr); + +} + +/*! + * Test that when a resize of the data vectors in the manager occurs, + * everything behaves correctly. + */ +void tst_DynamicArrayPolicy::registerResourcesResize() +{ + Qt3DCore::QResourceManager manager; + QList handles; + + for (uint i = 0; i < 2; i++) { + handles << manager.acquire(); + manager.data(handles.at(i))->m_value = i + 2; + } + + for (uint i = 0; i < 5; i++) { + handles << manager.acquire(); + manager.data(handles.at(i + 2))->m_value = i + 2 + 5; + } + + for (int i = 0; i < 7; i++) { + QVERIFY(handles.at(i).index() == static_cast(i)); + QVERIFY(handles.at(i).counter() == 1); + if (i < 2) + QVERIFY(manager.data(handles.at(i))->m_value == i + 2); + else + QVERIFY(manager.data(handles.at(i))->m_value == i + 5); + } +} + +/*! + * Checks for the removal of resources. + */ +void tst_DynamicArrayPolicy::removeResource() +{ + Qt3DCore::QResourceManager manager; + + QList resources; + QList handles; + + for (int i = 0; i < 32; i++) { + handles << manager.acquire(); + resources << manager.data(handles.at(i)); + } + + manager.release(handles.at(2)); + QVERIFY(manager.data(handles.at(2)) == nullptr); + // Triggers QASSERT so commented + // manager.release(handles.at(2)); + + tHandle nHandle = manager.acquire(); + QVERIFY(manager.data(nHandle) != nullptr); +} + +void tst_DynamicArrayPolicy::lookupResource() +{ + Qt3DCore::QResourceManager manager; + + QList resources; + QList handles; + + for (int i = 0; i < 5; i++) { + handles << manager.acquire(); + resources << manager.data(handles.at(i)); + resources.at(i)->m_value = 4; + } + + tHandle16 t = manager.lookupHandle(2); + QVERIFY(t.handle() == 0); + QVERIFY(manager.data(t) == nullptr); + tst_ArrayResource *resource = manager.getOrCreateResource(2); + QVERIFY(resource != nullptr); + t = manager.lookupHandle(2); + QVERIFY(manager.data(t) == manager.lookupResource(2)); + QVERIFY(t == manager.getOrAcquireHandle(2)); + QVERIFY(resource == manager.getOrCreateResource(2)); + QVERIFY(manager.data(t) == resource); +} + +void tst_DynamicArrayPolicy::releaseResource() +{ + Qt3DCore::QResourceManager manager; + QList resources; + + for (int i = 0; i < 5; i++) { + resources << manager.getOrCreateResource(i); + } + + for (int i = 0; i < 5; i++) { + QVERIFY(resources.at(i) == manager.lookupResource(i)); + } + + for (int i = 0; i < 5; i++) { + manager.releaseResource(i); + QVERIFY(manager.lookupResource(i) == nullptr); + } +} + +class tst_Thread : public QThread +{ + Q_OBJECT +public: + + typedef Qt3DCore::QResourceManager Manager; + + tst_Thread() + : QThread() + { + } + + void setManager(Manager *manager) + { + m_manager = manager; + } + + // QThread interface +protected: + void run() + { + int i = 0; + int max = tHandle::maxIndex(); + while (i < max) { + tst_ArrayResource *r = m_manager->getOrCreateResource(i); + i++; + QVERIFY(r != nullptr); + r->m_value.fetchAndAddOrdered(+1); + } + qDebug() << QThread::currentThread() << "Done"; + } + + Manager *m_manager; +}; + +void tst_DynamicArrayPolicy::heavyDutyMultiThreadedAccess() +{ + tst_Thread::Manager *manager = new tst_Thread::Manager(); + + QList threads; + + int iterations = 8; + int max = tHandle16::maxIndex(); + + for (int i = 0; i < iterations; i++) { + tst_Thread *thread = new tst_Thread(); + thread->setManager(manager); + threads << thread; + } + + for (int i = 0; i < iterations; i++) { + threads[i]->start(); + } + + for (int i = 0; i < iterations; i++) { + threads[i]->wait(); + } + + for (int i = 0; i < max; i++) { + QVERIFY(manager->lookupResource(i) != nullptr); + QVERIFY(manager->lookupResource(i)->m_value = iterations); + } + + qDeleteAll(threads); + delete manager; +} + +class tst_Thread2 : public QThread +{ + Q_OBJECT +public: + + typedef Qt3DCore::QResourceManager Manager; + + tst_Thread2(int releaseAbove = 7) + : QThread() + , m_releaseAbove(releaseAbove) + { + } + + void setManager(Manager *manager) + { + m_manager = manager; + } + + // QThread interface +protected: + void run() + { + int i = 0; + int max = tHandle::maxIndex(); + while (i < max) { + tst_ArrayResource *r = m_manager->getOrCreateResource(i); + QVERIFY(r != nullptr); + int oldValue = r->m_value.fetchAndAddOrdered(+1); + if (oldValue == m_releaseAbove) + m_manager->releaseResource(i); + i++; + } + qDebug() << QThread::currentThread() << "Done"; + } + + Manager *m_manager; + int m_releaseAbove; +}; + +void tst_DynamicArrayPolicy::heavyDutyMultiThreadedAccessRelease() +{ + tst_Thread2::Manager *manager = new tst_Thread2::Manager(); + + QList threads; + + int iterations = 8; + int max = tHandle16::maxIndex(); + + for (int u = 0; u < 2; u++) { + + for (int i = 0; i < iterations; i++) { + tst_Thread2 *thread = new tst_Thread2(); + thread->setManager(manager); + threads << thread; + } + + for (int i = 0; i < iterations; i++) { + threads[i]->start(); + } + + for (int i = 0; i < iterations; i++) { + threads[i]->wait(); + } + + for (int i = 0; i < max; i++) { + QVERIFY(manager->lookupResource(i) == nullptr); + } + + qDeleteAll(threads); + threads.clear(); + } + + delete manager; +} + +void tst_DynamicArrayPolicy::maximumNumberOfResources() +{ + Qt3DCore::QResourceManager manager; + + QList resources; + QList handles; + + QCOMPARE(tHandle16::maxIndex(), (uint)manager.maximumSize()); + + for (int i = 0; i < manager.maximumSize(); i++) { + handles << manager.acquire(); + resources << manager.data(handles.at(i)); + resources.at(i)->m_value = 4; + } +} + +void tst_DynamicArrayPolicy::activeHandles() +{ + // GIVEN + Qt3DCore::QResourceManager manager; + + { + // WHEN + const tHandle newHandle = manager.getOrAcquireHandle(883U); + // THEN + QCOMPARE(manager.activeHandles().size(), 1); + QCOMPARE(manager.activeHandles().first(), newHandle); + } + + { + // WHEN + manager.releaseResource(883U); + // THEN + QVERIFY(manager.activeHandles().empty()); + } + + { + // WHEN + const tHandle newHandle = manager.acquire(); + // THEN + QCOMPARE(manager.activeHandles().size(), 1); + QCOMPARE(manager.activeHandles().first(), newHandle); + + // WHEN + manager.release(newHandle); + // THEN + QVERIFY(manager.activeHandles().empty()); + } +} + + + + +QTEST_APPLESS_MAIN(tst_DynamicArrayPolicy) + +#include "tst_qresourcemanager.moc" -- cgit v1.2.3