App/Toponaming: Add tests for findTagInElementName

Also apply clang-tidy to that function, and fix an error with the postfix return.
This commit is contained in:
Chris Hennes
2023-07-15 22:47:08 -05:00
parent 15371a04f3
commit 2ad35ea03e
3 changed files with 202 additions and 65 deletions

View File

@@ -833,6 +833,125 @@ TEST(MappedName, startsWith)
EXPECT_EQ(mappedName.startsWith("WASD"), false);
}
TEST(MappedName, findTagInElementNameHexPositiveIndexNonrecursive)
{
// The non-recursive version will find just the last tag, prefixed by the POSTFIX_TAG (";:H").
// It consists of a tag (stored in hexadecimal) and a length (also stored in hex), separated by
// a colon. In this example, we expect the get ;:H1b:10,F as our element, which is a tag of
// 0x1b and an indicated length of 0x10 (16 bytes). So the output length is the position of the
// tag (36) minus the indicated length, giving 20.
// Arrange
Data::MappedName mappedName("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H1b:10,F");
long tagOutput {0};
int lenOutput {0};
std::string postfix;
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
EXPECT_EQ(tagOutput, 0x1b);// The tag
EXPECT_EQ(lenOutput, 20); // The calculated length based on the tag's length parameter
EXPECT_EQ(postfix, ";:H1b:10,F");
EXPECT_EQ(type, 'F');// F=Face
}
TEST(MappedName, findTagInElementNameDecPositiveIndexNonrecursive)
{
// Test backwards compatibility with the older style decimal tag storage.
// Arrange
Data::MappedName mappedName("#94;:G0;XTR;:T19:8,F;:T26,F;BND:-1:0;:T27:16,F");
long tagOutput {0};
int lenOutput {0};
std::string postfix;
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
EXPECT_EQ(tagOutput, 27);// The tag
EXPECT_EQ(lenOutput, 16);// The specified length
EXPECT_EQ(postfix, ";:T27:16,F");
EXPECT_EQ(type, 'F');// F=Face
}
TEST(MappedName, findTagInElementNameHexNegativeIndexNonrecursive)
{
// Test handling a negative index that is flipped to positive
// Arrange
Data::MappedName mappedName("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H-1b:10,F");
long tagOutput {0};
int lenOutput {0};
std::string postfix;
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
EXPECT_EQ(tagOutput, 0x1b);// The tag is returned positive, even though it was input negative
EXPECT_EQ(lenOutput, 20); // The calculated length based on the tag's length parameter
EXPECT_EQ(postfix, ";:H-1b:10,F");
EXPECT_EQ(type, 'F');// F=Face
}
TEST(MappedName, findTagInElementNameHexExpectedNegativeIndexNonrecursive)
{
// Test handling an untransformed negative index
// Arrange
Data::MappedName mappedName("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H-1b:10,F");
long tagOutput {0};
int lenOutput {0};
std::string postfix;
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, true, false);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
EXPECT_EQ(tagOutput, -0x1b);// The tag is returned negative
EXPECT_EQ(lenOutput, 20); // The calculated length based on the tag's length parameter
EXPECT_EQ(postfix, ";:H-1b:10,F");
EXPECT_EQ(type, 'F');// F=Face
}
TEST(MappedName, findTagInElementNameRecursive)
{
// Test the recursive resolution of the name
// Arrange
Data::MappedName mappedName("#94;:G0;XTR;:H19:8,F;:H1a,F;BND:-1:0;:H1b:10,F");
long tagOutput {0};
int lenOutput {0};
std::string postfix;
char type {0};
// Act
int result =
mappedName.findTagInElementName(&tagOutput, &lenOutput, &postfix, &type, false, true);
// Assert
EXPECT_EQ(result, 36); // The location of the tag
EXPECT_EQ(tagOutput, 0x1b);// The tag
EXPECT_EQ(lenOutput, 27); // Now includes the next tag, from the recursive search
EXPECT_EQ(postfix, ";:H1b:10,F");
EXPECT_EQ(type, 'F');// F=Face
}
TEST(MappedName, hash)
{
// Arrange