File: Curves.cpp

package info (click to toggle)
darkradiant 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 41,080 kB
  • sloc: cpp: 264,743; ansic: 10,659; python: 1,852; xml: 1,650; sh: 92; makefile: 21
file content (83 lines) | stat: -rw-r--r-- 2,674 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "RadiantTest.h"

#include "ientity.h"
#include "iselection.h"
#include "imap.h"
#include "algorithm/Scene.h"
#include "algorithm/Selection.h"

namespace test
{

using CurveTest = RadiantTest;

inline Vector3 getFirstNurbsVertex(const scene::INodePtr& splineEntity)
{
    auto entity = Node_getEntity(splineEntity);
    auto fullValue = entity->getKeyValue("curve_Nurbs");

    Vector3 position;
    int vertexCount;
    std::string parenthesis;

    std::istringstream stream(fullValue);
    stream >> std::skipws;
    stream >> vertexCount;
    stream >> parenthesis;
    stream >> position.x() >> position.y() >> position.z();

    return position;
}

inline void performSelectionTestOnSplineEntity(const std::string& splineEntityName)
{
    auto splineEntity = algorithm::getEntityByName(GlobalMapModule().getRoot(), splineEntityName);
    auto firstNurbsVertex = getFirstNurbsVertex(splineEntity);

    EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0) << "Nothing should be selected at first";

    algorithm::performPointSelectionOnPosition(firstNurbsVertex, selection::SelectionSystem::eToggle);

    EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1) << "Curve " << splineEntityName << " should be selected";
    EXPECT_EQ(GlobalSelectionSystem().ultimateSelected(), splineEntity);
}

TEST_F(CurveTest, SplineWithoutChildBrushIsSelectable)
{
    loadMap("splines.map");
    performSelectionTestOnSplineEntity("spline_without_child_brush");
}

TEST_F(CurveTest, SplineWithChildBrushIsSelectable)
{
    loadMap("splines.map");
    performSelectionTestOnSplineEntity("spline_with_child_brush");
}

TEST_F(CurveTest, SplineWithoutModelKeyIsSelectable)
{
    loadMap("splines.map");
    performSelectionTestOnSplineEntity("spline_without_model");
}

TEST_F(CurveTest, CreateCatmullRomCurve)
{
    GlobalCommandSystem().executeCommand("CreateCurveCatmullRom");
    auto entity = Node_getEntity(GlobalSelectionSystem().ultimateSelected());

    EXPECT_EQ(entity->getKeyValue("classname"), "func_splinemover") << "wrong eclass";
    EXPECT_NE(entity->getKeyValue("curve_CatmullRomSpline"), "") << "catmull rom key is missing";
    EXPECT_EQ(entity->getKeyValue("model"), "") << "model spawnarg should be empty";
}

TEST_F(CurveTest, CreateNurbsCurve)
{
    GlobalCommandSystem().executeCommand("CreateCurveNURBS");
    auto entity = Node_getEntity(GlobalSelectionSystem().ultimateSelected());

    EXPECT_EQ(entity->getKeyValue("classname"), "func_splinemover") << "wrong eclass";
    EXPECT_NE(entity->getKeyValue("curve_Nurbs"), "") << "catmull rom key is missing";
    EXPECT_EQ(entity->getKeyValue("model"), "") << "model spawnarg should be empty";
}

}