All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -43,14 +43,14 @@ class ApplicationDirectoriesTestClass: public App::ApplicationDirectories
using App::ApplicationDirectories::ApplicationDirectories;
public:
void wrapAppendVersionIfPossible(const fs::path& basePath,
std::vector<std::string>& subdirs) const
void wrapAppendVersionIfPossible(const fs::path& basePath, std::vector<std::string>& subdirs) const
{
appendVersionIfPossible(basePath, subdirs);
}
std::tuple<int, int>
wrapExtractVersionFromConfigMap(const std::map<std::string, std::string>& config)
std::tuple<int, int> wrapExtractVersionFromConfigMap(
const std::map<std::string, std::string>& config
)
{
return extractVersionFromConfigMap(config);
}
@@ -69,14 +69,17 @@ protected:
_tempDir = MakeUniqueTempDir();
}
std::map<std::string, std::string>
generateConfig(const std::map<std::string, std::string>& overrides) const
std::map<std::string, std::string> generateConfig(
const std::map<std::string, std::string>& overrides
) const
{
std::map<std::string, std::string> config {{"AppHomePath", _tempDir.string()},
{"ExeVendor", "Vendor"},
{"ExeName", "Test"},
{"BuildVersionMajor", "4"},
{"BuildVersionMinor", "2"}};
std::map<std::string, std::string> config {
{"AppHomePath", _tempDir.string()},
{"ExeVendor", "Vendor"},
{"ExeName", "Test"},
{"BuildVersionMajor", "4"},
{"BuildVersionMinor", "2"}
};
for (const auto& override : overrides) {
config[override.first] = override.second;
}
@@ -85,8 +88,10 @@ protected:
std::unique_ptr<ApplicationDirectoriesTestClass> makeAppDirsForVersion(int major, int minor)
{
auto configuration = generateConfig({{"BuildVersionMajor", std::to_string(major)},
{"BuildVersionMinor", std::to_string(minor)}});
auto configuration = generateConfig(
{{"BuildVersionMajor", std::to_string(major)},
{"BuildVersionMinor", std::to_string(minor)}}
);
return std::make_unique<ApplicationDirectoriesTestClass>(configuration);
}
@@ -136,8 +141,10 @@ TEST_F(ApplicationDirectoriesTest, usingCurrentVersionConfigFalseWhenDirDoesntMa
/ App::ApplicationDirectories::versionStringForPath(major, minor);
// Act: generate a directory structure with the same version
auto configuration = generateConfig({{"BuildVersionMajor", std::to_string(major + 1)},
{"BuildVersionMinor", std::to_string(minor)}});
auto configuration = generateConfig(
{{"BuildVersionMajor", std::to_string(major + 1)},
{"BuildVersionMinor", std::to_string(minor)}}
);
auto appDirs = std::make_unique<App::ApplicationDirectories>(configuration);
// Assert
@@ -216,8 +223,10 @@ TEST_F(ApplicationDirectoriesTest, mostRecentAvailReturnsExactCurrentVersionIfDi
auto appDirs = makeAppDirsForVersion(5, 4);
fs::create_directories(versionedPath(tempDir(), 5, 4));
EXPECT_EQ(appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(5, 4));
EXPECT_EQ(
appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(5, 4)
);
}
// No exact match in the current major: choose the highest available minor <= current
@@ -229,8 +238,10 @@ TEST_F(ApplicationDirectoriesTest, mostRecentAvailPrefersSameMajorAndPicksHighes
fs::create_directories(versionedPath(tempDir(), 5, 3));
fs::create_directories(versionedPath(tempDir(), 4, 99)); // distractor in lower major
EXPECT_EQ(appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(5, 3));
EXPECT_EQ(
appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(5, 3)
);
}
// No directories in current major: scan next lower major from 99 downward,
@@ -241,8 +252,10 @@ TEST_F(ApplicationDirectoriesTest, mostRecentAvailForLowerMajorPicksHighestAvail
fs::create_directories(versionedPath(tempDir(), 4, 3));
fs::create_directories(versionedPath(tempDir(), 4, 42));
EXPECT_EQ(appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(4, 42));
EXPECT_EQ(
appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(4, 42)
);
}
// If the candidate path exists but is a regular file, it must be ignored and
@@ -253,8 +266,10 @@ TEST_F(ApplicationDirectoriesTest, mostRecentAvailSkipsFilesAndFallsBackToNextDi
touchFile(versionedPath(tempDir(), 5, 4)); // file at the current version
fs::create_directories(versionedPath(tempDir(), 5, 3)); // directory at next lower minor
EXPECT_EQ(appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(5, 3));
EXPECT_EQ(
appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(5, 3)
);
}
// Higher minor in the current major is not considered (loop starts at the current minor);
@@ -262,12 +277,13 @@ TEST_F(ApplicationDirectoriesTest, mostRecentAvailSkipsFilesAndFallsBackToNextDi
TEST_F(ApplicationDirectoriesTest, mostRecentAvailIgnoresHigherMinorThanCurrentInSameMajor)
{
auto appDirs = makeAppDirsForVersion(5, 4);
fs::create_directories(
versionedPath(tempDir(), 5, 7)); // higher than the current minor; ignored
fs::create_directories(versionedPath(tempDir(), 5, 7)); // higher than the current minor; ignored
fs::create_directories(versionedPath(tempDir(), 4, 1)); // fallback target
EXPECT_EQ(appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(4, 1));
EXPECT_EQ(
appDirs->mostRecentAvailableConfigVersion(tempDir()),
App::ApplicationDirectories::versionStringForPath(4, 1)
);
}
// No candidates anywhere -> empty string returned.
@@ -289,8 +305,7 @@ TEST_F(ApplicationDirectoriesTest, mostRecentConfigReturnsCurrentVersionDirector
}
// The current version missing -> falls back to most recent available in same major
TEST_F(ApplicationDirectoriesTest,
mostRecentConfigFallsBackToMostRecentInSameMajorWhenCurrentMissing)
TEST_F(ApplicationDirectoriesTest, mostRecentConfigFallsBackToMostRecentInSameMajorWhenCurrentMissing)
{
auto appDirs = makeAppDirsForVersion(5, 4);
// There is no directory called "5.4"; provide candidates 5.3 and 5.1; also a distractor in a
@@ -604,7 +619,8 @@ TEST_F(ApplicationDirectoriesTest, appendVecAlreadyVersionedBails)
fs::path base = tempDir() / "bail_vec";
std::vector<std::string> sub {
"configs",
App::ApplicationDirectories::versionStringForPath(5, 2)}; // versioned tail
App::ApplicationDirectories::versionStringForPath(5, 2)
}; // versioned tail
fs::create_directories(base / sub[0] / sub[1]);
auto before = sub;
@@ -704,8 +720,10 @@ TEST_F(ApplicationDirectoriesTest, extractVersionSucceedsWithPlainIntegers)
TEST_F(ApplicationDirectoriesTest, extractVersionSucceedsWithWhitespace)
{
auto appDirs = makeAppDirsForVersion(5, 4);
std::map<std::string, std::string> m {{"BuildVersionMajor", " 10 "},
{"BuildVersionMinor", "\t3\n"}};
std::map<std::string, std::string> m {
{"BuildVersionMajor", " 10 "},
{"BuildVersionMinor", "\t3\n"}
};
auto [maj, min] = appDirs->wrapExtractVersionFromConfigMap(m);
EXPECT_EQ(maj, 10);
EXPECT_EQ(min, 3);
@@ -739,8 +757,10 @@ TEST_F(ApplicationDirectoriesTest, extractVersionNonNumericThrowsRuntimeError)
TEST_F(ApplicationDirectoriesTest, extractVersionOverflowThrowsRuntimeError)
{
auto appDirs = makeAppDirsForVersion(5, 4);
std::map<std::string, std::string> m {{"BuildVersionMajor", "9999999999999999999999999"},
{"BuildVersionMinor", "1"}};
std::map<std::string, std::string> m {
{"BuildVersionMajor", "9999999999999999999999999"},
{"BuildVersionMinor", "1"}
};
EXPECT_THROW(appDirs->wrapExtractVersionFromConfigMap(m), Base::RuntimeError);
}

View File

@@ -35,14 +35,14 @@
#include <regex>
#include <string>
#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907L && defined(_LIBCPP_VERSION) \
#if defined(__cpp_lib_chrono) && __cpp_lib_chrono >= 201907L && defined(_LIBCPP_VERSION) \
&& _LIBCPP_VERSION >= 13000
// Apple's clang compiler did not support timezones fully until a quite recent version:
// before removing this preprocessor check, verify that it compiles on our oldest-supported
// macOS version.
#define CAN_USE_CHRONO_AND_FORMAT
#include <chrono>
#include <format>
# define CAN_USE_CHRONO_AND_FORMAT
# include <chrono>
# include <format>
#endif
@@ -56,8 +56,7 @@ protected:
void SetUp() override
{
_tempDir =
std::filesystem::temp_directory_path() / ("fc_backup_policy-" + randomString(16));
_tempDir = std::filesystem::temp_directory_path() / ("fc_backup_policy-" + randomString(16));
std::filesystem::create_directory(_tempDir);
}
@@ -105,9 +104,7 @@ protected:
std::string result;
result.reserve(length);
std::ranges::generate_n(std::back_inserter(result), length, [&]() {
return chars[dis(gen)];
});
std::ranges::generate_n(std::back_inserter(result), length, [&]() { return chars[dis(gen)]; });
return result;
}
@@ -115,18 +112,20 @@ protected:
std::string filenameFromDateFormatString(const std::string& fmt)
{
#if CAN_USE_CHRONO_AND_FORMAT
std::chrono::zoned_time local_time {std::chrono::current_zone(),
std::chrono::system_clock::now()};
std::chrono::zoned_time local_time {
std::chrono::current_zone(),
std::chrono::system_clock::now()
};
std::string fmt_str = "{:" + fmt + "}";
std::string result = std::vformat(fmt_str, std::make_format_args(local_time));
#else
std::time_t now = std::time(nullptr);
std::tm local_tm {};
#if defined(_WIN32)
# if defined(_WIN32)
localtime_s(&local_tm, &now); // Windows
#else
# else
localtime_r(&now, &local_tm); // POSIX
#endif
# endif
constexpr size_t bufferLength = 128;
std::array<char, bufferLength> buffer {};
size_t bytes = std::strftime(buffer.data(), bufferLength, fmt.c_str(), &local_tm);
@@ -411,11 +410,13 @@ TEST_F(BackupPolicyTest, DISABLED_TimestampWithAbsurdlyLongFormatStringThrows)
// OPERATIONS, AND GENERATES AN INVALID FILENAME. FIXME.
// Arrange
setPolicyTerms(App::BackupPolicy::Policy::TimeStamp,
1,
true,
"%A, %B %d, %Y at %H:%M:%S %Z (Day %j of the year, Week %U/%W) — This is a "
"verbose date string for demonstration purposes.");
setPolicyTerms(
App::BackupPolicy::Policy::TimeStamp,
1,
true,
"%A, %B %d, %Y at %H:%M:%S %Z (Day %j of the year, Week %U/%W) — This is a "
"verbose date string for demonstration purposes."
);
auto source = createTempFile("source.fcstd");
auto target = createTempFile("target.fcstd");
@@ -436,7 +437,8 @@ TEST_F(BackupPolicyTest, TimestampDetectsOldBackupFormat)
// Assert
bool check1 = std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak"));
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak")
);
bool check2 = std::filesystem::exists(backup);
EXPECT_NE(check1, check2);
}
@@ -455,7 +457,8 @@ TEST_F(BackupPolicyTest, TimestampDetectsOldBackupFormatIgnoresOther)
// Assert
bool check1 = std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak"));
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak")
);
bool check2 = std::filesystem::exists(backup);
EXPECT_NE(check1, check2);
EXPECT_TRUE(std::filesystem::exists(weird));
@@ -473,8 +476,11 @@ TEST_F(BackupPolicyTest, TimestampDetectsAndRetainsOldBackupWhenAllowed)
apply(source.string(), target.string());
// Assert
EXPECT_TRUE(std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak")));
EXPECT_TRUE(
std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak")
)
);
EXPECT_TRUE(std::filesystem::exists(backup));
}
@@ -489,8 +495,11 @@ TEST_F(BackupPolicyTest, TimestampFormatStringEndsWithSpace)
apply(source.string(), target.string());
// Assert (the space is stripped, and an index is added)
EXPECT_TRUE(std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "1.FCBak")));
EXPECT_TRUE(
std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "1.FCBak")
)
);
}
TEST_F(BackupPolicyTest, TimestampFormatStringEndsWithDash)
@@ -504,8 +513,11 @@ TEST_F(BackupPolicyTest, TimestampFormatStringEndsWithDash)
apply(source.string(), target.string());
// Assert (the dash is left, and an index is added)
EXPECT_TRUE(std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "-1.FCBak")));
EXPECT_TRUE(
std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "-1.FCBak")
)
);
}
TEST_F(BackupPolicyTest, TimestampFormatFileAlreadyExists)
@@ -521,8 +533,11 @@ TEST_F(BackupPolicyTest, TimestampFormatFileAlreadyExists)
// Assert (An index is appended)
EXPECT_TRUE(std::filesystem::exists(backup));
EXPECT_TRUE(std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "-1.FCBak")));
EXPECT_TRUE(
std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "-1.FCBak")
)
);
}
TEST_F(BackupPolicyTest, TimestampFormatFileAlreadyExistsMultipleTimes)
@@ -532,12 +547,9 @@ TEST_F(BackupPolicyTest, TimestampFormatFileAlreadyExistsMultipleTimes)
auto source = createTempFile("source.fcstd");
auto target = createTempFile("target.fcstd");
auto backup = createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + ".FCBak");
auto backup1 =
createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + "-1.FCBak");
auto backup2 =
createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + "-2.FCBak");
auto backup3 =
createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + "-3.FCBak");
auto backup1 = createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + "-1.FCBak");
auto backup2 = createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + "-2.FCBak");
auto backup3 = createTempFile("target." + filenameFromDateFormatString("%Y-%m-%d") + "-3.FCBak");
// Act
apply(source.string(), target.string());
@@ -547,6 +559,9 @@ TEST_F(BackupPolicyTest, TimestampFormatFileAlreadyExistsMultipleTimes)
EXPECT_TRUE(std::filesystem::exists(backup1));
EXPECT_TRUE(std::filesystem::exists(backup2));
EXPECT_TRUE(std::filesystem::exists(backup3));
EXPECT_TRUE(std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "-4.FCBak")));
EXPECT_TRUE(
std::filesystem::exists(
getTempPath() / ("target." + filenameFromDateFormatString("%Y-%m-%d") + "-4.FCBak")
)
);
}

View File

@@ -219,12 +219,16 @@ TEST_F(DISABLED_DocumentObserverTest, normalize)
// The subName is modified replacing "Part__Box" with "$Cube" to test the effect of using
// SubObjectT::NormalizeOption::KeepSubName, that is leaving the "$Cube" instead of replacing it
// with the name of the DocumentObject with that label ("Part__Box")
auto subObjTKeepSubName {SubObjectT(lGrp,
subName
.replace(strlen(partName) + strlen(fuseName) + 2,
strlen(boxName),
std::string("$").append(boxLabel).c_str())
.c_str())};
auto subObjTKeepSubName {SubObjectT(
lGrp,
subName
.replace(
strlen(partName) + strlen(fuseName) + 2,
strlen(boxName),
std::string("$").append(boxLabel).c_str()
)
.c_str()
)};
// An App::SubObjectT object used to test SubObjectT::normalize() with the option argument set
// to SubObjectT::NormalizeOption::ConvertIndex
// The subName is modified replacing "App_Part" with "0" to test the effect of using
@@ -255,8 +259,7 @@ TEST_F(DISABLED_DocumentObserverTest, normalize)
normalizeWithoutEl = subObjTWithoutEl.normalize(SubObjectT::NormalizeOption::NoElement);
normalizeNoFlatten = subObjTNoFlatten.normalize(SubObjectT::NormalizeOption::NoFlatten);
normalizeKeepSubName = subObjTKeepSubName.normalize(SubObjectT::NormalizeOption::KeepSubName);
normalizeConvertIndex =
subObjTConvertIndex.normalize(SubObjectT::NormalizeOption::ConvertIndex);
normalizeConvertIndex = subObjTConvertIndex.normalize(SubObjectT::NormalizeOption::ConvertIndex);
// Assert
@@ -441,14 +444,14 @@ TEST_F(DISABLED_DocumentObserverTest, normalized)
subObjTEmptyNormalized = subObjTEmpty.normalized();
subObjTWithoutSubObjNormalized = subObjTWithoutSubObj.normalized();
subObjTWithSubObjNormalized = subObjTWithSubObj.normalized();
subObjTWithoutElNormalized =
subObjTWithoutEl.normalized(SubObjectT::NormalizeOption::NoElement);
subObjTNoFlattenNormalized =
subObjTNoFlatten.normalized(SubObjectT::NormalizeOption::NoFlatten);
subObjTKeepSubNameNormalized =
subObjTKeepSubName.normalized(SubObjectT::NormalizeOption::KeepSubName);
subObjTConvertIndexNormalized =
subObjTConvertIndex.normalized(SubObjectT::NormalizeOption::ConvertIndex);
subObjTWithoutElNormalized = subObjTWithoutEl.normalized(SubObjectT::NormalizeOption::NoElement);
subObjTNoFlattenNormalized = subObjTNoFlatten.normalized(SubObjectT::NormalizeOption::NoFlatten);
subObjTKeepSubNameNormalized = subObjTKeepSubName.normalized(
SubObjectT::NormalizeOption::KeepSubName
);
subObjTConvertIndexNormalized = subObjTConvertIndex.normalized(
SubObjectT::NormalizeOption::ConvertIndex
);
// Assert

View File

@@ -149,8 +149,7 @@ TEST_F(ElementMapTest, setElementNameWithHashing)
const Data::MappedName expectedName(element);
// Act
elementMap
.encodeElementName(element.getType()[0], elementNameHolder, ss, nullptr, 0, nullptr, 0);
elementMap.encodeElementName(element.getType()[0], elementNameHolder, ss, nullptr, 0, nullptr, 0);
auto resultName = elementMap.setElementName(element, elementNameHolder, 0, _sids);
auto mappedToElement = elementMap.find(element);
@@ -378,25 +377,29 @@ TEST_F(ElementMapTest, mimicSimpleUnion)
// act: simulate a union/fuse operation
auto parent = cube.elementMapPtr->getAll()[5];
Data::MappedName postfixHolder(std::string(Data::POSTFIX_MOD) + "2");
unionPart.elementMapPtr->encodeElementName(postfixHolder[0],
postfixHolder,
ss,
nullptr,
unionPart.Tag,
nullptr,
unionPart.Tag);
unionPart.elementMapPtr->encodeElementName(
postfixHolder[0],
postfixHolder,
ss,
nullptr,
unionPart.Tag,
nullptr,
unionPart.Tag
);
auto postfixStr = postfixHolder.toString() + Data::ELEMENT_MAP_PREFIX + PartOp;
// act: with the fuse op, name against the cube's Face6
Data::MappedName uface3Holder(parent.index);
// we will invoke the encoder for face 3
unionPart.elementMapPtr->encodeElementName(uface3Holder[0],
uface3Holder,
ss,
nullptr,
unionPart.Tag,
postfixStr.c_str(),
cube.Tag);
unionPart.elementMapPtr->encodeElementName(
uface3Holder[0],
uface3Holder,
ss,
nullptr,
unionPart.Tag,
postfixStr.c_str(),
cube.Tag
);
unionPart.elementMapPtr->setElementName(uface3, uface3Holder, unionPart.Tag, nullptr, true);
// act: generate a full toponame string for testing purposes
@@ -443,22 +446,26 @@ TEST_F(ElementMapTest, mimicOperationAgainstSelf)
// Act
// act: with the mystery op, name against its own Face6 for some reason
Data::MappedName postfixHolder(workbenchId);
finalPart.elementMapPtr->encodeElementName(postfixHolder[0],
postfixHolder,
ss,
nullptr,
finalPart.Tag,
nullptr,
finalPart.Tag);
finalPart.elementMapPtr->encodeElementName(
postfixHolder[0],
postfixHolder,
ss,
nullptr,
finalPart.Tag,
nullptr,
finalPart.Tag
);
auto postfixStr = postfixHolder.toString() + Data::ELEMENT_MAP_PREFIX + PartOp;
// we will invoke the encoder for face 3
finalPart.elementMapPtr->encodeElementName(uface3Holder[0],
uface3Holder,
ss,
nullptr,
finalPart.Tag,
postfixStr.c_str(),
finalPart.Tag);
finalPart.elementMapPtr->encodeElementName(
uface3Holder[0],
uface3Holder,
ss,
nullptr,
finalPart.Tag,
postfixStr.c_str(),
finalPart.Tag
);
// override not forced
finalPart.elementMapPtr->setElementName(uface3, uface3Holder, finalPart.Tag, nullptr, false);
@@ -479,8 +486,8 @@ TEST_F(ElementMapTest, mimicOperationAgainstSelf)
TEST_F(ElementMapTest, hasChildElementMapTest)
{
// Arrange
Data::ElementMap::MappedChildElements child =
{Data::IndexedName("face", 1), 2, 7, 4L, Data::ElementMapPtr(), QByteArray(""), _sid};
Data::ElementMap::MappedChildElements child
= {Data::IndexedName("face", 1), 2, 7, 4L, Data::ElementMapPtr(), QByteArray(""), _sid};
std::vector<Data::ElementMap::MappedChildElements> children = {child};
LessComplexPart cubeFull(3L, "FullBox", _hasher);
cubeFull.elementMapPtr->addChildElements(cubeFull.Tag, children);
@@ -508,7 +515,8 @@ TEST_F(ElementMapTest, hashChildMapsTest)
3L,
Data::ElementMapPtr(),
QByteArray("abcdefghij"), // postfix must be 10 or more bytes to invoke hasher
_sid};
_sid
};
std::vector<Data::ElementMap::MappedChildElements> children = {childOne};
cube.elementMapPtr->addChildElements(cube.Tag, children);
auto before = _hasher->getIDMap();
@@ -533,9 +541,10 @@ TEST_F(ElementMapTest, addAndGetChildElementsTest)
3L,
Data::ElementMapPtr(),
QByteArray("abcdefghij"), // postfix must be 10 or more bytes to invoke hasher
_sid};
Data::ElementMap::MappedChildElements childTwo =
{Data::IndexedName("Pong", 2), 2, 7, 4L, Data::ElementMapPtr(), QByteArray("abc"), _sid};
_sid
};
Data::ElementMap::MappedChildElements childTwo
= {Data::IndexedName("Pong", 2), 2, 7, 4L, Data::ElementMapPtr(), QByteArray("abc"), _sid};
std::vector<Data::ElementMap::MappedChildElements> children = {childOne, childTwo};
// Act
@@ -544,13 +553,11 @@ TEST_F(ElementMapTest, addAndGetChildElementsTest)
// Assert
EXPECT_EQ(result.size(), 2);
EXPECT_TRUE(
std::any_of(result.begin(), result.end(), [](Data::ElementMap::MappedChildElements e) {
return e.indexedName.toString() == "Ping1";
}));
EXPECT_TRUE(
std::any_of(result.begin(), result.end(), [](Data::ElementMap::MappedChildElements e) {
return e.indexedName.toString() == "Pong2";
}));
EXPECT_TRUE(std::any_of(result.begin(), result.end(), [](Data::ElementMap::MappedChildElements e) {
return e.indexedName.toString() == "Ping1";
}));
EXPECT_TRUE(std::any_of(result.begin(), result.end(), [](Data::ElementMap::MappedChildElements e) {
return e.indexedName.toString() == "Pong2";
}));
}
// NOLINTEND(readability-magic-numbers)

View File

@@ -42,16 +42,20 @@ TEST_F(ElementNamingUtilsTest, findElementName)
// Act
Data::ElementMap elementMap = Data::ElementMap();
auto name1 = Data::findElementName("Edge1");
auto name2 = Data::findElementName(";g5v2;SKT;:Had6,V;:G;OFS;:Had6:7,V;:G;OFS;:Had6:7,V;WIR;:"
"Had6:4,V;:G;XTR;:Had6:7,E;:H,E.Face1.Edge2");
auto name2 = Data::findElementName(
";g5v2;SKT;:Had6,V;:G;OFS;:Had6:7,V;:G;OFS;:Had6:7,V;WIR;:"
"Had6:4,V;:G;XTR;:Had6:7,E;:H,E.Face1.Edge2"
);
auto name3 = Data::findElementName("An.Example.Assembly.Edge3");
auto name4 = Data::findElementName(".Edge4");
// Assert
EXPECT_STREQ(name1, "Edge1");
EXPECT_STREQ(name2,
";g5v2;SKT;:Had6,V;:G;OFS;:Had6:7,V;:G;OFS;:Had6:7,V;WIR;:"
"Had6:4,V;:G;XTR;:Had6:7,E;:H,E.Face1.Edge2");
EXPECT_STREQ(
name2,
";g5v2;SKT;:Had6,V;:G;OFS;:Had6:7,V;:G;OFS;:Had6:7,V;WIR;:"
"Had6:4,V;:G;XTR;:Had6:7,E;:H,E.Face1.Edge2"
);
EXPECT_STREQ(name3, "Edge3");
EXPECT_STREQ(name4, "Edge4");
}

View File

@@ -18,19 +18,23 @@ protected:
// Create and return a list of invalid IndexedNames
static std::vector<Data::IndexedName> givenInvalidIndexedNames()
{
return std::vector<Data::IndexedName> {Data::IndexedName(),
Data::IndexedName("", 1),
Data::IndexedName("INVALID42NAME", 1),
Data::IndexedName(".EDGE", 1)};
return std::vector<Data::IndexedName> {
Data::IndexedName(),
Data::IndexedName("", 1),
Data::IndexedName("INVALID42NAME", 1),
Data::IndexedName(".EDGE", 1)
};
}
// Create and return a list of valid IndexedNames
static std::vector<Data::IndexedName> givenValidIndexedNames()
{
return std::vector<Data::IndexedName> {Data::IndexedName("NAME"),
Data::IndexedName("NAME1"),
Data::IndexedName("NAME", 1),
Data::IndexedName("NAME_WITH_UNDERSCORES12345")};
return std::vector<Data::IndexedName> {
Data::IndexedName("NAME"),
Data::IndexedName("NAME1"),
Data::IndexedName("NAME", 1),
Data::IndexedName("NAME_WITH_UNDERSCORES12345")
};
}
// An arbitrary list of C strings used for testing some types of construction

View File

@@ -28,9 +28,11 @@ TEST(License, UnknownIdentifier)
TEST(License, direct)
{
int posn {App::findLicense("CC_BY_40")};
App::TLicenseArr tt {"CC_BY_40",
"Creative Commons Attribution 4.0",
"https://creativecommons.org/licenses/by/4.0/"};
App::TLicenseArr tt {
"CC_BY_40",
"Creative Commons Attribution 4.0",
"https://creativecommons.org/licenses/by/4.0/"
};
EXPECT_STREQ(App::licenseItems.at(posn).at(0), tt.at(0));
EXPECT_STREQ(App::licenseItems.at(posn).at(1), tt.at(1));
EXPECT_STREQ(App::licenseItems.at(posn).at(2), tt.at(2));

View File

@@ -259,9 +259,11 @@ TEST_F(MappedElementTest, comparatorThreeComplexHexNamesInMap)
// The expected order depends on your comparator logic.
// If you want to check the exact order, set it here:
// (Replace with the correct expected order if needed)
std::vector<std::string> expectedOrder = {"#19c9:e;:U;FUS;:Hce4:7,E",
"#1dadb:11;:L#1061a;FUS;:H:d,E",
"#1dae6:8;:L#1dae4;FUS;:H:d,E"};
std::vector<std::string> expectedOrder = {
"#19c9:e;:U;FUS;:Hce4:7,E",
"#1dadb:11;:L#1061a;FUS;:H:d,E",
"#1dae6:8;:L#1dae4;FUS;:H:d,E"
};
EXPECT_EQ(keys, expectedOrder);
}
@@ -311,7 +313,8 @@ TEST_F(MappedElementTest, comparatorLargerWorkedExampleWithMap)
"g4v2;SKT;:H1234,F;:H5678:2,E;:G0(g1;SKT;:H9012,E);XTR;:H3456:2,F",
"#1dad:e;:U;FUS;:Hce4:7,E",
"#1dadb:11;:L#1061a;FUS;:H:d,E",
"#1dae6:8;:L#1dae4;FUS;:H:d,E"};
"#1dae6:8;:L#1dae4;FUS;:H:d,E"
};
EXPECT_EQ(keys, expectedOrder);
}

View File

@@ -583,9 +583,11 @@ TEST(MappedName, appendToBufferWithPrefix)
mappedName2.appendToBufferWithPrefix(buffer);
// Assert
EXPECT_EQ(buffer,
std::string("STUFF") + elemMapPrefix + std::string("TESTPOSTFIXTEST")
+ /*missing prefix*/ std::string("TEST"));
EXPECT_EQ(
buffer,
std::string("STUFF") + elemMapPrefix + std::string("TESTPOSTFIXTEST")
+ /*missing prefix*/ std::string("TEST")
);
}
TEST(MappedName, toPrefixedString)
@@ -609,9 +611,11 @@ TEST(MappedName, toPrefixedString)
buffer += mappedName2.toPrefixedString();
// Assert
EXPECT_EQ(buffer,
std::string("STUFF") + elemMapPrefix + std::string("TESTPOSTFIXTEST")
+ /*missing prefix*/ std::string("TEST"));
EXPECT_EQ(
buffer,
std::string("STUFF") + elemMapPrefix + std::string("TESTPOSTFIXTEST")
+ /*missing prefix*/ std::string("TEST")
);
}
TEST(MappedName, toBytes)
@@ -849,8 +853,7 @@ TEST(MappedName, findTagInElementNameHexPositiveIndexNonrecursive)
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
int result = mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
@@ -872,8 +875,7 @@ TEST(MappedName, findTagInElementNameDecPositiveIndexNonrecursive)
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
int result = mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
@@ -895,8 +897,7 @@ TEST(MappedName, findTagInElementNameHexNegativeIndexNonrecursive)
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
int result = mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
@@ -918,8 +919,7 @@ TEST(MappedName, findTagInElementNameHexExpectedNegativeIndexNonrecursive)
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, true, false);
int result = mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, true, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
@@ -941,8 +941,7 @@ TEST(MappedName, findTagInElementNameRecursive)
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, true);
int result = mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, true);
// Assert
EXPECT_EQ(result, 36); // The location of the tag

View File

@@ -113,7 +113,8 @@ TEST_F(RenameProperty, renamePropertyPython)
{
// Act
Base::Interpreter().runString(
"App.ActiveDocument.getObject('VarSet').renameProperty('Variable', 'NewName')");
"App.ActiveDocument.getObject('VarSet').renameProperty('Variable', 'NewName')"
);
// Assert
EXPECT_STREQ(varSet->getPropertyName(prop), "NewName");
@@ -170,8 +171,10 @@ TEST_F(RenameProperty, renameStaticPropertyPython)
// Act / Assert
EXPECT_THROW(
Base::Interpreter().runString(
"App.ActiveDocument.getObject('VarSet006').renameProperty('Label', 'NewName')"),
Base::Exception);
"App.ActiveDocument.getObject('VarSet006').renameProperty('Label', 'NewName')"
),
Base::Exception
);
// Assert
EXPECT_STREQ(varSet->getPropertyName(prop), "Label");
@@ -198,8 +201,7 @@ TEST_F(RenameProperty, renameLockedProperty)
TEST_F(RenameProperty, renameToExistingProperty)
{
// Arrange
App::Property* prop2 =
varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables");
App::Property* prop2 = varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables");
// Act / Assert
EXPECT_THROW(varSet->renameDynamicProperty(prop2, "Variable"), Base::NameError);
@@ -230,7 +232,8 @@ TEST_F(RenameProperty, updateExpressionSameContainer)
{
// Arrange
const auto* prop2 = freecad_cast<App::PropertyInteger*>(
varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables"));
varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables")
);
App::ObjectIdentifier path(*prop2);
std::shared_ptr<App::Expression> expr(App::Expression::parse(varSet, "Variable"));
@@ -260,7 +263,8 @@ TEST_F(RenameProperty, updateExpressionDifferentContainer)
// Arrange
auto* varSet2 = freecad_cast<App::VarSet*>(_doc->addObject("App::VarSet", "VarSet2"));
const auto* prop2 = freecad_cast<App::PropertyInteger*>(
varSet2->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables"));
varSet2->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables")
);
App::ObjectIdentifier path(*prop2);
std::shared_ptr<App::Expression> expr(App::Expression::parse(varSet, "VarSet.Variable"));
@@ -296,7 +300,8 @@ TEST_F(RenameProperty, updateExpressionDifferentDocument)
auto* varSet2 = freecad_cast<App::VarSet*>(doc->addObject("App::VarSet", "VarSet2"));
const auto* prop2 = freecad_cast<App::PropertyInteger*>(
varSet2->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables"));
varSet2->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables")
);
App::ObjectIdentifier path(*prop2);
std::shared_ptr<App::Expression> expr(App::Expression::parse(varSet, "test#VarSet.Variable"));
@@ -330,7 +335,8 @@ TEST_F(RenameProperty, renamePropertyWithExpression)
{
// Arrange
auto* prop2 = freecad_cast<App::PropertyInteger*>(
varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables"));
varSet->addDynamicProperty("App::PropertyInteger", "Variable2", "Variables")
);
prop2->setValue(Value);
App::ObjectIdentifier path(*prop);

View File

@@ -46,7 +46,8 @@ protected:
{
varSet = freecad_cast<App::VarSet*>(_doc->addObject("App::VarSet", "VarSet"));
prop = freecad_cast<App::PropertyInteger*>(
varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables"));
varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables")
);
prop->setValue(Value);
}

View File

@@ -284,8 +284,8 @@ TEST_F(StringIDTest, fromStringWithEOFAndLengthGood) // NOLINT
const std::string testString {"#1:fcad"};
// Act
auto result =
App::StringID::fromString(testString.c_str(), true, static_cast<int>(testString.length()));
auto result
= App::StringID::fromString(testString.c_str(), true, static_cast<int>(testString.length()));
// Assert
EXPECT_EQ(result.id, 1);
@@ -298,10 +298,10 @@ TEST_F(StringIDTest, fromStringExtraData) // NOLINT
const std::string testString {"#1:fcad#2:bad"};
// Act
auto trueResult =
App::StringID::fromString(testString.c_str(), true, static_cast<int>(testString.length()));
auto falseResult =
App::StringID::fromString(testString.c_str(), false, static_cast<int>(testString.length()));
auto trueResult
= App::StringID::fromString(testString.c_str(), true, static_cast<int>(testString.length()));
auto falseResult
= App::StringID::fromString(testString.c_str(), false, static_cast<int>(testString.length()));
// Assert
EXPECT_EQ(trueResult.id, -1);
@@ -748,8 +748,8 @@ TEST_F(StringIDRefTest, swap) // NOLINT
}
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wself-assign-overloaded"
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wself-assign-overloaded"
#endif
TEST_F(StringIDRefTest, assignmentFromSelf) // NOLINT
@@ -765,7 +765,7 @@ TEST_F(StringIDRefTest, assignmentFromSelf) // NOLINT
}
#if defined(__clang__)
#pragma clang diagnostic pop
# pragma clang diagnostic pop
#endif
TEST_F(StringIDRefTest, assignmentToEmptyFromStringID) // NOLINT

View File

@@ -89,7 +89,8 @@ TEST_F(VarSet, addProperty)
// Act
auto prop = dynamic_cast<App::PropertyInteger*>(
varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables"));
varSet->addDynamicProperty("App::PropertyInteger", "Variable", "Variables")
);
prop->setValue(VALUE);
// Assert

View File

@@ -54,9 +54,10 @@ TEST(Base64, exactlyFourBytes)
std::string rest0_original = "abc";
// std::string rest0_reference = "YWJj";
std::string rest0_encoded =
base64_encode(reinterpret_cast<const unsigned char*>(rest0_original.c_str()),
rest0_original.length());
std::string rest0_encoded = base64_encode(
reinterpret_cast<const unsigned char*>(rest0_original.c_str()),
rest0_original.length()
);
std::string rest0_decoded = base64_decode(rest0_encoded);
ASSERT_EQ(rest0_decoded, rest0_original);
@@ -67,9 +68,10 @@ TEST(Base64, twoEqualsSignsPadding)
std::string rest1_original = "abcd";
// std::string rest1_reference = "YWJjZA==";
std::string rest1_encoded =
base64_encode(reinterpret_cast<const unsigned char*>(rest1_original.c_str()),
rest1_original.length());
std::string rest1_encoded = base64_encode(
reinterpret_cast<const unsigned char*>(rest1_original.c_str()),
rest1_original.length()
);
std::string rest1_decoded = base64_decode(rest1_encoded);
ASSERT_EQ(rest1_decoded, rest1_original);
@@ -80,9 +82,10 @@ TEST(Base64, oneEqualsSignPadding)
std::string rest2_original = "abcde";
// std::string rest2_reference = "YWJjZGU=";
std::string rest2_encoded =
base64_encode(reinterpret_cast<const unsigned char*>(rest2_original.c_str()),
rest2_original.length());
std::string rest2_encoded = base64_encode(
reinterpret_cast<const unsigned char*>(rest2_original.c_str()),
rest2_original.length()
);
std::string rest2_decoded = base64_decode(rest2_encoded);
ASSERT_EQ(rest2_decoded, rest2_original);

View File

@@ -1,10 +1,10 @@
#include <gtest/gtest.h>
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Windows.h>
# define WIN32_LEAN_AND_MEAN
# ifndef NOMINMAX
# define NOMINMAX
# endif
# include <Windows.h>
#endif
#include <Base/BoundBox.h>
#include <boost/beast/core/span.hpp>
@@ -95,9 +95,11 @@ TEST(BoundBox, TestEmptySpan)
TEST(BoundBox, TestNonEmptySpan)
{
std::vector<Base::Vector3d> points = {Base::Vector3d {1.0, 0.0, 0.0},
Base::Vector3d {0.0, 1.0, 0.0},
Base::Vector3d {0.0, 0.0, 1.0}};
std::vector<Base::Vector3d> points = {
Base::Vector3d {1.0, 0.0, 0.0},
Base::Vector3d {0.0, 1.0, 0.0},
Base::Vector3d {0.0, 0.0, 1.0}
};
Base::BoundBox3d box = createBox({points.data(), 2});
EXPECT_EQ(box.IsValid(), true);
EXPECT_EQ(box.MinX, 0);
@@ -110,9 +112,11 @@ TEST(BoundBox, TestNonEmptySpan)
TEST(BoundBox, TestArray)
{
std::vector<Base::Vector3d> points = {Base::Vector3d {1.0, 0.0, 0.0},
Base::Vector3d {0.0, 1.0, 0.0},
Base::Vector3d {0.0, 0.0, 1.0}};
std::vector<Base::Vector3d> points = {
Base::Vector3d {1.0, 0.0, 0.0},
Base::Vector3d {0.0, 1.0, 0.0},
Base::Vector3d {0.0, 0.0, 1.0}
};
Base::BoundBox3d box(points.data(), points.size());
EXPECT_EQ(box.IsValid(), true);
EXPECT_EQ(box.MinX, 0);

View File

@@ -5,8 +5,8 @@
#include <QString>
#ifdef _MSC_VER
#pragma warning(disable : 4996)
#pragma warning(disable : 4305)
# pragma warning(disable : 4996)
# pragma warning(disable : 4305)
#endif
#include "Base/Exception.h"
@@ -43,8 +43,7 @@ public:
ReaderXML()
{
_tempDir = fs::temp_directory_path();
fs::path filename =
std::string("unit_test_Reader-") + random_string(4) + std::string(".xml");
fs::path filename = std::string("unit_test_Reader-") + random_string(4) + std::string(".xml");
_tempFile = _tempDir / filename;
}
~ReaderXML()
@@ -64,8 +63,8 @@ public:
void givenDataAsXMLStream(const std::string& data)
{
auto stringData =
R"(<?xml version="1.0" encoding="UTF-8"?><document>)" + data + "</document>";
auto stringData = R"(<?xml version="1.0" encoding="UTF-8"?><document>)" + data
+ "</document>";
std::istringstream stream(stringData);
std::ofstream fileStream(_tempFile.string());
fileStream.write(stringData.data(), static_cast<std::streamsize>(stringData.length()));
@@ -366,8 +365,7 @@ TEST_F(ReaderTest, readNextStartEndElement)
// next element
EXPECT_TRUE(xml.Reader()->readNextElement());
EXPECT_STREQ(xml.Reader()->localName(), "node7");
EXPECT_EQ(xml.Reader()->getAttribute<std::string>("attr"),
std::string("const char* is faster :'("));
EXPECT_EQ(xml.Reader()->getAttribute<std::string>("attr"), std::string("const char* is faster :'("));
// next element
EXPECT_TRUE(xml.Reader()->readNextElement());
@@ -440,8 +438,7 @@ TEST_F(ReaderTest, validDefaults)
bool value14 = xml.Reader()->getAttribute<bool>("missing", 1);
bool value16 = xml.Reader()->getAttribute<bool>("missing", -10);
bool value18 = xml.Reader()->getAttribute<bool>("missing", 10);
TimesIGoToBed value20 =
xml.Reader()->getAttribute<TimesIGoToBed>("missing", TimesIGoToBed::Late);
TimesIGoToBed value20 = xml.Reader()->getAttribute<TimesIGoToBed>("missing", TimesIGoToBed::Late);
// Assert
EXPECT_THROW({ xml.Reader()->getAttribute<const char*>("missing"); }, Base::XMLBaseException);

View File

@@ -53,18 +53,19 @@ protected:
void TearDown() override
{}
static std::string
set(const std::string& schemaName, const Unit unit, const double value) // NOLINT
static std::string set(const std::string& schemaName, const Unit unit, const double value) // NOLINT
{
UnitsApi::setSchema(schemaName);
const auto quantity = Quantity {value, unit};
return quantity.getSafeUserString();
}
static std::string setWithPrecision(const std::string& name,
const double value,
const Unit unit,
const int precision)
static std::string setWithPrecision(
const std::string& name,
const double value,
const Unit unit,
const int precision
)
{
UnitsApi::setSchema(name);
Quantity quantity {value, unit};
@@ -74,10 +75,12 @@ protected:
return quantity.getSafeUserString();
}
static std::string setWithDenominator(const std::string& name,
const double value,
const Unit unit,
const int denominator)
static std::string setWithDenominator(
const std::string& name,
const double value,
const Unit unit,
const int denominator
)
{
UnitsApi::setSchema(name);
Quantity quantity {value, unit};
@@ -124,8 +127,8 @@ TEST_F(SchemaTest, meter_decimal_123456000_W_precision_6)
TEST_F(SchemaTest, meter_decimal_123456000_V_precision_6)
{
const std::string result =
setWithPrecision("MeterDecimal", 123456000.0, Unit::ElectricPotential, 6);
const std::string result
= setWithPrecision("MeterDecimal", 123456000.0, Unit::ElectricPotential, 6);
const auto expect {"123.456000 V"};
EXPECT_EQ(result, expect);

View File

@@ -3,7 +3,7 @@
#include <gtest/gtest.h>
#ifdef _MSC_VER
#pragma warning(disable : 4996)
# pragma warning(disable : 4996)
#endif
#include "Base/Stream.h"

View File

@@ -40,16 +40,20 @@ TEST(UnlimitedUnsigned, ToString)
TEST(UnlimitedUnsigned, TestSubtraction1)
{
// Check subtraction and comparison with byte-sized number
EXPECT_EQ(Base::UnlimitedUnsigned::fromString("6842357951")
- Base::UnlimitedUnsigned::fromString("6842357948"),
3);
EXPECT_EQ(
Base::UnlimitedUnsigned::fromString("6842357951")
- Base::UnlimitedUnsigned::fromString("6842357948"),
3
);
}
TEST(UnlimitedUnsigned, TestSubtraction2)
{
// Check subtraction and comparison
EXPECT_EQ(Base::UnlimitedUnsigned::fromString("6842357951")
- Base::UnlimitedUnsigned::fromString("6000000000"),
Base::UnlimitedUnsigned::fromString("842357951"));
EXPECT_EQ(
Base::UnlimitedUnsigned::fromString("6842357951")
- Base::UnlimitedUnsigned::fromString("6000000000"),
Base::UnlimitedUnsigned::fromString("842357951")
);
}
// NOLINTEND(cppcoreguidelines-*,readability-*)

View File

@@ -218,9 +218,11 @@ TEST(Vector, TestNormalize)
TEST(Vector, TestCSTransform)
{
Base::Vector3d vec(1, 2, 3);
vec.TransformToCoordinateSystem(Base::Vector3d(1, 1, 1),
Base::Vector3d(0, 1, 0),
Base::Vector3d(1, 0, 0));
vec.TransformToCoordinateSystem(
Base::Vector3d(1, 1, 1),
Base::Vector3d(0, 1, 0),
Base::Vector3d(1, 0, 0)
);
EXPECT_EQ(vec.x, 1);
EXPECT_EQ(vec.y, 0);
EXPECT_EQ(vec.z, -2);

View File

@@ -47,8 +47,10 @@ TEST_F(InputHintTest, LookupHintsSimpleState)
std::list<InputHint> hintsSeekFirst = {firstHint};
std::list<InputHint> hintsSeekSecond = {secondHint};
HintTable<State> table = {{.state = State::SeekFirst, .hints = hintsSeekFirst},
{.state = State::SeekSecond, .hints = hintsSeekSecond}};
HintTable<State> table = {
{.state = State::SeekFirst, .hints = hintsSeekFirst},
{.state = State::SeekSecond, .hints = hintsSeekSecond}
};
// Act
auto resultFirst = lookupHints(State::SeekFirst, table);
@@ -71,7 +73,8 @@ TEST_F(InputHintTest, LookupHintsPairState)
{.state = {State::SeekFirst, Method::FirstMethod}, .hints = firstFirstHints},
{.state = {State::SeekFirst, Method::SecondMethod}, .hints = firstSecondHints},
{.state = {State::SeekSecond, Method::FirstMethod}, .hints = secondFirstHints},
{.state = {State::SeekSecond, Method::SecondMethod}, .hints = secondSecondHints}};
{.state = {State::SeekSecond, Method::SecondMethod}, .hints = secondSecondHints}
};
// Act
auto resultFirstFirst = lookupHints({State::SeekFirst, Method::FirstMethod}, table);

View File

@@ -41,7 +41,8 @@ protected:
{"PrimaryColor", "#ff0000"},
{"SecondaryColor", "#00ff00"},
},
ParameterSource::Metadata {"Source 1"});
ParameterSource::Metadata {"Source 1"}
);
auto source2 = std::make_unique<InMemoryParameterSource>(
std::list<Parameter> {
@@ -49,7 +50,8 @@ protected:
{"Margin", "@BaseSize * 2"},
{"Padding", "@BaseSize / 2"},
},
ParameterSource::Metadata {"Source 2"});
ParameterSource::Metadata {"Source 2"}
);
manager.addSource(source1.get());
manager.addSource(source2.get());
@@ -160,7 +162,8 @@ TEST_F(ParameterManagerTest, SourcePriority)
std::list<Parameter> {
{"BaseSize", "24px"}, // Should override both previous sources
},
ParameterSource::Metadata {"Source 3"});
ParameterSource::Metadata {"Source 3"}
);
manager.addSource(source3.get());
sources.push_back(std::move(source3));
@@ -254,7 +257,8 @@ TEST_F(ParameterManagerTest, CircularReferenceDetection)
{"A", "@B"},
{"B", "@A"},
},
ParameterSource::Metadata {"Circular Source"});
ParameterSource::Metadata {"Circular Source"}
);
manager.addSource(circularSource.get());
sources.push_back(std::move(circularSource));
@@ -275,7 +279,8 @@ TEST_F(ParameterManagerTest, ComplexExpressions)
{"ComplexPadding", "(@BaseSize - 2px) / 2"},
{"ColorWithFunction", "lighten(@PrimaryColor, 20)"},
},
ParameterSource::Metadata {"Complex Source"});
ParameterSource::Metadata {"Complex Source"}
);
manager.addSource(complexSource.get());
sources.push_back(std::move(complexSource));
@@ -317,7 +322,8 @@ TEST_F(ParameterManagerTest, ErrorHandling)
std::list<Parameter> {
{"Invalid", "invalid expression that will fail"},
},
ParameterSource::Metadata {"Invalid Source"});
ParameterSource::Metadata {"Invalid Source"}
);
manager.addSource(invalidSource.get());
sources.push_back(std::move(invalidSource));

View File

@@ -42,7 +42,8 @@ protected:
{"TestColor", "#ff0000"},
{"TestNumber", "5"},
},
ParameterSource::Metadata {"Test Source"});
ParameterSource::Metadata {"Test Source"}
);
manager.addSource(source.get());
sources.push_back(std::move(source));
@@ -396,7 +397,8 @@ TEST_F(ParserTest, ParseErrors)
Parser parser("#invalid");
parser.parse();
},
Base::ParserError);
Base::ParserError
);
// Invalid RGB format
EXPECT_THROW(
@@ -404,7 +406,8 @@ TEST_F(ParserTest, ParseErrors)
Parser parser("rgb(invalid)");
parser.parse();
},
Base::ParserError);
Base::ParserError
);
// Missing closing parenthesis
EXPECT_THROW(
@@ -412,7 +415,8 @@ TEST_F(ParserTest, ParseErrors)
Parser parser("(10 + 5");
parser.parse();
},
Base::ParserError);
Base::ParserError
);
// Invalid function
EXPECT_THROW(
@@ -421,7 +425,8 @@ TEST_F(ParserTest, ParseErrors)
auto expr = parser.parse();
expr->evaluate({&manager, {}});
},
Base::ExpressionError);
Base::ExpressionError
);
// Division by zero
EXPECT_THROW(
@@ -430,7 +435,8 @@ TEST_F(ParserTest, ParseErrors)
auto expr = parser.parse();
expr->evaluate({&manager, {}});
},
Base::RuntimeError);
Base::RuntimeError
);
// Unit mismatch
EXPECT_THROW(
@@ -439,7 +445,8 @@ TEST_F(ParserTest, ParseErrors)
auto expr = parser.parse();
expr->evaluate({&manager, {}});
},
Base::RuntimeError);
Base::RuntimeError
);
// Unary operation on color
EXPECT_THROW(
@@ -448,7 +455,8 @@ TEST_F(ParserTest, ParseErrors)
auto expr = parser.parse();
expr->evaluate({&manager, {}});
},
Base::ExpressionError);
Base::ExpressionError
);
// Function with wrong number of arguments
EXPECT_THROW(
@@ -457,7 +465,8 @@ TEST_F(ParserTest, ParseErrors)
auto expr = parser.parse();
expr->evaluate({&manager, {}});
},
Base::ExpressionError);
Base::ExpressionError
);
// Function with wrong argument type
EXPECT_THROW(
@@ -466,7 +475,8 @@ TEST_F(ParserTest, ParseErrors)
auto expr = parser.parse();
expr->evaluate({&manager, {}});
},
Base::ExpressionError);
Base::ExpressionError
);
}
// Test whitespace handling
@@ -513,7 +523,8 @@ TEST_F(ParserTest, ParseEdgeCases)
Parser parser("");
parser.parse();
},
Base::ParserError);
Base::ParserError
);
// Just whitespace
EXPECT_THROW(
@@ -521,7 +532,8 @@ TEST_F(ParserTest, ParseEdgeCases)
Parser parser(" ");
parser.parse();
},
Base::ParserError);
Base::ParserError
);
// Single number
{

View File

@@ -53,7 +53,8 @@ protected:
{.name = "FontSize", .value = "12px"},
{.name = "BoxWidth", .value = "100px"},
},
{.name = "Fixture Source"}));
{.name = "Fixture Source"}
));
}
};

View File

@@ -44,25 +44,30 @@ protected:
void SetUp() override
{
// 2D Properties
modelProp = Materials::ModelProperty(QStringLiteral("Density"), // Name
QStringLiteral("D"), // Header
QStringLiteral("2DArray"), // Type
QStringLiteral(""), // Units
QStringLiteral(""), // URL
QStringLiteral("desc")); // Description
modelProp1 = Materials::ModelProperty(QStringLiteral("Temperature"),
QStringLiteral("T"),
QStringLiteral("Quantity"),
QStringLiteral("C"),
QStringLiteral(""),
QStringLiteral("desc1"));
modelProp2 =
Materials::ModelProperty(QStringLiteral("Density"),
QStringLiteral("D"),
QStringLiteral("Quantity"),
QStringLiteral("kg/m^3"),
QStringLiteral("https://en.wikipedia.org/wiki/Density"),
QStringLiteral("desc2"));
modelProp = Materials::ModelProperty(
QStringLiteral("Density"), // Name
QStringLiteral("D"), // Header
QStringLiteral("2DArray"), // Type
QStringLiteral(""), // Units
QStringLiteral(""), // URL
QStringLiteral("desc")
); // Description
modelProp1 = Materials::ModelProperty(
QStringLiteral("Temperature"),
QStringLiteral("T"),
QStringLiteral("Quantity"),
QStringLiteral("C"),
QStringLiteral(""),
QStringLiteral("desc1")
);
modelProp2 = Materials::ModelProperty(
QStringLiteral("Density"),
QStringLiteral("D"),
QStringLiteral("Quantity"),
QStringLiteral("kg/m^3"),
QStringLiteral("https://en.wikipedia.org/wiki/Density"),
QStringLiteral("desc2")
);
modelProp.addColumn(modelProp1);
modelProp.addColumn(modelProp2);
@@ -74,26 +79,35 @@ protected:
QStringLiteral("3DArray"), // Type
QStringLiteral(""), // Units
QStringLiteral(""), // URL
QStringLiteral("3 Dimensional array showing stress and strain as a function of "
"temperature")); // Description
model3DProp1 = Materials::ModelProperty(QStringLiteral("Temperature"),
QStringLiteral("T"),
QStringLiteral("Quantity"),
QStringLiteral("C"),
QStringLiteral(""),
QStringLiteral("desc1"));
model3DProp2 = Materials::ModelProperty(QStringLiteral("Stress"),
QStringLiteral("Stress"),
QStringLiteral("Quantity"),
QStringLiteral("MPa"),
QStringLiteral(""),
QStringLiteral("desc2"));
model3DProp3 = Materials::ModelProperty(QStringLiteral("Strain"),
QStringLiteral("Strain"),
QStringLiteral("Quantity"),
QStringLiteral("MPa"),
QStringLiteral(""),
QStringLiteral("desc3"));
QStringLiteral(
"3 Dimensional array showing stress and strain as a function of "
"temperature"
)
); // Description
model3DProp1 = Materials::ModelProperty(
QStringLiteral("Temperature"),
QStringLiteral("T"),
QStringLiteral("Quantity"),
QStringLiteral("C"),
QStringLiteral(""),
QStringLiteral("desc1")
);
model3DProp2 = Materials::ModelProperty(
QStringLiteral("Stress"),
QStringLiteral("Stress"),
QStringLiteral("Quantity"),
QStringLiteral("MPa"),
QStringLiteral(""),
QStringLiteral("desc2")
);
model3DProp3 = Materials::ModelProperty(
QStringLiteral("Strain"),
QStringLiteral("Strain"),
QStringLiteral("Quantity"),
QStringLiteral("MPa"),
QStringLiteral(""),
QStringLiteral("desc3")
);
model3DProp.addColumn(model3DProp1);
model3DProp.addColumn(model3DProp2);

View File

@@ -39,7 +39,7 @@
#include <Mod/Material/App/ModelUuids.h>
#ifdef _MSC_VER
#pragma warning(disable : 4834)
# pragma warning(disable : 4834)
#endif
// clang-format off

View File

@@ -67,8 +67,10 @@ TEST_F(KDTreeTest, TestKDTreeNearestMaxDist)
Base::Vector3f nor;
float dist;
EXPECT_EQ(tree.FindNearest(Base::Vector3f(0.9F, 0.1F, 0.1F), 0.0F, nor, dist),
MeshCore::POINT_INDEX_MAX);
EXPECT_EQ(
tree.FindNearest(Base::Vector3f(0.9F, 0.1F, 0.1F), 0.0F, nor, dist),
MeshCore::POINT_INDEX_MAX
);
}
TEST_F(KDTreeTest, TestKDTreeFindExact)

View File

@@ -324,35 +324,43 @@ TEST_F(AttacherTest, TestAllModesBoundaries)
_boxes[1]->MapMode.setValue(mmInertialCS);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mm1FaceNormal);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mmOZX);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mmOZY);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mmOXY);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mmOXZ);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mmOYZ);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
_boxes[1]->MapMode.setValue(mmOYX);
_boxes[1]->recomputeFeature();
EXPECT_TRUE(
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5)));
boxesMatch(_boxes[1]->Shape.getBoundingBox(), Base::BoundBox3d(0.5, 1, 1.5, 3.5, 2, 3.5))
);
}

View File

@@ -22,9 +22,11 @@ protected:
_boxes[0]->Width.setValue(width);
_boxes[0]->Height.setValue(height);
_boxes[0]->Placement.setValue(
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d()));
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())
);
_boxes[1]->Placement.setValue(
Base::Placement(Base::Vector3d(0, 1, height), Base::Rotation(), Base::Vector3d()));
Base::Placement(Base::Vector3d(0, 1, height), Base::Rotation(), Base::Vector3d())
);
_boxes[1]->Length.setValue(1);
_boxes[1]->Width.setValue(2);
_boxes[1]->Height.setValue(3);
@@ -55,8 +57,8 @@ protected:
TEST_F(FeatureChamferTest, testOther)
{
const double baseVolume =
_boxes[0]->Length.getValue() * _boxes[0]->Width.getValue() * _boxes[0]->Height.getValue()
const double baseVolume = _boxes[0]->Length.getValue() * _boxes[0]->Width.getValue()
* _boxes[0]->Height.getValue()
+ _boxes[1]->Length.getValue() * _boxes[1]->Width.getValue() * _boxes[1]->Height.getValue();
// Arrange
_chamfer->Base.setValue(_fused);
@@ -93,11 +95,14 @@ TEST_F(FeatureChamferTest, testMost)
_fused->Refine.setValue(true);
_fused->execute();
_chamfer->Base.setValue(_fused);
_chamfer->Edges.setValues(PartTestHelpers::_getFilletEdges(
{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // NOLINT magic number
15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // NOLINT magic number
0.4, // NOLINT magic number
0.4)); // NOLINT magic number
_chamfer->Edges.setValues(
PartTestHelpers::_getFilletEdges(
{3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // NOLINT magic number
15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, // NOLINT magic number
0.4, // NOLINT magic number
0.4
)
); // NOLINT magic number
// Act
_chamfer->execute();
double chamferVolume = PartTestHelpers::getVolume(_chamfer->Shape.getValue());

View File

@@ -165,8 +165,7 @@ TEST_F(FeatureExtrusionTest, testExecuteSymmetric)
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, len * wid * ext1);
EXPECT_TRUE(
PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext1 / 2, len, wid, ext1 / 2)));
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, -ext1 / 2, len, wid, ext1 / 2)));
}
TEST_F(FeatureExtrusionTest, testExecuteAngled)
@@ -182,8 +181,7 @@ TEST_F(FeatureExtrusionTest, testExecuteAngled)
const double centerWidth = longerSide - shorterSide; // Width of the triang prism.
const double topHeight = shorterSide / tangent / 2; // Height of the truncation
const double fullHeight = ext1 + topHeight;
const double fullPrismVol =
fullHeight * (shorterSide + ext1 * tangent * 2.0) / 2.0 * centerWidth;
const double fullPrismVol = fullHeight * (shorterSide + ext1 * tangent * 2.0) / 2.0 * centerWidth;
const double fullPyrVol = pow(shorterSide + ext1 * tangent * 2.0, 2.0) / 3.0 * fullHeight;
const double topPrismVol = topHeight * shorterSide / 2.0 * centerWidth;
const double topPyrVol = pow(shorterSide, 2.0) / 3.0 * topHeight;
@@ -197,13 +195,12 @@ TEST_F(FeatureExtrusionTest, testExecuteAngled)
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, targetVol);
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb,
Base::BoundBox3d(-ext1 * tangent,
-ext1 * tangent,
0,
len + ext1 * tangent,
wid + ext1 * tangent,
ext1)));
EXPECT_TRUE(
PartTestHelpers::boxesMatch(
bb,
Base::BoundBox3d(-ext1 * tangent, -ext1 * tangent, 0, len + ext1 * tangent, wid + ext1 * tangent, ext1)
)
);
}
TEST_F(FeatureExtrusionTest, testExecuteAngledRev)
@@ -219,13 +216,13 @@ TEST_F(FeatureExtrusionTest, testExecuteAngledRev)
const double centerWidth = longerSide - shorterSide; // Width of the triang prism.
const double topHeight = shorterSide / tangent / 2; // Height of the truncation
const double fullHeight = ext1 / 2 + topHeight;
const double fullPrismVol =
fullHeight * (shorterSide + ext1 / 2 * tangent * 2.0) / 2.0 * centerWidth;
const double fullPrismVol = fullHeight * (shorterSide + ext1 / 2 * tangent * 2.0) / 2.0
* centerWidth;
const double fullPyrVol = pow(shorterSide + ext1 / 2 * tangent * 2.0, 2.0) / 3.0 * fullHeight;
const double topPrismVol = topHeight * shorterSide / 2.0 * centerWidth;
const double topPyrVol = pow(shorterSide, 2.0) / 3.0 * topHeight;
const double targetVol =
(fullPyrVol + fullPrismVol) - (topPyrVol + topPrismVol) + len * wid * ext1 / 2;
const double targetVol = (fullPyrVol + fullPrismVol) - (topPyrVol + topPrismVol)
+ len * wid * ext1 / 2;
_extrusion->Solid.setValue(true);
_extrusion->Symmetric.setValue(true);
@@ -237,13 +234,19 @@ TEST_F(FeatureExtrusionTest, testExecuteAngledRev)
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, targetVol);
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb,
Base::BoundBox3d(-ext1 * tangent / 2,
-ext1 * tangent / 2,
-ext1 / 2,
len + ext1 * tangent / 2,
wid + ext1 * tangent / 2,
ext1 / 2)));
EXPECT_TRUE(
PartTestHelpers::boxesMatch(
bb,
Base::BoundBox3d(
-ext1 * tangent / 2,
-ext1 * tangent / 2,
-ext1 / 2,
len + ext1 * tangent / 2,
wid + ext1 * tangent / 2,
ext1 / 2
)
)
);
}
TEST_F(FeatureExtrusionTest, testExecuteEdge)
@@ -263,9 +266,12 @@ TEST_F(FeatureExtrusionTest, testExecuteEdge)
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, len * wid * ext1 * tangent);
EXPECT_TRUE(PartTestHelpers::boxesMatch(
bb,
Base::BoundBox3d(0, 0, 0, len + ext1 * tangent, wid + ext1 * tangent, ext1 * tangent)));
EXPECT_TRUE(
PartTestHelpers::boxesMatch(
bb,
Base::BoundBox3d(0, 0, 0, len + ext1 * tangent, wid + ext1 * tangent, ext1 * tangent)
)
);
}
TEST_F(FeatureExtrusionTest, testExecuteDir)
@@ -281,9 +287,9 @@ TEST_F(FeatureExtrusionTest, testExecuteDir)
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, len * wid * ext1 * sin45);
EXPECT_TRUE(PartTestHelpers::boxesMatch(
bb,
Base::BoundBox3d(0, 0, 0, len, wid + ext1 * sin45, ext1 * sin45)));
EXPECT_TRUE(
PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid + ext1 * sin45, ext1 * sin45))
);
}
TEST_F(FeatureExtrusionTest, testExecuteFaceMaker)
@@ -322,8 +328,6 @@ TEST_F(FeatureExtrusionTest, testFaceWithHoles)
// Assert
EXPECT_FLOAT_EQ(volume, len * wid * ext1 - radius * radius * std::numbers::pi * ext1);
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1)));
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face1),
len * wid + radius * radius * std::numbers::pi);
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face2),
len * wid - radius * radius * std::numbers::pi);
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face1), len * wid + radius * radius * std::numbers::pi);
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face2), len * wid - radius * radius * std::numbers::pi);
}

View File

@@ -22,9 +22,11 @@ protected:
_boxes[0]->Width.setValue(5);
_boxes[0]->Height.setValue(6);
_boxes[0]->Placement.setValue(
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d()));
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())
);
_boxes[1]->Placement.setValue(
Base::Placement(Base::Vector3d(0, 1, 6), Base::Rotation(), Base::Vector3d()));
Base::Placement(Base::Vector3d(0, 1, 6), Base::Rotation(), Base::Vector3d())
);
_boxes[1]->Length.setValue(1);
_boxes[1]->Width.setValue(2);
_boxes[1]->Height.setValue(3);
@@ -49,8 +51,8 @@ protected:
TEST_F(FeatureFilletTest, testOtherEdges)
{
const double baseVolume =
_boxes[0]->Length.getValue() * _boxes[0]->Width.getValue() * _boxes[0]->Height.getValue()
const double baseVolume = _boxes[0]->Length.getValue() * _boxes[0]->Width.getValue()
* _boxes[0]->Height.getValue()
+ _boxes[1]->Length.getValue() * _boxes[1]->Width.getValue() * _boxes[1]->Height.getValue();
// Arrange
_fillet->Base.setValue(_fused);
@@ -86,10 +88,13 @@ TEST_F(FeatureFilletTest, testMostEdges)
_fused->Refine.setValue(true);
// _fused->execute();
_fillet->Base.setValue(_fused);
_fillet->Edges.setValues(PartTestHelpers::_getFilletEdges(
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 23, 24},
0.4,
0.4));
_fillet->Edges.setValues(
PartTestHelpers::_getFilletEdges(
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, 22, 23, 24},
0.4,
0.4
)
);
// Act
_fillet->execute();
double filletVolume = PartTestHelpers::getVolume(_fillet->Shape.getValue());

View File

@@ -54,7 +54,8 @@ TEST_F(FeatureMirroringTest, testXMirror)
"Vertex1;:M;MIR;:H70c:7,V", "Vertex2;:M;MIR;:H70c:7,V", "Vertex3;:M;MIR;:H70c:7,V",
"Vertex4;:M;MIR;:H70c:7,V", "Vertex5;:M;MIR;:H70c:7,V", "Vertex6;:M;MIR;:H70c:7,V",
"Vertex7;:M;MIR;:H70c:7,V", "Vertex8;:M;MIR;:H70c:7,V",
}));
}
));
}
TEST_F(FeatureMirroringTest, testYMirrorWithExistingElementMap)
@@ -77,67 +78,69 @@ TEST_F(FeatureMirroringTest, testYMirrorWithExistingElementMap)
// Mirrored it around X from 0,0,0 -> 1,2,3 to 0,0,-3 -> 1,2,0
EXPECT_TRUE(boxesMatch(bb, Base::BoundBox3d(0, 0, -3, 1, 3, 0)));
// Assert correct element Map
EXPECT_TRUE(elementsMatch(_mirror->Shape.getShape(),
{
"Edge10;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge10;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge11;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge11;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge12;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge12;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge1;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge1;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge2;:M2(Edge2;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge2;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge2;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge3;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge3;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge4;:M2(Edge4;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge4;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge4;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge5;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge5;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge6;:M2(Edge6;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge6;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge6;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge7;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge7;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge8;:M2(Edge8;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge8;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge8;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge9;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge9;:H11c4,E;:M;MIR;:H11ca:7,E",
"Face1;:M2(Face1;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face1;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face1;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Face2;:M2(Face2;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face2;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face2;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Face3;:H11c3,F;:M;MIR;:H11ca:7,F",
"Face4;:H11c4,F;:M;MIR;:H11ca:7,F",
"Face5;:M2(Face5;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face5;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face5;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Face6;:M2(Face6;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face6;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face6;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Vertex1;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex1;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex2;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex2;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex3;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex3;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex4;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex4;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex5;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex5;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex6;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex6;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex7;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex7;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex8;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex8;:H11c4,V;:M;MIR;:H11ca:7,V",
}));
EXPECT_TRUE(elementsMatch(
_mirror->Shape.getShape(),
{
"Edge10;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge10;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge11;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge11;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge12;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge12;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge1;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge1;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge2;:M2(Edge2;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge2;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge2;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge3;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge3;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge4;:M2(Edge4;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge4;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge4;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge5;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge5;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge6;:M2(Edge6;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge6;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge6;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge7;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge7;:H11c4,E;:M;MIR;:H11ca:7,E",
"Edge8;:M2(Edge8;:H11c4,E);FUS;:H11c3:18,E;:M;MIR;:H11ca:7,E",
"Edge8;:M2;FUS;:H11c4:8,E;:M;MIR;:H11ca:7,E",
"Edge8;:M;FUS;:H11c3:7,E;:M;MIR;:H11ca:7,E",
"Edge9;:H11c3,E;:M;MIR;:H11ca:7,E",
"Edge9;:H11c4,E;:M;MIR;:H11ca:7,E",
"Face1;:M2(Face1;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face1;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face1;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Face2;:M2(Face2;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face2;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face2;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Face3;:H11c3,F;:M;MIR;:H11ca:7,F",
"Face4;:H11c4,F;:M;MIR;:H11ca:7,F",
"Face5;:M2(Face5;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face5;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face5;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Face6;:M2(Face6;:H11c4,F);FUS;:H11c3:18,F;:M;MIR;:H11ca:7,F",
"Face6;:M2;FUS;:H11c4:8,F;:M;MIR;:H11ca:7,F",
"Face6;:M;FUS;:H11c3:7,F;:M;MIR;:H11ca:7,F",
"Vertex1;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex1;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex2;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex2;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex3;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex3;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex4;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex4;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex5;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex5;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex6;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex6;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex7;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex7;:H11c4,V;:M;MIR;:H11ca:7,V",
"Vertex8;:H11c3,V;:M;MIR;:H11ca:7,V",
"Vertex8;:H11c4,V;:M;MIR;:H11ca:7,V",
}
));
}
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)

View File

@@ -164,18 +164,22 @@ TEST_F(FeaturePartCommonTest, testHistory)
// Manually create the histories classically generated by FreeCAD for comparison
using MapList = std::map<int, std::vector<int>>;
using List = std::vector<int>;
MapList compare1 = {{0, List {0}},
{1, List {5}}, // NOLINT magic number
{2, List()},
{3, List {2}},
{4, List {3}},
{5, List {1}}}; // NOLINT magic number
MapList compare2 = {{0, List {0}},
{1, List {5}}, // NOLINT magic number
{2, List {4}},
{3, List()},
{4, List {3}},
{5, List {1}}}; // NOLINT magic number
MapList compare1 = {
{0, List {0}},
{1, List {5}}, // NOLINT magic number
{2, List()},
{3, List {2}},
{4, List {3}},
{5, List {1}}
}; // NOLINT magic number
MapList compare2 = {
{0, List {0}},
{1, List {5}}, // NOLINT magic number
{2, List {4}},
{3, List()},
{4, List {3}},
{5, List {1}}
}; // NOLINT magic number
// Act and Assert no histories yet
std::vector<Part::ShapeHistory> hist = _common->History.getValues();
@@ -185,8 +189,10 @@ TEST_F(FeaturePartCommonTest, testHistory)
_common->execute();
hist = _common->History.getValues();
// Assert
ASSERT_EQ(hist.size(),
0); // TODO: with TNP enabled, this becomes 0, matches the code. Correct?
ASSERT_EQ(
hist.size(),
0
); // TODO: with TNP enabled, this becomes 0, matches the code. Correct?
}
TEST_F(FeaturePartCommonTest, testMapping)

View File

@@ -244,8 +244,8 @@ TEST_F(FeaturePartFuseTest, testRefine)
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
std::vector<Part::TopoShape> subs =
ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate approach
std::vector<Part::TopoShape> subs = ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate
// approach
// Assert two boxes, plus redundant faces at the joint.
EXPECT_EQ(subs.size(), 14);
// 14 Faces

View File

@@ -107,9 +107,9 @@ TEST_F(FeatureRevolutionTest, testAxisLink)
// Assert
double puckVolume = 0; // Someday make this test use a more interesting edge angle
EXPECT_FLOAT_EQ(volume, puckVolume);
EXPECT_TRUE(PartTestHelpers::boxesMatch(
bb,
Base::BoundBox3d(-ext1 / 2, -ext1 / 2, 0, ext1 / 2, ext1 / 2, 0)));
EXPECT_TRUE(
PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-ext1 / 2, -ext1 / 2, 0, ext1 / 2, ext1 / 2, 0))
);
}
TEST_F(FeatureRevolutionTest, testSymmetric)

View File

@@ -59,10 +59,12 @@ TEST_F(FuzzyBooleanTest, testDefaultFuzzy)
_fuse->execute();
// Verify
EXPECT_NEAR(PartTestHelpers::getVolume(_fuse->Shape.getValue()),
PartTestHelpers::getVolume(_helix1->Shape.getValue())
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
0.1);
EXPECT_NEAR(
PartTestHelpers::getVolume(_fuse->Shape.getValue()),
PartTestHelpers::getVolume(_helix1->Shape.getValue())
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
0.1
);
// Analyse
Part::TopoShape ts = _fuse->Shape.getValue();
@@ -88,10 +90,12 @@ TEST_F(FuzzyBooleanTest, testGoodFuzzy)
Part::FuzzyHelper::setBooleanFuzzy(oldFuzzy);
// Verify
EXPECT_NEAR(PartTestHelpers::getVolume(_fuse->Shape.getValue()),
PartTestHelpers::getVolume(_helix1->Shape.getValue())
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
0.1);
EXPECT_NEAR(
PartTestHelpers::getVolume(_fuse->Shape.getValue()),
PartTestHelpers::getVolume(_helix1->Shape.getValue())
+ PartTestHelpers::getVolume(_cylinder1->Shape.getValue()),
0.1
);
// Analyse
Part::TopoShape ts = _fuse->Shape.getValue();

View File

@@ -44,33 +44,29 @@ TEST_F(GeometryTest, testTrimBSpline)
std::vector<double> weights(5, 1.0);
std::vector<double> knotsNonPeriodic = {0.0, 1.0, 2.0};
std::vector<int> multiplicitiesNonPeriodic = {degree + 1, 1, degree + 1};
Part::GeomBSplineCurve nonPeriodicBSpline1(poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false);
Part::GeomBSplineCurve nonPeriodicBSpline2(poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false);
Part::GeomBSplineCurve nonPeriodicBSpline1(
poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false
);
Part::GeomBSplineCurve nonPeriodicBSpline2(
poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false
);
std::vector<double> knotsPeriodic = {0.0, 0.3, 1.0, 1.5, 1.8, 2.0};
double period = knotsPeriodic.back() - knotsPeriodic.front();
std::vector<int> multiplicitiesPeriodic(6, 1);
Part::GeomBSplineCurve periodicBSpline1(poles,
weights,
knotsPeriodic,
multiplicitiesPeriodic,
degree,
true);
Part::GeomBSplineCurve periodicBSpline2(poles,
weights,
knotsPeriodic,
multiplicitiesPeriodic,
degree,
true);
Part::GeomBSplineCurve
periodicBSpline1(poles, weights, knotsPeriodic, multiplicitiesPeriodic, degree, true);
Part::GeomBSplineCurve
periodicBSpline2(poles, weights, knotsPeriodic, multiplicitiesPeriodic, degree, true);
// NOTE: These should be within the knot range, with param1 < param2
double param1 = 0.5, param2 = 1.4;
// TODO: Decide what to do if params are outside the range

View File

@@ -153,14 +153,18 @@ TEST_F(FeaturePartTest, getRelatedElements)
auto label2 = _boxes[1]->Label.getValue();
const TopoShape& ts = _common->Shape.getShape();
boost::ignore_unused(ts);
auto result = Feature::getRelatedElements(_doc->getObject(label1),
"Edge2",
HistoryTraceType::followTypeChange,
true);
auto result2 = Feature::getRelatedElements(_doc->getObject(label2),
"Edge1",
HistoryTraceType::followTypeChange,
true);
auto result = Feature::getRelatedElements(
_doc->getObject(label1),
"Edge2",
HistoryTraceType::followTypeChange,
true
);
auto result2 = Feature::getRelatedElements(
_doc->getObject(label2),
"Edge1",
HistoryTraceType::followTypeChange,
true
);
// Assert
EXPECT_EQ(result.size(), 1); // Found the one.
EXPECT_EQ(result2.size(), 0); // No element map, so no related elements
@@ -185,11 +189,13 @@ TEST_F(FeaturePartTest, getElementFromSource)
boost::ignore_unused(label1);
boost::ignore_unused(label2);
boost::ignore_unused(ts);
auto element = Feature::getElementFromSource(_common,
"Part__Box001", // "Edge1",
_boxes[0],
"Face1", // "Edge1",
false);
auto element = Feature::getElementFromSource(
_common,
"Part__Box001", // "Edge1",
_boxes[0],
"Face1", // "Edge1",
false
);
// Assert
EXPECT_EQ(element.size(), 0);
}

View File

@@ -41,7 +41,8 @@ void PartTestHelperClass::createTestDoc()
Base::Vector3d(0, 2, 0), // Touch the first box
Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching
// For the Just Inside Of Touching case, go enough that we exceed precision rounding
Base::Vector3d(0, 2 - minimalDistance, 0)};
Base::Vector3d(0, 2 - minimalDistance, 0)
};
for (unsigned i = 0; i < _boxes.size(); i++) {
auto box = _boxes[i] = _doc->addObject<Part::Box>(); // NOLINT
@@ -49,12 +50,16 @@ void PartTestHelperClass::createTestDoc()
box->Width.setValue(2);
box->Height.setValue(3);
box->Placement.setValue(
Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d())); // NOLINT
Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d())
); // NOLINT
}
}
std::vector<Part::FilletElement>
_getFilletEdges(const std::vector<int>& edges, double startRadius, double endRadius)
std::vector<Part::FilletElement> _getFilletEdges(
const std::vector<int>& edges,
double startRadius,
double endRadius
)
{
std::vector<Part::FilletElement> filletElements;
for (auto edge : edges) {
@@ -90,8 +95,10 @@ void rectangle(double height, double width, const char* name)
ExecutePython(rectstring);
}
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge>
CreateRectFace(float len, float wid)
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge> CreateRectFace(
float len,
float wid
)
{
auto edge1 = BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(len, 0.0, 0.0)).Edge();
auto edge2 = BRepBuilderAPI_MakeEdge(gp_Pnt(len, 0.0, 0.0), gp_Pnt(len, wid, 0.0)).Edge();
@@ -102,12 +109,10 @@ CreateRectFace(float len, float wid)
return {face1, wire1, edge1, edge2, edge3, edge4};
}
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire>
CreateFaceWithRoundHole(float len, float wid, float radius)
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire> CreateFaceWithRoundHole(float len, float wid, float radius)
{
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(len, wid);
auto circ1 =
GC_MakeCircle(gp_Pnt(len / 2.0, wid / 2.0, 0), gp_Dir(0.0, 0.0, 1.0), radius).Value();
auto circ1 = GC_MakeCircle(gp_Pnt(len / 2.0, wid / 2.0, 0), gp_Dir(0.0, 0.0, 1.0), radius).Value();
auto edge5 = BRepBuilderAPI_MakeEdge(circ1).Edge();
auto wire2 = BRepBuilderAPI_MakeWire(edge5).Wire();
auto face2 = BRepBuilderAPI_MakeFace(face1, wire2).Face();
@@ -116,8 +121,7 @@ CreateFaceWithRoundHole(float len, float wid, float radius)
return {face2, wire1, wire2};
}
testing::AssertionResult
boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec)
testing::AssertionResult boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec)
{
if (abs(b1.MinX - b2.MinX) < prec && abs(b1.MinY - b2.MinY) < prec
&& abs(b1.MinZ - b2.MinZ) < prec && abs(b1.MaxX - b2.MaxX) < prec
@@ -167,29 +171,31 @@ bool matchStringsWithoutClause(std::string first, std::string second, const std:
* @param names The vector of names
* @return An assertion usable by the gtest framework
*/
testing::AssertionResult elementsMatch(const TopoShape& shape,
const std::vector<std::string>& names)
testing::AssertionResult elementsMatch(const TopoShape& shape, const std::vector<std::string>& names)
{
auto elements = shape.getElementMap();
if (!elements.empty() || !names.empty()) {
for (const auto& name : names) {
if (std::find_if(elements.begin(),
elements.end(),
[&, name](const Data::MappedElement& element) {
return matchStringsWithoutClause(
element.name.toString(),
name,
"(;D|;:H|;K)-?[a-fA-F0-9]+(:[0-9]+)?|(\\(.*?\\))?");
// ;D ;:H and ;K are the sections of an encoded name for
// Duplicate, Tag and a Face name in slices. All three of these
// can vary from run to run or platform to platform, as they are
// based on either explicit random numbers or memory addresses.
// Thus we remove the value from comparisons and just check that
// they exist. The full form could be something like ;:He59:53
// which is what we match and remove. We also pull out any
// subexpressions wrapped in parens to keep the parse from
// becoming too complex.
})
if (std::find_if(
elements.begin(),
elements.end(),
[&, name](const Data::MappedElement& element) {
return matchStringsWithoutClause(
element.name.toString(),
name,
"(;D|;:H|;K)-?[a-fA-F0-9]+(:[0-9]+)?|(\\(.*?\\))?"
);
// ;D ;:H and ;K are the sections of an encoded name for
// Duplicate, Tag and a Face name in slices. All three of these
// can vary from run to run or platform to platform, as they are
// based on either explicit random numbers or memory addresses.
// Thus we remove the value from comparisons and just check that
// they exist. The full form could be something like ;:He59:53
// which is what we match and remove. We also pull out any
// subexpressions wrapped in parens to keep the parse from
// becoming too complex.
}
)
== elements.end()) {
return testing::AssertionFailure() << mappedElementVectorToString(elements);
}
@@ -198,14 +204,12 @@ testing::AssertionResult elementsMatch(const TopoShape& shape,
return testing::AssertionSuccess();
}
testing::AssertionResult allElementsMatch(const TopoShape& shape,
const std::vector<std::string>& names)
testing::AssertionResult allElementsMatch(const TopoShape& shape, const std::vector<std::string>& names)
{
auto elements = shape.getElementMap();
if (elements.size() != names.size()) {
return testing::AssertionFailure()
<< elements.size() << " != " << names.size()
<< " elements: " << mappedElementVectorToString(elements);
return testing::AssertionFailure() << elements.size() << " != " << names.size()
<< " elements: " << mappedElementVectorToString(elements);
}
return elementsMatch(shape, names);
}

View File

@@ -31,8 +31,11 @@ double getArea(const TopoDS_Shape& shape);
double getLength(const TopoDS_Shape& shape);
std::vector<Part::FilletElement>
_getFilletEdges(const std::vector<int>& edges, double startRadius, double endRadius);
std::vector<Part::FilletElement> _getFilletEdges(
const std::vector<int>& edges,
double startRadius,
double endRadius
);
class PartTestHelperClass
{
@@ -49,14 +52,22 @@ void executePython(const std::vector<std::string>& python);
void rectangle(double height, double width, const char* name);
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge>
CreateRectFace(float len = 2.0, float wid = 3.0);
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge, TopoDS_Edge> CreateRectFace(
float len = 2.0,
float wid = 3.0
);
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire>
CreateFaceWithRoundHole(float len = 2.0, float wid = 3.0, float radius = 1.0);
std::tuple<TopoDS_Face, TopoDS_Wire, TopoDS_Wire> CreateFaceWithRoundHole(
float len = 2.0,
float wid = 3.0,
float radius = 1.0
);
testing::AssertionResult
boxesMatch(const Base::BoundBox3d& b1, const Base::BoundBox3d& b2, double prec = 1e-05); // NOLINT
testing::AssertionResult boxesMatch(
const Base::BoundBox3d& b1,
const Base::BoundBox3d& b2,
double prec = 1e-05
); // NOLINT
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape);
@@ -66,8 +77,7 @@ std::map<IndexedName, MappedName> elementMap(const TopoShape& shape);
* @param names The Names
* @return A test result, suitable for display by the gtest framework
*/
testing::AssertionResult elementsMatch(const TopoShape& shape,
const std::vector<std::string>& names);
testing::AssertionResult elementsMatch(const TopoShape& shape, const std::vector<std::string>& names);
/**
* Checks that all the names occur in the shape's element map and that there are no additional names
@@ -75,8 +85,7 @@ testing::AssertionResult elementsMatch(const TopoShape& shape,
* @param names The Names
* @return A test result, suitable for display by the gtest framework
*/
testing::AssertionResult allElementsMatch(const TopoShape& shape,
const std::vector<std::string>& names);
testing::AssertionResult allElementsMatch(const TopoShape& shape, const std::vector<std::string>& names);
/**
*

View File

@@ -160,8 +160,8 @@ TEST_F(PropertyTopoShapeTest, testPropertyPartShapeGetPyObject)
partShape.setValue(topoDsShapeIn2);
auto pyObj2 = partShape.getPyObject();
// Assert the shape is no longer a compound
EXPECT_FALSE(
PyObject_TypeCheck(pyObj2, &TopoShapeCompoundPy::Type)); // _boxes[3] is not a compound.
EXPECT_FALSE(PyObject_TypeCheck(pyObj2, &TopoShapeCompoundPy::Type)); // _boxes[3] is not a
// compound.
Py_XDECREF(pyObj2);
// Act
partShape.setPyObject(pyObj);

View File

@@ -90,8 +90,7 @@ TEST_F(TopoShapeCacheTest, InsertRelationIntoEmptyTableCompacts)
{
// Arrange
Data::IndexedName indexedName {"EDGE1"};
auto mappedName =
Data::MappedName::fromRawData("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H1b:10,F");
auto mappedName = Data::MappedName::fromRawData("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H1b:10,F");
ASSERT_TRUE(mappedName.isRaw());
Data::MappedElement mappedElement1 {indexedName, mappedName};
QVector<Data::MappedElement> vectorOfElements {mappedElement1};

File diff suppressed because it is too large Load Diff

View File

@@ -59,8 +59,10 @@ TEST_F(TopoShapeMakeShapeTests, nullShapeThrows)
TopoDS_Vertex nullShape;
// Act and assert
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullShape, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullShape, *Mapper(), sources),
Part::NullShapeException
);
}
TEST_F(TopoShapeMakeShapeTests, shapeVertex)
@@ -92,8 +94,8 @@ TEST_F(TopoShapeMakeShapeTests, thruSections)
thruMaker.AddWire(wire2);
TopoShape topoShape {};
// Act
TopoShape& result =
topoShape.makeElementShape(thruMaker, {wire1ts, wire2ts}, OpCodes::ThruSections);
TopoShape& result
= topoShape.makeElementShape(thruMaker, {wire1ts, wire2ts}, OpCodes::ThruSections);
auto elements = elementMap(result);
// Assert
EXPECT_EQ(elements.size(), 24);
@@ -110,7 +112,8 @@ TEST_F(TopoShapeMakeShapeTests, thruSections)
"Vertex2;:G(Vertex2;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex2;:H1,V", "Vertex2;:H2,V",
"Vertex3;:G(Vertex3;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex3;:H1,V", "Vertex3;:H2,V",
"Vertex4;:G(Vertex4;K-1;:H2:4,V);TRU;:H1:1c,E", "Vertex4;:H1,V", "Vertex4;:H2,V",
}));
}
));
}
TEST_F(TopoShapeMakeShapeTests, sewing)
@@ -128,10 +131,12 @@ TEST_F(TopoShapeMakeShapeTests, sewing)
std::vector<TopoShape> sources {{face1, 1L}, {face2, 2L}};
TopoShape topoShape {};
// Act
TopoShape& result = topoShape.makeShapeWithElementMap(sewer.SewedShape(),
MapperSewing(sewer),
sources,
OpCodes::Sewing);
TopoShape& result = topoShape.makeShapeWithElementMap(
sewer.SewedShape(),
MapperSewing(sewer),
sources,
OpCodes::Sewing
);
auto elements = elementMap(result);
// Assert
@@ -141,25 +146,27 @@ TEST_F(TopoShapeMakeShapeTests, sewing)
EXPECT_EQ(getArea(result.getShape()), 12);
// TODO: This element map is suspiciously devoid of anything OpCodes::Sewing (SEW). Is that
// right?
EXPECT_TRUE(allElementsMatch(topoShape,
{
"Face1;:H1,F",
"Face1;:H2,F",
"Edge1;:H2,E",
"Edge2;:H2,E",
"Edge3;:H2,E",
"Edge4;:H2,E",
"Edge1;:H1,E",
"Edge2;:H1,E",
"Edge3;:H1,E",
"Edge4;:H1,E",
"Vertex1;:H2,V",
"Vertex2;:H2,V",
"Vertex3;:H2,V",
"Vertex4;:H2,V",
"Vertex1;:H1,V",
"Vertex2;:H1,V",
"Vertex3;:H1,V",
"Vertex4;:H1,V",
}));
EXPECT_TRUE(allElementsMatch(
topoShape,
{
"Face1;:H1,F",
"Face1;:H2,F",
"Edge1;:H2,E",
"Edge2;:H2,E",
"Edge3;:H2,E",
"Edge4;:H2,E",
"Edge1;:H1,E",
"Edge2;:H1,E",
"Edge3;:H1,E",
"Edge4;:H1,E",
"Vertex1;:H2,V",
"Vertex2;:H2,V",
"Vertex3;:H2,V",
"Vertex4;:H2,V",
"Vertex1;:H1,V",
"Vertex2;:H1,V",
"Vertex3;:H1,V",
"Vertex4;:H1,V",
}
));
}

View File

@@ -50,8 +50,10 @@ protected:
return &_mapper;
}
void testFindSourceSubShapesInElementMapForSource(const std::vector<TopoShape>& sources,
const TopoShape& source);
void testFindSourceSubShapesInElementMapForSource(
const std::vector<TopoShape>& sources,
const TopoShape& source
);
private:
std::string _docName;
@@ -75,22 +77,38 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, nullShapeThrows)
TopoDS_Compound nullCompound;
// Act and assert
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullVertex, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullEdge, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullWire, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullFace, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullShell, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullSolid, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullCompSolid, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(Shape()->makeShapeWithElementMap(nullCompound, *Mapper(), sources),
Part::NullShapeException);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullVertex, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullEdge, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullWire, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullFace, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullShell, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullSolid, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullCompSolid, *Mapper(), sources),
Part::NullShapeException
);
EXPECT_THROW(
Shape()->makeShapeWithElementMap(nullCompound, *Mapper(), sources),
Part::NullShapeException
);
}
std::map<IndexedName, MappedName> elementMap(const TopoShape& shape)
@@ -135,8 +153,9 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, mapCompoundCount)
EXPECT_STREQ(compound.shapeName().c_str(), "Compound");
EXPECT_EQ(
22,
compound.getMappedChildElements().size()); // Changed with PR#12471. Probably will change
// again after importing other TopoNaming logics
compound.getMappedChildElements().size()
); // Changed with PR#12471. Probably will change
// again after importing other TopoNaming logics
}
TEST_F(TopoShapeMakeShapeWithElementMapTests, emptySourceShapes)
@@ -153,7 +172,8 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, emptySourceShapes)
EXPECT_EQ(
&originalShape,
&modifiedShape.makeShapeWithElementMap(source.getShape(), *Mapper(), emptySources));
&modifiedShape.makeShapeWithElementMap(source.getShape(), *Mapper(), emptySources)
);
}
}
@@ -173,34 +193,41 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, nonMappableSources)
}
if (canMap == 0U) {
EXPECT_EQ(&source,
&source.makeShapeWithElementMap(source.getShape(), *Mapper(), sources));
EXPECT_EQ(&source, &source.makeShapeWithElementMap(source.getShape(), *Mapper(), sources));
}
}
}
void testFindSourceShapesInSingleShape(const Part::TopoShape& cmpdShape,
const Part::TopoShape& source,
const std::vector<Part::TopoShape>& sources,
const TopoShape::Mapper& mapper)
void testFindSourceShapesInSingleShape(
const Part::TopoShape& cmpdShape,
const Part::TopoShape& source,
const std::vector<Part::TopoShape>& sources,
const TopoShape::Mapper& mapper
)
{
std::vector<Part::TopoShape> tmpSources {source};
for (const auto& subSource : sources) {
Part::TopoShape tmpShape {source.getShape()};
tmpShape.makeShapeWithElementMap(source.getShape(), mapper, tmpSources);
if (&source == &subSource) {
EXPECT_NE(tmpShape.findShape(subSource.getShape()),
0); // if tmpShape uses, for example, cube1 and we search for cube1 than
// we should find it
EXPECT_NE(
tmpShape.findShape(subSource.getShape()),
0
); // if tmpShape uses, for example, cube1 and we search for cube1 than
// we should find it
}
else {
EXPECT_EQ(tmpShape.findShape(subSource.getShape()),
0); // if tmpShape uses, for example, cube1 and we search for cube2 than
// we shouldn't find it
EXPECT_EQ(
tmpShape.findShape(subSource.getShape()),
0
); // if tmpShape uses, for example, cube1 and we search for cube2 than
// we shouldn't find it
}
}
EXPECT_NE(cmpdShape.findShape(source.getShape()),
0); // as cmpdShape is made with cube1 and cube2 we should find both of them
EXPECT_NE(
cmpdShape.findShape(source.getShape()),
0
); // as cmpdShape is made with cube1 and cube2 we should find both of them
}
TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceShapesInShape)
@@ -221,9 +248,11 @@ TEST_F(TopoShapeMakeShapeWithElementMapTests, findSourceShapesInShape)
}
}
void testFindSubShapesForSourceWithTypeAndIndex(const std::string& shapeTypeStr,
std::map<IndexedName, MappedName>& elementStdMap,
unsigned long shapeIndex)
void testFindSubShapesForSourceWithTypeAndIndex(
const std::string& shapeTypeStr,
std::map<IndexedName, MappedName>& elementStdMap,
unsigned long shapeIndex
)
{
std::string shapeIndexStr = std::to_string(shapeIndex);
std::string shapeName {shapeTypeStr + shapeIndexStr};
@@ -242,9 +271,11 @@ void testFindSubShapesForSourceWithTypeAndIndex(const std::string& shapeTypeStr,
QT_WARNING_POP
}
void testFindSubShapesForSourceWithType(const TopoShape& source,
const char* shapeType,
std::map<IndexedName, MappedName>& elementStdMap)
void testFindSubShapesForSourceWithType(
const TopoShape& source,
const char* shapeType,
std::map<IndexedName, MappedName>& elementStdMap
)
{
std::string shapeTypeStr {shapeType};
@@ -265,7 +296,8 @@ void testFindSubShapesForSourceWithType(const TopoShape& source,
void TopoShapeMakeShapeWithElementMapTests::testFindSourceSubShapesInElementMapForSource(
const std::vector<TopoShape>& sources,
const TopoShape& source)
const TopoShape& source
)
{
TopoShape tmpShape {source.getShape()};
tmpShape.makeShapeWithElementMap(source.getShape(), *Mapper(), sources);
@@ -329,8 +361,7 @@ std::string composeTagInfo(const MappedElement& element, const TopoShape& shape)
{
std::string elementNameStr {element.name.constPostfix()};
std::string tagInfo = POSTFIX_TAG + std::to_string(shape.Tag);
tagInfo +=
":" + std::to_string(elementNameStr.substr(0, elementNameStr.find(tagInfo)).length());
tagInfo += ":" + std::to_string(elementNameStr.substr(0, elementNameStr.find(tagInfo)).length());
return tagInfo;
}

View File

@@ -150,7 +150,8 @@ TEST_F(WireJoinerTest, setOutline)
// To see the correct value for this parameter refer to method WireJoinerP::canShowShape()
auto hParam {App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/WireJoiner")};
"User parameter:BaseApp/Preferences/WireJoiner"
)};
auto catchIteration {hParam->GetInt("Iteration", 0)};
hParam->SetInt("Iteration", -1);
@@ -195,8 +196,8 @@ TEST_F(WireJoinerTest, setOutline)
auto foundRemovedNoOutline {false};
for (const auto& obj : objsInDoc) {
foundRemovedNoOutline =
(std::string(obj->Label.getValue()).find("removed") != std::string::npos);
foundRemovedNoOutline
= (std::string(obj->Label.getValue()).find("removed") != std::string::npos);
if (foundRemovedNoOutline) {
break;
}
@@ -216,8 +217,7 @@ TEST_F(WireJoinerTest, setOutline)
auto foundRemovedOutline {false};
for (const auto& obj : objsInDoc) {
foundRemovedOutline =
(std::string(obj->Label.getValue()).find("removed") != std::string::npos);
foundRemovedOutline = (std::string(obj->Label.getValue()).find("removed") != std::string::npos);
if (foundRemovedOutline) {
break;
}
@@ -473,10 +473,11 @@ TEST_F(WireJoinerTest, setTolerance)
auto edge2 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 0.0, 0.0), gp_Pnt(1.0, 1.0, 0.0)).Edge()};
auto edge3 {BRepBuilderAPI_MakeEdge(gp_Pnt(1.0, 1.0, 0.0), gp_Pnt(0.0, 0.0, 0.0)).Edge()};
auto edge4 {BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.9, 0.0, 0.0)).Edge()};
auto edge5 {
BRepBuilderAPI_MakeEdge(gp_Pnt(0.0, 0.0, 0.0),
gp_Pnt(0.9 * std::cos(pi / 18), 0.9 * std::sin(pi / 18), 0.0))
.Edge()};
auto edge5 {BRepBuilderAPI_MakeEdge(
gp_Pnt(0.0, 0.0, 0.0),
gp_Pnt(0.9 * std::cos(pi / 18), 0.9 * std::sin(pi / 18), 0.0)
)
.Edge()};
// A vector of edges used as argument for wjNegtol.addShape()
std::vector<TopoDS_Shape> edgesNegtol {edge1, edge2, edge3};
@@ -712,9 +713,7 @@ TEST_F(WireJoinerTest, getResultWires)
std::vector<TopoDS_Shape> edgesNoResultWires {edge1, edge2, edge3};
// A vector of TopoShape edges used as argument for wjNoOp.addShape(). A Tag is needed for every
// TopoShape, otherwise no element map will be created and no op can be found
std::vector<TopoShape> edgesNoOp {TopoShape(edge1, 4),
TopoShape(edge2, 5),
TopoShape(edge4, 6)};
std::vector<TopoShape> edgesNoOp {TopoShape(edge1, 4), TopoShape(edge2, 5), TopoShape(edge4, 6)};
// A vector of TopoShape edges used as argument for wjOp.addShape(). A Tag is needed for every
// TopoShape, otherwise no element map will be created and no op can be found
std::vector<TopoShape> edgesOp {TopoShape(edge1, 7), TopoShape(edge2, 8), TopoShape(edge4, 9)};

View File

@@ -56,7 +56,8 @@ TEST_F(BackwardCompatibilityTest, TestOpenV021Model)
// arrange
auto doc = App::GetApplication().openDocument(
std::string(getTestPath() + "ModelFromV021.FCStd").c_str());
std::string(getTestPath() + "ModelFromV021.FCStd").c_str()
);
setDocument(doc);
auto chamfer = dynamic_cast<PartDesign::Chamfer*>(doc->getObject("Chamfer"));
@@ -65,7 +66,8 @@ TEST_F(BackwardCompatibilityTest, TestOpenV021Model)
std::vector<TopoDS_Shape> chamferOriginalEdges {};
for (const auto& chamferEdgesName : chamferEdgesNames) {
chamferOriginalEdges.push_back(
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesName.c_str()).getShape());
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesName.c_str()).getShape()
);
}
// act
@@ -108,16 +110,20 @@ TEST_F(BackwardCompatibilityTest, TestOpenV021Model)
EXPECT_TRUE(checkSameVertexes(
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[0].c_str()).getShape(),
chamferOriginalEdges[0]));
chamferOriginalEdges[0]
));
EXPECT_TRUE(checkSameVertexes(
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[1].c_str()).getShape(),
chamferOriginalEdges[1]));
chamferOriginalEdges[1]
));
EXPECT_TRUE(checkSameVertexes(
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[2].c_str()).getShape(),
chamferOriginalEdges[2]));
chamferOriginalEdges[2]
));
EXPECT_TRUE(checkSameVertexes(
chamfer->getBaseTopoShape().getSubTopoShape(chamferEdgesNames[3].c_str()).getShape(),
chamferOriginalEdges[3]));
chamferOriginalEdges[3]
));
}
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)

View File

@@ -29,7 +29,8 @@ protected:
_box->Width.setValue(2);
_box->Height.setValue(3);
_box->Placement.setValue(
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())); // NOLINT
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d())
); // NOLINT
// _body->addObject(_box); // Invalid, Part::Features can't go in a PartDesign::Body,
// but we can bind them.
_binder = _doc->addObject<PartDesign::ShapeBinder>("ShapeBinderFoo");

View File

@@ -33,8 +33,7 @@ public:
}
};
::testing::Environment* const xercesEnv =
::testing::AddGlobalTestEnvironment(new XercesEnvironment);
::testing::Environment* const xercesEnv = ::testing::AddGlobalTestEnvironment(new XercesEnvironment);
class ConstraintPointsAccess: public ::testing::Test
{
@@ -66,12 +65,18 @@ TEST_F(ConstraintPointsAccess, testDefaultGeoElementIdsAreSane) // NOLINT
// New way of accessing elements
#endif
EXPECT_EQ(constraint.getElement(0),
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none));
EXPECT_EQ(constraint.getElement(1),
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none));
EXPECT_EQ(constraint.getElement(2),
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none));
EXPECT_EQ(
constraint.getElement(0),
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none)
);
EXPECT_EQ(
constraint.getElement(1),
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none)
);
EXPECT_EQ(
constraint.getElement(2),
Sketcher::GeoElementId(Sketcher::GeoEnum::GeoUndef, Sketcher::PointPos::none)
);
}
#if SKETCHER_CONSTRAINT_USE_LEGACY_ELEMENTS
@@ -89,12 +94,18 @@ TEST_F(ConstraintPointsAccess, testOldWriteIsReadByNew) // NOLINT
constraint.ThirdPos = Sketcher::PointPos::mid;
// Assert
EXPECT_EQ(constraint.getElement(0),
Sketcher::GeoElementId(Sketcher::GeoElementId(23, Sketcher::PointPos::start)));
EXPECT_EQ(constraint.getElement(1),
Sketcher::GeoElementId(Sketcher::GeoElementId(34, Sketcher::PointPos::end)));
EXPECT_EQ(constraint.getElement(2),
Sketcher::GeoElementId(Sketcher::GeoElementId(45, Sketcher::PointPos::mid)));
EXPECT_EQ(
constraint.getElement(0),
Sketcher::GeoElementId(Sketcher::GeoElementId(23, Sketcher::PointPos::start))
);
EXPECT_EQ(
constraint.getElement(1),
Sketcher::GeoElementId(Sketcher::GeoElementId(34, Sketcher::PointPos::end))
);
EXPECT_EQ(
constraint.getElement(2),
Sketcher::GeoElementId(Sketcher::GeoElementId(45, Sketcher::PointPos::mid))
);
}
TEST_F(ConstraintPointsAccess, testNewWriteIsReadByOld) // NOLINT
@@ -260,48 +271,49 @@ TEST_F(ConstraintPointsAccess, testElementsRestoredFromSerialization) // NOLINT
restoredConstraint.Restore(reader);
// Assert
EXPECT_EQ(restoredConstraint.getElement(0),
Sketcher::GeoElementId(23, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(1),
Sketcher::GeoElementId(34, Sketcher::PointPos::end));
EXPECT_EQ(restoredConstraint.getElement(2),
Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(23, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(34, Sketcher::PointPos::end));
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
inputFile.close();
}
TEST_F(ConstraintPointsAccess,
testElementsRestoredFromSerializationWithoutNewElementStorage) // NOLINT
TEST_F(
ConstraintPointsAccess,
testElementsRestoredFromSerializationWithoutNewElementStorage
) // NOLINT
{
// Arrange
// Manually craft a serialized version, only parts in "{}" are important.
// New way of storing elements is not present, like if it is an older file.
std::string serializedConstraint = fmt::format("<Constrain "
R"(Name="" )"
R"(Type="0" )"
R"(Value="0" )"
R"(LabelDistance="10" )"
R"(LabelPosition="0" )"
R"(IsDriving="1" )"
R"(IsInVirtualSpace="0" )"
R"(IsActive="1" )"
std::string serializedConstraint = fmt::format(
"<Constrain "
R"(Name="" )"
R"(Type="0" )"
R"(Value="0" )"
R"(LabelDistance="10" )"
R"(LabelPosition="0" )"
R"(IsDriving="1" )"
R"(IsInVirtualSpace="0" )"
R"(IsActive="1" )"
R"(First="{}" )"
R"(Second="{}" )"
R"(Third="{}" )"
R"(FirstPos="{}" )"
R"(SecondPos="{}" )"
R"(ThirdPos="{}" )"
R"(First="{}" )"
R"(Second="{}" )"
R"(Third="{}" )"
R"(FirstPos="{}" )"
R"(SecondPos="{}" )"
R"(ThirdPos="{}" )"
"/>",
"/>",
67,
78,
89,
static_cast<int>(Sketcher::PointPos::mid),
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end));
67,
78,
89,
static_cast<int>(Sketcher::PointPos::mid),
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end)
);
Base::StringWriter writer;
auto& stream {writer.Stream()};
@@ -326,45 +338,46 @@ TEST_F(ConstraintPointsAccess,
restoredConstraint.Restore(reader);
// Assert
EXPECT_EQ(restoredConstraint.getElement(0),
Sketcher::GeoElementId(67, Sketcher::PointPos::mid));
EXPECT_EQ(restoredConstraint.getElement(1),
Sketcher::GeoElementId(78, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(2),
Sketcher::GeoElementId(89, Sketcher::PointPos::end));
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(67, Sketcher::PointPos::mid));
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(78, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(89, Sketcher::PointPos::end));
inputFile.close();
}
TEST_F(ConstraintPointsAccess,
testLegacyIsPreferedDuringSerializationWithoutLegacyElementStorage) // NOLINT
TEST_F(
ConstraintPointsAccess,
testLegacyIsPreferedDuringSerializationWithoutLegacyElementStorage
) // NOLINT
{
// Arrange
// Manually craft a serialized version, only parts in "{}" are important.
// Only new way of storing elements is present.
std::string serializedConstraint = fmt::format("<Constrain "
R"(Name="" )"
R"(Type="0" )"
R"(Value="0" )"
R"(LabelDistance="10" )"
R"(LabelPosition="0" )"
R"(IsDriving="1" )"
R"(IsInVirtualSpace="0" )"
R"(IsActive="1" )"
std::string serializedConstraint = fmt::format(
"<Constrain "
R"(Name="" )"
R"(Type="0" )"
R"(Value="0" )"
R"(LabelDistance="10" )"
R"(LabelPosition="0" )"
R"(IsDriving="1" )"
R"(IsInVirtualSpace="0" )"
R"(IsActive="1" )"
// New way
R"(ElementIds="{} {} {}" )"
R"(ElementPositions="{} {} {}" )"
// New way
R"(ElementIds="{} {} {}" )"
R"(ElementPositions="{} {} {}" )"
"/>",
// New way data
23,
34,
45,
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end),
static_cast<int>(Sketcher::PointPos::mid));
"/>",
// New way data
23,
34,
45,
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end),
static_cast<int>(Sketcher::PointPos::mid)
);
Base::StringWriter writer;
auto& stream {writer.Stream()};
@@ -389,12 +402,9 @@ TEST_F(ConstraintPointsAccess,
restoredConstraint.Restore(reader);
// Assert
EXPECT_EQ(restoredConstraint.getElement(0),
Sketcher::GeoElementId(23, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(1),
Sketcher::GeoElementId(34, Sketcher::PointPos::end));
EXPECT_EQ(restoredConstraint.getElement(2),
Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(23, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(34, Sketcher::PointPos::end));
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(45, Sketcher::PointPos::mid));
inputFile.close();
}
@@ -405,45 +415,46 @@ TEST_F(ConstraintPointsAccess, testLegacyIsPreferedDuringSerializationIfContradi
// Manually craft a serialized version, only parts in "{}" are important.
// It is not important if legacy is included before or after, legacy should always be preferred.
std::string serializedConstraint =
fmt::format("<Constrain "
R"(Name="" )"
R"(Type="0" )"
R"(Value="0" )"
R"(LabelDistance="10" )"
R"(LabelPosition="0" )"
R"(IsDriving="1" )"
R"(IsInVirtualSpace="0" )"
R"(IsActive="1" )"
std::string serializedConstraint = fmt::format(
"<Constrain "
R"(Name="" )"
R"(Type="0" )"
R"(Value="0" )"
R"(LabelDistance="10" )"
R"(LabelPosition="0" )"
R"(IsDriving="1" )"
R"(IsInVirtualSpace="0" )"
R"(IsActive="1" )"
// New way
R"(ElementIds="{} {} {}" )"
R"(ElementPositions="{} {} {}" )"
// New way
R"(ElementIds="{} {} {}" )"
R"(ElementPositions="{} {} {}" )"
// Legacy
R"(First="{}" )"
R"(Second="{}" )"
R"(Third="{}" )"
R"(FirstPos="{}" )"
R"(SecondPos="{}" )"
R"(ThirdPos="{}" )"
// Legacy
R"(First="{}" )"
R"(Second="{}" )"
R"(Third="{}" )"
R"(FirstPos="{}" )"
R"(SecondPos="{}" )"
R"(ThirdPos="{}" )"
"/>",
// New way data
23,
34,
45,
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end),
static_cast<int>(Sketcher::PointPos::mid),
"/>",
// New way data
23,
34,
45,
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end),
static_cast<int>(Sketcher::PointPos::mid),
// Contradicting legacy data, this should be preferred if available
67,
78,
89,
static_cast<int>(Sketcher::PointPos::mid),
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end));
// Contradicting legacy data, this should be preferred if available
67,
78,
89,
static_cast<int>(Sketcher::PointPos::mid),
static_cast<int>(Sketcher::PointPos::start),
static_cast<int>(Sketcher::PointPos::end)
);
Base::StringWriter writer;
auto& stream {writer.Stream()};
@@ -468,12 +479,9 @@ TEST_F(ConstraintPointsAccess, testLegacyIsPreferedDuringSerializationIfContradi
restoredConstraint.Restore(reader);
// Assert
EXPECT_EQ(restoredConstraint.getElement(0),
Sketcher::GeoElementId(67, Sketcher::PointPos::mid));
EXPECT_EQ(restoredConstraint.getElement(1),
Sketcher::GeoElementId(78, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(2),
Sketcher::GeoElementId(89, Sketcher::PointPos::end));
EXPECT_EQ(restoredConstraint.getElement(0), Sketcher::GeoElementId(67, Sketcher::PointPos::mid));
EXPECT_EQ(restoredConstraint.getElement(1), Sketcher::GeoElementId(78, Sketcher::PointPos::start));
EXPECT_EQ(restoredConstraint.getElement(2), Sketcher::GeoElementId(89, Sketcher::PointPos::end));
inputFile.close();
}
@@ -484,8 +492,7 @@ TEST_F(ConstraintPointsAccess, testSubstituteIndex) // NOLINT
Sketcher::Constraint constraint;
constraint.setElement(0, Sketcher::GeoElementId(10, Sketcher::PointPos::start));
constraint.setElement(1, Sketcher::GeoElementId(20, Sketcher::PointPos::end));
constraint.setElement(2,
Sketcher::GeoElementId(10, Sketcher::PointPos::mid)); // same GeoId as 0
constraint.setElement(2, Sketcher::GeoElementId(10, Sketcher::PointPos::mid)); // same GeoId as 0
// Act
constraint.substituteIndex(10, 99);
@@ -510,8 +517,7 @@ TEST_F(ConstraintPointsAccess, testSubstituteIndexAndPos) // NOLINT
// Assert
EXPECT_EQ(constraint.getElement(0), Sketcher::GeoElementId(42, Sketcher::PointPos::end));
EXPECT_EQ(constraint.getElement(1), Sketcher::GeoElementId(20, Sketcher::PointPos::start));
EXPECT_EQ(constraint.getElement(2),
Sketcher::GeoElementId(10, Sketcher::PointPos::mid)); // unchanged
EXPECT_EQ(constraint.getElement(2), Sketcher::GeoElementId(10, Sketcher::PointPos::mid)); // unchanged
}
TEST_F(ConstraintPointsAccess, testInvolvesGeoId) // NOLINT

View File

@@ -134,8 +134,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomPoint)
auto ptMid = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::mid);
auto ptEnd = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&point, Sketcher::PointPos::none);
// Assert
EXPECT_DOUBLE_EQ(ptStart[0], 1.0);
@@ -157,12 +156,10 @@ TEST_F(SketchObjectTest, testGetPointFromGeomLineSegment)
// Act
auto ptStart = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::start);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptMid =
Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::mid);
[[maybe_unused]] auto ptMid = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::mid);
auto ptEnd = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&lineSeg, Sketcher::PointPos::none);
// Assert
EXPECT_DOUBLE_EQ(ptStart[0], 1.0);
@@ -187,8 +184,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomCircle)
// TODO: Maybe we want this to give an error instead of some default value
auto ptEnd = Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&circle, Sketcher::PointPos::none);
// Assert
// NOTE: Presently, start/end points of a circle are defined as the point on circle right of the
@@ -219,8 +215,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomEllipse)
// TODO: Maybe we want this to give an error instead of some default value
auto ptEnd = Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone = Sketcher::SketchObject::getPoint(&ellipse, Sketcher::PointPos::none);
// Assert
// NOTE: Presently, start/end points of an ellipse are defined as the point on the major axis in
@@ -248,8 +243,8 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfCircle)
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::mid);
auto ptEnd = Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone
= Sketcher::SketchObject::getPoint(&arcOfCircle, Sketcher::PointPos::none);
// Assert
// NOTE: parameters for arc of circle are CCW angles from positive x-axis
@@ -279,8 +274,8 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfEllipse)
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::mid);
auto ptEnd = Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone
= Sketcher::SketchObject::getPoint(&arcOfEllipse, Sketcher::PointPos::none);
// Assert
// NOTE: parameters for arc of ellipse are CCW angles from positive x-axis
@@ -306,14 +301,14 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfHyperbola)
arcOfHyperbola.setRange(startParam, endParam, true);
// Act
[[maybe_unused]] auto ptStart =
Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::start);
[[maybe_unused]] auto ptStart
= Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::start);
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::mid);
[[maybe_unused]] auto ptEnd =
Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::end);
[[maybe_unused]] auto ptEnd
= Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone
= Sketcher::SketchObject::getPoint(&arcOfHyperbola, Sketcher::PointPos::none);
// Assert
// FIXME: Figure out how this is defined
@@ -337,14 +332,14 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfParabola)
arcOfParabola.setRange(startParam, endParam, true);
// Act
[[maybe_unused]] auto ptStart =
Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::start);
[[maybe_unused]] auto ptStart
= Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::start);
auto ptMid = Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::mid);
[[maybe_unused]] auto ptEnd =
Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::end);
[[maybe_unused]] auto ptEnd
= Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone
= Sketcher::SketchObject::getPoint(&arcOfParabola, Sketcher::PointPos::none);
// Assert
// FIXME: Figure out how this is defined
@@ -369,22 +364,18 @@ TEST_F(SketchObjectTest, testGetPointFromGeomBSplineCurveNonPeriodic)
std::vector<double> weights(5, 1.0);
std::vector<double> knotsNonPeriodic = {0.0, 1.0, 2.0};
std::vector<int> multiplicitiesNonPeriodic = {degree + 1, 1, degree + 1};
Part::GeomBSplineCurve nonPeriodicBSpline(poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false);
Part::GeomBSplineCurve
nonPeriodicBSpline(poles, weights, knotsNonPeriodic, multiplicitiesNonPeriodic, degree, false);
// Act
auto ptStart = Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::start);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptMid =
Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::mid);
[[maybe_unused]] auto ptMid
= Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::mid);
auto ptEnd = Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone
= Sketcher::SketchObject::getPoint(&nonPeriodicBSpline, Sketcher::PointPos::none);
// Assert
EXPECT_DOUBLE_EQ(ptStart[0], poles.front()[0]);
@@ -406,24 +397,20 @@ TEST_F(SketchObjectTest, testGetPointFromGeomBSplineCurvePeriodic)
std::vector<double> weights(5, 1.0);
std::vector<double> knotsPeriodic = {0.0, 0.3, 1.0, 1.5, 1.8, 2.0};
std::vector<int> multiplicitiesPeriodic(6, 1);
Part::GeomBSplineCurve periodicBSpline(poles,
weights,
knotsPeriodic,
multiplicitiesPeriodic,
degree,
true);
Part::GeomBSplineCurve
periodicBSpline(poles, weights, knotsPeriodic, multiplicitiesPeriodic, degree, true);
// Act
// TODO: Maybe we want this to give an error instead of some default value
auto ptStart = Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::start);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptMid =
Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::mid);
[[maybe_unused]] auto ptMid
= Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::mid);
// TODO: Maybe we want this to give an error instead of some default value
auto ptEnd = Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::end);
// TODO: Maybe we want this to give an error instead of some default value
[[maybe_unused]] auto ptNone =
Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::none);
[[maybe_unused]] auto ptNone
= Sketcher::SketchObject::getPoint(&periodicBSpline, Sketcher::PointPos::none);
// Assert
// With non-trivial values for weights, knots, mults, etc, getting the coordinates is
@@ -523,19 +510,20 @@ TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfEllipse)
// Ensure all internal geometry is satisfied
// TODO: Also try to ensure types of geometries that have this type
const auto constraints = getObject()->Constraints.getValues();
for (auto alignmentType : {Sketcher::InternalAlignmentType::EllipseMajorDiameter,
Sketcher::InternalAlignmentType::EllipseMinorDiameter,
Sketcher::InternalAlignmentType::EllipseFocus1,
Sketcher::InternalAlignmentType::EllipseFocus2}) {
for (auto alignmentType :
{Sketcher::InternalAlignmentType::EllipseMajorDiameter,
Sketcher::InternalAlignmentType::EllipseMinorDiameter,
Sketcher::InternalAlignmentType::EllipseFocus1,
Sketcher::InternalAlignmentType::EllipseFocus2}) {
// TODO: Ensure there exists one and only one curve with this type
int numConstraintsOfThisType =
std::count_if(constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType
&& constr->Second == geoId;
});
int numConstraintsOfThisType = std::count_if(
constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
}
);
EXPECT_EQ(numConstraintsOfThisType, 1);
}
@@ -570,18 +558,19 @@ TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfHyperbola)
// Ensure all internal geometry is satisfied
// TODO: Also try to ensure types of geometries that have this type
const auto constraints = getObject()->Constraints.getValues();
for (auto alignmentType : {Sketcher::InternalAlignmentType::HyperbolaMajor,
Sketcher::InternalAlignmentType::HyperbolaMinor,
Sketcher::InternalAlignmentType::HyperbolaFocus}) {
for (auto alignmentType :
{Sketcher::InternalAlignmentType::HyperbolaMajor,
Sketcher::InternalAlignmentType::HyperbolaMinor,
Sketcher::InternalAlignmentType::HyperbolaFocus}) {
// TODO: Ensure there exists one and only one curve with this type
int numConstraintsOfThisType =
std::count_if(constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType
&& constr->Second == geoId;
});
int numConstraintsOfThisType = std::count_if(
constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
}
);
EXPECT_EQ(numConstraintsOfThisType, 1);
}
@@ -616,17 +605,18 @@ TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfParabola)
// Ensure all internal geometry is satisfied
// TODO: Also try to ensure types of geometries that have this type
const auto constraints = getObject()->Constraints.getValues();
for (auto alignmentType : {Sketcher::InternalAlignmentType::ParabolaFocalAxis,
Sketcher::InternalAlignmentType::ParabolaFocus}) {
for (auto alignmentType :
{Sketcher::InternalAlignmentType::ParabolaFocalAxis,
Sketcher::InternalAlignmentType::ParabolaFocus}) {
// TODO: Ensure there exists one and only one curve with this type
int numConstraintsOfThisType =
std::count_if(constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType
&& constr->Second == geoId;
});
int numConstraintsOfThisType = std::count_if(
constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
}
);
EXPECT_EQ(numConstraintsOfThisType, 1);
}
@@ -664,22 +654,27 @@ TEST_F(SketchObjectTest, testDeleteExposeInternalGeometryOfBSpline)
// TODO: Also try to ensure types of geometries that have this type
const auto constraints = getObject()->Constraints.getValues();
std::map<Sketcher::InternalAlignmentType, int> numConstraintsOfThisType;
for (auto alignmentType : {Sketcher::InternalAlignmentType::BSplineControlPoint,
Sketcher::InternalAlignmentType::BSplineKnotPoint}) {
for (auto alignmentType :
{Sketcher::InternalAlignmentType::BSplineControlPoint,
Sketcher::InternalAlignmentType::BSplineKnotPoint}) {
// TODO: Ensure there exists one and only one curve with this type
numConstraintsOfThisType[alignmentType] =
std::count_if(constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType
&& constr->Second == geoId;
});
numConstraintsOfThisType[alignmentType] = std::count_if(
constraints.begin(),
constraints.end(),
[&geoId, &alignmentType](const auto* constr) {
return constr->Type == Sketcher::ConstraintType::InternalAlignment
&& constr->AlignmentType == alignmentType && constr->Second == geoId;
}
);
}
EXPECT_EQ(numConstraintsOfThisType[Sketcher::InternalAlignmentType::BSplineControlPoint],
nonPeriodicBSpline->countPoles());
EXPECT_EQ(numConstraintsOfThisType[Sketcher::InternalAlignmentType::BSplineKnotPoint],
nonPeriodicBSpline->countKnots());
EXPECT_EQ(
numConstraintsOfThisType[Sketcher::InternalAlignmentType::BSplineControlPoint],
nonPeriodicBSpline->countPoles()
);
EXPECT_EQ(
numConstraintsOfThisType[Sketcher::InternalAlignmentType::BSplineKnotPoint],
nonPeriodicBSpline->countKnots()
);
// Act
// Delete internal geometry (again)
@@ -837,13 +832,14 @@ TEST_F(SketchObjectTest, testGetElementName)
// Act
// unless it's Export, we are really just testing the superclass App::GeoFeature::getElementName
// call.
auto forward_normal_name =
getObject()->getElementName((tagName + ";SKT").c_str(),
App::GeoFeature::ElementNameType::Normal);
auto reverse_normal_name =
getObject()->getElementName("Vertex2", App::GeoFeature::ElementNameType::Normal);
auto reverse_export_name =
getObject()->getElementName("Vertex1", App::GeoFeature::ElementNameType::Export);
auto forward_normal_name = getObject()->getElementName(
(tagName + ";SKT").c_str(),
App::GeoFeature::ElementNameType::Normal
);
auto reverse_normal_name
= getObject()->getElementName("Vertex2", App::GeoFeature::ElementNameType::Normal);
auto reverse_export_name
= getObject()->getElementName("Vertex1", App::GeoFeature::ElementNameType::Export);
auto map = getObject()->Shape.getShape().getElementMap();
ASSERT_EQ(map.size(), 3);
EXPECT_STREQ(map[0].name.toString().c_str(), (tagName + ";SKT").c_str());

View File

@@ -234,8 +234,7 @@ TEST_F(SketchObjectTest, testTrimLineSegmentMid)
// TODO: Once this line segment is trimmed, there should be two "smaller" curves in its place
EXPECT_EQ(getObject()->getHighestCurveIndex(), geoId + 1);
// TODO: There should be a "point-on-object" constraint on the intersecting curves
int numberOfPointOnObjectConstraints =
countConstraintsOfType(getObject(), Sketcher::PointOnObject);
int numberOfPointOnObjectConstraints = countConstraintsOfType(getObject(), Sketcher::PointOnObject);
EXPECT_EQ(numberOfPointOnObjectConstraints, 1);
int numberOfCoincidentConstraints = countConstraintsOfType(getObject(), Sketcher::Coincident);
EXPECT_EQ(numberOfCoincidentConstraints, 1);
@@ -297,8 +296,7 @@ TEST_F(SketchObjectTest, testTrimCircleMid)
EXPECT_EQ(getObject()->getHighestCurveIndex(), geoId);
// There should be one "coincident" and one "point-on-object" constraint on the intersecting
// curves
int numberOfPointOnObjectConstraints =
countConstraintsOfType(getObject(), Sketcher::PointOnObject);
int numberOfPointOnObjectConstraints = countConstraintsOfType(getObject(), Sketcher::PointOnObject);
EXPECT_EQ(numberOfPointOnObjectConstraints, 1);
int numberOfCoincidentConstraints = countConstraintsOfType(getObject(), Sketcher::Coincident);
EXPECT_EQ(numberOfCoincidentConstraints, 1);
@@ -362,8 +360,7 @@ TEST_F(SketchObjectTest, testTrimArcOfCircleMid)
EXPECT_EQ(result, 0);
EXPECT_EQ(getObject()->getHighestCurveIndex(), geoId + 1);
// There should be a "point-on-object" constraint on the intersecting curves
int numberOfPointOnObjectConstraints =
countConstraintsOfType(getObject(), Sketcher::PointOnObject);
int numberOfPointOnObjectConstraints = countConstraintsOfType(getObject(), Sketcher::PointOnObject);
EXPECT_EQ(numberOfPointOnObjectConstraints, 1);
// There should be 2 coincident constraints: one with lineSegCut1 and one between centers of the
// new arcs
@@ -438,8 +435,7 @@ TEST_F(SketchObjectTest, testTrimEllipseMid)
EXPECT_EQ(getObject()->getHighestCurveIndex(), 2);
// There should be one "coincident" and one "point-on-object" constraint on the intersecting
// curves
int numberOfPointOnObjectConstraints =
countConstraintsOfType(getObject(), Sketcher::PointOnObject);
int numberOfPointOnObjectConstraints = countConstraintsOfType(getObject(), Sketcher::PointOnObject);
EXPECT_EQ(numberOfPointOnObjectConstraints, 1);
int numberOfCoincidentConstraints = countConstraintsOfType(getObject(), Sketcher::Coincident);
EXPECT_EQ(numberOfCoincidentConstraints, 1);
@@ -510,8 +506,7 @@ TEST_F(SketchObjectTest, testTrimPeriodicBSplineMid)
EXPECT_EQ(getObject()->getHighestCurveIndex(), 2);
// There should be one "coincident" and one "point-on-object" constraint on the intersecting
// curves
int numberOfPointOnObjectConstraints =
countConstraintsOfType(getObject(), Sketcher::PointOnObject);
int numberOfPointOnObjectConstraints = countConstraintsOfType(getObject(), Sketcher::PointOnObject);
EXPECT_EQ(numberOfPointOnObjectConstraints, 1);
int numberOfCoincidentConstraints = countConstraintsOfType(getObject(), Sketcher::Coincident);
EXPECT_EQ(numberOfCoincidentConstraints, 1);
@@ -587,8 +582,7 @@ TEST_F(SketchObjectTest, testTrimNonPeriodicBSplineMid)
// Only remaining: one line segment and the trimmed B-spline
EXPECT_EQ(getObject()->getHighestCurveIndex(), 3);
// There should be a "point-on-object" constraint on the intersecting curves
int numberOfPointOnObjectConstraints =
countConstraintsOfType(getObject(), Sketcher::PointOnObject);
int numberOfPointOnObjectConstraints = countConstraintsOfType(getObject(), Sketcher::PointOnObject);
EXPECT_EQ(numberOfPointOnObjectConstraints, 1);
int numberOfCoincidentConstraints = countConstraintsOfType(getObject(), Sketcher::Coincident);
EXPECT_EQ(numberOfCoincidentConstraints, 1);
@@ -740,9 +734,11 @@ TEST_F(SketchObjectTest, testTrimEndEffectOnUnrelatedTangent)
EXPECT_EQ(result, 0);
// TODO: find tangent and confirm nature
const auto& constraints = getObject()->Constraints.getValues();
auto tangIt = std::ranges::find(constraints,
Sketcher::ConstraintType::Tangent,
&Sketcher::Constraint::Type);
auto tangIt = std::ranges::find(
constraints,
Sketcher::ConstraintType::Tangent,
&Sketcher::Constraint::Type
);
EXPECT_NE(tangIt, constraints.end());
EXPECT_EQ((*tangIt)->FirstPos, Sketcher::PointPos::none);
EXPECT_EQ((*tangIt)->SecondPos, Sketcher::PointPos::none);
@@ -1067,9 +1063,7 @@ TEST_F(SketchObjectTest, testJoinCurvesWhenTangent)
EXPECT_EQ(getObject()->getHighestCurveIndex(), 0);
// TODO: Check the shape is conserved (how?)
// Check there is no C-0 knot (should be possible for the chosen example)
auto mults = static_cast<const Part::GeomBSplineCurve*>(getObject()->getGeometry(0))
->getMultiplicities();
EXPECT_TRUE(std::all_of(mults.begin(), mults.end(), [](auto mult) {
return mult >= 1;
}));
auto mults
= static_cast<const Part::GeomBSplineCurve*>(getObject()->getGeometry(0))->getMultiplicities();
EXPECT_TRUE(std::all_of(mults.begin(), mults.end(), [](auto mult) { return mult >= 1; }));
}

View File

@@ -107,12 +107,14 @@ std::unique_ptr<Part::GeomBSplineCurve> createTypicalNonPeriodicBSpline()
std::vector<double> weights(5, 1.0);
std::vector<double> knotsNonPeriodic = {0.0, 1.0, 2.0};
std::vector<int> multiplicitiesNonPeriodic = {degree + 1, 1, degree + 1};
return std::make_unique<Part::GeomBSplineCurve>(poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false);
return std::make_unique<Part::GeomBSplineCurve>(
poles,
weights,
knotsNonPeriodic,
multiplicitiesNonPeriodic,
degree,
false
);
}
std::unique_ptr<Part::GeomBSplineCurve> createTypicalPeriodicBSpline()
@@ -127,12 +129,14 @@ std::unique_ptr<Part::GeomBSplineCurve> createTypicalPeriodicBSpline()
std::vector<double> weights(5, 1.0);
std::vector<double> knotsPeriodic = {0.0, 0.3, 1.0, 1.5, 1.8, 2.0};
std::vector<int> multiplicitiesPeriodic(6, 1);
return std::make_unique<Part::GeomBSplineCurve>(poles,
weights,
knotsPeriodic,
multiplicitiesPeriodic,
degree,
true);
return std::make_unique<Part::GeomBSplineCurve>(
poles,
weights,
knotsPeriodic,
multiplicitiesPeriodic,
degree,
true
);
}
int countConstraintsOfType(const Sketcher::SketchObject* obj, const Sketcher::ConstraintType cType)
@@ -146,7 +150,8 @@ int countConstraintsOfType(const Sketcher::SketchObject* obj, const Sketcher::Co
Base::Vector3d getPointAtNormalizedParameter(const Part::GeomCurve& curve, double param)
{
return curve.pointAtParameter(curve.getFirstParameter()
+ (curve.getLastParameter() - curve.getFirstParameter()) * param);
return curve.pointAtParameter(
curve.getFirstParameter() + (curve.getLastParameter() - curve.getFirstParameter()) * param
);
}
} // namespace SketcherTestHelpers

View File

@@ -25,12 +25,8 @@ private:
// TODO: use shared_ptr or something else here?
Sketcher::SketchObject* _sketchobj;
std::string _docName;
std::vector<const char*> allowedTypes {"Vertex",
"Edge",
"ExternalEdge",
"H_Axis",
"V_Axis",
"RootPoint"};
std::vector<const char*>
allowedTypes {"Vertex", "Edge", "ExternalEdge", "H_Axis", "V_Axis", "RootPoint"};
};
namespace SketcherTestHelpers

View File

@@ -113,31 +113,33 @@ TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT
bspline.periodic = false;
double bsplineParam = 0.35;
std::vector<double*> params = {point.x,
point.y,
arcStart.x,
arcStart.y,
arcEnd.x,
arcEnd.y,
arcCenter.x,
arcCenter.y,
&arcRadius,
bSplineStart.x,
bSplineStart.y,
bSplineEnd.x,
bSplineEnd.y,
&bSplineControlPointsX[0],
&bSplineControlPointsY[0],
&bSplineControlPointsX[1],
&bSplineControlPointsY[1],
&bSplineControlPointsX[2],
&bSplineControlPointsY[2],
&bSplineControlPointsX[3],
&bSplineControlPointsY[3],
&bSplineControlPointsX[4],
&bSplineControlPointsY[4],
&desiredAngle,
&bsplineParam};
std::vector<double*> params = {
point.x,
point.y,
arcStart.x,
arcStart.y,
arcEnd.x,
arcEnd.y,
arcCenter.x,
arcCenter.y,
&arcRadius,
bSplineStart.x,
bSplineStart.y,
bSplineEnd.x,
bSplineEnd.y,
&bSplineControlPointsX[0],
&bSplineControlPointsY[0],
&bSplineControlPointsX[1],
&bSplineControlPointsY[1],
&bSplineControlPointsX[2],
&bSplineControlPointsY[2],
&bSplineControlPointsX[3],
&bSplineControlPointsY[3],
&bSplineControlPointsX[4],
&bSplineControlPointsY[4],
&desiredAngle,
&bsplineParam
};
params.insert(params.end(), weightsAsPtr.begin(), weightsAsPtr.end());
params.insert(params.end(), knotsAsPtr.begin(), knotsAsPtr.end());
@@ -146,13 +148,7 @@ TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT
System()->addConstraintArcRules(arc);
System()->addConstraintPointOnArc(point, arc, 0, true);
System()->addConstraintPointOnBSpline(point, bspline, &bsplineParam, 0, true);
System()->addConstraintAngleViaPointAndParam(bspline,
arc,
point,
&bsplineParam,
&desiredAngle,
0,
true);
System()->addConstraintAngleViaPointAndParam(bspline, arc, point, &bsplineParam, &desiredAngle, 0, true);
int solveResult = System()->solve(params);
if (solveResult == GCS::Success) {
System()->applySolution();
@@ -161,9 +157,10 @@ TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT
// Assert
EXPECT_EQ(solveResult, GCS::Success);
// is point on arc?
EXPECT_DOUBLE_EQ((arcRadius) * (arcRadius),
(pointX - arcCenterX) * (pointX - arcCenterX)
+ (pointY - arcCenterY) * (pointY - arcCenterY));
EXPECT_DOUBLE_EQ(
(arcRadius) * (arcRadius),
(pointX - arcCenterX) * (pointX - arcCenterX) + (pointY - arcCenterY) * (pointY - arcCenterY)
);
// is point on B-spline?
GCS::DeriVector2 pointAtBSplineParam = bspline.Value(bsplineParam, 1.0);
EXPECT_DOUBLE_EQ(pointAtBSplineParam.x, pointX);
@@ -174,8 +171,10 @@ TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT
double dprd;
// FIXME: This error is probably too high. Fixing this may require improving the solver,
// however.
EXPECT_NEAR(std::fabs(centerToPoint.crossProdZ(tangentBSplineAtPoint, dprd))
/ (centerToPoint.length() * tangentBSplineAtPoint.length()),
1.0,
0.005);
EXPECT_NEAR(
std::fabs(centerToPoint.crossProdZ(tangentBSplineAtPoint, dprd))
/ (centerToPoint.length() * tangentBSplineAtPoint.length()),
1.0,
0.005
);
}

View File

@@ -64,10 +64,12 @@ TEST_F(PropertySheetTest, isValidCellAddressNameInvalidNames) // NOLINT
TEST_F(PropertySheetTest, validAliases) // NOLINT
{
std::vector<std::string> validAliases {"Bork",
"Bork_de_bork"
"A",
"AA123456"};
std::vector<std::string> validAliases {
"Bork",
"Bork_de_bork"
"A",
"AA123456"
};
for (const auto& name : validAliases) {
EXPECT_TRUE(propertySheet()->isValidAlias(name))
<< "\"" << name << "\" was not accepted as an alias name, and should be";
@@ -76,11 +78,8 @@ TEST_F(PropertySheetTest, validAliases) // NOLINT
TEST_F(PropertySheetTest, invalidAliases) // NOLINT
{
std::vector<std::string> invalidAliases {"A1",
"ZZ1234",
"mm",
"no spaces allowed",
"\'NoLeadingQuotes"};
std::vector<std::string>
invalidAliases {"A1", "ZZ1234", "mm", "no spaces allowed", "\'NoLeadingQuotes"};
for (const auto& name : invalidAliases) {
EXPECT_FALSE(propertySheet()->isValidAlias(name))

View File

@@ -41,12 +41,14 @@ TEST_F(FileUtilitiesTest, humanReadableSizeBytesHasNoDecimal)
TEST_F(FileUtilitiesTest, humanReadableSizeOthersHaveDecimal)
{
constexpr std::array<uint64_t, 6> testSizes {1000,
123456,
123456789,
123456789013,
100000000000000,
std::numeric_limits<uint64_t>::max()};
constexpr std::array<uint64_t, 6> testSizes {
1000,
123456,
123456789,
123456789013,
100000000000000,
std::numeric_limits<uint64_t>::max()
};
for (const auto size : testSizes) {
auto result = Start::humanReadableSize(size);
EXPECT_NE(result.find('.'), std::string::npos);

View File

@@ -29,8 +29,7 @@ TEST(Collection, TestCopy)
EXPECT_EQ(copy.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), nullptr);
EXPECT_EQ(copy.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), nullptr);
EXPECT_EQ(copy.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), nullptr);
EXPECT_EQ(copy.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE),
nullptr);
EXPECT_EQ(copy.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), nullptr);
EXPECT_EQ(copy.getName(), "-"); // default name is "-"
EXPECT_EQ(copy.size(), 0);
}
@@ -45,8 +44,7 @@ TEST(Collection, TestCopyAssign)
EXPECT_EQ(copy.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), nullptr);
EXPECT_EQ(copy.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), nullptr);
EXPECT_EQ(copy.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), nullptr);
EXPECT_EQ(copy.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE),
nullptr);
EXPECT_EQ(copy.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), nullptr);
EXPECT_EQ(copy.getName(), "-"); // default name is "-"
EXPECT_EQ(copy.size(), 0);
}
@@ -59,10 +57,8 @@ TEST(Collection, TestClone)
EXPECT_EQ(pointer->entries().empty(), true);
EXPECT_EQ(pointer->getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH), nullptr);
EXPECT_EQ(pointer->getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE), nullptr);
EXPECT_EQ(pointer->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH),
nullptr);
EXPECT_EQ(pointer->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE),
nullptr);
EXPECT_EQ(pointer->getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH), nullptr);
EXPECT_EQ(pointer->getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE), nullptr);
EXPECT_EQ(pointer->getName(), "-"); // default name is "-"
EXPECT_EQ(pointer->size(), 0);
}

View File

@@ -11,14 +11,22 @@ TEST(ZipFile, TestValidity)
zipios::ZipFile zf;
EXPECT_EQ(zf.isValid(), false);
EXPECT_THROW(zf.entries(), zipios::InvalidStateException);
EXPECT_THROW(zf.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH),
zipios::InvalidStateException);
EXPECT_THROW(zf.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE),
zipios::InvalidStateException);
EXPECT_THROW(zf.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH),
zipios::InvalidStateException);
EXPECT_THROW(zf.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE),
zipios::InvalidStateException);
EXPECT_THROW(
zf.getEntry("inexistant", zipios::FileCollection::MatchPath::MATCH),
zipios::InvalidStateException
);
EXPECT_THROW(
zf.getEntry("inexistant", zipios::FileCollection::MatchPath::IGNORE),
zipios::InvalidStateException
);
EXPECT_THROW(
zf.getInputStream("inexistant", zipios::FileCollection::MatchPath::MATCH),
zipios::InvalidStateException
);
EXPECT_THROW(
zf.getInputStream("inexistant", zipios::FileCollection::MatchPath::IGNORE),
zipios::InvalidStateException
);
EXPECT_THROW(zf.getName(), zipios::InvalidStateException);
EXPECT_THROW(zf.size(), zipios::InvalidStateException);
zf.close();