Merge pull request #10667 from chennes/toponamingHasherToDocument
App/Toponaming: Add StringHasher to Document
This commit is contained in:
@@ -4,6 +4,7 @@ target_sources(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Application.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Branding.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ComplexGeoData.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Document.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Expression.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ElementMap.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/IndexedName.cpp
|
||||
|
||||
101
tests/src/App/Document.cpp
Normal file
101
tests/src/App/Document.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "App/Application.h"
|
||||
#include "App/Document.h"
|
||||
#include "App/StringHasher.h"
|
||||
#include "Base/Writer.h"
|
||||
|
||||
using ::testing::Eq;
|
||||
using ::testing::Ne;
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers)
|
||||
|
||||
class FakeWriter: public Base::Writer
|
||||
{
|
||||
void writeFiles() override
|
||||
{}
|
||||
std::ostream& Stream() override
|
||||
{
|
||||
return std::cout;
|
||||
}
|
||||
};
|
||||
|
||||
class DocumentTest: public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
static void SetUpTestSuite()
|
||||
{
|
||||
if (App::Application::GetARGC() == 0) {
|
||||
constexpr int argc = 1;
|
||||
std::array<char*, argc> argv {"FreeCAD"};
|
||||
App::Application::Config()["ExeName"] = "FreeCAD";
|
||||
App::Application::init(argc, const_cast<char**>(argv.data())); // NOLINT
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
_docName = App::GetApplication().getUniqueDocumentName("test");
|
||||
_doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
App::GetApplication().closeDocument(_docName.c_str());
|
||||
}
|
||||
|
||||
App::Document* doc()
|
||||
{
|
||||
return _doc;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string _docName;
|
||||
App::Document* _doc {};
|
||||
};
|
||||
|
||||
|
||||
TEST_F(DocumentTest, addStringHasherIndicatesUnwrittenWhenNew)
|
||||
{
|
||||
// Arrange
|
||||
App::StringHasherRef hasher(new App::StringHasher);
|
||||
|
||||
// Act
|
||||
auto addResult = doc()->addStringHasher(hasher);
|
||||
|
||||
// Assert
|
||||
EXPECT_TRUE(addResult.first);
|
||||
EXPECT_THAT(addResult.second, Ne(-1));
|
||||
}
|
||||
|
||||
TEST_F(DocumentTest, addStringHasherIndicatesAlreadyWritten)
|
||||
{
|
||||
// Arrange
|
||||
App::StringHasherRef hasher(new App::StringHasher);
|
||||
doc()->addStringHasher(hasher);
|
||||
|
||||
// Act
|
||||
auto addResult = doc()->addStringHasher(hasher);
|
||||
|
||||
// Assert
|
||||
EXPECT_FALSE(addResult.first);
|
||||
}
|
||||
|
||||
TEST_F(DocumentTest, getStringHasherGivesExpectedHasher)
|
||||
{
|
||||
// Arrange
|
||||
App::StringHasherRef hasher(new App::StringHasher);
|
||||
auto pair = doc()->addStringHasher(hasher);
|
||||
int index = pair.second;
|
||||
|
||||
// Act
|
||||
auto foundHasher = doc()->getStringHasher(index);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(hasher, foundHasher);
|
||||
}
|
||||
|
||||
// NOLINTEND(readability-magic-numbers)
|
||||
Reference in New Issue
Block a user