Files
EVEngine/test/pcg_photo_mode_session.cpp

9 lines
2.7 KiB
C++

#include "zeroerr/unittest.h"
#include "ui/PcgPhotoModeSession.h"
using namespace eve::ui;
namespace { std::string profile(const char*scene,int64_t light,float fov){PcgPhotoModeValues v;v.setString("m_lastSceneName",scene).value();v.setBool("m_isUsingPcgLighting",light>=0).value();v.setInt("m_selectedPcgLightingProfile",light).value();v.setFloat("m_fieldOfView",fov).value();auto j=v.snapshotJson();j.value();return std::move(j).takeValue();} float fov(const std::string&j){PcgPhotoModeValues v;v.restoreJson(j).value();auto x=v.getFloat("m_fieldOfView");x.value();return std::move(x).takeValue();} }
TEST_CASE("ui.pcgPhotoModeSession.loadsOnlyCompatibleSavedValues") {auto current=profile("World",2,60);auto saved=profile("World",2,90);PcgPhotoModeSession s;REQUIRE(s.begin(current,saved,true,true,1,1,"World",2).ok());CHECK_EQ(s.getLoadDecision(),1);auto w=s.workingJson();REQUIRE(w.ok());CHECK_EQ(fov(w.value()),90.0f);REQUIRE(s.end(false,true).ok());CHECK(!s.getRestoreRequested());auto out=s.outputJson();REQUIRE(out.ok());CHECK_EQ(fov(out.value()),90.0f);CHECK(s.getRemovePhotoCameraRequested());CHECK(s.getUnfreezePlayerRequested());}
TEST_CASE("ui.pcgPhotoModeSession.matchesMismatchBranches") {auto current=profile("World",2,60);auto sceneMismatch=profile("Other",2,90);PcgPhotoModeSession a;REQUIRE(a.begin(current,sceneMismatch,true,true,1,1,"World",2).ok());CHECK_EQ(a.getLoadDecision(),2);REQUIRE(a.end(true,true).ok());CHECK(a.getRestoreRequested());auto restored=a.outputJson();REQUIRE(restored.ok());CHECK_EQ(fov(restored.value()),60.0f);PcgPhotoModeSession b;REQUIRE(b.begin(current,sceneMismatch,true,true,1,2,"World",2).ok());CHECK_EQ(b.getLoadDecision(),0);REQUIRE(b.end(true,false).ok());CHECK(!b.getRestoreRequested());}
TEST_CASE("ui.pcgPhotoModeSession.isAtomicAndSingleActive") {auto current=profile("World",2,60);PcgPhotoModeSession s;CHECK(!s.begin("bad","",false,false,0,0,"",0).ok());CHECK(!s.getActive());REQUIRE(s.begin(current,"",false,false,0,0,"World",2).ok());auto rev=s.getRevision();CHECK(!s.begin(current,"",false,false,0,0,"World",2).ok());CHECK_EQ(s.getRevision(),rev);CHECK(!s.replaceWorkingJson("bad").ok());auto w=s.workingJson();REQUIRE(w.ok());CHECK_EQ(fov(w.value()),60.0f);REQUIRE(s.replaceWorkingJson(profile("World",2,75)).ok());REQUIRE(s.end(true,true).ok());CHECK(!s.end(true,true).ok());}
TEST_CASE("ui.pcgPhotoModeSession.rejectsInconsistentPcgLightingIdentity") {auto current=profile("World",2,60);PcgPhotoModeValues saved;saved.restoreJson(profile("World",2,90)).value();saved.setBool("m_isUsingPcgLighting",false).value();auto json=saved.snapshotJson();REQUIRE(json.ok());PcgPhotoModeSession session;REQUIRE(session.begin(current,json.value(),true,true,1,1,"World",2).ok());CHECK_EQ(session.getLoadDecision(),2);}