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

Function TestResourceFileLocator

Common/Misc/Testing/Cxx/TestResourceFileLocator.cxx:12–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10#include <iostream>
11
12int TestResourceFileLocator(int, char*[])
13{
14 auto vtklib = vtkGetLibraryPathForSymbol(GetVTKVersion);
15 if (vtklib.empty())
16 {
17 std::cerr << "FAILED to locate `GetVTKVersion`." << std::endl;
18 return EXIT_FAILURE;
19 }
20
21 vtkNew<vtkResourceFileLocator> locator;
22 locator->SetLogVerbosity(vtkLogger::VERBOSITY_INFO);
23
24 // ------------------------------------------------------------
25 // Test: new unified API
26 // ------------------------------------------------------------
27 auto pathFromAddress =
28 vtkResourceFileLocator::GetLibraryPathForAddress(reinterpret_cast<const void*>(&GetVTKVersion));
29
30 if (pathFromAddress.empty())
31 {
32 std::cerr << "FAILED to locate 'Testing/Temporary' dir." << std::endl;
33 return EXIT_FAILURE;
34 }
35
36 std::string libDir = vtksys::SystemTools::GetFilenamePath(pathFromAddress);
37 if (!vtksys::SystemTools::FileIsDirectory(libDir))
38 {
39 std::cerr << "FAILED: Library directory from GetLibraryPathForAddress() does not exist: "
40 << libDir << "\n";
41 return EXIT_FAILURE;
42 }
43
44 // ------------------------------------------------------------
45 // Test: legacy macro API (kept for compatibility)
46 // ------------------------------------------------------------
47 auto pathFromMacro = vtkGetLibraryPathForSymbol(GetVTKVersion);
48 if (pathFromMacro.empty())
49 {
50 std::cerr << "FAILED: vtkGetLibraryPathForSymbol() macro returned empty path.\n";
51 return EXIT_FAILURE;
52 }
53
54 // ------------------------------------------------------------
55 // Test: Locate(anchor, landmark)
56 // Look for directory that should exist in build tree
57 // ------------------------------------------------------------
58 auto located1 = locator->Locate(libDir, "Testing/Temporary");
59 if (located1.empty())
60 {
61 std::cerr << "FAILED: Locate() did not find Testing/Temporary relative to library dir.\n";
62 return EXIT_FAILURE;
63 }
64
65 // verify the directory is real
66 if (!vtksys::SystemTools::FileIsDirectory(located1))
67 {
68 std::cerr << "FAILED: Located path is not a directory: " << located1 << "\n";
69 return EXIT_FAILURE;

Callers

nothing calls this directly

Calls 3

SetLogVerbosityMethod · 0.80
LocateMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected