Moves model flags to ModelAbstract.
[0ad.git] / source / graphics / tests / test_Model.h
blob2a309dd870912387619d509d02e7b8c90b974d6d
1 /* Copyright (C) 2023 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "lib/self_test.h"
20 #include "graphics/Material.h"
21 #include "graphics/Model.h"
22 #include "graphics/ModelDef.h"
23 #include "graphics/ShaderDefines.h"
24 #include "ps/CStrInternStatic.h"
25 #include "scriptinterface/ScriptInterface.h"
26 #include "simulation2/Simulation2.h"
28 #include <memory>
30 class TestModel : public CxxTest::TestSuite
32 public:
33 bool HasShaderDefine(const CShaderDefines& defines, CStrIntern define)
35 const auto& map = defines.GetMap();
36 const auto it = map.find(define);
37 return it != map.end() && it->second == str_1;
40 bool HasMaterialDefine(CModel* model, CStrIntern define)
42 return HasShaderDefine(model->GetMaterial().GetShaderDefines(), define);
45 void test_model_with_flags()
47 CMaterial material{};
48 CSimulation2 simulation{nullptr, g_ScriptContext, nullptr};
50 // TODO: load a proper mock for modeldef.
51 CModelDefPtr modeldef = std::make_shared<CModelDef>();
53 std::unique_ptr<CModel> model = std::make_unique<CModel>(simulation, material, modeldef);
55 SPropPoint propPoint{};
56 model->AddProp(&propPoint, std::make_unique<CModel>(simulation, material, modeldef), nullptr);
58 model->AddFlagsRec(ModelFlag::IGNORE_LOS);
59 model->RemoveShadowsRec();
61 TS_ASSERT(HasMaterialDefine(model.get(), str_DISABLE_RECEIVE_SHADOWS));
62 TS_ASSERT(HasMaterialDefine(model.get(), str_IGNORE_LOS));
63 for (const CModel::Prop& prop : model->GetProps())
65 TS_ASSERT(prop.m_Model->ToCModel());
66 TS_ASSERT(HasMaterialDefine(prop.m_Model->ToCModel(), str_DISABLE_RECEIVE_SHADOWS));
67 TS_ASSERT(HasMaterialDefine(prop.m_Model->ToCModel(), str_IGNORE_LOS));
70 std::unique_ptr<CModelAbstract> clonedModel = model->Clone();
71 TS_ASSERT(clonedModel->ToCModel());
72 TS_ASSERT(HasMaterialDefine(clonedModel->ToCModel(), str_DISABLE_RECEIVE_SHADOWS));
73 TS_ASSERT(HasMaterialDefine(clonedModel->ToCModel(), str_IGNORE_LOS));
75 TS_ASSERT_EQUALS(model->GetProps().size(), clonedModel->ToCModel()->GetProps().size());
76 for (const CModel::Prop& prop : clonedModel->ToCModel()->GetProps())
78 TS_ASSERT(prop.m_Model->ToCModel());
79 TS_ASSERT(HasMaterialDefine(prop.m_Model->ToCModel(), str_DISABLE_RECEIVE_SHADOWS));
80 TS_ASSERT(HasMaterialDefine(prop.m_Model->ToCModel(), str_IGNORE_LOS));