FreeCAD

Форк
0
/
TestModel.cpp 
140 строк · 5.5 Кб
1
// SPDX-License-Identifier: LGPL-2.1-or-later
2
/***************************************************************************
3
 *   Copyright (c) 2023 David Carter <dcarter@david.carter.ca>             *
4
 *                                                                         *
5
 *   This file is part of FreeCAD.                                         *
6
 *                                                                         *
7
 *   FreeCAD is free software: you can redistribute it and/or modify it    *
8
 *   under the terms of the GNU Lesser General Public License as           *
9
 *   published by the Free Software Foundation, either version 2.1 of the  *
10
 *   License, or (at your option) any later version.                       *
11
 *                                                                         *
12
 *   FreeCAD is distributed in the hope that it will be useful, but        *
13
 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
14
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      *
15
 *   Lesser General Public License for more details.                       *
16
 *                                                                         *
17
 *   You should have received a copy of the GNU Lesser General Public      *
18
 *   License along with FreeCAD. If not, see                               *
19
 *   <https://www.gnu.org/licenses/>.                                      *
20
 *                                                                         *
21
 **************************************************************************/
22

23
#include <gtest/gtest.h>
24

25
#include <Mod/Material/App/PreCompiled.h>
26
#ifndef _PreComp_
27
#endif
28

29
#include <QString>
30

31
#include <App/Application.h>
32
#include <src/App/InitApplication.h>
33

34
#include <Mod/Material/App/MaterialManager.h>
35
#include <Mod/Material/App/Model.h>
36
#include <Mod/Material/App/ModelManager.h>
37

38
// clang-format off
39

40
class TestModel : public ::testing::Test {
41
 protected:
42
  static void SetUpTestSuite() {
43
    if (App::Application::GetARGC() == 0) {
44
        tests::initApplication();
45
    }
46
  }
47

48
  void SetUp() override {
49
    _modelManager = new Materials::ModelManager();
50
  }
51

52
  // void TearDown() override {}
53
  Materials::ModelManager* _modelManager;
54
};
55

56
TEST_F(TestModel, TestApplication)
57
{
58
    ASSERT_NO_THROW(App::GetApplication());
59
}
60

61
TEST_F(TestModel, TestResources)
62
{
63
    try {
64
        auto param = App::GetApplication().GetParameterGroupByPath(
65
            "User parameter:BaseApp/Preferences/Mod/Material/Resources");
66
        EXPECT_NE(param, nullptr);
67
    }
68
    catch (const std::exception &e)
69
    {
70
        FAIL() << "Exception: " << e.what() << "\n";
71
    }
72
}
73

74
TEST_F(TestModel, TestInstallation)
75
{
76
    ASSERT_NE(_modelManager, nullptr);
77

78
    // We should have loaded at least the system library
79
    auto libraries = _modelManager->getModelLibraries();
80
    ASSERT_GT(libraries->size(), 0);
81

82
    // We should have at least one model
83
    auto models = _modelManager->getModels();
84
    ASSERT_GT(models->size(), 0);
85
}
86

87
TEST_F(TestModel, TestModelLoad)
88
{
89
    ASSERT_NE(_modelManager, nullptr);
90

91
    auto density = _modelManager->getModel(QString::fromStdString("454661e5-265b-4320-8e6f-fcf6223ac3af"));
92
    EXPECT_EQ(density->getName(), QString::fromStdString("Density"));
93
    EXPECT_EQ(density->getUUID(), QString::fromStdString("454661e5-265b-4320-8e6f-fcf6223ac3af"));
94

95
    auto& prop = (*density)[QString::fromStdString("Density")];
96
    EXPECT_EQ(prop.getName(), QString::fromStdString("Density"));
97
}
98

99
TEST_F(TestModel, TestModelByPath)
100
{
101
    ASSERT_NE(_modelManager, nullptr);
102

103
    auto linearElastic = _modelManager->getModelByPath(
104
        QString::fromStdString("Mechanical/LinearElastic.yml"),
105
        QString::fromStdString("System"));
106
    EXPECT_NE(&linearElastic, nullptr);
107
    EXPECT_EQ(linearElastic->getName(), QString::fromStdString("Linear Elastic"));
108
    EXPECT_EQ(linearElastic->getUUID(), QString::fromStdString("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
109

110
    // The same but with a leading '/'
111
    auto linearElastic2 = _modelManager->getModelByPath(
112
        QString::fromStdString("/Mechanical/LinearElastic.yml"),
113
        QString::fromStdString("System"));
114
    EXPECT_NE(&linearElastic2, nullptr);
115
    EXPECT_EQ(linearElastic2->getName(), QString::fromStdString("Linear Elastic"));
116
    EXPECT_EQ(linearElastic2->getUUID(), QString::fromStdString("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
117

118
    // Same with the library name as a prefix
119
    auto linearElastic3 = _modelManager->getModelByPath(
120
        QString::fromStdString("/System/Mechanical/LinearElastic.yml"),
121
        QString::fromStdString("System"));
122
    EXPECT_NE(&linearElastic3, nullptr);
123
    EXPECT_EQ(linearElastic3->getName(), QString::fromStdString("Linear Elastic"));
124
    EXPECT_EQ(linearElastic3->getUUID(), QString::fromStdString("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
125

126
    // Test with the file system path
127
    ASSERT_NO_THROW(linearElastic->getLibrary());
128
    ASSERT_NO_THROW(linearElastic->getLibrary()->getName());
129
    ASSERT_NO_THROW(linearElastic->getLibrary()->getDirectoryPath());
130
    EXPECT_EQ(linearElastic->getLibrary()->getName(), QString::fromStdString("System"));
131
    QString path = linearElastic->getLibrary()->getDirectoryPath() + QString::fromStdString("/Mechanical/LinearElastic.yml");
132

133
    ASSERT_NO_THROW(_modelManager->getModelByPath(path));
134
    auto linearElastic4 = _modelManager->getModelByPath(path);
135
    EXPECT_NE(&linearElastic4, nullptr);
136
    EXPECT_EQ(linearElastic4->getName(), QString::fromStdString("Linear Elastic"));
137
    EXPECT_EQ(linearElastic4->getUUID(), QString::fromStdString("7b561d1d-fb9b-44f6-9da9-56a4f74d7536"));
138
}
139

140
// clang-format on
141

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.