MCPcopy Create free account
hub / github.com/Kitware/VTK / TestStringToken

Function TestStringToken

Common/Core/Testing/Cxx/TestStringToken.cxx:15–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#include <iostream>
14
15int TestStringToken(int, char*[])
16{
17 using namespace vtk::literals; // for ""_token().
18 int result = 0;
19
20 vtkStringToken defaultToken; // default constructor should be Invalid token.
21 vtkStringToken eid("");
22 auto missing = "not present in manager because token constructed from hash, not string."_token;
23 vtkStringToken fooTheBar1("foo the bar");
24 auto fooTheBar2 = "foo the bar"_token;
25
26 std::cout << "default token is " << defaultToken.GetId() << "\n";
27 std::cout << "empty string is " << eid.GetId() << "\n";
28 std::cout << "missing is " << missing.GetId() << "\n";
29 std::cout << "foo the bar is " << fooTheBar1.GetId() << " == " << fooTheBar2.GetId() << "\n";
30
31 if (defaultToken.IsValid())
32 {
33 std::cerr << "ERROR: Default token constructor should be initialized to Invalid token\n";
34 }
35
36 std::vector<std::pair<std::string, vtkStringToken::Hash>> tests{ { { "", 2166136261u },
37 { "a", 3826002220u }, { "b", 3876335077u }, { "cell", 1759288501u }, { "curve", 2570585620u },
38 { "edge", 1459017788u }, { "face", 292255708u }, { "point", 414084241u },
39 { "surface", 425316092u }, { "vertex", 2488493991u }, { "volume", 786459023u } } };
40 for (const auto& test : tests)
41 {
42 vtkStringToken xx(test.first);
43 std::cout << " " << xx.GetId() << " \"" << test.first << "\"\n";
44 if (test.second != xx.GetId())
45 {
46 std::cerr << " ERROR: Expected " << test.second << " got " << xx.GetId() << "\n";
47 result = 1;
48 }
49 }
50
51 // Group some tokens into a named set (emulating a dynamic enumeration).
52
53 // I. Verify that there are no enumeration-sets to begin with.
54 auto groups = vtkStringToken::AllGroups();
55 if (!groups.empty())
56 {
57 std::cerr << "ERROR: Expected an empty set of keys, found " << groups.size() << "\n";
58 result = 1;
59 }
60
61 // Test adding an enumeration-set.
62 vtkStringToken geomEnum("geometries");
63 std::cout << "Create an enumeration set for \"geometries\" (" << geomEnum.GetId() << ")\n";
64 bool added = true;
65 added &= geomEnum.AddChild("point"_hash);
66 added &= geomEnum.AddChild("curve"_hash);
67 added &= geomEnum.AddChild("surface"_hash);
68 added &= geomEnum.AddChild("volume"_hash);
69 if (!added)
70 {
71 std::cerr << "ERROR: Failed to add at least 1 child.\n";
72 result = 1;

Callers

nothing calls this directly

Calls 8

ChildrenMethod · 0.80
GetIdMethod · 0.45
IsValidMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
AddChildMethod · 0.45
DataMethod · 0.45
RemoveChildMethod · 0.45

Tested by

no test coverage detected