ctkAbstractPythonManagerTest1.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // CTK includes
  2. #include "ctkAbstractPythonManager.h"
  3. // PythonQt includes
  4. #include <PythonQt.h>
  5. // STD includes
  6. #include <cstdlib>
  7. #include <iostream>
  8. //-----------------------------------------------------------------------------
  9. int ctkAbstractPythonManagerTest1(int argc, char * argv [] )
  10. {
  11. Q_UNUSED(argc);
  12. Q_UNUSED(argv);
  13. ctkAbstractPythonManager pythonManager;
  14. if (pythonManager.isPythonInitialized())
  15. {
  16. std::cerr << "Line " << __LINE__ << " - Problem with isPythonInitialized()" << std::endl;
  17. return EXIT_FAILURE;
  18. }
  19. pythonManager.mainContext();
  20. if (!pythonManager.isPythonInitialized())
  21. {
  22. std::cerr << "Line " << __LINE__ << " - Problem with isPythonInitialized()" << std::endl;
  23. return EXIT_FAILURE;
  24. }
  25. pythonManager.executeString("a = 6542");
  26. if (pythonManager.getVariable("a").toInt() != 6542)
  27. {
  28. std::cerr << "Line " << __LINE__ << " - Problem with executeString()" << std::endl;
  29. return EXIT_FAILURE;
  30. }
  31. // Expected to return an empty value
  32. QVariant result = pythonManager.executeString("6542");
  33. if (!result.isNull())
  34. {
  35. std::cerr << "Line " << __LINE__ << " - Problem with executeString()" << std::endl;
  36. return EXIT_FAILURE;
  37. }
  38. // Expected to fail
  39. result = pythonManager.executeString("b = 6542", ctkAbstractPythonManager::EvalInput);
  40. if (!result.isNull())
  41. {
  42. std::cerr << "Line " << __LINE__ << " - Problem with executeString()" << std::endl;
  43. return EXIT_FAILURE;
  44. }
  45. result = pythonManager.executeString("7", ctkAbstractPythonManager::EvalInput);
  46. if (result.toInt() != 7)
  47. {
  48. std::cerr << "Line " << __LINE__ << " - Problem with executeString()" << std::endl;
  49. return EXIT_FAILURE;
  50. }
  51. return EXIT_SUCCESS;
  52. }