testDebuggerThread.cxx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include <memory>
  2. #include <string>
  3. #include <vector>
  4. #include <cmext/string_view>
  5. #include <cm3p/cppdap/optional.h>
  6. #include <cm3p/cppdap/protocol.h>
  7. #include <cm3p/cppdap/types.h>
  8. #include "cmDebuggerThread.h"
  9. #include "cmListFileCache.h"
  10. #include "testCommon.h"
  11. static bool testStackFrameFunctionName(
  12. dap::optional<dap::StackFrameFormat> format, char const* expectedName)
  13. {
  14. auto thread = std::make_shared<cmDebugger::cmDebuggerThread>(0, "name");
  15. auto const* functionName = "function_name";
  16. auto arguments = std::vector<cmListFileArgument>{ cmListFileArgument(
  17. "arg"_s, cmListFileArgument::Delimiter::Unquoted, 0) };
  18. cmListFileFunction func(functionName, 10, 20, arguments);
  19. thread->PushStackFrame(nullptr, "CMakeLists.txt", func);
  20. auto stackTrace = GetStackTraceResponse(thread, format);
  21. ASSERT_TRUE(stackTrace.stackFrames[0].name == expectedName);
  22. return true;
  23. }
  24. bool testStackFrameNoFormatting()
  25. {
  26. return testStackFrameFunctionName({}, "function_name");
  27. }
  28. bool testStackFrameFormatParameters()
  29. {
  30. dap::StackFrameFormat format;
  31. format.parameters = true;
  32. return testStackFrameFunctionName(format, "function_name()");
  33. }
  34. bool testStackFrameFormatParameterValues()
  35. {
  36. dap::StackFrameFormat format;
  37. format.parameters = true;
  38. format.parameterValues = true;
  39. return testStackFrameFunctionName(format, "function_name(arg)");
  40. }
  41. bool testStackFrameFormatLine()
  42. {
  43. dap::StackFrameFormat format;
  44. format.line = true;
  45. return testStackFrameFunctionName(format, "function_name Line: 10");
  46. }
  47. int testDebuggerThread(int, char*[])
  48. {
  49. return runTests({ testStackFrameNoFormatting, testStackFrameFormatParameters,
  50. testStackFrameFormatParameterValues,
  51. testStackFrameFormatLine });
  52. }