ctkCheckBoxPixmapsTest1.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.commontk.org/LICENSE
  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 <QApplication>
  16. // CTK includes
  17. #include "ctkCheckBoxPixmaps.h"
  18. // STD includes
  19. #include <cstdlib>
  20. #include <iostream>
  21. //-----------------------------------------------------------------------------
  22. int ctkCheckBoxPixmapsTest1(int argc, char * argv [] )
  23. {
  24. QApplication app(argc, argv);
  25. ctkCheckBoxPixmaps checkBoxPixmaps;
  26. // make sure all the pixmaps are valid
  27. if (checkBoxPixmaps.pixmap(Qt::Checked, true).isNull())
  28. {
  29. std::cerr << "Failed to create active Qt::Checked pixmap" << std::endl;
  30. return EXIT_FAILURE;
  31. }
  32. if (checkBoxPixmaps.pixmap(Qt::PartiallyChecked, true).isNull())
  33. {
  34. std::cerr << "Failed to create active Qt::PartiallyChecked pixmap" << std::endl;
  35. return EXIT_FAILURE;
  36. }
  37. if (checkBoxPixmaps.pixmap(Qt::Unchecked, true).isNull())
  38. {
  39. std::cerr << "Failed to create active Qt::Unchecked pixmap" << std::endl;
  40. return EXIT_FAILURE;
  41. }
  42. if (checkBoxPixmaps.pixmap(Qt::Checked, false).isNull())
  43. {
  44. std::cerr << "Failed to create unactive Qt::Checked pixmap" << std::endl;
  45. return EXIT_FAILURE;
  46. }
  47. if (checkBoxPixmaps.pixmap(Qt::PartiallyChecked, false).isNull())
  48. {
  49. std::cerr << "Failed to create unactive Qt::PartiallyChecked pixmap" << std::endl;
  50. return EXIT_FAILURE;
  51. }
  52. if (checkBoxPixmaps.pixmap(Qt::Unchecked, false).isNull())
  53. {
  54. std::cerr << "Failed to create unactive Qt::Unchecked pixmap" << std::endl;
  55. return EXIT_FAILURE;
  56. }
  57. // check the int version of the ctkCheckBoxPixmaps::pixmap()
  58. if (checkBoxPixmaps.pixmap(0, false).isNull())
  59. {
  60. std::cerr << "Failed to create unactive Qt::Checked pixmap" << std::endl;
  61. return EXIT_FAILURE;
  62. }
  63. // Same pixmap ?
  64. const QPixmap& p1 = checkBoxPixmaps.pixmap(Qt::PartiallyChecked, false);
  65. const QPixmap& p2 = checkBoxPixmaps.pixmap(Qt::PartiallyChecked, false);
  66. if ( &p1 != &p2)
  67. {
  68. std::cerr << "The returned pixmap should be the same" << std::endl;
  69. return EXIT_FAILURE;
  70. }
  71. // Same pixmap ?
  72. if (&checkBoxPixmaps.pixmap(Qt::Unchecked, false) ==
  73. &checkBoxPixmaps.pixmap(Qt::Unchecked, true))
  74. {
  75. std::cerr << "The returned pixmaps should not be the same" << std::endl;
  76. return EXIT_FAILURE;
  77. }
  78. return EXIT_SUCCESS;
  79. }