53 lines
1.8 KiB
C++
53 lines
1.8 KiB
C++
#include <huestream/effect/base/LightSourceEffect.h>
|
|
#include <huestream/effect/animation/data/Playables/PlayableConstant.h>
|
|
#include "gtest/gtest.h"
|
|
#include "TestSerializeBase.h"
|
|
|
|
namespace huestream {
|
|
|
|
class TestLightSourceEffect : public testing::Test, public TestSerializeBase {
|
|
protected:
|
|
shared_ptr<LightSourceEffect> _effect;
|
|
LightPtr _lightInRadius;
|
|
LightPtr _lightOutRadius;
|
|
|
|
virtual void SetUp() {
|
|
_effect = make_shared<LightSourceEffect>("Lightsource", 4);
|
|
_effect->SetPositionAnimation(std::make_shared<PlayableConstant>(-1), std::make_shared<PlayableConstant>(1));
|
|
_effect->SetColorAnimation(std::make_shared<PlayableConstant>(0.1), std::make_shared<PlayableConstant>(0.2), std::make_shared<PlayableConstant>(0.3));
|
|
_effect->SetRadiusAnimation(std::make_shared<PlayableConstant>(0.5));
|
|
|
|
_lightInRadius = std::make_shared<Light>(1, Location(-0.9, 0.9));
|
|
_lightOutRadius = std::make_shared<Light>(2, Location(-0.1, 0.1));
|
|
}
|
|
|
|
virtual void TearDown() { }
|
|
|
|
void assert_colors_matching(shared_ptr<LightSourceEffect> effect)
|
|
{
|
|
auto inRadiusColor = effect->GetColor(_lightInRadius);
|
|
auto outRadiusColor = effect->GetColor(_lightOutRadius);
|
|
ASSERT_DOUBLE_EQ(inRadiusColor.GetR(), 0.1);
|
|
ASSERT_DOUBLE_EQ(inRadiusColor.GetG(), 0.2);
|
|
ASSERT_DOUBLE_EQ(inRadiusColor.GetB(), 0.3);
|
|
ASSERT_NEAR(inRadiusColor.GetAlpha(), 0.9, 0.05);
|
|
ASSERT_DOUBLE_EQ(outRadiusColor.GetAlpha(), 0);
|
|
}
|
|
};
|
|
|
|
TEST_F(TestLightSourceEffect, GetColor) {
|
|
assert_colors_matching(_effect);
|
|
}
|
|
|
|
TEST_F(TestLightSourceEffect, Serialize) {
|
|
JSONNode node;
|
|
_effect->Serialize(&node);
|
|
|
|
std::cout << node.write_formatted() << std::endl;
|
|
|
|
auto e = make_shared<LightSourceEffect>();
|
|
e->Deserialize(&node);
|
|
assert_colors_matching(e);
|
|
}
|
|
|
|
} // namespace huestream
|