diff --git a/src/io/policyfile.cpp b/src/io/policyfile.cpp index 38e8a1f..90c6b43 100644 --- a/src/io/policyfile.cpp +++ b/src/io/policyfile.cpp @@ -49,6 +49,11 @@ PolicyFile::PolicyFile() } +PolicyFile::~PolicyFile() +{ + delete d; +} + /*! * \brief PolicyFile::addPolicy Adds policy to the file. * \param policy Policy to add. @@ -64,11 +69,11 @@ void PolicyFile::addPolicy(std::shared_ptr policy) */ void PolicyFile::removePolicy(std::shared_ptr policy) { - std::remove_if(d->policies.begin(), d->policies.end(), - [policy](std::shared_ptr currentPolicy) - { - return currentPolicy == policy; - }); + d->policies.erase(std::remove_if(d->policies.begin(), d->policies.end(), + [policy](std::shared_ptr currentPolicy) + { + return currentPolicy == policy; + })); } /*! diff --git a/src/io/policyfile.h b/src/io/policyfile.h index 69a34ba..6c0ef2f 100644 --- a/src/io/policyfile.h +++ b/src/io/policyfile.h @@ -42,7 +42,7 @@ namespace io { public: PolicyFile(); - ~PolicyFile() = default; + ~PolicyFile(); void addPolicy(std::shared_ptr policy); @@ -59,7 +59,7 @@ namespace io { bool contains(const std::string& name); private: - std::unique_ptr d; + PolicyFilePrivate* const d; }; } diff --git a/tests/auto/CMakeLists.txt b/tests/auto/CMakeLists.txt index 7614253..73fd302 100644 --- a/tests/auto/CMakeLists.txt +++ b/tests/auto/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(gui) +add_subdirectory(io) diff --git a/tests/auto/io/CMakeLists.txt b/tests/auto/io/CMakeLists.txt new file mode 100644 index 0000000..3336c0c --- /dev/null +++ b/tests/auto/io/CMakeLists.txt @@ -0,0 +1,7 @@ +find_package(GPUI COMPONENTS io model REQUIRED) +include_directories(${GPUI_INCLUDE_DIRS}) + +find_package(Qt5 COMPONENTS Core Test REQUIRED) +set(QT_USE_QTTEST TRUE) + +add_subdirectory(policyfile) diff --git a/tests/auto/io/policyfile/CMakeLists.txt b/tests/auto/io/policyfile/CMakeLists.txt new file mode 100644 index 0000000..973378d --- /dev/null +++ b/tests/auto/io/policyfile/CMakeLists.txt @@ -0,0 +1,4 @@ +qt5_wrap_cpp(MOC_SOURCES policyfiletest.h) +add_executable(policyfiletest policyfiletest.cpp ${MOC_SOURCES}) +target_link_libraries(policyfiletest gpui-model gpui-io Qt5::Core Qt5::Test) +add_gpui_test(io.policyfiletest policyfiletest) diff --git a/tests/auto/io/policyfile/policyfiletest.cpp b/tests/auto/io/policyfile/policyfiletest.cpp new file mode 100644 index 0000000..5bb77dc --- /dev/null +++ b/tests/auto/io/policyfile/policyfiletest.cpp @@ -0,0 +1,80 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2021 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#include "policyfiletest.h" + +#include "../../../../src/io/policyfile.h" +#include "../../../../src/model/admx/policy.h" +#include "../../../../src/model/admx/policyelement.h" + +using namespace io; +using namespace model::admx; + +namespace tests { + +void PolciyFileTest::getPolicy() +{ + PolicyFile file; + + auto policyA = std::make_shared(); + auto policyB = std::make_shared(); + auto policyC = std::make_shared(); + + file.addPolicy(policyA); + file.addPolicy(policyB); + file.addPolicy(policyC); + + QVERIFY(file.getPolicy(0) == policyA); + QVERIFY(file.getPolicy(1) == policyB); + QVERIFY(file.getPolicy(2) == policyC); + + policyA->name = "policyA"; + policyB->name = "policyB"; + policyC->name = "policyC"; + + QVERIFY(file.getPolicy("policyC") == policyC); + QVERIFY(file.getPolicy("policyA") == policyA); + QVERIFY(file.getPolicy("policyB") == policyB); + QVERIFY(file.getPolicy("no-policy") == nullptr); +} + +void PolciyFileTest::contains() +{ + PolicyFile file; + + QVERIFY(file.policyCount() == 0); + + auto policy = std::make_shared(); + policy->name = "policy"; + + file.addPolicy(policy); + + QVERIFY(file.policyCount() == 1); + QVERIFY(file.contains("policy")); + + file.removePolicy(policy); + + QVERIFY(file.policyCount() == 0); + QVERIFY(file.contains("policy") == false); +} + +} + +QTEST_MAIN(tests::PolciyFileTest) diff --git a/tests/auto/io/policyfile/policyfiletest.h b/tests/auto/io/policyfile/policyfiletest.h new file mode 100644 index 0000000..0d0f199 --- /dev/null +++ b/tests/auto/io/policyfile/policyfiletest.h @@ -0,0 +1,37 @@ +/*********************************************************************************************************************** +** +** Copyright (C) 2021 BaseALT Ltd. +** +** This program is free software; you can redistribute it and/or +** modify it under the terms of the GNU General Public License +** as published by the Free Software Foundation; either version 2 +** of the License, or (at your option) any later version. +** +** This program 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 General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +** +***********************************************************************************************************************/ + +#ifndef GPUI_POLICYFILE_TEST_H +#define GPUI_POLICYFILE_TEST_H + +#include + +namespace tests { + class PolciyFileTest : public QObject + { + Q_OBJECT + + private slots: + void getPolicy(); + void contains(); + }; +} + +#endif // GPUI_POLICYFILE_TEST_H