ctkUtilsTest1.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*=========================================================================
  2. Library: qCTK
  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. // CTK includes
  11. #include "ctkUtils.h"
  12. // Qt includes
  13. #include <QStringList>
  14. // STD includes
  15. #include <stdlib.h>
  16. #include <iostream>
  17. #include <string>
  18. #include <vector>
  19. int ctkUtilsTest1(int argc, char * argv [] )
  20. {
  21. Q_UNUSED(argc);
  22. Q_UNUSED(argv);
  23. // Test qListToSTLVector(const QStringList& list, std::vector<char*>& vector)
  24. QStringList inputStringList;
  25. inputStringList << "Testing";
  26. inputStringList << " is ";
  27. inputStringList << "awesome !";
  28. std::vector<char*> outputCharVector;
  29. ctkUtils::qListToSTLVector(inputStringList, outputCharVector);
  30. if (outputCharVector.size() != 3)
  31. {
  32. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<char*>&)" << std::endl
  33. << "outputCharVector should contains 3 elements." << std::endl;
  34. return EXIT_FAILURE;
  35. }
  36. if ((strcmp(outputCharVector[0], "Testing") != 0) ||
  37. (strcmp(outputCharVector[1], " is ") != 0) ||
  38. (strcmp(outputCharVector[2], "awesome !") != 0))
  39. {
  40. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<char*>&)" << std::endl
  41. << "Content of outputCharVector is incorrect" << std::endl
  42. << "inputStringList[0] => [" << qPrintable(inputStringList[0]) << "]" << std::endl
  43. << "inputStringList[1] => [" << qPrintable(inputStringList[1]) << "]" << std::endl
  44. << "inputStringList[2] => [" << qPrintable(inputStringList[2]) << "]" << std::endl
  45. << "outputCharVector[0] => [" << outputCharVector[0] << "]" << std::endl
  46. << "outputCharVector[1] => [" << outputCharVector[1] << "]" << std::endl
  47. << "outputCharVector[2] => [" << outputCharVector[2] << "]" << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. delete [] outputCharVector[0];
  51. delete [] outputCharVector[1];
  52. delete [] outputCharVector[2];
  53. // Test qListToSTLVector(const QStringList& list, std::vector<std::string>& vector)
  54. std::vector<std::string> outputStringVector;
  55. ctkUtils::qListToSTLVector(inputStringList, outputStringVector);
  56. if (outputStringVector.size() != 3)
  57. {
  58. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<std::string>&)" << std::endl
  59. << "outputStringVector should contains 3 elements." << std::endl;
  60. return EXIT_FAILURE;
  61. }
  62. if ((outputStringVector[0].compare("Testing") != 0) ||
  63. (outputStringVector[1].compare(" is ") != 0) ||
  64. (outputStringVector[2].compare("awesome !") != 0))
  65. {
  66. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<std::string>&)" << std::endl
  67. << "Content of outputStringVector is incorrect" << std::endl
  68. << "inputStringList[0] => [" << qPrintable(inputStringList[0]) << "]" << std::endl
  69. << "inputStringList[1] => [" << qPrintable(inputStringList[1]) << "]" << std::endl
  70. << "inputStringList[2] => [" << qPrintable(inputStringList[2]) << "]" << std::endl
  71. << "outputStringVector[0] => [" << outputStringVector[0] << "]" << std::endl
  72. << "outputStringVector[1] => [" << outputStringVector[1] << "]" << std::endl
  73. << "outputStringVector[2] => [" << outputStringVector[2] << "]" << std::endl;
  74. return EXIT_FAILURE;
  75. }
  76. // Test stlVectorToQList(const std::vector<std::string>& vector, QStringList& list)
  77. std::vector<std::string> inputStringVector;
  78. inputStringVector.push_back("Testing");
  79. inputStringVector.push_back(" is ");
  80. inputStringVector.push_back("awesome !");
  81. QStringList ouputStringList;
  82. ctkUtils::stlVectorToQList(inputStringVector, ouputStringList);
  83. if (ouputStringList.size() != 3)
  84. {
  85. std::cerr << "Error in stlVectorToQList(const std::vector<std::string>&, QStringList&)" << std::endl
  86. << "ouputStringList should contains 3 elements." << std::endl;
  87. return EXIT_FAILURE;
  88. }
  89. if ((ouputStringList[0] != QLatin1String("Testing")) ||
  90. (ouputStringList[1] != QLatin1String(" is ")) ||
  91. (ouputStringList[2] != QLatin1String("awesome !")))
  92. {
  93. std::cerr << "Error in stlVectorToQList(const std::vector<std::string>&, QStringList&)" << std::endl
  94. << "Content of ouputStringList is incorrect" << std::endl
  95. << "inputStringVector[0] => [" << inputStringVector[0] << "]" << std::endl
  96. << "inputStringVector[1] => [" << inputStringVector[1] << "]" << std::endl
  97. << "inputStringVector[2] => [" << inputStringVector[2] << "]" << std::endl
  98. << "ouputStringList[0] => [" << qPrintable(ouputStringList[0]) << "]" << std::endl
  99. << "ouputStringList[1] => [" << qPrintable(ouputStringList[1]) << "]" << std::endl
  100. << "ouputStringList[2] => [" << qPrintable(ouputStringList[2]) << "]" << std::endl;
  101. return EXIT_FAILURE;
  102. }
  103. return EXIT_SUCCESS;
  104. }