You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pixelformat.cxx 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. int main(int argc, char** argv)
  48. {
  49. /* Normal true color formats */
  50. doTest(false, 32, 24, false, true, 255, 255, 255, 0, 8, 16);
  51. doTest(false, 32, 24, false, true, 255, 255, 255, 24, 16, 8);
  52. doTest(false, 16, 16, false, true, 15, 31, 15, 0, 5, 11);
  53. doTest(false, 8, 8, false, true, 3, 7, 3, 0, 2, 5);
  54. /* Excessive bpp */
  55. doTest(false, 32, 16, false, true, 15, 31, 15, 0, 5, 11);
  56. doTest(false, 16, 16, false, true, 15, 31, 15, 0, 5, 11);
  57. doTest(false, 32, 8, false, true, 3, 7, 3, 0, 2, 5);
  58. doTest(false, 16, 8, false, true, 3, 7, 3, 0, 2, 5);
  59. /* Colour map */
  60. doTest(false, 8, 8, false, false, 0, 0, 0, 0, 0, 0);
  61. /* Invalid bpp */
  62. doTest(true, 64, 24, false, true, 255, 255, 255, 0, 8, 16);
  63. doTest(true, 18, 16, false, true, 15, 31, 15, 0, 5, 11);
  64. doTest(true, 3, 3, false, true, 1, 1, 1, 0, 1, 2);
  65. /* Invalid depth */
  66. doTest(true, 16, 24, false, true, 15, 31, 15, 0, 5, 11);
  67. doTest(true, 8, 24, false, true, 3, 7, 3, 0, 2, 5);
  68. doTest(true, 8, 16, false, true, 3, 7, 3, 0, 2, 5);
  69. doTest(true, 32, 24, false, false, 0, 0, 0, 0, 0, 0);
  70. /* Invalid max values */
  71. doTest(true, 32, 24, false, true, 254, 255, 255, 0, 8, 16);
  72. doTest(true, 32, 24, false, true, 255, 253, 255, 0, 8, 16);
  73. doTest(true, 32, 24, false, true, 255, 255, 252, 0, 8, 16);
  74. doTest(true, 32, 24, false, true, 511, 127, 127, 0, 16, 20);
  75. doTest(true, 32, 24, false, true, 127, 511, 127, 0, 4, 20);
  76. doTest(true, 32, 24, false, true, 127, 127, 511, 0, 4, 8);
  77. /* Overlapping channels */
  78. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 7, 16);
  79. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 8, 15);
  80. doTest(true, 32, 24, false, true, 255, 255, 255, 0, 16, 7);
  81. return 0;
  82. }