testDebuggerThread.cxx 1.7 KB

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