File size: 5,583 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
 *   Copyright (c) 2023 David Carter <dcarter@david.carter.ca>             *
 *                                                                         *
 *   This file is part of FreeCAD.                                         *
 *                                                                         *
 *   FreeCAD is free software: you can redistribute it and/or modify it    *
 *   under the terms of the GNU Lesser General Public License as           *
 *   published by the Free Software Foundation, either version 2.1 of the  *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 *   FreeCAD is distributed in the hope that it will be useful, but        *
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
 *   Lesser General Public License for more details.                       *
 *                                                                         *
 *   You should have received a copy of the GNU Lesser General Public      *
 *   License along with FreeCAD. If not, see                               *
 *   <https://www.gnu.org/licenses/>.                                      *
 *                                                                         *
 **************************************************************************/

#include <gtest/gtest.h>

#include <QMetaType>
#include <QString>

#include <App/Application.h>
#include <Gui/MetaTypes.h>

#include <Mod/Material/App/MaterialManager.h>
#include <Mod/Material/App/Model.h>
#include <Mod/Material/App/ModelManager.h>
#include <Mod/Material/App/ModelUuids.h>

// clang-format off

class TestModelProperties : public ::testing::Test {
 protected:
  static void SetUpTestSuite() {
  }
};

TEST_F(TestModelProperties, TestEmpty)
{
    auto prop = Materials::ModelProperty();
    EXPECT_TRUE(prop.getName().isNull());
    EXPECT_TRUE(prop.getPropertyType().isNull());
    EXPECT_TRUE(prop.getUnits().isNull());
    EXPECT_TRUE(prop.getURL().isNull());
    EXPECT_TRUE(prop.getDescription().isNull());
    EXPECT_TRUE(prop.getInheritance().isNull());
    EXPECT_FALSE(prop.isInherited());
    EXPECT_EQ(prop.columns(), 0);
}

TEST_F(TestModelProperties, TestBasic)
{
    auto prop = Materials::ModelProperty(QStringLiteral("1"),
                           QStringLiteral("2"),
                           QStringLiteral("3"),
                           QStringLiteral("4"),
                           QStringLiteral("5"),
                           QStringLiteral("6"));
    EXPECT_EQ(prop.getName(), QStringLiteral("1"));
    EXPECT_EQ(prop.getDisplayName(), QStringLiteral("2"));
    EXPECT_EQ(prop.getPropertyType(), QStringLiteral("3"));
    EXPECT_EQ(prop.getUnits(), QStringLiteral("4"));
    EXPECT_EQ(prop.getURL(), QStringLiteral("5"));
    EXPECT_EQ(prop.getDescription(), QStringLiteral("6"));
    EXPECT_TRUE(prop.getInheritance().isNull());
    EXPECT_FALSE(prop.isInherited());
    EXPECT_EQ(prop.columns(), 0);

    prop.setInheritance(QStringLiteral("12345"));
    EXPECT_EQ(prop.getInheritance(), QStringLiteral("12345"));
    EXPECT_TRUE(prop.isInherited());
}

TEST_F(TestModelProperties, TestAddColumns)
{
    auto prop = Materials::ModelProperty(QStringLiteral("1"),
                           QStringLiteral("2"),
                           QStringLiteral("3"),
                           QStringLiteral("4"),
                           QStringLiteral("5"),
                           QStringLiteral("6"));
    auto prop1 = Materials::ModelProperty(QStringLiteral("10"),
                           QStringLiteral("9"),
                           QStringLiteral("8"),
                           QStringLiteral("7"),
                           QStringLiteral("6"),
                           QStringLiteral("5"));
    auto prop2 = Materials::ModelProperty(QStringLiteral("a"),
                           QStringLiteral("b"),
                           QStringLiteral("c"),
                           QStringLiteral("d"),
                           QStringLiteral("e"),
                           QStringLiteral("f"));

    EXPECT_EQ(prop.columns(), 0);
    prop.addColumn(prop1);
    EXPECT_EQ(prop.columns(), 1);
    prop.addColumn(prop2);
    EXPECT_EQ(prop.columns(), 2);

    auto columns = prop.getColumns();
    auto entry1 = columns.at(0);
    EXPECT_EQ(entry1.getName(), QStringLiteral("10"));
    EXPECT_EQ(entry1.getDisplayName(), QStringLiteral("9"));
    EXPECT_EQ(entry1.getPropertyType(), QStringLiteral("8"));
    EXPECT_EQ(entry1.getUnits(), QStringLiteral("7"));
    EXPECT_EQ(entry1.getURL(), QStringLiteral("6"));
    EXPECT_EQ(entry1.getDescription(), QStringLiteral("5"));
    EXPECT_TRUE(entry1.getInheritance().isNull());
    EXPECT_FALSE(entry1.isInherited());
    EXPECT_EQ(entry1.columns(), 0);

    auto entry2 = columns.at(1);
    EXPECT_EQ(entry2.getName(), QStringLiteral("a"));
    EXPECT_EQ(entry2.getDisplayName(), QStringLiteral("b"));
    EXPECT_EQ(entry2.getPropertyType(), QStringLiteral("c"));
    EXPECT_EQ(entry2.getUnits(), QStringLiteral("d"));
    EXPECT_EQ(entry2.getURL(), QStringLiteral("e"));
    EXPECT_EQ(entry2.getDescription(), QStringLiteral("f"));
    EXPECT_TRUE(entry2.getInheritance().isNull());
    EXPECT_FALSE(entry2.isInherited());
    EXPECT_EQ(entry2.columns(), 0);

}

// clang-format on