CTC++ Coverage Report- Execution Profile#3/7

Directory Summary | Files Summary | Functions Summary | Untested Code | Execution Profile
To files: First | Previous | Next | Last | Index | No Index


Source file:f:\ctcwork\Demos\cube\cubeview.cpp
Instrumentation mode:multiconditionReduced to:MC/DC coverage
TER:63 % (67/107) structural,79 % (155/196) statement

Hits/TrueFalseLineSource
1// cubeview.cpp : implementation of the CCubeView class
2//
3// This is a part of the Microsoft Foundation Classes C++ library.
4// Copyright (c) Microsoft Corporation.  All rights reserved.
5//
6// This source code is only intended as a supplement to the
7// Microsoft Foundation Classes Reference and related
8// electronic documentation provided with the library.
9// See these sources for detailed information regarding the
10// Microsoft Foundation Classes product.
11
12#include "stdafx.h"
13#include "cube.h"
14
15#include "cubedoc.h"
16#include "cubeview.h"
17
18#include "gl/gl.h"
19#include "gl/glu.h"
20
21#ifdef _DEBUG
22#undef THIS_FILE
23static char BASED_CODE THIS_FILE[] = __FILE__;
24#endif
25
26unsigned char threeto8[8] =
27{
28   0, 0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1, 0666>>1, 0377
29};
30
31unsigned char twoto8[4] =
32{
33   0, 0x55, 0xaa, 0xff
34};
35
36unsigned char oneto8[2] =
37{
38   0, 255
39};
40
41static int defaultOverride[13] =
42{
43   0, 3, 24, 27, 64, 67, 88, 173, 181, 236, 247, 164, 91
44};
45
46static PALETTEENTRY defaultPalEntry[20] =
47{
48   { 0,   0,   0,    0 },
49   { 0x80,0,   0,    0 },
50   { 0,   0x80,0,    0 },
51   { 0x80,0x80,0,    0 },
52   { 0,   0,   0x80, 0 },
53   { 0x80,0,   0x80, 0 },
54   { 0,   0x80,0x80, 0 },
55   { 0xC0,0xC0,0xC0, 0 },
56
57   { 192, 220, 192,  0 },
58   { 166, 202, 240,  0 },
59   { 255, 251, 240,  0 },
60   { 160, 160, 164,  0 },
61
62   { 0x80,0x80,0x80, 0 },
63   { 0xFF,0,   0,    0 },
64   { 0,   0xFF,0,    0 },
65   { 0xFF,0xFF,0,    0 },
66   { 0,   0,   0xFF, 0 },
67   { 0xFF,0,   0xFF, 0 },
68   { 0,   0xFF,0xFF, 0 },
69   { 0xFF,0xFF,0xFF, 0 }
70};
71
72/////////////////////////////////////////////////////////////////////////////
73// CCubeView
74
Top
475IMPLEMENT_DYNCREATE(CCubeView, CView)
475  return new CCubeView
75}
Top
2642475FUNCTION CCubeView::_GetBaseClass()
2642475  return ( CView::GetThisClass ( ) )
75}
Top
475FUNCTION CCubeView::GetThisClass()
475  return ( ( CRuntimeClass * ) ( & CCubeView::classCCubeView ) )
75}
Top
6300975FUNCTION CCubeView::GetRuntimeClass()
6300975  return ( ( CRuntimeClass * ) ( & CCubeView::classCCubeView ) )
75}
76
Top
1257077BEGIN_MESSAGE_MAP(CCubeView, CView)
1257077  return GetThisMessageMap ( )
77}
Top
1257077FUNCTION CCubeView::GetThisMessageMap()
78   //{{AFX_MSG_MAP(CCubeView)
79   ON_COMMAND(ID_FILE_PLAY, OnFilePlay)
80   ON_UPDATE_COMMAND_UI(ID_FILE_PLAY, OnUpdateFilePlay)
81   ON_WM_CREATE()
82   ON_WM_DESTROY()
83   ON_WM_SIZE()
84   ON_WM_TIMER()
85   ON_WM_ERASEBKGND()
86   //}}AFX_MSG_MAP
1257087END_MESSAGE_MAP()
87}
88
89/////////////////////////////////////////////////////////////////////////////
90// CCubeView construction/destruction
91
Top
492CCubeView::CCubeView()
93{
94   m_pDC = NULL;
95   m_pOldPalette = NULL;
96   m_play = FALSE;
497}
98
Top
499CCubeView::~CCubeView()
100{
4101}
102
103/////////////////////////////////////////////////////////////////////////////
104// CCubeView drawing
105
Top
5106void CCubeView::OnDraw(CDC* /*pDC*/)
107{
108   CCubeDoc* pDoc = GetDocument();
109   ASSERT_VALID(pDoc);
110
111   DrawScene();
5112}
113
114/////////////////////////////////////////////////////////////////////////////
115// CCubeView diagnostics
116
117#ifdef _DEBUG
Top
34634118void CCubeView::AssertValid() const
119{
120   CView::AssertValid();
34634121}
122
Top
0123void CCubeView::Dump(CDumpContext& dc) const
124{
125   CView::Dump(dc);
0126}
127
Top
5128CCubeDoc* CCubeView::GetDocument() // non-debug version is inline
129{
5130   return STATIC_DOWNCAST(CCubeDoc, m_pDocument);
131}
132#endif //_DEBUG
133
134/////////////////////////////////////////////////////////////////////////////
135// CCubeView message handlers
136
Top
14137void CCubeView::OnFilePlay()
138{
77139   m_play = m_play ? FALSE : TRUE;
77140   if (m_play)
141      SetTimer(1, 15, NULL);
142   else
143      KillTimer(1);
14144}
145
Top
1941146void CCubeView::OnUpdateFilePlay(CCmdUI* pCmdUI)
147{
148   pCmdUI->SetCheck(m_play);
1941149}
150
Top
4151BOOL CCubeView::PreCreateWindow(CREATESTRUCT& cs)
152{
153   // An OpenGL window must be created with the following flags and must not
154   // include CS_PARENTDC for the class style. Refer to SetPixelFormat
155   // documentation in the "Comments" section for further information.
156   cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
157
4158   return CView::PreCreateWindow(cs);
159}
160
Top
4161int CCubeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
162{
04163   if (CView::OnCreate(lpCreateStruct) == -1)
0164      return -1;
165
166   Init(); // initialize OpenGL
167
4168   return 0;
169}
170
Top
4171void CCubeView::OnDestroy()
172{
173   HGLRC   hrc;
174
175   KillTimer(1);
176
177   hrc = ::wglGetCurrentContext();
178
179   ::wglMakeCurrent(NULL,  NULL);
180
40181   if (hrc)
182      ::wglDeleteContext(hrc);
183
04184   if (m_pOldPalette)
185      m_pDC->SelectPalette(m_pOldPalette, FALSE);
186
40187   if (m_pDC)
188      delete m_pDC;
189
190   CView::OnDestroy();
4191}
192
Top
12193void CCubeView::OnSize(UINT nType, int cx, int cy)
194{
195   CView::OnSize(nType, cx, cy);
196
84197   if(cy > 0)
198   {
199      glViewport(0, 0, cx, cy);
200
44201      if((m_oldRect.right > cx) || (m_oldRect.bottom > cy))
0201      1: (T) || (_)
4201      2: (F) || (T)
4201      3: (F) || (F)
-201      MC/DC (cond 1): 1 - 3
+201      MC/DC (cond 2): 2 + 3
202         RedrawWindow();
203
204      m_oldRect.right = cx;
205      m_oldRect.bottom = cy;
206
207      glMatrixMode(GL_PROJECTION);
208      glLoadIdentity();
209      gluPerspective(45.0f, (GLdouble)cx/cy, 3.0f, 7.0f);
210      glMatrixMode(GL_MODELVIEW);
211   }
12212}
213
Top
637214void CCubeView::OnTimer(UINT_PTR nIDEvent)
215{
216   DrawScene();
217
218   CView::OnTimer(nIDEvent);
219
220   // Eat spurious WM_TIMER messages
221   MSG msg;
5637222   while(::PeekMessage(&msg, m_hWnd, WM_TIMER, WM_TIMER, PM_REMOVE));
637223}
224
225/////////////////////////////////////////////////////////////////////////////
226// GL helper functions
227
Top
4228void CCubeView::Init()
229{
230   PIXELFORMATDESCRIPTOR pfd;
231   int         n;
232   HGLRC       hrc;
233   GLfloat     fMaxObjSize, fAspect;
234   GLfloat     fNearPlane, fFarPlane;
235
236   m_pDC = new CClientDC(this);
237
238   ASSERT(m_pDC != NULL);
239
04240   if (!bSetupPixelFormat())
0241      return;
242
243   n = ::GetPixelFormat(m_pDC->GetSafeHdc());
244   ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
245
246   CreateRGBPalette();
247
248   hrc = wglCreateContext(m_pDC->GetSafeHdc());
249   wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
250
251   GetClientRect(&m_oldRect);
252   glClearDepth(1.0f);
253   glEnable(GL_DEPTH_TEST);
254
04255   if (m_oldRect.bottom)
256      fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom;
257   else    // don't divide by zero, not that we should ever run into that...
258      fAspect = 1.0f;
259   fNearPlane = 3.0f;
260   fFarPlane = 7.0f;
261   fMaxObjSize = 3.0f;
262   m_fRadius = fNearPlane + fMaxObjSize / 2.0f;
263
264   glMatrixMode(GL_PROJECTION);
265   glLoadIdentity();
266   gluPerspective(45.0f, fAspect, fNearPlane, fFarPlane);
267   glMatrixMode(GL_MODELVIEW);
4268}
269
Top
4270BOOL CCubeView::bSetupPixelFormat()
271{
272   static PIXELFORMATDESCRIPTOR pfd =
273   {
274      sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
275      1,                              // version number
276      PFD_DRAW_TO_WINDOW |            // support window
277        PFD_SUPPORT_OPENGL |          // support OpenGL
278        PFD_DOUBLEBUFFER,             // double buffered
279      PFD_TYPE_RGBA,                  // RGBA type
280      24,                             // 24-bit color depth
281      0, 0, 0, 0, 0, 0,               // color bits ignored
282      0,                              // no alpha buffer
283      0,                              // shift bit ignored
284      0,                              // no accumulation buffer
285      0, 0, 0, 0,                     // accum bits ignored
286      32,                             // 32-bit z-buffer
287      0,                              // no stencil buffer
288      0,                              // no auxiliary buffer
289      PFD_MAIN_PLANE,                 // main layer
290      0,                              // reserved
291      0, 0, 0                         // layer masks ignored
292   };
293   int pixelformat;
294
04295   if ( (pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd)) == 0 )
296   {
297      MessageBox("ChoosePixelFormat failed");
0298      return FALSE;
299   }
300
04301   if (SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
302   {
303      MessageBox("SetPixelFormat failed");
0304      return FALSE;
305   }
306
4307   return TRUE;
308}
309
Top
0310unsigned char CCubeView::ComponentFromIndex(int i, UINT nbits, UINT shift)
311{
312   unsigned char val;
313
314   val = (unsigned char) (i >> shift);
315   switch (nbits)
316   {
317
0318   case 1:
319      val &= 0x1;
0320      return oneto8[val];
0321   case 2:
322      val &= 0x3;
0323      return twoto8[val];
0324   case 3:
325      val &= 0x7;
0326      return threeto8[val];
327
0328   default:
0329      return 0;
330   }
331}
332
333#pragma warning(disable : 4244)
Top
4334void CCubeView::CreateRGBPalette()
335{
336   PIXELFORMATDESCRIPTOR pfd;
337   LOGPALETTE *pPal;
338   int n, i;
339
340   n = ::GetPixelFormat(m_pDC->GetSafeHdc());
341   ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
342
04343   if (pfd.dwFlags & PFD_NEED_PALETTE)
344   {
345      n = 1 << pfd.cColorBits;
346      pPal = (PLOGPALETTE) new char[sizeof(LOGPALETTE) + n * sizeof(PALETTEENTRY)];
347
348      ASSERT(pPal != NULL);
349
350      pPal->palVersion = 0x300;
351      pPal->palNumEntries = n;
00352      for (i=0; i<n; i++)
353      {
354         pPal->palPalEntry[i].peRed =
355               ComponentFromIndex(i, pfd.cRedBits, pfd.cRedShift);
356         pPal->palPalEntry[i].peGreen =
357               ComponentFromIndex(i, pfd.cGreenBits, pfd.cGreenShift);
358         pPal->palPalEntry[i].peBlue =
359               ComponentFromIndex(i, pfd.cBlueBits, pfd.cBlueShift);
360         pPal->palPalEntry[i].peFlags = 0;
361      }
362
363      /* fix up the palette to include the default GDI palette */
364      if ((pfd.cColorBits == 8)                           &&
365         (pfd.cRedBits   == 3) && (pfd.cRedShift   == 0) &&
366         (pfd.cGreenBits == 3) && (pfd.cGreenShift == 3) &&
00367         (pfd.cBlueBits  == 2) && (pfd.cBlueShift  == 6)
0367      1: (T) && (T) && (T) && (T) && (T) && (T) && (T)
0367      2: (T) && (T) && (T) && (T) && (T) && (T) && (F)
0367      3: (T) && (T) && (T) && (T) && (T) && (F) && (_)
0367      4: (T) && (T) && (T) && (T) && (F) && (_) && (_)
0367      5: (T) && (T) && (T) && (F) && (_) && (_) && (_)
0367      6: (T) && (T) && (F) && (_) && (_) && (_) && (_)
0367      7: (T) && (F) && (_) && (_) && (_) && (_) && (_)
0367      8: (F) && (_) && (_) && (_) && (_) && (_) && (_)
-367      MC/DC (cond 1): 1 - 8
-367      MC/DC (cond 2): 1 - 7
-367      MC/DC (cond 3): 1 - 6
-367      MC/DC (cond 4): 1 - 5
-367      MC/DC (cond 5): 1 - 4
-367      MC/DC (cond 6): 1 - 3
-367      MC/DC (cond 7): 1 - 2
368         )
369      {
00370         for (i = 1 ; i <= 12 ; i++)
371            pPal->palPalEntry[defaultOverride[i]] = defaultPalEntry[i];
372      }
373
374      m_cPalette.CreatePalette(pPal);
375      delete [] pPal;
376
377      m_pOldPalette = m_pDC->SelectPalette(&m_cPalette, FALSE);
378      m_pDC->RealizePalette();
379   }
4380}
381#pragma warning(default : 4244)
382
Top
642383void CCubeView::DrawScene(void)
384{
385   static BOOL     bBusy = FALSE;
386   static GLfloat  wAngleY = 10.0f;
387   static GLfloat  wAngleX = 1.0f;
388   static GLfloat  wAngleZ = 5.0f;
389
0642390   if(bBusy)
0391      return;
392   bBusy = TRUE;
393
394   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
395   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
396
397   glPushMatrix();
398
399      glTranslatef(0.0f, 0.0f, -m_fRadius);
400      glRotatef(wAngleX, 1.0f, 0.0f, 0.0f);
401      glRotatef(wAngleY, 0.0f, 1.0f, 0.0f);
402      glRotatef(wAngleZ, 0.0f, 0.0f, 1.0f);
403
404      wAngleX += 1.0f;
405      wAngleY += 10.0f;
406      wAngleZ += 5.0f;
407
408
409      glBegin(GL_QUAD_STRIP);
410         glColor3f(1.0f, 0.0f, 1.0f);
411         glVertex3f(-0.5f, 0.5f, 0.5f);
412
413         glColor3f(1.0f, 0.0f, 0.0f);
414         glVertex3f(-0.5f, -0.5f, 0.5f);
415
416         glColor3f(1.0f, 1.0f, 1.0f);
417         glVertex3f(0.5f, 0.5f, 0.5f);
418
419         glColor3f(1.0f, 1.0f, 0.0f);
420         glVertex3f(0.5f, -0.5f, 0.5f);
421
422         glColor3f(0.0f, 1.0f, 1.0f);
423         glVertex3f(0.5f, 0.5f, -0.5f);
424
425         glColor3f(0.0f, 1.0f, 0.0f);
426         glVertex3f(0.5f, -0.5f, -0.5f);
427
428         glColor3f(0.0f, 0.0f, 1.0f);
429         glVertex3f(-0.5f, 0.5f, -0.5f);
430
431         glColor3f(0.0f, 0.0f, 0.0f);
432         glVertex3f(-0.5f, -0.5f,  -0.5f);
433
434         glColor3f(1.0f, 0.0f, 1.0f);
435         glVertex3f(-0.5f, 0.5f, 0.5f);
436
437         glColor3f(1.0f, 0.0f, 0.0f);
438         glVertex3f(-0.5f, -0.5f, 0.5f);
439
440      glEnd();
441
442      glBegin(GL_QUADS);
443         glColor3f(1.0f, 0.0f, 1.0f);
444         glVertex3f(-0.5f, 0.5f, 0.5f);
445
446         glColor3f(1.0f, 1.0f, 1.0f);
447         glVertex3f(0.5f, 0.5f, 0.5f);
448
449         glColor3f(0.0f, 1.0f, 1.0f);
450         glVertex3f(0.5f, 0.5f, -0.5f);
451
452         glColor3f(0.0f, 0.0f, 1.0f);
453         glVertex3f(-0.5f, 0.5f, -0.5f);
454      glEnd();
455
456      glBegin(GL_QUADS);
457         glColor3f(1.0f, 0.0f, 0.0f);
458         glVertex3f(-0.5f, -0.5f, 0.5f);
459
460         glColor3f(1.0f, 1.0f, 0.0f);
461         glVertex3f(0.5f, -0.5f, 0.5f);
462
463         glColor3f(0.0f, 1.0f, 0.0f);
464         glVertex3f(0.5f, -0.5f, -0.5f);
465
466         glColor3f(0.0f, 0.0f, 0.0f);
467         glVertex3f(-0.5f, -0.5f,  -0.5f);
468      glEnd();
469
470   glPopMatrix();
471
472   glFinish();
473   SwapBuffers(wglGetCurrentDC());
474
475   bBusy = FALSE;
642476}
477
Top
5478BOOL CCubeView::OnEraseBkgnd(CDC* /*pDC*/)
479{
5480   return TRUE;
481}
***TER63 % (67/107) of FILE cubeview.cpp
79 % (155/196) statement

Directory Summary | Files Summary | Functions Summary | Untested Code | Execution Profile
To files: First | Previous | Next | Last | Top | Index | No Index