Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* Copyright 2019 Pierre Ossman <ossman@cendio.se> for Cendio AB
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. #include <stdio.h>
  19. #include <rfb/PixelFormat.h>
  20. #include <rfb/Exception.h>
  21. static void doTest(bool should_fail, int b, int d, bool e, bool t,
  22. int rm, int gm, int bm, int rs, int gs, int bs)
  23. {
  24. rfb::PixelFormat* pf;
  25. printf("PixelFormat(%d, %d, %s, %s, %d, %d, %d, %d, %d, %d): ",
  26. b, d, e ? "true" : "false", t ? "true": "false",
  27. rm, gm, bm, rs, gs, bs);
  28. try {
  29. pf = new rfb::PixelFormat(b, d, e, t, rm, gm, bm, rs, gs, bs);
  30. } catch(rfb::Exception &e) {
  31. if (should_fail)
  32. printf("OK");
  33. else
  34. printf("FAILED");
  35. printf("\n");
  36. fflush(stdout);
  37. return;
  38. }
  39. delete pf;
  40. if (should_fail)
  41. printf("FAILED");
  42. else
  43. printf("OK");
  44. printf("\n");
  45. fflush(stdout);
  46. }
  47. static void do888Test(bool expected, int b, int d, bool e, bool t,
  48. int rm, int gm, int bm, int rs, int gs, int bs)
  49. {
  50. rfb::PixelFormat* pf;
  51. printf("PixelFormat(%d, %d, %s, %s, %d, %d, %d, %d, %d, %d): ",
  52. b, d, e ? "true" : "false", t ? "true": "false",
  53. rm, gm, bm, rs, gs, bs);
  54. pf = new rfb::PixelFormat(b, d, e, t, rm, gm, bm, rs, gs, bs);
  55. if (pf->is888() == expected)
  56. printf("OK");
  57. else
  58. printf("FAILED");
  59. printf("\n");
  60. fflush(stdout);
  61. delete pf;
  62. }
  63. static void sanityTests()
  64. {
  65. printf("Sanity checks:\n\n");
  66. /* Normal true color formats */
  67. doTest(false, 32, 24, false, true, 255, 255, 255, 0, 8, 16);
  68. doTest(false, 32, 24, false, true, 255, 255, 255, 24, 16, 8);
  69. doTest(false, 16, 16, false, true, 15, 31, 15, 0, 5, 11);
  70. doTest(false, 8, 8, false, true, 3, 7, 3, 0, 2, 5);
  71. /* Excessive bpp */
  72. doTest(false, 32, 16, false, true, 15, 31, 15, 0, 5, 11);
  73. doTest(false, 16, 16, false, true, 15, 31, 15, 0, 5, 11);
  74. doTest(false, 32, 8, false, true, 3, 7, 3, 0, 2, 5);
  75. doTest(false, 16, 8, false, true, 3, 7, 3, 0, 2, 5);
  76. /* Colour map */
  77. doTest(false, 8, 8, false, false, 0, 0, 0, 0, 0, 0);
  78. /* Invalid bpp */
  79. doTest(true, 64, 24, false, true, 255, 255, 255, 0, 8, 16);
  80. doTest(true, 18, 16, false, true, 15, 31, 15, 0, 5, 11);
  81. doTest(true, 3, 3, false, true, 1, 1, 1, 0, 1, 2);
  82. /* Invalid depth */
  83. doTest(true, 16, 24, false, true, 15, 31, 15, 0, 5, 11);
  84. doTest(true, 8, 24, false, true, 3, 7, 3, 0, 2, 5);
  85. doTest(true, 8, 16, false, true, 3, 7, 3, 0, 2, 5);
  86. doTest(true, 32, 24, false, false, 0, 0, 0, 0, 0, 0);
  87. /* Invalid max values */
  88. doTest(true, 32, 24, false, true, 254, 255, 255, 0, 8, 16);
  89. doTest(true, 32, 24, false, true, 255, 253, 255, 0, 8, 16);
  90. doTest(true, 32, 24, false, true, 255, 255, 252, 0, 8, 16);
  91. doTest(true, 32, 24, false, true, 511, 127, 127, 0, 16, 20);
  92. doTest(true, 32, 24, false, true, 127, 511, 127, 0, 4, 20);
  93. doTest(true, 32, 24, false, true, 127, 127, 511, 0, 4, 8);
  94. /* Insufficient depth */
  95. doTest(true, 32, 16, false, true, 255, 255, 255, 0, 8, 16);
  96. /* Invalid shift values */
  97. doTest(true, 32, 24, false, true, 255, 255, 255, 25, 8, 16);
  98. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 25, 16);
  99. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 8, 25);
  100. /* Overlapping channels */
  101. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 7, 16);
  102. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 8, 15);
  103. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 16, 7);
  104. printf("\n");
  105. }
  106. void is888Tests()
  107. {
  108. printf("Simple format detection:\n\n");
  109. /* Positive cases */
  110. do888Test(true, 32, 24, false, true, 255, 255, 255, 0, 8, 16);
  111. do888Test(true, 32, 24, false, true, 255, 255, 255, 24, 16, 8);
  112. do888Test(true, 32, 24, false, true, 255, 255, 255, 24, 8, 0);
  113. /* Low depth */
  114. do888Test(false, 32, 16, false, true, 15, 31, 15, 0, 8, 16);
  115. do888Test(false, 32, 8, false, true, 3, 7, 3, 0, 8, 16);
  116. /* Low bpp and depth */
  117. do888Test(false, 16, 16, false, true, 15, 31, 15, 0, 5, 11);
  118. do888Test(false, 8, 8, false, true, 3, 7, 3, 0, 2, 5);
  119. /* Colour map */
  120. do888Test(false, 8, 8, false, false, 0, 0, 0, 0, 0, 0);
  121. /* Odd shifts */
  122. do888Test(false, 32, 24, false, true, 255, 255, 255, 0, 8, 18);
  123. do888Test(false, 32, 24, false, true, 255, 255, 255, 0, 11, 24);
  124. do888Test(false, 32, 24, false, true, 255, 255, 255, 4, 16, 24);
  125. printf("\n");
  126. }
  127. int main(int argc, char** argv)
  128. {
  129. sanityTests();
  130. is888Tests();
  131. return 0;
  132. }