-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parsing pid and pindex to group nodes
CURA-9755
- Loading branch information
Showing
6 changed files
with
3,880 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) 2022 Ultimaker B.V. | ||
// libSavitar is released under the terms of the LGPLv3 or higher. | ||
|
||
#include "Savitar/ThreeMFParser.h" | ||
#include "Savitar/Scene.h" | ||
#include "Savitar/SceneNode.h" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <array> | ||
#include <filesystem> | ||
#include <fstream> | ||
#include <iterator> | ||
#include <map> | ||
#include <string> | ||
|
||
namespace Savitar | ||
{ | ||
|
||
/* | ||
* Fixture that loads a testing XML model and gives an instance of the parser to | ||
* test with. | ||
*/ | ||
class ParserForPidTest : public testing::Test | ||
{ | ||
public: | ||
std::string xml_string; | ||
ThreeMFParser* parser; | ||
|
||
void SetUp() override | ||
{ | ||
xml_string = ""; | ||
std::ifstream test_model_file(std::filesystem::path(__FILE__).parent_path().append("parser_pid.xml").string()); | ||
if (test_model_file.is_open()) | ||
{ | ||
xml_string = std::string(std::istreambuf_iterator<char>{ test_model_file }, {}); | ||
} | ||
|
||
parser = new ThreeMFParser(); | ||
} | ||
|
||
void TearDown() override | ||
{ | ||
delete parser; | ||
} | ||
}; | ||
|
||
TEST_F(ParserForPidTest, parse) | ||
{ | ||
ASSERT_FALSE(xml_string.empty()); | ||
|
||
Scene scene; | ||
ASSERT_NO_THROW(scene = parser->parse(xml_string)); | ||
|
||
std::vector<SceneNode*> nodes = scene.getSceneNodes(); | ||
ASSERT_FALSE(nodes.empty()); | ||
ASSERT_EQ(nodes.size(), 20UL); | ||
|
||
std::array<std::string, 20> expected_pid = { "23", "23", "23", "23", "23", "23", "23", "23" ,"23", "23","", "", "", "", "", "", "", "" ,"", ""}; | ||
|
||
int i = -1; | ||
for (SceneNode* node : nodes) | ||
{ | ||
++i; | ||
MeshData& data = node->getMeshData(); | ||
const std::pair<std::string, std::string> pindex = node->getPidPindex(); | ||
std:: string pidval = pindex.first; | ||
EXPECT_EQ(pidval, expected_pid[i]); | ||
|
||
} | ||
// NOTE: To/from for content of vertices/triangles is tested in MeshDataTest. | ||
} | ||
|
||
TEST_F(ParserForPidTest, sceneToString) | ||
{ | ||
ASSERT_FALSE(xml_string.empty()); | ||
Scene scene = parser->parse(xml_string); | ||
|
||
const std::string scene_string = parser->sceneToString(scene); | ||
EXPECT_FALSE(scene_string.empty()); | ||
} | ||
|
||
} // namespace Savitar |
Oops, something went wrong.