FreeCAD

Форк
0
/
VarSet.cpp 
97 строк · 3.2 Кб
1
/****************************************************************************
2
 *   Copyright (c) 2024 Ondsel <development@ondsel.com>                     *
3
 *                                                                          *
4
 *   This file is part of the FreeCAD CAx development system.               *
5
 *                                                                          *
6
 *   This library is free software; you can redistribute it and/or          *
7
 *   modify it under the terms of the GNU Library General Public            *
8
 *   License as published by the Free Software Foundation; either           *
9
 *   version 2 of the License, or (at your option) any later version.       *
10
 *                                                                          *
11
 *   This library  is distributed in the hope that it will be useful,       *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
14
 *   GNU Library General Public License for more details.                   *
15
 *                                                                          *
16
 *   You should have received a copy of the GNU Library General Public      *
17
 *   License along with this library; see the file COPYING.LIB. If not,     *
18
 *   write to the Free Software Foundation, Inc., 59 Temple Place,          *
19
 *   Suite 330, Boston, MA  02111-1307, USA                                 *
20
 *                                                                          *
21
 ****************************************************************************/
22

23
#include "gtest/gtest.h"
24
#include "gmock/gmock.h"
25

26
#include <App/Application.h>
27
#include "App/Document.h"
28
#include <App/VarSet.h>
29
#include <src/App/InitApplication.h>
30

31
using ::testing::NotNull;
32

33
// NOLINTBEGIN(readability-magic-numbers)
34

35
class VarSet: public ::testing::Test
36
{
37
protected:
38
    static void SetUpTestSuite()
39
    {
40
        tests::initApplication();
41
    }
42

43
    void SetUp() override
44
    {
45
        _docName = App::GetApplication().getUniqueDocumentName("test");
46
        _doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
47
    }
48

49
    void TearDown() override
50
    {
51
        App::GetApplication().closeDocument(_docName.c_str());
52
    }
53

54
    App::Document* doc()
55
    {
56
        return _doc;
57
    }
58

59
private:
60
    std::string _docName;
61
    App::Document* _doc {};
62
};
63

64
// Tests whether we can create a VarSet
65
TEST_F(VarSet, createVarSet)
66
{
67
    // Arrange
68
    const char* nameVarSet = "VarSet";
69

70
    // Act
71
    doc()->addObject("App::VarSet", nameVarSet);
72
    auto varSet = dynamic_cast<App::VarSet*>(doc()->getObject(nameVarSet));
73

74
    // Assert
75
    EXPECT_THAT(varSet, NotNull());
76
}
77

78
// Tests whether we can add a property to a VarSet
79
TEST_F(VarSet, addProperty)
80
{
81
    // Arrange
82
    const char* nameVarSet = "VarSet001";
83
    const long VALUE = 123;
84

85
    doc()->addObject("App::VarSet", nameVarSet);
86
    auto varSet = dynamic_cast<App::VarSet*>(doc()->getObject(nameVarSet));
87

88
    // Act
89
    auto prop = dynamic_cast<App::PropertyInteger*>(
90
        varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables"));
91
    prop->setValue(VALUE);
92

93
    // Assert
94
    EXPECT_EQ(prop->getValue(), VALUE);
95
}
96

97
// NOLINTEND(readability-magic-numbers)
98

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

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

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

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