diff --git a/data/tests/TestVRMLTextures.FCStd b/data/tests/TestVRMLTextures.FCStd new file mode 100644 index 0000000000..2c9e210d12 Binary files /dev/null and b/data/tests/TestVRMLTextures.FCStd differ diff --git a/tests/src/App/CMakeLists.txt b/tests/src/App/CMakeLists.txt index 0bc121285f..cdd545cadf 100644 --- a/tests/src/App/CMakeLists.txt +++ b/tests/src/App/CMakeLists.txt @@ -20,4 +20,5 @@ target_sources( ${CMAKE_CURRENT_SOURCE_DIR}/PropertyExpressionEngine.cpp ${CMAKE_CURRENT_SOURCE_DIR}/StringHasher.cpp ${CMAKE_CURRENT_SOURCE_DIR}/VarSet.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/VRMLObject.cpp ) diff --git a/tests/src/App/VRMLObject.cpp b/tests/src/App/VRMLObject.cpp new file mode 100644 index 0000000000..f6e2a6ef36 --- /dev/null +++ b/tests/src/App/VRMLObject.cpp @@ -0,0 +1,97 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later + +/*************************************************************************** + * Copyright (c) 2024 Werner Mayer * + * * + * 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 * + * . * + * * + **************************************************************************/ + +#include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include +#include +#include +#include +#include + +// NOLINTBEGIN + +class VRMLObjectTest: public ::testing::Test +{ +protected: + static void SetUpTestSuite() + { + tests::initApplication(); + } + + void SetUp() override + { + document = App::GetApplication().openDocument(fileName().c_str()); + } + + void TearDown() override + { + if (document) { + App::GetApplication().closeDocument(document->getName()); + } + } + + std::string fileName() const + { + std::string resDir(DATADIR); + resDir.append("/tests/TestVRMLTextures.FCStd"); + return resDir; + } + + App::Document* getDocument() const + { + return document; + } + +private: + App::Document* document {}; +}; + +TEST_F(VRMLObjectTest, loadVRMLWithTextures) +{ + App::Document* doc = getDocument(); + ASSERT_TRUE(doc); + + auto vrml = dynamic_cast(doc->getActiveObject()); + ASSERT_TRUE(vrml); + + auto res = vrml->Resources.getValues(); + EXPECT_EQ(res.size(), 6); + EXPECT_EQ(res[0], std::string("FreeCAD/FreeCAD1.png")); + EXPECT_EQ(res[1], std::string("FreeCAD/FreeCAD2.png")); + EXPECT_EQ(res[2], std::string("FreeCAD/FreeCAD3.png")); + EXPECT_EQ(res[3], std::string("FreeCAD/FreeCAD4.png")); + EXPECT_EQ(res[4], std::string("FreeCAD/FreeCAD5.png")); + EXPECT_EQ(res[5], std::string("FreeCAD/FreeCAD6.png")); + + auto url = vrml->Urls.getValues(); + EXPECT_EQ(url.size(), 6); + for (const auto& it : url) { + Base::FileInfo fi(it); + EXPECT_TRUE(fi.isFile()); + EXPECT_TRUE(fi.exists()); + } +} + +// NOLINTEND