1
/****************************************************************************
2
* Copyright (c) 2024 Ondsel <development@ondsel.com> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
****************************************************************************/
23
#include "gtest/gtest.h"
24
#include "gmock/gmock.h"
26
#include <App/Application.h>
27
#include "App/Document.h"
28
#include <App/VarSet.h>
29
#include <src/App/InitApplication.h>
31
using ::testing::NotNull;
33
// NOLINTBEGIN(readability-magic-numbers)
35
class VarSet: public ::testing::Test
38
static void SetUpTestSuite()
40
tests::initApplication();
45
_docName = App::GetApplication().getUniqueDocumentName("test");
46
_doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
49
void TearDown() override
51
App::GetApplication().closeDocument(_docName.c_str());
61
App::Document* _doc {};
64
// Tests whether we can create a VarSet
65
TEST_F(VarSet, createVarSet)
68
const char* nameVarSet = "VarSet";
71
doc()->addObject("App::VarSet", nameVarSet);
72
auto varSet = dynamic_cast<App::VarSet*>(doc()->getObject(nameVarSet));
75
EXPECT_THAT(varSet, NotNull());
78
// Tests whether we can add a property to a VarSet
79
TEST_F(VarSet, addProperty)
82
const char* nameVarSet = "VarSet001";
83
const long VALUE = 123;
85
doc()->addObject("App::VarSet", nameVarSet);
86
auto varSet = dynamic_cast<App::VarSet*>(doc()->getObject(nameVarSet));
89
auto prop = dynamic_cast<App::PropertyInteger*>(
90
varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables"));
91
prop->setValue(VALUE);
94
EXPECT_EQ(prop->getValue(), VALUE);
97
// NOLINTEND(readability-magic-numbers)