// Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include #include #include #include #include #include #include "testarbiter.h" class tst_QEnvironmentLight: public QObject { Q_OBJECT private Q_SLOTS: void checkDefaultConstruction() { // GIVEN Qt3DRender::QEnvironmentLight light; // THEN QVERIFY(light.findChild()); QCOMPARE(light.irradiance(), nullptr); QCOMPARE(light.specular(), nullptr); } void shouldTakeOwnershipOfParentlessTextures() { // GIVEN Qt3DRender::QEnvironmentLight light; auto irradiance = new Qt3DRender::QTexture2D; auto specular = new Qt3DRender::QTexture2D; // WHEN light.setIrradiance(irradiance); light.setSpecular(specular); // THEN QCOMPARE(irradiance->parent(), &light); QCOMPARE(specular->parent(), &light); } void shouldNotChangeOwnershipOfParentedTextures() { // GIVEN Qt3DCore::QNode node; Qt3DRender::QEnvironmentLight light; auto irradiance = new Qt3DRender::QTexture2D(&node); auto specular = new Qt3DRender::QTexture2D(&node); // WHEN light.setIrradiance(irradiance); light.setSpecular(specular); // WHEN delete irradiance; delete specular; // THEN } void checkPropertyChanges() { // GIVEN Qt3DRender::QEnvironmentLight light; auto shaderData = light.findChild(); { auto texture = new Qt3DRender::QTexture2D(&light); QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); // WHEN light.setIrradiance(texture); // THEN QCOMPARE(light.irradiance(), texture); QCOMPARE(shaderData->property("irradiance").value(), texture); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN light.setIrradiance(texture); // THEN QCOMPARE(light.irradiance(), texture); QCOMPARE(shaderData->property("irradiance").value(), texture); QCOMPARE(spy.size(), 0); // WHEN light.setIrradiance(nullptr); // THEN QCOMPARE(light.irradiance(), nullptr); QCOMPARE(shaderData->property("irradiance").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); } { auto texture = new Qt3DRender::QTexture2D(&light); QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); // WHEN light.setIrradiance(texture); // THEN QCOMPARE(light.irradiance(), texture); QCOMPARE(shaderData->property("irradiance").value(), texture); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN delete texture; // THEN QCOMPARE(light.irradiance(), nullptr); QCOMPARE(shaderData->property("irradiance").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); } { auto texture = new Qt3DRender::QTexture2D; QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); // WHEN light.setIrradiance(texture); // THEN QCOMPARE(light.irradiance(), texture); QCOMPARE(shaderData->property("irradiance").value(), texture); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN delete texture; // THEN QCOMPARE(light.irradiance(), nullptr); QCOMPARE(shaderData->property("irradiance").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); } { auto texture = new Qt3DRender::QTexture2D(&light); QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::irradianceChanged); // WHEN light.setIrradiance(texture); // THEN QCOMPARE(light.irradiance(), texture); QCOMPARE(shaderData->property("irradiance").value(), texture); QCOMPARE(shaderData->property("irradianceSize").value(), QVector3D(texture->width(), texture->height(), texture->depth())); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN texture->setWidth(883); // THEN QCOMPARE(shaderData->property("irradianceSize").value(), QVector3D(883.0f, texture->height(), texture->depth())); // WHEN texture->setHeight(1340); // THEN QCOMPARE(shaderData->property("irradianceSize").value(), QVector3D(883.0f, 1340.0f, texture->depth())); // WHEN texture->setDepth(1584); // THEN QCOMPARE(shaderData->property("irradianceSize").value(), QVector3D(883.0f, 1340.0f, 1584.0f)); // WHEN delete texture; // THEN QCOMPARE(light.irradiance(), nullptr); QCOMPARE(shaderData->property("irradiance").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); // THEN QCOMPARE(shaderData->property("irradianceSize").value(), QVector3D()); } { auto texture = new Qt3DRender::QTexture2D(&light); QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); // WHEN light.setSpecular(texture); // THEN QCOMPARE(light.specular(), texture); QCOMPARE(shaderData->property("specular").value(), texture); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN light.setSpecular(texture); // THEN QCOMPARE(light.specular(), texture); QCOMPARE(shaderData->property("specular").value(), texture); QCOMPARE(spy.size(), 0); // WHEN light.setSpecular(nullptr); // THEN QCOMPARE(light.specular(), nullptr); QCOMPARE(shaderData->property("specular").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); } { auto texture = new Qt3DRender::QTexture2D(&light); QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); // WHEN light.setSpecular(texture); // THEN QCOMPARE(light.specular(), texture); QCOMPARE(shaderData->property("specular").value(), texture); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN delete texture; // THEN QCOMPARE(light.specular(), nullptr); QCOMPARE(shaderData->property("specular").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); } { auto texture = new Qt3DRender::QTexture2D; QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); // WHEN light.setSpecular(texture); // THEN QCOMPARE(light.specular(), texture); QCOMPARE(shaderData->property("specular").value(), texture); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN delete texture; // THEN QCOMPARE(light.specular(), nullptr); QCOMPARE(shaderData->property("specular").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); } { auto texture = new Qt3DRender::QTexture2D(&light); QSignalSpy spy(&light, &Qt3DRender::QEnvironmentLight::specularChanged); // WHEN light.setSpecular(texture); // THEN QCOMPARE(light.specular(), texture); QCOMPARE(shaderData->property("specular").value(), texture); QCOMPARE(shaderData->property("specularSize").value(), QVector3D(texture->width(), texture->height(), texture->depth())); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), texture); // WHEN texture->setWidth(883); // THEN QCOMPARE(shaderData->property("specularSize").value(), QVector3D(883.0f, texture->height(), texture->depth())); // WHEN texture->setHeight(1340); // THEN QCOMPARE(shaderData->property("specularSize").value(), QVector3D(883.0f, 1340.0f, texture->depth())); // WHEN texture->setDepth(1584); // THEN QCOMPARE(shaderData->property("specularSize").value(), QVector3D(883.0f, 1340.0f, 1584.0f)); // WHEN delete texture; // THEN QCOMPARE(light.specular(), nullptr); QCOMPARE(shaderData->property("specular").value(), nullptr); QCOMPARE(spy.size(), 1); QCOMPARE(spy.takeFirst().first().value(), nullptr); // THEN QCOMPARE(shaderData->property("specularSize").value(), QVector3D()); } } }; QTEST_MAIN(tst_QEnvironmentLight) #include "tst_qenvironmentlight.moc"