ctkUtilsTest1.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QStringList>
  16. // CTK includes
  17. #include "ctkUtils.h"
  18. // STD includes
  19. #include <cstdlib>
  20. #include <iostream>
  21. #include <string>
  22. #include <vector>
  23. //-----------------------------------------------------------------------------
  24. int ctkUtilsTest1(int argc, char * argv [] )
  25. {
  26. Q_UNUSED(argc);
  27. Q_UNUSED(argv);
  28. // Test qListToSTLVector(const QStringList& list, std::vector<char*>& vector)
  29. QStringList inputStringList;
  30. inputStringList << "Testing";
  31. inputStringList << " is ";
  32. inputStringList << "awesome !";
  33. std::vector<char*> outputCharVector;
  34. ctk::qListToSTLVector(inputStringList, outputCharVector);
  35. if (outputCharVector.size() != 3)
  36. {
  37. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<char*>&)" << std::endl
  38. << "outputCharVector should contains 3 elements." << std::endl;
  39. return EXIT_FAILURE;
  40. }
  41. if ((strcmp(outputCharVector[0], "Testing") != 0) ||
  42. (strcmp(outputCharVector[1], " is ") != 0) ||
  43. (strcmp(outputCharVector[2], "awesome !") != 0))
  44. {
  45. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<char*>&)" << std::endl
  46. << "Content of outputCharVector is incorrect" << std::endl
  47. << "inputStringList[0] => [" << qPrintable(inputStringList[0]) << "]" << std::endl
  48. << "inputStringList[1] => [" << qPrintable(inputStringList[1]) << "]" << std::endl
  49. << "inputStringList[2] => [" << qPrintable(inputStringList[2]) << "]" << std::endl
  50. << "outputCharVector[0] => [" << outputCharVector[0] << "]" << std::endl
  51. << "outputCharVector[1] => [" << outputCharVector[1] << "]" << std::endl
  52. << "outputCharVector[2] => [" << outputCharVector[2] << "]" << std::endl;
  53. return EXIT_FAILURE;
  54. }
  55. delete [] outputCharVector[0];
  56. delete [] outputCharVector[1];
  57. delete [] outputCharVector[2];
  58. // Test qListToSTLVector(const QStringList& list, std::vector<std::string>& vector)
  59. std::vector<std::string> outputStringVector;
  60. ctk::qListToSTLVector(inputStringList, outputStringVector);
  61. if (outputStringVector.size() != 3)
  62. {
  63. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<std::string>&)" << std::endl
  64. << "outputStringVector should contains 3 elements." << std::endl;
  65. return EXIT_FAILURE;
  66. }
  67. if ((outputStringVector[0].compare("Testing") != 0) ||
  68. (outputStringVector[1].compare(" is ") != 0) ||
  69. (outputStringVector[2].compare("awesome !") != 0))
  70. {
  71. std::cerr << "Error in qListToSTLVector(const QStringList&, std::vector<std::string>&)" << std::endl
  72. << "Content of outputStringVector is incorrect" << std::endl
  73. << "inputStringList[0] => [" << qPrintable(inputStringList[0]) << "]" << std::endl
  74. << "inputStringList[1] => [" << qPrintable(inputStringList[1]) << "]" << std::endl
  75. << "inputStringList[2] => [" << qPrintable(inputStringList[2]) << "]" << std::endl
  76. << "outputStringVector[0] => [" << outputStringVector[0] << "]" << std::endl
  77. << "outputStringVector[1] => [" << outputStringVector[1] << "]" << std::endl
  78. << "outputStringVector[2] => [" << outputStringVector[2] << "]" << std::endl;
  79. return EXIT_FAILURE;
  80. }
  81. // Test stlVectorToQList(const std::vector<std::string>& vector, QStringList& list)
  82. std::vector<std::string> inputStringVector;
  83. inputStringVector.push_back("Testing");
  84. inputStringVector.push_back(" is ");
  85. inputStringVector.push_back("awesome !");
  86. QStringList ouputStringList;
  87. ctk::stlVectorToQList(inputStringVector, ouputStringList);
  88. if (ouputStringList.size() != 3)
  89. {
  90. std::cerr << "Error in stlVectorToQList(const std::vector<std::string>&, QStringList&)" << std::endl
  91. << "ouputStringList should contains 3 elements." << std::endl;
  92. return EXIT_FAILURE;
  93. }
  94. if ((ouputStringList[0] != QLatin1String("Testing")) ||
  95. (ouputStringList[1] != QLatin1String(" is ")) ||
  96. (ouputStringList[2] != QLatin1String("awesome !")))
  97. {
  98. std::cerr << "Error in stlVectorToQList(const std::vector<std::string>&, QStringList&)" << std::endl
  99. << "Content of ouputStringList is incorrect" << std::endl
  100. << "inputStringVector[0] => [" << inputStringVector[0] << "]" << std::endl
  101. << "inputStringVector[1] => [" << inputStringVector[1] << "]" << std::endl
  102. << "inputStringVector[2] => [" << inputStringVector[2] << "]" << std::endl
  103. << "ouputStringList[0] => [" << qPrintable(ouputStringList[0]) << "]" << std::endl
  104. << "ouputStringList[1] => [" << qPrintable(ouputStringList[1]) << "]" << std::endl
  105. << "ouputStringList[2] => [" << qPrintable(ouputStringList[2]) << "]" << std::endl;
  106. return EXIT_FAILURE;
  107. }
  108. return EXIT_SUCCESS;
  109. }