1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2011 Intel Corporation
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20bf215546Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21bf215546Sopenharmony_ci * DEALINGS IN THE SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci#include <gtest/gtest.h>
24bf215546Sopenharmony_ci#include <string.h>
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci#include "glxclient.h"
27bf215546Sopenharmony_ci#include "glx_error.h"
28bf215546Sopenharmony_ci
29bf215546Sopenharmony_ci#include <xcb/glx.h>
30bf215546Sopenharmony_ci#include "mock_xdisplay.h"
31bf215546Sopenharmony_ci#include "fake_glx_screen.h"
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_cistatic bool CreateContextAttribsARB_was_sent;
34bf215546Sopenharmony_cistatic xcb_glx_create_context_attribs_arb_request_t req;
35bf215546Sopenharmony_cistatic uint32_t sent_attribs[1024];
36bf215546Sopenharmony_cistatic uint32_t next_id;
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci
39bf215546Sopenharmony_cistruct glx_screen *psc;
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ciextern "C" Bool
42bf215546Sopenharmony_ciglx_context_init(struct glx_context *gc,
43bf215546Sopenharmony_ci		 struct glx_screen *psc, struct glx_config *config)
44bf215546Sopenharmony_ci{
45bf215546Sopenharmony_ci   gc->majorOpcode = 123;
46bf215546Sopenharmony_ci   gc->screen = psc->scr;
47bf215546Sopenharmony_ci   gc->psc = psc;
48bf215546Sopenharmony_ci   gc->config = config;
49bf215546Sopenharmony_ci   gc->isDirect = GL_TRUE;
50bf215546Sopenharmony_ci   gc->currentContextTag = -1;
51bf215546Sopenharmony_ci
52bf215546Sopenharmony_ci   return GL_TRUE;
53bf215546Sopenharmony_ci}
54bf215546Sopenharmony_ci
55bf215546Sopenharmony_cibool GetGLXScreenConfigs_called = false;
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_ciextern "C" struct glx_screen *
58bf215546Sopenharmony_ciGetGLXScreenConfigs(Display * dpy, int scrn)
59bf215546Sopenharmony_ci{
60bf215546Sopenharmony_ci   (void) dpy;
61bf215546Sopenharmony_ci   (void) scrn;
62bf215546Sopenharmony_ci
63bf215546Sopenharmony_ci   GetGLXScreenConfigs_called = true;
64bf215546Sopenharmony_ci   return psc;
65bf215546Sopenharmony_ci}
66bf215546Sopenharmony_ci
67bf215546Sopenharmony_ciextern "C" uint32_t
68bf215546Sopenharmony_cixcb_generate_id(xcb_connection_t *c)
69bf215546Sopenharmony_ci{
70bf215546Sopenharmony_ci   (void) c;
71bf215546Sopenharmony_ci
72bf215546Sopenharmony_ci   return next_id++;
73bf215546Sopenharmony_ci}
74bf215546Sopenharmony_ci
75bf215546Sopenharmony_ciextern "C" xcb_void_cookie_t
76bf215546Sopenharmony_cixcb_glx_create_context_attribs_arb_checked(xcb_connection_t *c,
77bf215546Sopenharmony_ci					   xcb_glx_context_t context,
78bf215546Sopenharmony_ci					   uint32_t fbconfig,
79bf215546Sopenharmony_ci					   uint32_t screen,
80bf215546Sopenharmony_ci					   uint32_t share_list,
81bf215546Sopenharmony_ci					   uint8_t is_direct,
82bf215546Sopenharmony_ci					   uint32_t num_attribs,
83bf215546Sopenharmony_ci					   const uint32_t *attribs)
84bf215546Sopenharmony_ci{
85bf215546Sopenharmony_ci   (void) c;
86bf215546Sopenharmony_ci
87bf215546Sopenharmony_ci   CreateContextAttribsARB_was_sent = true;
88bf215546Sopenharmony_ci   req.context = context;
89bf215546Sopenharmony_ci   req.fbconfig = fbconfig;
90bf215546Sopenharmony_ci   req.screen = screen;
91bf215546Sopenharmony_ci   req.share_list = share_list;
92bf215546Sopenharmony_ci   req.is_direct = is_direct;
93bf215546Sopenharmony_ci   req.num_attribs = num_attribs;
94bf215546Sopenharmony_ci
95bf215546Sopenharmony_ci   if (num_attribs != 0 && attribs != NULL)
96bf215546Sopenharmony_ci      memcpy(sent_attribs, attribs, num_attribs * 2 * sizeof(uint32_t));
97bf215546Sopenharmony_ci
98bf215546Sopenharmony_ci   xcb_void_cookie_t cookie;
99bf215546Sopenharmony_ci   cookie.sequence = 0xbadc0de;
100bf215546Sopenharmony_ci
101bf215546Sopenharmony_ci   return cookie;
102bf215546Sopenharmony_ci}
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ciextern "C" xcb_void_cookie_t
105bf215546Sopenharmony_cixcb_glx_destroy_context(xcb_connection_t *c, xcb_glx_context_t context)
106bf215546Sopenharmony_ci{
107bf215546Sopenharmony_ci   xcb_void_cookie_t cookie;
108bf215546Sopenharmony_ci   cookie.sequence = 0xbadc0de;
109bf215546Sopenharmony_ci
110bf215546Sopenharmony_ci   return cookie;
111bf215546Sopenharmony_ci}
112bf215546Sopenharmony_ci
113bf215546Sopenharmony_ciextern "C" xcb_generic_error_t *
114bf215546Sopenharmony_cixcb_request_check(xcb_connection_t *c, xcb_void_cookie_t cookie)
115bf215546Sopenharmony_ci{
116bf215546Sopenharmony_ci   return NULL;
117bf215546Sopenharmony_ci}
118bf215546Sopenharmony_ci
119bf215546Sopenharmony_ciextern "C" void
120bf215546Sopenharmony_ci__glXSendErrorForXcb(Display * dpy, const xcb_generic_error_t *err)
121bf215546Sopenharmony_ci{
122bf215546Sopenharmony_ci}
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ciextern "C" void
125bf215546Sopenharmony_ci__glXSendError(Display * dpy, int_fast8_t errorCode, uint_fast32_t resourceID,
126bf215546Sopenharmony_ci               uint_fast16_t minorCode, bool coreX11error)
127bf215546Sopenharmony_ci{
128bf215546Sopenharmony_ci}
129bf215546Sopenharmony_ci
130bf215546Sopenharmony_ciclass glXCreateContextAttribARB_test : public ::testing::Test {
131bf215546Sopenharmony_cipublic:
132bf215546Sopenharmony_ci   virtual void SetUp();
133bf215546Sopenharmony_ci   virtual void TearDown();
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci   /**
136bf215546Sopenharmony_ci    * Replace the existing screen with a direct-rendering screen
137bf215546Sopenharmony_ci    */
138bf215546Sopenharmony_ci   void use_direct_rendering_screen();
139bf215546Sopenharmony_ci
140bf215546Sopenharmony_ci   mock_XDisplay *dpy;
141bf215546Sopenharmony_ci   GLXContext ctx;
142bf215546Sopenharmony_ci   struct glx_config fbc;
143bf215546Sopenharmony_ci};
144bf215546Sopenharmony_ci
145bf215546Sopenharmony_civoid
146bf215546Sopenharmony_ciglXCreateContextAttribARB_test::SetUp()
147bf215546Sopenharmony_ci{
148bf215546Sopenharmony_ci   CreateContextAttribsARB_was_sent = false;
149bf215546Sopenharmony_ci   memset(&req, 0, sizeof(req));
150bf215546Sopenharmony_ci   next_id = 99;
151bf215546Sopenharmony_ci   fake_glx_context::contexts_allocated = 0;
152bf215546Sopenharmony_ci   psc = new fake_glx_screen(NULL, 0, "");
153bf215546Sopenharmony_ci
154bf215546Sopenharmony_ci   this->dpy = new mock_XDisplay(1);
155bf215546Sopenharmony_ci
156bf215546Sopenharmony_ci   memset(&this->fbc, 0, sizeof(this->fbc));
157bf215546Sopenharmony_ci   this->fbc.fbconfigID = 0xbeefcafe;
158bf215546Sopenharmony_ci
159bf215546Sopenharmony_ci   this->ctx = NULL;
160bf215546Sopenharmony_ci}
161bf215546Sopenharmony_ci
162bf215546Sopenharmony_civoid
163bf215546Sopenharmony_ciglXCreateContextAttribARB_test::TearDown()
164bf215546Sopenharmony_ci{
165bf215546Sopenharmony_ci   if (ctx)
166bf215546Sopenharmony_ci      delete (fake_glx_context *)ctx;
167bf215546Sopenharmony_ci
168bf215546Sopenharmony_ci   delete (fake_glx_screen *)psc;
169bf215546Sopenharmony_ci
170bf215546Sopenharmony_ci   delete this->dpy;
171bf215546Sopenharmony_ci}
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_civoid
174bf215546Sopenharmony_ciglXCreateContextAttribARB_test::use_direct_rendering_screen()
175bf215546Sopenharmony_ci{
176bf215546Sopenharmony_ci   struct glx_screen *direct_psc =
177bf215546Sopenharmony_ci      new fake_glx_screen_direct(psc->display,
178bf215546Sopenharmony_ci				 psc->scr,
179bf215546Sopenharmony_ci				 psc->serverGLXexts);
180bf215546Sopenharmony_ci
181bf215546Sopenharmony_ci   delete (fake_glx_screen *)psc;
182bf215546Sopenharmony_ci   psc = direct_psc;
183bf215546Sopenharmony_ci}
184bf215546Sopenharmony_ci
185bf215546Sopenharmony_ci/**
186bf215546Sopenharmony_ci * \name Verify detection of client-side errors
187bf215546Sopenharmony_ci */
188bf215546Sopenharmony_ci/*@{*/
189bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, NULL_display_returns_None)
190bf215546Sopenharmony_ci{
191bf215546Sopenharmony_ci   GLXContext ctx =
192bf215546Sopenharmony_ci      glXCreateContextAttribsARB(NULL, (GLXFBConfig) &this->fbc, 0,
193bf215546Sopenharmony_ci				 False, NULL);
194bf215546Sopenharmony_ci
195bf215546Sopenharmony_ci   EXPECT_EQ(None, ctx);
196bf215546Sopenharmony_ci   EXPECT_EQ(0, fake_glx_context::contexts_allocated);
197bf215546Sopenharmony_ci}
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, NULL_screen_returns_None)
200bf215546Sopenharmony_ci{
201bf215546Sopenharmony_ci   delete (fake_glx_screen *)psc;
202bf215546Sopenharmony_ci   psc = NULL;
203bf215546Sopenharmony_ci
204bf215546Sopenharmony_ci   GLXContext ctx =
205bf215546Sopenharmony_ci      glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
206bf215546Sopenharmony_ci				 False, NULL);
207bf215546Sopenharmony_ci
208bf215546Sopenharmony_ci   EXPECT_EQ(None, ctx);
209bf215546Sopenharmony_ci   EXPECT_EQ(0, fake_glx_context::contexts_allocated);
210bf215546Sopenharmony_ci}
211bf215546Sopenharmony_ci/*@}*/
212bf215546Sopenharmony_ci
213bf215546Sopenharmony_ci/**
214bf215546Sopenharmony_ci * \name Verify that correct protocol bits are sent to the server.
215bf215546Sopenharmony_ci */
216bf215546Sopenharmony_ci/*@{*/
217bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, does_send_protocol)
218bf215546Sopenharmony_ci{
219bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
220bf215546Sopenharmony_ci			      False, NULL);
221bf215546Sopenharmony_ci
222bf215546Sopenharmony_ci   EXPECT_TRUE(CreateContextAttribsARB_was_sent);
223bf215546Sopenharmony_ci}
224bf215546Sopenharmony_ci
225bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_context)
226bf215546Sopenharmony_ci{
227bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
228bf215546Sopenharmony_ci			      False, NULL);
229bf215546Sopenharmony_ci   EXPECT_EQ(99u, req.context);
230bf215546Sopenharmony_ci}
231bf215546Sopenharmony_ci
232bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_fbconfig)
233bf215546Sopenharmony_ci{
234bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
235bf215546Sopenharmony_ci			      False, NULL);
236bf215546Sopenharmony_ci
237bf215546Sopenharmony_ci   EXPECT_EQ(0xbeefcafe, req.fbconfig);
238bf215546Sopenharmony_ci}
239bf215546Sopenharmony_ci
240bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_share_list)
241bf215546Sopenharmony_ci{
242bf215546Sopenharmony_ci   GLXContext share =
243bf215546Sopenharmony_ci      glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
244bf215546Sopenharmony_ci				 False, NULL);
245bf215546Sopenharmony_ci
246bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, share);
247bf215546Sopenharmony_ci
248bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, share,
249bf215546Sopenharmony_ci			      False, NULL);
250bf215546Sopenharmony_ci
251bf215546Sopenharmony_ci   struct glx_context *glx_ctx = (struct glx_context *) share;
252bf215546Sopenharmony_ci   EXPECT_EQ(glx_ctx->xid, req.share_list);
253bf215546Sopenharmony_ci
254bf215546Sopenharmony_ci   delete (fake_glx_context *)share;
255bf215546Sopenharmony_ci}
256bf215546Sopenharmony_ci
257bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_is_direct_for_indirect_screen_and_direct_set_to_true)
258bf215546Sopenharmony_ci{
259bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
260bf215546Sopenharmony_ci			      True, NULL);
261bf215546Sopenharmony_ci
262bf215546Sopenharmony_ci   EXPECT_FALSE(req.is_direct);
263bf215546Sopenharmony_ci}
264bf215546Sopenharmony_ci
265bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_is_direct_for_indirect_screen_and_direct_set_to_false)
266bf215546Sopenharmony_ci{
267bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
268bf215546Sopenharmony_ci			      False, NULL);
269bf215546Sopenharmony_ci
270bf215546Sopenharmony_ci   EXPECT_FALSE(req.is_direct);
271bf215546Sopenharmony_ci}
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_is_direct_for_direct_screen_and_direct_set_to_true)
274bf215546Sopenharmony_ci{
275bf215546Sopenharmony_ci   this->use_direct_rendering_screen();
276bf215546Sopenharmony_ci
277bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
278bf215546Sopenharmony_ci			      True, NULL);
279bf215546Sopenharmony_ci
280bf215546Sopenharmony_ci   EXPECT_TRUE(req.is_direct);
281bf215546Sopenharmony_ci}
282bf215546Sopenharmony_ci
283bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_is_direct_for_direct_screen_and_direct_set_to_false)
284bf215546Sopenharmony_ci{
285bf215546Sopenharmony_ci   this->use_direct_rendering_screen();
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
288bf215546Sopenharmony_ci			      False, NULL);
289bf215546Sopenharmony_ci
290bf215546Sopenharmony_ci   EXPECT_FALSE(req.is_direct);
291bf215546Sopenharmony_ci}
292bf215546Sopenharmony_ci
293bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_screen)
294bf215546Sopenharmony_ci{
295bf215546Sopenharmony_ci   this->fbc.screen = 7;
296bf215546Sopenharmony_ci   psc->scr = 7;
297bf215546Sopenharmony_ci
298bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
299bf215546Sopenharmony_ci			      False, NULL);
300bf215546Sopenharmony_ci
301bf215546Sopenharmony_ci   EXPECT_EQ(7u, req.screen);
302bf215546Sopenharmony_ci}
303bf215546Sopenharmony_ci
304bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_num_attribs)
305bf215546Sopenharmony_ci{
306bf215546Sopenharmony_ci   /* Use zeros in the second half of each attribute pair to try and trick the
307bf215546Sopenharmony_ci    * implementation into termiating the list early.
308bf215546Sopenharmony_ci    *
309bf215546Sopenharmony_ci    * Use non-zero in the second half of the last attribute pair to try and
310bf215546Sopenharmony_ci    * trick the implementation into not terminating the list early enough.
311bf215546Sopenharmony_ci    */
312bf215546Sopenharmony_ci   static const int attribs[] = {
313bf215546Sopenharmony_ci      1, 0,
314bf215546Sopenharmony_ci      2, 0,
315bf215546Sopenharmony_ci      3, 0,
316bf215546Sopenharmony_ci      4, 0,
317bf215546Sopenharmony_ci      0, 6,
318bf215546Sopenharmony_ci      0, 0
319bf215546Sopenharmony_ci   };
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
322bf215546Sopenharmony_ci			      False, attribs);
323bf215546Sopenharmony_ci
324bf215546Sopenharmony_ci   EXPECT_EQ(4u, req.num_attribs);
325bf215546Sopenharmony_ci}
326bf215546Sopenharmony_ci
327bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_num_attribs_empty_list)
328bf215546Sopenharmony_ci{
329bf215546Sopenharmony_ci   static const int attribs[] = {
330bf215546Sopenharmony_ci      0,
331bf215546Sopenharmony_ci   };
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
334bf215546Sopenharmony_ci			      False, attribs);
335bf215546Sopenharmony_ci
336bf215546Sopenharmony_ci   EXPECT_EQ(0u, req.num_attribs);
337bf215546Sopenharmony_ci}
338bf215546Sopenharmony_ci
339bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_num_attribs_NULL_list_pointer)
340bf215546Sopenharmony_ci{
341bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
342bf215546Sopenharmony_ci			      False, NULL);
343bf215546Sopenharmony_ci
344bf215546Sopenharmony_ci   EXPECT_EQ(0u, req.num_attribs);
345bf215546Sopenharmony_ci}
346bf215546Sopenharmony_ci
347bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, sent_correct_attrib_list)
348bf215546Sopenharmony_ci{
349bf215546Sopenharmony_ci   int attribs[] = {
350bf215546Sopenharmony_ci      GLX_RENDER_TYPE, GLX_RGBA_TYPE,
351bf215546Sopenharmony_ci      GLX_CONTEXT_MAJOR_VERSION_ARB, 1,
352bf215546Sopenharmony_ci      GLX_CONTEXT_MINOR_VERSION_ARB, 2,
353bf215546Sopenharmony_ci      0
354bf215546Sopenharmony_ci   };
355bf215546Sopenharmony_ci
356bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
357bf215546Sopenharmony_ci			      False, attribs);
358bf215546Sopenharmony_ci
359bf215546Sopenharmony_ci   for (unsigned i = 0; i < 6; i++) {
360bf215546Sopenharmony_ci      EXPECT_EQ((uint32_t) attribs[i], sent_attribs[i]);
361bf215546Sopenharmony_ci   }
362bf215546Sopenharmony_ci}
363bf215546Sopenharmony_ci/*@}*/
364bf215546Sopenharmony_ci
365bf215546Sopenharmony_ci/**
366bf215546Sopenharmony_ci * \name Verify details of the returned GLXContext
367bf215546Sopenharmony_ci */
368bf215546Sopenharmony_ci/*@{*/
369bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context)
370bf215546Sopenharmony_ci{
371bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
372bf215546Sopenharmony_ci				 False, NULL);
373bf215546Sopenharmony_ci
374bf215546Sopenharmony_ci   /* Since the server did not return an error, the GLXContext should not be
375bf215546Sopenharmony_ci    * NULL.
376bf215546Sopenharmony_ci    */
377bf215546Sopenharmony_ci   EXPECT_NE((GLXContext)0, ctx);
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_ci   /* It shouldn't be the XID of the context either.
380bf215546Sopenharmony_ci    */
381bf215546Sopenharmony_ci   EXPECT_NE((GLXContext)99, ctx);
382bf215546Sopenharmony_ci}
383bf215546Sopenharmony_ci
384bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_xid)
385bf215546Sopenharmony_ci{
386bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
387bf215546Sopenharmony_ci				 False, NULL);
388bf215546Sopenharmony_ci
389bf215546Sopenharmony_ci   /* Since the server did not return an error, the GLXContext should not be
390bf215546Sopenharmony_ci    * NULL.
391bf215546Sopenharmony_ci    */
392bf215546Sopenharmony_ci   ASSERT_NE((GLXContext)0, ctx);
393bf215546Sopenharmony_ci
394bf215546Sopenharmony_ci   struct glx_context *glx_ctx = (struct glx_context *) ctx;
395bf215546Sopenharmony_ci   EXPECT_EQ(99u, glx_ctx->xid);
396bf215546Sopenharmony_ci}
397bf215546Sopenharmony_ci
398bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_share_xid)
399bf215546Sopenharmony_ci{
400bf215546Sopenharmony_ci   GLXContext first =
401bf215546Sopenharmony_ci      glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
402bf215546Sopenharmony_ci				 False, NULL);
403bf215546Sopenharmony_ci
404bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, first);
405bf215546Sopenharmony_ci
406bf215546Sopenharmony_ci   GLXContext second =
407bf215546Sopenharmony_ci      glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, first,
408bf215546Sopenharmony_ci				 False, NULL);
409bf215546Sopenharmony_ci
410bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, second);
411bf215546Sopenharmony_ci
412bf215546Sopenharmony_ci   struct glx_context *share = (struct glx_context *) first;
413bf215546Sopenharmony_ci   struct glx_context *ctx = (struct glx_context *) second;
414bf215546Sopenharmony_ci   EXPECT_EQ(share->xid, ctx->share_xid);
415bf215546Sopenharmony_ci
416bf215546Sopenharmony_ci   delete (fake_glx_context *)first;
417bf215546Sopenharmony_ci   delete (fake_glx_context *)second;
418bf215546Sopenharmony_ci}
419bf215546Sopenharmony_ci
420bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_isDirect_for_indirect_screen_and_direct_set_to_true)
421bf215546Sopenharmony_ci{
422bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
423bf215546Sopenharmony_ci				 True, NULL);
424bf215546Sopenharmony_ci
425bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
426bf215546Sopenharmony_ci
427bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
428bf215546Sopenharmony_ci
429bf215546Sopenharmony_ci   EXPECT_FALSE(gc->isDirect);
430bf215546Sopenharmony_ci}
431bf215546Sopenharmony_ci
432bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_isDirect_for_indirect_screen_and_direct_set_to_false)
433bf215546Sopenharmony_ci{
434bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
435bf215546Sopenharmony_ci				 False, NULL);
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
438bf215546Sopenharmony_ci
439bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
440bf215546Sopenharmony_ci
441bf215546Sopenharmony_ci   EXPECT_FALSE(gc->isDirect);
442bf215546Sopenharmony_ci}
443bf215546Sopenharmony_ci
444bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_isDirect_for_direct_screen_and_direct_set_to_true)
445bf215546Sopenharmony_ci{
446bf215546Sopenharmony_ci   this->use_direct_rendering_screen();
447bf215546Sopenharmony_ci
448bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
449bf215546Sopenharmony_ci				 True, NULL);
450bf215546Sopenharmony_ci
451bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
452bf215546Sopenharmony_ci
453bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
454bf215546Sopenharmony_ci
455bf215546Sopenharmony_ci   EXPECT_TRUE(gc->isDirect);
456bf215546Sopenharmony_ci}
457bf215546Sopenharmony_ci
458bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_isDirect_for_direct_screen_and_direct_set_to_false)
459bf215546Sopenharmony_ci{
460bf215546Sopenharmony_ci   this->use_direct_rendering_screen();
461bf215546Sopenharmony_ci
462bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
463bf215546Sopenharmony_ci				 False, NULL);
464bf215546Sopenharmony_ci
465bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
466bf215546Sopenharmony_ci
467bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
468bf215546Sopenharmony_ci
469bf215546Sopenharmony_ci   EXPECT_FALSE(gc->isDirect);
470bf215546Sopenharmony_ci}
471bf215546Sopenharmony_ci
472bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_indirect_context_client_state_private)
473bf215546Sopenharmony_ci{
474bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
475bf215546Sopenharmony_ci				 False, NULL);
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
478bf215546Sopenharmony_ci
479bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci   ASSERT_FALSE(gc->isDirect);
482bf215546Sopenharmony_ci   EXPECT_EQ((struct __GLXattributeRec *) 0xcafebabe,
483bf215546Sopenharmony_ci	     gc->client_state_private);
484bf215546Sopenharmony_ci}
485bf215546Sopenharmony_ci
486bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_indirect_context_config)
487bf215546Sopenharmony_ci{
488bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
489bf215546Sopenharmony_ci				 False, NULL);
490bf215546Sopenharmony_ci
491bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
494bf215546Sopenharmony_ci
495bf215546Sopenharmony_ci   EXPECT_EQ(&this->fbc, gc->config);
496bf215546Sopenharmony_ci}
497bf215546Sopenharmony_ci
498bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_screen_number)
499bf215546Sopenharmony_ci{
500bf215546Sopenharmony_ci   this->fbc.screen = 7;
501bf215546Sopenharmony_ci   psc->scr = 7;
502bf215546Sopenharmony_ci
503bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
504bf215546Sopenharmony_ci				 False, NULL);
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
507bf215546Sopenharmony_ci
508bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
509bf215546Sopenharmony_ci
510bf215546Sopenharmony_ci   EXPECT_EQ(7, gc->screen);
511bf215546Sopenharmony_ci}
512bf215546Sopenharmony_ci
513bf215546Sopenharmony_ciTEST_F(glXCreateContextAttribARB_test, correct_context_screen_pointer)
514bf215546Sopenharmony_ci{
515bf215546Sopenharmony_ci   ctx = glXCreateContextAttribsARB(this->dpy, (GLXFBConfig) &this->fbc, 0,
516bf215546Sopenharmony_ci				 False, NULL);
517bf215546Sopenharmony_ci
518bf215546Sopenharmony_ci   ASSERT_NE((GLXContext) 0, ctx);
519bf215546Sopenharmony_ci
520bf215546Sopenharmony_ci   struct glx_context *gc = (struct glx_context *) ctx;
521bf215546Sopenharmony_ci
522bf215546Sopenharmony_ci   EXPECT_EQ(psc, gc->psc);
523bf215546Sopenharmony_ci}
524bf215546Sopenharmony_ci/*@}*/
525