1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
/*
 * PROJECT:         ReactOS api tests
 * LICENSE:         GPL - See COPYING in the top level directory
 * PURPOSE:         Test for NtGdiDdCreateDirectDrawObject
 * PROGRAMMERS:
 */

#include <win32nt.h>

#include <ddrawi.h>

/* Note : OsThunkDdQueryDirectDrawObject is the usermode name of NtGdiDdQueryDirectDrawObject
 *        it lives in d3d8thk.dll and in windows 2000 it doing syscall direcly to win32k.sus
 *        in windows xp and higher it call to gdi32.dll to DdEntry41 and it doing the syscall
 */
START_TEST(NtGdiDdQueryDirectDrawObject)
{
    HANDLE hDirectDraw;
    DD_HALINFO *pHalInfo = NULL;
    DWORD *pCallBackFlags = NULL;
    LPD3DNTHAL_CALLBACKS puD3dCallbacks = NULL;
    LPD3DNTHAL_GLOBALDRIVERDATA puD3dDriverData = NULL;
    PDD_D3DBUFCALLBACKS puD3dBufferCallbacks = NULL;
    LPDDSURFACEDESC puD3dTextureFormats = NULL;
    DWORD *puNumHeaps = NULL;
    VIDEOMEMORY *puvmList = NULL;
    DWORD *puNumFourCC = NULL;
    DWORD *puFourCC = NULL;

    DD_HALINFO HalInfo;
    DD_HALINFO oldHalInfo;
    DWORD CallBackFlags[4];

    D3DNTHAL_CALLBACKS D3dCallbacks;
    D3DNTHAL_CALLBACKS oldD3dCallbacks;

    D3DNTHAL_GLOBALDRIVERDATA D3dDriverData;
    D3DNTHAL_GLOBALDRIVERDATA oldD3dDriverData;

    DD_D3DBUFCALLBACKS D3dBufferCallbacks;
    DD_D3DBUFCALLBACKS oldD3dBufferCallbacks;

    DDSURFACEDESC2 D3dTextureFormats[100];
    DWORD NumHeaps = 0;
    VIDEOMEMORY vmList;
    //DWORD NumFourCC = 0;
    //DWORD FourCC = 0;
    DEVMODE devmode;
    HDC hdc;

    DWORD dwTextureCounter = 0;
    DDSURFACEDESC *myDesc = NULL;

    /* clear data */
    memset(&vmList,0,sizeof(VIDEOMEMORY));
    memset(&D3dTextureFormats,0,sizeof(DDSURFACEDESC));
    memset(&D3dBufferCallbacks,0,sizeof(DD_D3DBUFCALLBACKS));
    memset(&D3dDriverData,0,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
    memset(&D3dCallbacks,0,sizeof(D3DNTHAL_CALLBACKS));
    memset(&HalInfo,0,sizeof(DD_HALINFO));
    memset(CallBackFlags,0,sizeof(DWORD)*3);

    /* Get current display mode */
    EnumDisplaySettingsA(NULL, ENUM_CURRENT_SETTINGS, &devmode);

    /* Create hdc that we can use */
    hdc = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
    ASSERT(hdc != NULL);


    hDirectDraw = NtGdiDdCreateDirectDrawObject(hdc);
    RTEST(hDirectDraw != NULL);

    /* testing  OsThunkDdQueryDirectDrawObject( NULL, ....  */
    RTEST(NtGdiDdQueryDirectDrawObject( NULL, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC) == FALSE);

    RTEST(pHalInfo == NULL);
    RTEST(pCallBackFlags == NULL);
    RTEST(puD3dCallbacks == NULL);
    RTEST(puD3dDriverData == NULL);
    RTEST(puD3dBufferCallbacks == NULL);
    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    if (hDirectDraw == NULL)
    {
        skip("No DirectDrawObject\n");
        ok(DeleteDC(hdc) != 0, "DeleteDC() failed\n");
        return;
    }

    /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, NULL, ....  */
    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC) == FALSE);

    RTEST(pHalInfo == NULL);
    RTEST(pCallBackFlags == NULL);
    RTEST(puD3dCallbacks == NULL);
    RTEST(puD3dDriverData == NULL);
    RTEST(puD3dBufferCallbacks == NULL);
    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, pHalInfo, NULL, ....  */
    pHalInfo = &HalInfo;
    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);

    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags == NULL);
    RTEST(puD3dCallbacks == NULL);
    RTEST(puD3dDriverData == NULL);
    RTEST(puD3dBufferCallbacks == NULL);
    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    if ((pHalInfo->dwSize != sizeof(DD_HALINFO)) &&
        (pHalInfo->dwSize != sizeof(DD_HALINFO_V4)))
    {
        RTEST(pHalInfo->dwSize != sizeof(DD_HALINFO));
        ASSERT(pHalInfo->dwSize != sizeof(DD_HALINFO));
    }

    if (pHalInfo->dwSize == sizeof(DD_HALINFO))
    {
        /*the offset, in bytes, to primary surface in the display memory  */
        /* some graphic card like  sis 760 GX, Nvida GF7900GS does not set any offset at all */
        // RTEST(pHalInfo->vmiData.fpPrimary != 0 );

        /* unsuse always 0 */
        RTEST(pHalInfo->vmiData.dwFlags == 0 );

        /* Check the res */
        RTEST(pHalInfo->vmiData.dwDisplayWidth == devmode.dmPelsWidth );
        RTEST(pHalInfo->vmiData.dwDisplayHeight == devmode.dmPelsHeight );

        /*  This can never be test for it is who big the line is after it been align displayPitch */
        RTEST(pHalInfo->vmiData.lDisplayPitch != 0);

        RTEST(pHalInfo->vmiData.ddpfDisplay.dwSize == sizeof(DDPIXELFORMAT) );
        ASSERT(pHalInfo->vmiData.ddpfDisplay.dwSize == sizeof(DDPIXELFORMAT));

        /* We can not check if it DDPF_RGB flags been set for primary surface
         * for it can be DDPF_PALETTEINDEXED1,DDPF_PALETTEINDEXED2,DDPF_PALETTEINDEXED4,DDPF_PALETTEINDEXED8, DDPF_PALETTEINDEXEDTO8, DDPF_RGB, DDPF_YUV
         */
        RTEST( (pHalInfo->vmiData.ddpfDisplay.dwFlags & (DDPF_PALETTEINDEXED1 | DDPF_PALETTEINDEXED2 | DDPF_PALETTEINDEXED4 |
                                                         DDPF_PALETTEINDEXED8 | DDPF_PALETTEINDEXEDTO8 | DDPF_RGB | DDPF_YUV)) != 0);


        /* No fourcc are use on primary screen */
        RTEST(pHalInfo->vmiData.ddpfDisplay.dwFourCC == 0 );

        /* Count RGB Bits 8/16/24/32 */
        RTEST(pHalInfo->vmiData.ddpfDisplay.dwRGBBitCount == devmode.dmBitsPerPel );

        /* The rgb mask can not be detected in user mode, for it can be 15Bpp convert to 16Bpp mode, so we have no way detect correct mask
         * But the mask can never be Zero
         */
        RTEST(pHalInfo->vmiData.ddpfDisplay.dwRBitMask  !=  0 );
        RTEST(pHalInfo->vmiData.ddpfDisplay.dwGBitMask !=  0 );
        RTEST(pHalInfo->vmiData.ddpfDisplay.dwBBitMask != 0 );

        /* primary never set the alpha blend mask */
        RTEST(pHalInfo->vmiData.ddpfDisplay.dwRGBAlphaBitMask ==  0 );

        /* This can not be test at usermode it is each hardware drv that fill in it,
         * only way to found them is to use this call  */
        // pHalInfo->vmiData->dwOffscreenAlign
        // pHalInfo->vmiData->dwOverlayAlign
        // pHalInfo->vmiData->dwTextureAlign
        // pHalInfo->vmiData->dwZBufferAlign
        // pHalInfo->vmiData->dwAlphaAlign

        /* the primary display address */
        RTEST( ( (DWORD_PTR)pHalInfo->vmiData.pvPrimary & (~0x80000000)) != 0 );

        /* test see if we got back the pvmList here
         * acording msdn vmiData.dwNumHeaps and vmiData.pvmList
         * exists for _VIDEOMEMORYINFO but they do not, it reviews
         * in ddk and wdk and own testcase
         */
         // RTEST(pHalInfo->vmiData.dwNumHeaps  != 0 );
         // RTEST(pHalInfo->vmiData.pvmList  != 0 );

        /* Test see if we got any hardware acclartions for 2d or 3d, this always fill in
         * that mean we found a bugi drv and dx does not work on this drv
         */

        /* the SIS 760 GX will never fill it in, it is a bugi drv */
        RTEST(pHalInfo->ddCaps.dwSize == sizeof(DDCORECAPS));

        /* Testing see if we got any hw support for
         * This test can fail on video card that does not support 2d/overlay/3d
         */
        RTEST( pHalInfo->ddCaps.dwCaps != 0);
        RTEST( pHalInfo->ddCaps.ddsCaps.dwCaps != 0);

        /* This flags is obsolete and should not be used by the driver */
        RTEST( pHalInfo->ddCaps.dwFXAlphaCaps == 0);


        /* basic dx 2 is found if this flags not set
         * if this fail we do not have a dx driver install acodring ms, some version of windows it
         * is okay this fail and drv does then only support basic dx
         *
         */
        if (pHalInfo->dwFlags != 0)
        {
            RTEST( (pHalInfo->dwFlags & (DDHALINFO_GETDRIVERINFOSET | DDHALINFO_GETDRIVERINFO2)) != 0 );
            RTEST( ( (DWORD_PTR)pHalInfo->GetDriverInfo & 0x80000000) != 0 );
            ASSERT( ((DWORD_PTR)pHalInfo->GetDriverInfo & 0x80000000) != 0 );
        }

        /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/


       /* the pHalInfo->ddCaps.ddsCaps.dwCaps & DDSCAPS_3DDEVICE will be ignore, only way detect it proper follow code,
        * this will be fill in of all drv, it is not only for 3d stuff, this always fill by win32k.sys or dxg.sys depns
        * if it windows 2000 or windows xp/2003
        *
        * point to kmode direcly to the win32k.sys, win32k.sys is kmode and it is kmode address we getting back
        */
        RTEST( ( (DWORD_PTR)pHalInfo->lpD3DGlobalDriverData & (~0x80000000)) != 0 );
        RTEST( ( (DWORD_PTR)pHalInfo->lpD3DHALCallbacks & (~0x80000000)) != 0 );
        RTEST( ( (DWORD_PTR)pHalInfo->lpD3DHALCallbacks & (~0x80000000)) != 0 );
    }

    /* Backup DD_HALINFO so we do not need resting it */
    RtlCopyMemory(&oldHalInfo, &HalInfo, sizeof(DD_HALINFO));

    /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, pHalInfo, pCallBackFlags, NULL, ....  */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);
    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    RTEST(puD3dCallbacks == NULL);
    RTEST(puD3dDriverData == NULL);
    RTEST(puD3dBufferCallbacks == NULL);
    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    /* We do not retesting DD_HALINFO, instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);

    /* Rember on some nivida drv the pCallBackFlags will not be set even they api exists in the drv
     * known workaround is to check if the drv really return a kmode pointer for the drv functions
     * we want to use.
     */
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* testing  NtGdiDdQueryDirectDrawObject( hDirectDrawLocal, pHalInfo, pCallBackFlags, D3dCallbacks, NULL, ....  */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    puD3dCallbacks = &D3dCallbacks;

    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
    RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);
    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    /* rember puD3dCallbacks shall never return NULL */
    RTEST(puD3dCallbacks != NULL);
    ASSERT(puD3dCallbacks != NULL);

    /* the pHalInfo->ddCaps.ddsCaps.dwCaps & DDSCAPS_3DDEVICE will be ignore, only way detect it proper follow code,
     * this will be fill in of all drv, it is not only for 3d stuff, this always fill by win32k.sys or dxg.sys depns
     * if it windows 2000 or windows xp/2003
     */
    RTEST(puD3dCallbacks->dwSize == sizeof(D3DNTHAL_CALLBACKS));

    /* Nivda like GF7900GS will not follow ms design rule here,
     * ContextDestroyAll must alwyas be NULL for it is not longer inuse in windows 2000 and higher
     */
    RTEST(puD3dCallbacks->ContextDestroyAll == NULL);

    /* Nivda like GF7900GS will not follow ms design rule here,
     * SceneCapture must alwyas be NULL for it is not longer inuse in windows 2000 and higher
     */
    RTEST(puD3dCallbacks->SceneCapture  == NULL);
    RTEST(puD3dCallbacks->dwReserved10 == 0);
    RTEST(puD3dCallbacks->dwReserved11 == 0);
    RTEST(puD3dCallbacks->dwReserved22 == 0);
    RTEST(puD3dCallbacks->dwReserved23 == 0);
    RTEST(puD3dCallbacks->dwReserved == 0);
    RTEST(puD3dCallbacks->TextureCreate  == NULL);
    RTEST(puD3dCallbacks->TextureDestroy  == NULL);
    RTEST(puD3dCallbacks->TextureSwap  == NULL);
    RTEST(puD3dCallbacks->TextureGetSurf  == NULL);
    RTEST(puD3dCallbacks->dwReserved12 == 0);
    RTEST(puD3dCallbacks->dwReserved13 == 0);
    RTEST(puD3dCallbacks->dwReserved14 == 0);
    RTEST(puD3dCallbacks->dwReserved15 == 0);
    RTEST(puD3dCallbacks->dwReserved16 == 0);
    RTEST(puD3dCallbacks->dwReserved17 == 0);
    RTEST(puD3dCallbacks->dwReserved18 == 0);
    RTEST(puD3dCallbacks->dwReserved19 == 0);
    RTEST(puD3dCallbacks->dwReserved20 == 0);
    RTEST(puD3dCallbacks->dwReserved21 == 0);
    RTEST(puD3dCallbacks->dwReserved24 == 0);
    RTEST(puD3dCallbacks->dwReserved0 == 0);
    RTEST(puD3dCallbacks->dwReserved1 == 0);
    RTEST(puD3dCallbacks->dwReserved2 == 0);
    RTEST(puD3dCallbacks->dwReserved3 == 0);
    RTEST(puD3dCallbacks->dwReserved4 == 0);
    RTEST(puD3dCallbacks->dwReserved5 == 0);
    RTEST(puD3dCallbacks->dwReserved6 == 0);
    RTEST(puD3dCallbacks->dwReserved7 == 0);
    RTEST(puD3dCallbacks->dwReserved8 == 0);
    RTEST(puD3dCallbacks->dwReserved9 == 0);

    /* how detect puD3dCallbacks->ContextCreate and puD3dCallbacks->ContextDestroy shall be set for bugi drv like nivda ? */
    /* pointer direcly to the graphic drv, it is kmode pointer */
    // RTEST( ( (DWORD)puD3dCallbacks->ContextCreate & (~0x80000000)) != 0 );
    // RTEST( ( (DWORD)puD3dCallbacks->ContextDestroy & (~0x80000000)) != 0 );

    RTEST(puD3dDriverData == NULL);
    RTEST(puD3dBufferCallbacks == NULL);
    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    /* We do not retesting DD_HALINFO, instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* Backup D3DNTHAL_CALLBACKS so we do not need resting it */
    RtlCopyMemory(&oldD3dCallbacks, &D3dCallbacks, sizeof(D3DNTHAL_CALLBACKS));


/* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, NULL, */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    puD3dCallbacks = &D3dCallbacks;
    puD3dDriverData = &D3dDriverData;

    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
    RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
    RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);
    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    RTEST(puD3dCallbacks != NULL);
    ASSERT(puD3dCallbacks != NULL);

    RTEST(puD3dDriverData != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dBufferCallbacks == NULL);
    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    /* We retesting pCallBackFlags  */
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* We do not retesting instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
    RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);

    /* start test of puD3dDriverData */

    RTEST(puD3dDriverData->dwSize == sizeof(D3DNTHAL_GLOBALDRIVERDATA));
    RTEST(puD3dDriverData->hwCaps.dwSize == sizeof(D3DNTHALDEVICEDESC_V1));
    RTEST(puD3dDriverData->hwCaps.dtcTransformCaps.dwSize == sizeof(D3DTRANSFORMCAPS));
    RTEST(puD3dDriverData->hwCaps.dlcLightingCaps.dwSize == sizeof(D3DLIGHTINGCAPS));
    RTEST(puD3dDriverData->hwCaps.dpcLineCaps.dwSize == sizeof(D3DPRIMCAPS));
    RTEST(puD3dDriverData->hwCaps.dpcTriCaps.dwSize  == sizeof(D3DPRIMCAPS));
    RTEST(puD3dDriverData->hwCaps.dwMaxBufferSize == 0);
    RTEST(puD3dDriverData->hwCaps.dwMaxVertexCount == 0);

    /* Backup D3DHAL_GLOBALDRIVERDATA so we do not need resting it */
    RtlCopyMemory(&oldD3dDriverData, &D3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA));

/* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, NULL, */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    puD3dCallbacks = &D3dCallbacks;
    puD3dDriverData = &D3dDriverData;
    puD3dBufferCallbacks = &D3dBufferCallbacks;

    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
    RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
    RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
    RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_CALLBACKS));

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);
    RTEST(pHalInfo != NULL);
    RTEST(pCallBackFlags != NULL);

    if (pHalInfo->ddCaps.ddsCaps.dwCaps  & DDSCAPS_3DDEVICE )<--- Null pointer dereference
    {
        RTEST(puD3dCallbacks != NULL);
        RTEST(puD3dDriverData != NULL);
        RTEST(puD3dBufferCallbacks != NULL);
    }

    RTEST(pHalInfo != NULL);<--- Assuming that condition 'pHalInfo!=NULL' is not redundant
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    RTEST(puD3dCallbacks != NULL);
    ASSERT(puD3dCallbacks != NULL);

    RTEST(puD3dDriverData != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dBufferCallbacks != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dTextureFormats == NULL);
    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    /* We retesting the flags */
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* We do not retesting instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
    RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
    RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);

    /* start test of puD3dBufferCallbacks */
    RTEST(puD3dBufferCallbacks->dwSize == sizeof(DD_D3DBUFCALLBACKS));
    if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_CANCREATED3DBUF)
    {
        /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
        RTEST( ( (DWORD_PTR)puD3dBufferCallbacks->CanCreateD3DBuffer & (~0x80000000)) != 0 );
    }
    else
    {
        RTEST( puD3dBufferCallbacks->CanCreateD3DBuffer == NULL);
    }

    if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_CREATED3DBUF)
    {
        /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
        RTEST( ( (DWORD_PTR)puD3dBufferCallbacks->CreateD3DBuffer & (~0x80000000)) != 0 );
    }
    else
    {
        RTEST( puD3dBufferCallbacks->CreateD3DBuffer == NULL);
    }

    if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_DESTROYD3DBUF)
    {
        /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
        RTEST( ( (DWORD_PTR)puD3dBufferCallbacks->DestroyD3DBuffer & (~0x80000000)) != 0 );
    }
    else
    {
        RTEST( puD3dBufferCallbacks->DestroyD3DBuffer == NULL);
    }

    if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_LOCKD3DBUF)
    {
        /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
        RTEST( ( (DWORD_PTR)puD3dBufferCallbacks->LockD3DBuffer & (~0x80000000)) != 0 );
    }
    else
    {
        RTEST( puD3dBufferCallbacks->LockD3DBuffer == NULL);
    }

    if (puD3dBufferCallbacks->dwFlags & DDHAL_D3DBUFCB32_UNLOCKD3DBUF)
    {
        /* point to kmode direcly to the graphic drv, the drv is kmode and it is kmode address we getting back*/
        RTEST( ( (DWORD_PTR)puD3dBufferCallbacks->UnlockD3DBuffer & (~0x80000000)) != 0 );
    }
    else
    {
        RTEST( puD3dBufferCallbacks->UnlockD3DBuffer == NULL);
    }

    /* Backup DD_D3DBUFCALLBACKS so we do not need resting it */
    RtlCopyMemory(&oldD3dBufferCallbacks, &D3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS));


/* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, puD3dTextureFormats, NULL, */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    puD3dCallbacks = &D3dCallbacks;
    puD3dDriverData = &D3dDriverData;
    puD3dBufferCallbacks = &D3dBufferCallbacks;

    /* It is forbein to return a  DDSURFACEDESC2 it should always be DDSURFACEDESC
        This is only for detected bad drivers that does not follow the rules, if they
        does not follow tthe rules, not everthing being copy then in gdi32.dll
        gdi32.dll always assume it is DDSURFACEDESC size
    */
    if (puD3dDriverData->dwNumTextureFormats != 0)
    {
        puD3dTextureFormats = malloc (puD3dDriverData->dwNumTextureFormats * sizeof(DDSURFACEDESC2));
    }

    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
    RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
    RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
    RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
    RtlZeroMemory(&D3dBufferCallbacks,sizeof(DD_D3DBUFCALLBACKS));

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);

    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    RTEST(puD3dCallbacks != NULL);
    ASSERT(puD3dCallbacks != NULL);

    RTEST(puD3dDriverData != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dBufferCallbacks != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dTextureFormats != NULL);
    ASSERT(puD3dTextureFormats != NULL);

    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);
    RTEST(puNumHeaps == NULL);
    RTEST(puvmList == NULL);

    /* We retesting the flags */
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* We do not retesting instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
    RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
    RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
    RTEST(memcmp(&oldD3dBufferCallbacks, puD3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS)) == 0);

    /* start test of dwNumTextureFormats */
    if (puD3dDriverData->dwNumTextureFormats != 0)
    {
        myDesc = puD3dTextureFormats;
        for (dwTextureCounter=0;dwTextureCounter<puD3dDriverData->dwNumTextureFormats;dwTextureCounter++)
        {
            RTEST(myDesc->dwSize == sizeof(DDSURFACEDESC));
            ASSERT(myDesc->dwSize == sizeof(DDSURFACEDESC));

            RTEST( (myDesc->dwFlags & (~(DDSD_CAPS|DDSD_PIXELFORMAT))) == 0);
            RTEST(myDesc->dwHeight == 0);
            RTEST(myDesc->dwWidth == 0);
            RTEST(myDesc->dwLinearSize == 0);
            RTEST(myDesc->dwBackBufferCount == 0);
            RTEST(myDesc->dwZBufferBitDepth == 0);
            RTEST(myDesc->dwAlphaBitDepth == 0);
            RTEST(myDesc->dwReserved == 0);
            RTEST(myDesc->lpSurface == 0);
            RTEST(myDesc->ddckCKDestOverlay.dwColorSpaceLowValue == 0);
            RTEST(myDesc->ddckCKDestOverlay.dwColorSpaceHighValue == 0);
            RTEST(myDesc->ddckCKDestBlt.dwColorSpaceLowValue == 0);
            RTEST(myDesc->ddckCKDestBlt.dwColorSpaceHighValue == 0);
            RTEST(myDesc->ddckCKSrcOverlay.dwColorSpaceLowValue == 0);
            RTEST(myDesc->ddckCKSrcOverlay.dwColorSpaceHighValue == 0);
            RTEST(myDesc->ddckCKSrcBlt.dwColorSpaceLowValue == 0);
            RTEST(myDesc->ddckCKSrcBlt.dwColorSpaceHighValue == 0);
            RTEST(myDesc->ddpfPixelFormat.dwSize == sizeof(DDPIXELFORMAT));
            RTEST(myDesc->ddpfPixelFormat.dwFlags != 0);
            if (myDesc->ddpfPixelFormat.dwFlags & DDPF_FOURCC)
            {
                RTEST(myDesc->ddpfPixelFormat.dwFourCC != 0);
            }
            RTEST(myDesc->ddsCaps.dwCaps == DDSCAPS_TEXTURE);

            myDesc = (DDSURFACEDESC *) (((DWORD_PTR) myDesc) + sizeof(DDSURFACEDESC));
        }
    }


    /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, puD3dTextureFormats, puNumHeaps, NULL, */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    puD3dCallbacks = &D3dCallbacks;
    puD3dDriverData = &D3dDriverData;
    puD3dBufferCallbacks = &D3dBufferCallbacks;
    puNumHeaps = &NumHeaps;

    if (puD3dDriverData->dwNumTextureFormats != 0)
    {
        RtlZeroMemory(puD3dTextureFormats, puD3dDriverData->dwNumTextureFormats * sizeof(DDSURFACEDESC2));
    }
    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
    RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
    RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
    RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
    RtlZeroMemory(&D3dBufferCallbacks,sizeof(DD_D3DBUFCALLBACKS));

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);

    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    RTEST(puD3dCallbacks != NULL);
    ASSERT(puD3dCallbacks != NULL);

    RTEST(puD3dDriverData != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dBufferCallbacks != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dTextureFormats != NULL);
    ASSERT(puD3dTextureFormats != NULL);

    RTEST(puNumHeaps != NULL);
    ASSERT(puNumHeaps != NULL);
    RTEST(NumHeaps == 0);

    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);

    RTEST(puvmList == NULL);

    /* We retesting the flags */
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* We do not retesting instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
    RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
    RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
    RTEST(memcmp(&oldD3dBufferCallbacks, puD3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS)) == 0);
    /* we skip resting texture */


    /* testing  NtGdiDdQueryDirectDrawObject( hDD, pHalInfo, pCallBackFlags, puD3dCallbacks, puD3dDriverData, puD3dBufferCallbacks, puD3dTextureFormats, puNumHeaps, puvmList, NULL, */
    pHalInfo = &HalInfo;
    pCallBackFlags = CallBackFlags;
    puD3dCallbacks = &D3dCallbacks;
    puD3dDriverData = &D3dDriverData;
    puD3dBufferCallbacks = &D3dBufferCallbacks;
    puNumHeaps = &NumHeaps;
    puvmList = &vmList;

    if (puD3dDriverData->dwNumTextureFormats != 0)
    {
        RtlZeroMemory(puD3dTextureFormats, puD3dDriverData->dwNumTextureFormats * sizeof(DDSURFACEDESC2));
    }
    RtlZeroMemory(pHalInfo,sizeof(DD_HALINFO));
    RtlZeroMemory(pCallBackFlags,sizeof(DWORD)*3);
    RtlZeroMemory(puD3dCallbacks,sizeof(D3DNTHAL_CALLBACKS));
    RtlZeroMemory(puD3dDriverData,sizeof(D3DNTHAL_GLOBALDRIVERDATA));
    RtlZeroMemory(&D3dBufferCallbacks,sizeof(DD_D3DBUFCALLBACKS));

    RTEST(NtGdiDdQueryDirectDrawObject( hDirectDraw, pHalInfo,
                                        pCallBackFlags, puD3dCallbacks,
                                        puD3dDriverData, puD3dBufferCallbacks,
                                        puD3dTextureFormats, puNumHeaps,
                                        puvmList, puNumFourCC,
                                        puFourCC)== FALSE);

    RTEST(pHalInfo != NULL);
    ASSERT(pHalInfo != NULL);

    RTEST(pCallBackFlags != NULL);
    ASSERT(pCallBackFlags != NULL);

    RTEST(puD3dCallbacks != NULL);
    ASSERT(puD3dCallbacks != NULL);

    RTEST(puD3dDriverData != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dBufferCallbacks != NULL);
    ASSERT(puD3dDriverData != NULL);

    RTEST(puD3dTextureFormats != NULL);
    ASSERT(puD3dTextureFormats != NULL);

    RTEST(puNumHeaps != NULL);
    ASSERT(puNumHeaps != NULL);
    RTEST(NumHeaps == 0);

    RTEST(puvmList != NULL);

    RTEST(puNumFourCC == NULL);
    RTEST(puFourCC == NULL);



    /* We retesting the flags */
    RTEST(pCallBackFlags[0] != 0);
    RTEST(pCallBackFlags[1] != 0);
    RTEST(pCallBackFlags[2] == 0);

    /* We do not retesting instead we compare it */
    RTEST(memcmp(&oldHalInfo, pHalInfo, sizeof(DD_HALINFO)) == 0);
    RTEST(memcmp(&oldD3dCallbacks, puD3dCallbacks, sizeof(D3DNTHAL_CALLBACKS)) == 0);
    RTEST(memcmp(&oldD3dDriverData, puD3dDriverData, sizeof(D3DNTHAL_GLOBALDRIVERDATA)) == 0);
    RTEST(memcmp(&oldD3dBufferCallbacks, puD3dBufferCallbacks, sizeof(DD_D3DBUFCALLBACKS)) == 0);
    /* we skip resting texture */

    /* Todo
    * adding test for
    * puNumFourCC
    * puFourCC
    */

    ok(NtGdiDdDeleteDirectDrawObject(hDirectDraw) == TRUE,
       "NtGdiDdDeleteDirectDrawObject() failed\n");

    ok(DeleteDC(hdc) != 0, "DeleteDC() failed\n");
}