ctkDICOMPersonNameTest1.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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 <QCoreApplication>
  16. #include <QTimer>
  17. // ctkDICOMCore includes
  18. #include "ctkDICOMPersonName.h"
  19. // STD includes
  20. #include <iostream>
  21. #include <cstdlib>
  22. int ctkDICOMPersonNameTest1( int argc, char * argv [] )
  23. {
  24. QCoreApplication app(argc, argv);
  25. ctkDICOMPersonName personName("lastName", "firstName", "middleName", "namePrefix", "nameSuffix");
  26. if (personName.lastName() != "lastName")
  27. {
  28. std::cerr << "ctkDICOMPersonName::lastName() failed:"
  29. << qPrintable(personName.lastName()) << std::endl;
  30. return EXIT_FAILURE;
  31. }
  32. if (personName.firstName() != "firstName")
  33. {
  34. std::cerr << "ctkDICOMPersonName::firstName() failed:"
  35. << qPrintable(personName.firstName()) << std::endl;
  36. return EXIT_FAILURE;
  37. }
  38. if (personName.middleName() != "middleName")
  39. {
  40. std::cerr << "ctkDICOMPersonName::middleName() failed:"
  41. << qPrintable(personName.middleName()) << std::endl;
  42. return EXIT_FAILURE;
  43. }
  44. if (personName.namePrefix() != "namePrefix")
  45. {
  46. std::cerr << "ctkDICOMPersonName::namePrefix() failed:"
  47. << qPrintable(personName.namePrefix()) << std::endl;
  48. return EXIT_FAILURE;
  49. }
  50. if (personName.nameSuffix() != "nameSuffix")
  51. {
  52. std::cerr << "ctkDICOMPersonName::nameSuffix() failed:"
  53. << qPrintable(personName.nameSuffix()) << std::endl;
  54. return EXIT_FAILURE;
  55. }
  56. if (personName.formattedName() != "lastName, firstName middleName, nameSuffix")
  57. {
  58. std::cerr << "ctkDICOMPersonName::nameSuffix() failed:"
  59. << qPrintable(personName.formattedName()) << std::endl;
  60. return EXIT_FAILURE;
  61. }
  62. // test operator QString()
  63. if (QString(personName) != QString("lastName, firstName middleName, nameSuffix"))
  64. {
  65. std::cerr << "ctkDICOMPersonName::nameSuffix() failed:"
  66. << qPrintable(QString(personName)) << std::endl;
  67. return EXIT_FAILURE;
  68. }
  69. // test toStdString()
  70. // TODO: make it fail
  71. if (personName.toStdString() != std::string("lastName, firstName middleName, nameSuffix"))
  72. {
  73. std::cerr << "ctkDICOMPersonName::nameSuffix() failed:"
  74. << personName.toStdString() << std::endl;
  75. return EXIT_FAILURE;
  76. }
  77. ctkDICOMPersonName samePersonName(personName);
  78. if (samePersonName.lastName() != personName.lastName() ||
  79. samePersonName.firstName() != personName.firstName() ||
  80. samePersonName.middleName() != personName.middleName() ||
  81. samePersonName.namePrefix() != personName.namePrefix() ||
  82. samePersonName.nameSuffix() != personName.nameSuffix() ||
  83. samePersonName.formattedName() != personName.formattedName())
  84. {
  85. std::cerr << "ctkDICOMPersonName::ctkDICOMPersonName(ctkDICOMPersonName&) failed:"
  86. << qPrintable(samePersonName.formattedName()) << std::endl;
  87. return EXIT_FAILURE;
  88. }
  89. ctkDICOMPersonName otherPerson("just a last name");
  90. if (otherPerson.lastName() != "just a last name" ||
  91. !otherPerson.firstName().isEmpty() ||
  92. !otherPerson.middleName().isEmpty() ||
  93. !otherPerson.namePrefix().isEmpty() ||
  94. !otherPerson.nameSuffix().isEmpty() ||
  95. otherPerson.formattedName() != "just a last name")
  96. {
  97. std::cerr << "ctkDICOMPersonName with empty fields failed:"
  98. << qPrintable(otherPerson.formattedName()) << std::endl;
  99. return EXIT_FAILURE;
  100. }
  101. otherPerson = samePersonName;
  102. if (otherPerson.lastName() != personName.lastName() ||
  103. otherPerson.firstName() != personName.firstName() ||
  104. otherPerson.middleName() != personName.middleName() ||
  105. otherPerson.namePrefix() != personName.namePrefix() ||
  106. otherPerson.nameSuffix() != personName.nameSuffix() ||
  107. otherPerson.formattedName() != personName.formattedName())
  108. {
  109. std::cerr << "ctkDICOMPersonName::operator=(const ctkDICOMPersonName&) failed:"
  110. << qPrintable(otherPerson.formattedName()) << std::endl;
  111. return EXIT_FAILURE;
  112. }
  113. if (argc <= 1 || QString(argv[1]) != "-I")
  114. {
  115. QTimer::singleShot(200, &app, SLOT(quit()));
  116. }
  117. return app.exec();
  118. }