ctkUtilsTest1.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. // Qt includes
  11. #include <QStringList>
  12. // CTK includes
  13. #include "ctkUtils.h"
  14. // STD includes
  15. #include <stdlib.h>
  16. #include <iostream>
  17. #include <string>
  18. #include <vector>
  19. //-----------------------------------------------------------------------------
  20. int ctkUtilsTest1(int argc, char * argv [] )
  21. {
  22. Q_UNUSED(argc);
  23. Q_UNUSED(argv);
  24. // Test qListToSTLVector(const QStringList& list, std::vector<char*>& vector)
  25. QStringList inputStringList;
  26. inputStringList << "Testing";
  27. inputStringList << " is ";
  28. inputStringList << "awesome !";
  29. std::vector<char*> outputCharVector;
  30. ctkUtils::qListToSTLVector(inputStringList, outputCharVector);
  31. if (outputCharVector.size() != 3)
  32. {
  33. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<char*>&)" << std::endl
  34. << "outputCharVector should contains 3 elements." << std::endl;
  35. return EXIT_FAILURE;
  36. }
  37. if ((strcmp(outputCharVector[0], "Testing") != 0) ||
  38. (strcmp(outputCharVector[1], " is ") != 0) ||
  39. (strcmp(outputCharVector[2], "awesome !") != 0))
  40. {
  41. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<char*>&)" << std::endl
  42. << "Content of outputCharVector is incorrect" << std::endl
  43. << "inputStringList[0] => [" << qPrintable(inputStringList[0]) << "]" << std::endl
  44. << "inputStringList[1] => [" << qPrintable(inputStringList[1]) << "]" << std::endl
  45. << "inputStringList[2] => [" << qPrintable(inputStringList[2]) << "]" << std::endl
  46. << "outputCharVector[0] => [" << outputCharVector[0] << "]" << std::endl
  47. << "outputCharVector[1] => [" << outputCharVector[1] << "]" << std::endl
  48. << "outputCharVector[2] => [" << outputCharVector[2] << "]" << std::endl;
  49. return EXIT_FAILURE;
  50. }
  51. delete [] outputCharVector[0];
  52. delete [] outputCharVector[1];
  53. delete [] outputCharVector[2];
  54. // Test qListToSTLVector(const QStringList& list, std::vector<std::string>& vector)
  55. std::vector<std::string> outputStringVector;
  56. ctkUtils::qListToSTLVector(inputStringList, outputStringVector);
  57. if (outputStringVector.size() != 3)
  58. {
  59. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<std::string>&)" << std::endl
  60. << "outputStringVector should contains 3 elements." << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. if ((outputStringVector[0].compare("Testing") != 0) ||
  64. (outputStringVector[1].compare(" is ") != 0) ||
  65. (outputStringVector[2].compare("awesome !") != 0))
  66. {
  67. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<std::string>&)" << std::endl
  68. << "Content of outputStringVector is incorrect" << std::endl
  69. << "inputStringList[0] => [" << qPrintable(inputStringList[0]) << "]" << std::endl
  70. << "inputStringList[1] => [" << qPrintable(inputStringList[1]) << "]" << std::endl
  71. << "inputStringList[2] => [" << qPrintable(inputStringList[2]) << "]" << std::endl
  72. << "outputStringVector[0] => [" << outputStringVector[0] << "]" << std::endl
  73. << "outputStringVector[1] => [" << outputStringVector[1] << "]" << std::endl
  74. << "outputStringVector[2] => [" << outputStringVector[2] << "]" << std::endl;
  75. return EXIT_FAILURE;
  76. }
  77. // Test stlVectorToQList(const std::vector<std::string>& vector, QStringList& list)
  78. std::vector<std::string> inputStringVector;
  79. inputStringVector.push_back("Testing");
  80. inputStringVector.push_back(" is ");
  81. inputStringVector.push_back("awesome !");
  82. QStringList ouputStringList;
  83. ctkUtils::stlVectorToQList(inputStringVector, ouputStringList);
  84. if (ouputStringList.size() != 3)
  85. {
  86. std::cerr << "Error in stlVectorToQList(const std::vector<std::string>&, QStringList&)" << std::endl
  87. << "ouputStringList should contains 3 elements." << std::endl;
  88. return EXIT_FAILURE;
  89. }
  90. if ((ouputStringList[0] != QLatin1String("Testing")) ||
  91. (ouputStringList[1] != QLatin1String(" is ")) ||
  92. (ouputStringList[2] != QLatin1String("awesome !")))
  93. {
  94. std::cerr << "Error in stlVectorToQList(const std::vector<std::string>&, QStringList&)" << std::endl
  95. << "Content of ouputStringList is incorrect" << std::endl
  96. << "inputStringVector[0] => [" << inputStringVector[0] << "]" << std::endl
  97. << "inputStringVector[1] => [" << inputStringVector[1] << "]" << std::endl
  98. << "inputStringVector[2] => [" << inputStringVector[2] << "]" << std::endl
  99. << "ouputStringList[0] => [" << qPrintable(ouputStringList[0]) << "]" << std::endl
  100. << "ouputStringList[1] => [" << qPrintable(ouputStringList[1]) << "]" << std::endl
  101. << "ouputStringList[2] => [" << qPrintable(ouputStringList[2]) << "]" << std::endl;
  102. return EXIT_FAILURE;
  103. }
  104. return EXIT_SUCCESS;
  105. }