DwarfTests.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright 2014-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <folly/experimental/symbolizer/Dwarf.h>
  17. #include <folly/portability/GTest.h>
  18. using folly::symbolizer::Dwarf;
  19. void checkPath(
  20. std::string expectedPath,
  21. std::string expectedBaseDir,
  22. std::string expectedSubDir,
  23. std::string expectedFile,
  24. std::string rawBaseDir,
  25. std::string rawSubDir,
  26. std::string rawFile) {
  27. Dwarf::Path path(rawBaseDir, rawSubDir, rawFile);
  28. CHECK_EQ(expectedBaseDir, path.baseDir())
  29. << "Path(" << rawBaseDir << ", " << rawSubDir << ", " << rawFile << ")";
  30. CHECK_EQ(expectedSubDir, path.subDir())
  31. << "Path(" << rawBaseDir << ", " << rawSubDir << ", " << rawFile << ")";
  32. CHECK_EQ(expectedFile, path.file())
  33. << "Path(" << rawBaseDir << ", " << rawSubDir << ", " << rawFile << ")";
  34. CHECK_EQ(expectedPath, path.toString());
  35. // Check the the `toBuffer` function.
  36. char buf[1024];
  37. size_t len;
  38. len = path.toBuffer(buf, 1024);
  39. CHECK_EQ(expectedPath, std::string(buf, len));
  40. }
  41. TEST(Dwarf, Path) {
  42. checkPath("hello.cpp", "", "", "hello.cpp", "", "", "hello.cpp");
  43. checkPath("foo/hello.cpp", "foo", "", "hello.cpp", "foo", "", "hello.cpp");
  44. checkPath("foo/hello.cpp", "foo", "", "hello.cpp", "", "foo", "hello.cpp");
  45. checkPath("hello.cpp", "", "", "hello.cpp", "./////", "./////", "hello.cpp");
  46. checkPath("/hello.cpp", "/", "", "hello.cpp", "/////", "./////", "hello.cpp");
  47. checkPath(
  48. "/hello.cpp", "/", "", "hello.cpp", "/./././././././", "", "hello.cpp");
  49. }