Clone of mesa.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

clientinfo_unittest.cpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * Copyright © 2011 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. */
  23. #include <gtest/gtest.h>
  24. #include <string.h>
  25. extern "C" {
  26. #include "glxclient.h"
  27. }
  28. #include <xcb/glx.h>
  29. #include "mock_xdisplay.h"
  30. #include "fake_glx_screen.h"
  31. /**
  32. * \name Wrappers around some X structures to make the more usable for tests
  33. */
  34. /*@{*/
  35. class fake_glx_screen;
  36. class fake_glx_display : public glx_display {
  37. public:
  38. fake_glx_display(mock_XDisplay *dpy, int major, int minor)
  39. {
  40. this->next = 0;
  41. this->dpy = dpy;
  42. this->majorOpcode = 0;
  43. this->majorVersion = major;
  44. this->minorVersion = minor;
  45. this->serverGLXvendor = 0;
  46. this->serverGLXversion = 0;
  47. this->glXDrawHash = 0;
  48. this->screens = new glx_screen *[dpy->nscreens];
  49. memset(this->screens, 0, sizeof(struct glx_screen *) * dpy->nscreens);
  50. }
  51. ~fake_glx_display()
  52. {
  53. for (int i = 0; i < this->dpy->nscreens; i++) {
  54. if (this->screens[i] != NULL)
  55. delete this->screens[i];
  56. }
  57. delete [] this->screens;
  58. }
  59. void init_screen(int i, const char *ext);
  60. };
  61. class glX_send_client_info_test : public ::testing::Test {
  62. public:
  63. glX_send_client_info_test();
  64. virtual ~glX_send_client_info_test();
  65. virtual void SetUp();
  66. void common_protocol_expected_false_test(unsigned major, unsigned minor,
  67. const char *glx_ext, bool *value);
  68. void common_protocol_expected_true_test(unsigned major, unsigned minor,
  69. const char *glx_ext, bool *value);
  70. void create_single_screen_display(unsigned major, unsigned minor,
  71. const char *glx_ext);
  72. void destroy_display();
  73. protected:
  74. fake_glx_display *glx_dpy;
  75. mock_XDisplay *display;
  76. };
  77. void
  78. fake_glx_display::init_screen(int i, const char *ext)
  79. {
  80. if (this->screens[i] != NULL)
  81. delete this->screens[i];
  82. this->screens[i] = new fake_glx_screen(this, i, ext);
  83. }
  84. /*@}*/
  85. static const char ext[] = "GL_XXX_dummy";
  86. static bool ClientInfo_was_sent;
  87. static bool SetClientInfoARB_was_sent;
  88. static bool SetClientInfo2ARB_was_sent;
  89. static xcb_connection_t *connection_used;
  90. static int gl_ext_length;
  91. static char *gl_ext_string;
  92. static int glx_ext_length;
  93. static char *glx_ext_string;
  94. static int num_gl_versions;
  95. static uint32_t *gl_versions;
  96. static int glx_major;
  97. static int glx_minor;
  98. extern "C" xcb_connection_t *
  99. XGetXCBConnection(Display *dpy)
  100. {
  101. return (xcb_connection_t *) 0xdeadbeef;
  102. }
  103. extern "C" xcb_void_cookie_t
  104. xcb_glx_client_info(xcb_connection_t *c,
  105. uint32_t major_version,
  106. uint32_t minor_version,
  107. uint32_t str_len,
  108. const char *string)
  109. {
  110. xcb_void_cookie_t cookie;
  111. ClientInfo_was_sent = true;
  112. connection_used = c;
  113. gl_ext_string = (char *) malloc(str_len);
  114. memcpy(gl_ext_string, string, str_len);
  115. gl_ext_length = str_len;
  116. glx_major = major_version;
  117. glx_minor = minor_version;
  118. cookie.sequence = 0;
  119. return cookie;
  120. }
  121. extern "C" xcb_void_cookie_t
  122. xcb_glx_set_client_info_arb(xcb_connection_t *c,
  123. uint32_t major_version,
  124. uint32_t minor_version,
  125. uint32_t num_versions,
  126. uint32_t gl_str_len,
  127. uint32_t glx_str_len,
  128. const uint32_t *versions,
  129. const char *gl_string,
  130. const char *glx_string)
  131. {
  132. xcb_void_cookie_t cookie;
  133. SetClientInfoARB_was_sent = true;
  134. connection_used = c;
  135. gl_ext_string = new char[gl_str_len];
  136. memcpy(gl_ext_string, gl_string, gl_str_len);
  137. gl_ext_length = gl_str_len;
  138. glx_ext_string = new char[glx_str_len];
  139. memcpy(glx_ext_string, glx_string, glx_str_len);
  140. glx_ext_length = glx_str_len;
  141. gl_versions = new uint32_t[num_versions * 2];
  142. memcpy(gl_versions, versions, sizeof(uint32_t) * num_versions * 2);
  143. num_gl_versions = num_versions;
  144. glx_major = major_version;
  145. glx_minor = minor_version;
  146. cookie.sequence = 0;
  147. return cookie;
  148. }
  149. extern "C" xcb_void_cookie_t
  150. xcb_glx_set_client_info_2arb(xcb_connection_t *c,
  151. uint32_t major_version,
  152. uint32_t minor_version,
  153. uint32_t num_versions,
  154. uint32_t gl_str_len,
  155. uint32_t glx_str_len,
  156. const uint32_t *versions,
  157. const char *gl_string,
  158. const char *glx_string)
  159. {
  160. xcb_void_cookie_t cookie;
  161. SetClientInfo2ARB_was_sent = true;
  162. connection_used = c;
  163. gl_ext_string = new char[gl_str_len];
  164. memcpy(gl_ext_string, gl_string, gl_str_len);
  165. gl_ext_length = gl_str_len;
  166. glx_ext_string = new char[glx_str_len];
  167. memcpy(glx_ext_string, glx_string, glx_str_len);
  168. glx_ext_length = glx_str_len;
  169. gl_versions = new uint32_t[num_versions * 3];
  170. memcpy(gl_versions, versions, sizeof(uint32_t) * num_versions * 3);
  171. num_gl_versions = num_versions;
  172. glx_major = major_version;
  173. glx_minor = minor_version;
  174. cookie.sequence = 0;
  175. return cookie;
  176. }
  177. extern "C" char *
  178. __glXGetClientGLExtensionString()
  179. {
  180. char *str = (char *) malloc(sizeof(ext));
  181. memcpy(str, ext, sizeof(ext));
  182. return str;
  183. }
  184. glX_send_client_info_test::glX_send_client_info_test()
  185. : glx_dpy(0), display(0)
  186. {
  187. /* empty */
  188. }
  189. glX_send_client_info_test::~glX_send_client_info_test()
  190. {
  191. if (glx_dpy)
  192. delete glx_dpy;
  193. if (display)
  194. delete display;
  195. }
  196. void
  197. glX_send_client_info_test::destroy_display()
  198. {
  199. if (this->glx_dpy != NULL) {
  200. if (this->glx_dpy->screens != NULL) {
  201. for (int i = 0; i < this->display->nscreens; i++) {
  202. delete [] this->glx_dpy->screens[i]->serverGLXexts;
  203. delete this->glx_dpy->screens[i];
  204. }
  205. delete [] this->glx_dpy->screens;
  206. }
  207. delete this->glx_dpy;
  208. delete this->display;
  209. }
  210. }
  211. void
  212. glX_send_client_info_test::SetUp()
  213. {
  214. ClientInfo_was_sent = false;
  215. SetClientInfoARB_was_sent = false;
  216. SetClientInfo2ARB_was_sent = false;
  217. connection_used = (xcb_connection_t *) ~0;
  218. gl_ext_length = 0;
  219. gl_ext_string = (char *) 0;
  220. glx_ext_length = 0;
  221. glx_ext_string = (char *) 0;
  222. num_gl_versions = 0;
  223. gl_versions = (uint32_t *) 0;
  224. glx_major = 0;
  225. glx_minor = 0;
  226. }
  227. void
  228. glX_send_client_info_test::create_single_screen_display(unsigned major,
  229. unsigned minor,
  230. const char *glx_ext)
  231. {
  232. this->display = new mock_XDisplay(1);
  233. this->glx_dpy = new fake_glx_display(this->display, major, minor);
  234. this->glx_dpy->init_screen(0, glx_ext);
  235. }
  236. void
  237. glX_send_client_info_test::common_protocol_expected_false_test(unsigned major,
  238. unsigned minor,
  239. const char *glx_ext,
  240. bool *value)
  241. {
  242. create_single_screen_display(major, minor, glx_ext);
  243. __glX_send_client_info(this->glx_dpy);
  244. EXPECT_FALSE(*value);
  245. }
  246. void
  247. glX_send_client_info_test::common_protocol_expected_true_test(unsigned major,
  248. unsigned minor,
  249. const char *glx_ext,
  250. bool *value)
  251. {
  252. create_single_screen_display(major, minor, glx_ext);
  253. __glX_send_client_info(this->glx_dpy);
  254. EXPECT_TRUE(*value);
  255. }
  256. TEST_F(glX_send_client_info_test, doesnt_send_ClientInfo_for_1_0)
  257. {
  258. /* The glXClientInfo protocol was added in GLX 1.1. Verify that no
  259. * glXClientInfo is sent to a GLX server that only has GLX 1.0.
  260. */
  261. common_protocol_expected_false_test(1, 0, "", &ClientInfo_was_sent);
  262. }
  263. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfoARB_for_1_0)
  264. {
  265. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  266. * GLX_ARB_create_context extension. Verify that no glXSetClientInfoARB is
  267. * sent to a GLX server that only has GLX 1.0 regardless of the extension
  268. * setting.
  269. */
  270. common_protocol_expected_false_test(1, 0,
  271. "GLX_ARB_create_context",
  272. &SetClientInfoARB_was_sent);
  273. }
  274. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfoARB_for_1_1)
  275. {
  276. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  277. * GLX_ARB_create_context extension. Verify that no glXSetClientInfoARB is
  278. * sent to a GLX server that only has GLX 1.0 regardless of the extension
  279. * setting.
  280. */
  281. common_protocol_expected_false_test(1, 1,
  282. "GLX_ARB_create_context",
  283. &SetClientInfoARB_was_sent);
  284. }
  285. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfoARB_for_1_4_with_empty_extensions)
  286. {
  287. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  288. * GLX_ARB_create_context extension. Verify that no glXSetClientInfoARB is
  289. * sent to a GLX server that has GLX 1.4 but has an empty extension string
  290. * (i.e., no extensions at all).
  291. */
  292. common_protocol_expected_false_test(1, 4,
  293. "",
  294. &SetClientInfoARB_was_sent);
  295. }
  296. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfoARB_for_1_4_without_extension)
  297. {
  298. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  299. * GLX_ARB_create_context extension. Verify that no glXSetClientInfoARB is
  300. * sent to a GLX server that has GLX 1.4 but doesn't have the extension.
  301. */
  302. common_protocol_expected_false_test(1, 4,
  303. "GLX_EXT_texture_from_pixmap",
  304. &SetClientInfoARB_was_sent);
  305. }
  306. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfoARB_for_1_4_with_wrong_extension)
  307. {
  308. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  309. * GLX_ARB_create_context extension. Verify that no glXSetClientInfoARB is
  310. * sent to a GLX server that has GLX 1.4 but does not have the extension.
  311. *
  312. * This test differs from
  313. * doesnt_send_SetClientInfoARB_for_1_4_without_extension in that an
  314. * extension exists that looks like the correct extension but isn't.
  315. */
  316. common_protocol_expected_false_test(1, 4,
  317. "GLX_ARB_create_context2",
  318. &SetClientInfoARB_was_sent);
  319. }
  320. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfoARB_for_1_4_with_profile_extension)
  321. {
  322. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  323. * GLX_ARB_create_context extension. Verify that no glXSetClientInfoARB is
  324. * sent to a GLX server that has GLX 1.4 but does not have the extension.
  325. *
  326. * This test differs from
  327. * doesnt_send_SetClientInfoARB_for_1_4_without_extension in that an
  328. * extension exists that looks like the correct extension but isn't.
  329. */
  330. common_protocol_expected_false_test(1, 4,
  331. "GLX_ARB_create_context_profile",
  332. &SetClientInfoARB_was_sent);
  333. }
  334. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfo2ARB_for_1_0)
  335. {
  336. /* The glXSetClientInfo2ARB protocol was added in GLX 1.4 with the
  337. * GLX_ARB_create_context_profile extension. Verify that no
  338. * glXSetClientInfo2ARB is sent to a GLX server that only has GLX 1.0
  339. * regardless of the extension setting.
  340. */
  341. common_protocol_expected_false_test(1, 0,
  342. "GLX_ARB_create_context_profile",
  343. &SetClientInfo2ARB_was_sent);
  344. }
  345. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfo2ARB_for_1_1)
  346. {
  347. /* The glXSetClientInfo2ARB protocol was added in GLX 1.4 with the
  348. * GLX_ARB_create_context_profile extension. Verify that no
  349. * glXSetClientInfo2ARB is sent to a GLX server that only has GLX 1.1
  350. * regardless of the extension setting.
  351. */
  352. common_protocol_expected_false_test(1, 1,
  353. "GLX_ARB_create_context_profile",
  354. &SetClientInfo2ARB_was_sent);
  355. }
  356. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfo2ARB_for_1_4_with_empty_extensions)
  357. {
  358. /* The glXSetClientInfo2ARB protocol was added in GLX 1.4 with the
  359. * GLX_ARB_create_context_profile extension. Verify that no
  360. * glXSetClientInfo2ARB is sent to a GLX server that has GLX 1.4 but has an
  361. * empty extension string (i.e., no extensions at all).
  362. */
  363. common_protocol_expected_false_test(1, 4,
  364. "",
  365. &SetClientInfo2ARB_was_sent);
  366. }
  367. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfo2ARB_for_1_4_without_extension)
  368. {
  369. /* The glXSetClientInfo2ARB protocol was added in GLX 1.4 with the
  370. * GLX_ARB_create_context_profile extension. Verify that no
  371. * glXSetClientInfo2ARB is sent to a GLX server that has GLX 1.4 but
  372. * doesn't have the extension.
  373. */
  374. common_protocol_expected_false_test(1, 4,
  375. "GLX_EXT_texture_from_pixmap",
  376. &SetClientInfo2ARB_was_sent);
  377. }
  378. TEST_F(glX_send_client_info_test, doesnt_send_SetClientInfo2ARB_for_1_4_with_wrong_extension)
  379. {
  380. /* The glXSetClientInfo2ARB protocol was added in GLX 1.4 with the
  381. * GLX_ARB_create_context_profile extension. Verify that no
  382. * glXSetClientInfo2ARB is sent to a GLX server that has GLX 1.4 but does
  383. * not have the extension.
  384. *
  385. * This test differs from
  386. * doesnt_send_SetClientInfo2ARB_for_1_4_without_extension in that an
  387. * extension exists that looks like the correct extension but isn't.
  388. */
  389. common_protocol_expected_false_test(1, 4,
  390. "GLX_ARB_create_context_profile2",
  391. &SetClientInfo2ARB_was_sent);
  392. }
  393. TEST_F(glX_send_client_info_test, does_send_ClientInfo_for_1_1)
  394. {
  395. /* The glXClientInfo protocol was added in GLX 1.1. Verify that
  396. * glXClientInfo is sent to a GLX server that has GLX 1.1.
  397. */
  398. common_protocol_expected_true_test(1, 1,
  399. "",
  400. &ClientInfo_was_sent);
  401. }
  402. TEST_F(glX_send_client_info_test, does_send_SetClientInfoARB_for_1_4_with_extension)
  403. {
  404. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  405. * GLX_ARB_create_context extension. Verify that glXSetClientInfoARB is
  406. * sent to a GLX server that has GLX 1.4 and the extension.
  407. */
  408. common_protocol_expected_true_test(1, 4,
  409. "GLX_ARB_create_context",
  410. &SetClientInfoARB_was_sent);
  411. }
  412. TEST_F(glX_send_client_info_test, does_send_SetClientInfo2ARB_for_1_4_with_just_profile_extension)
  413. {
  414. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  415. * GLX_ARB_create_context extension. Verify that glXSetClientInfoARB is
  416. * sent to a GLX server that has GLX 1.4 and the extension.
  417. */
  418. common_protocol_expected_true_test(1, 4,
  419. "GLX_ARB_create_context_profile",
  420. &SetClientInfo2ARB_was_sent);
  421. }
  422. TEST_F(glX_send_client_info_test, does_send_SetClientInfo2ARB_for_1_4_with_both_extensions)
  423. {
  424. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  425. * GLX_ARB_create_context extension. Verify that glXSetClientInfoARB is
  426. * sent to a GLX server that has GLX 1.4 and the extension.
  427. */
  428. common_protocol_expected_true_test(1, 4,
  429. "GLX_ARB_create_context "
  430. "GLX_ARB_create_context_profile",
  431. &SetClientInfo2ARB_was_sent);
  432. }
  433. TEST_F(glX_send_client_info_test, does_send_SetClientInfo2ARB_for_1_4_with_both_extensions_reversed)
  434. {
  435. /* The glXSetClientInfoARB protocol was added in GLX 1.4 with the
  436. * GLX_ARB_create_context extension. Verify that glXSetClientInfoARB is
  437. * sent to a GLX server that has GLX 1.4 and the extension.
  438. */
  439. common_protocol_expected_true_test(1, 4,
  440. "GLX_ARB_create_context_profile "
  441. "GLX_ARB_create_context",
  442. &SetClientInfo2ARB_was_sent);
  443. }
  444. TEST_F(glX_send_client_info_test, uses_correct_connection)
  445. {
  446. create_single_screen_display(1, 1, "");
  447. __glX_send_client_info(this->glx_dpy);
  448. EXPECT_EQ((xcb_connection_t *) 0xdeadbeef, connection_used);
  449. }
  450. TEST_F(glX_send_client_info_test, sends_correct_gl_extension_string)
  451. {
  452. create_single_screen_display(1, 1, "");
  453. __glX_send_client_info(this->glx_dpy);
  454. ASSERT_EQ(sizeof(ext), gl_ext_length);
  455. ASSERT_NE((char *) 0, gl_ext_string);
  456. EXPECT_EQ(0, memcmp(gl_ext_string, ext, sizeof(ext)));
  457. }
  458. TEST_F(glX_send_client_info_test, gl_versions_are_sane)
  459. {
  460. create_single_screen_display(1, 4, "GLX_ARB_create_context");
  461. __glX_send_client_info(this->glx_dpy);
  462. ASSERT_NE(0, num_gl_versions);
  463. unsigned versions_below_3_0 = 0;
  464. for (int i = 0; i < num_gl_versions; i++) {
  465. EXPECT_LT(0, gl_versions[i * 2]);
  466. EXPECT_GE(4, gl_versions[i * 2]);
  467. /* Verify that the minor version advertised with the major version makes
  468. * sense.
  469. */
  470. switch (gl_versions[i * 2]) {
  471. case 1:
  472. EXPECT_GE(5, gl_versions[i * 2 + 1]);
  473. versions_below_3_0++;
  474. break;
  475. case 2:
  476. EXPECT_GE(1, gl_versions[i * 2 + 1]);
  477. versions_below_3_0++;
  478. break;
  479. case 3:
  480. EXPECT_GE(3, gl_versions[i * 2 + 1]);
  481. break;
  482. case 4:
  483. EXPECT_GE(2, gl_versions[i * 2 + 1]);
  484. break;
  485. }
  486. }
  487. /* From the GLX_ARB_create_context spec:
  488. *
  489. * "Only the highest supported version below 3.0 should be sent, since
  490. * OpenGL 2.1 is backwards compatible with all earlier versions."
  491. */
  492. EXPECT_LE(versions_below_3_0, 1);
  493. }
  494. TEST_F(glX_send_client_info_test, gl_versions_and_profiles_are_sane)
  495. {
  496. create_single_screen_display(1, 4, "GLX_ARB_create_context_profile");
  497. __glX_send_client_info(this->glx_dpy);
  498. ASSERT_NE(0, num_gl_versions);
  499. const uint32_t all_valid_bits = GLX_CONTEXT_CORE_PROFILE_BIT_ARB
  500. | GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
  501. unsigned versions_below_3_0 = 0;
  502. for (int i = 0; i < num_gl_versions; i++) {
  503. EXPECT_LT(0, gl_versions[i * 3]);
  504. EXPECT_GE(4, gl_versions[i * 3]);
  505. /* Verify that the minor version advertised with the major version makes
  506. * sense.
  507. */
  508. switch (gl_versions[i * 3]) {
  509. case 1:
  510. EXPECT_GE(5, gl_versions[i * 3 + 1]);
  511. EXPECT_EQ(0, gl_versions[i * 3 + 2]);
  512. versions_below_3_0++;
  513. break;
  514. case 2:
  515. EXPECT_GE(1, gl_versions[i * 3 + 1]);
  516. EXPECT_EQ(0, gl_versions[i * 3 + 2]);
  517. versions_below_3_0++;
  518. break;
  519. case 3:
  520. EXPECT_GE(3, gl_versions[i * 3 + 1]);
  521. /* Profiles were not introduced until OpenGL 3.2.
  522. */
  523. if (gl_versions[i * 3 + 1] < 2) {
  524. EXPECT_EQ(0, gl_versions[i * 3 + 2]);
  525. } else {
  526. EXPECT_EQ(0, gl_versions[i * 3 + 2] & ~all_valid_bits);
  527. }
  528. break;
  529. case 4:
  530. EXPECT_GE(2, gl_versions[i * 3 + 1]);
  531. EXPECT_EQ(0, gl_versions[i * 3 + 2] & ~all_valid_bits);
  532. break;
  533. }
  534. }
  535. /* From the GLX_ARB_create_context_profile spec:
  536. *
  537. * "Only the highest supported version below 3.0 should be sent, since
  538. * OpenGL 2.1 is backwards compatible with all earlier versions."
  539. */
  540. EXPECT_LE(versions_below_3_0, 1);
  541. }
  542. TEST_F(glX_send_client_info_test, glx_version_is_1_4_for_1_1)
  543. {
  544. create_single_screen_display(1, 1, "");
  545. __glX_send_client_info(this->glx_dpy);
  546. EXPECT_EQ(1, glx_major);
  547. EXPECT_EQ(4, glx_minor);
  548. }
  549. TEST_F(glX_send_client_info_test, glx_version_is_1_4_for_1_4)
  550. {
  551. create_single_screen_display(1, 4, "");
  552. __glX_send_client_info(this->glx_dpy);
  553. EXPECT_EQ(1, glx_major);
  554. EXPECT_EQ(4, glx_minor);
  555. }
  556. TEST_F(glX_send_client_info_test, glx_version_is_1_4_for_1_4_with_ARB_create_context)
  557. {
  558. create_single_screen_display(1, 4, "GLX_ARB_create_context");
  559. __glX_send_client_info(this->glx_dpy);
  560. EXPECT_EQ(1, glx_major);
  561. EXPECT_EQ(4, glx_minor);
  562. }
  563. TEST_F(glX_send_client_info_test, glx_version_is_1_4_for_1_4_with_ARB_create_context_profile)
  564. {
  565. create_single_screen_display(1, 4, "GLX_ARB_create_context_profile");
  566. __glX_send_client_info(this->glx_dpy);
  567. EXPECT_EQ(1, glx_major);
  568. EXPECT_EQ(4, glx_minor);
  569. }
  570. TEST_F(glX_send_client_info_test, glx_version_is_1_4_for_1_5)
  571. {
  572. create_single_screen_display(1, 5, "");
  573. __glX_send_client_info(this->glx_dpy);
  574. EXPECT_EQ(1, glx_major);
  575. EXPECT_EQ(4, glx_minor);
  576. }
  577. TEST_F(glX_send_client_info_test, glx_extensions_has_GLX_ARB_create_context)
  578. {
  579. create_single_screen_display(1, 4, "GLX_ARB_create_context");
  580. __glX_send_client_info(this->glx_dpy);
  581. ASSERT_NE(0, glx_ext_length);
  582. ASSERT_NE((char *) 0, glx_ext_string);
  583. bool found_GLX_ARB_create_context = false;
  584. const char *const needle = "GLX_ARB_create_context";
  585. const unsigned len = strlen(needle);
  586. char *haystack = glx_ext_string;
  587. while (haystack != NULL) {
  588. char *match = strstr(haystack, needle);
  589. if (match[len] == '\0' || match[len] == ' ') {
  590. found_GLX_ARB_create_context = true;
  591. break;
  592. }
  593. haystack = match + len;
  594. }
  595. EXPECT_TRUE(found_GLX_ARB_create_context);
  596. }
  597. TEST_F(glX_send_client_info_test, glx_extensions_has_GLX_ARB_create_context_profile)
  598. {
  599. create_single_screen_display(1, 4, "GLX_ARB_create_context_profile");
  600. __glX_send_client_info(this->glx_dpy);
  601. ASSERT_NE(0, glx_ext_length);
  602. ASSERT_NE((char *) 0, glx_ext_string);
  603. bool found_GLX_ARB_create_context_profile = false;
  604. const char *const needle = "GLX_ARB_create_context_profile";
  605. const unsigned len = strlen(needle);
  606. char *haystack = glx_ext_string;
  607. while (haystack != NULL) {
  608. char *match = strstr(haystack, needle);
  609. if (match[len] == '\0' || match[len] == ' ') {
  610. found_GLX_ARB_create_context_profile = true;
  611. break;
  612. }
  613. haystack = match + len;
  614. }
  615. EXPECT_TRUE(found_GLX_ARB_create_context_profile);
  616. }