1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbgloop.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #error Wer fummelt denn an den makefiles rum?
37 #include <tools/stream.hxx>
38 #include "dbgloop.hxx"
41 DbgLoopStack
DbgLoop::aDbgLoopStack
;
43 /*************************************************************************
45 *************************************************************************/
47 DbgLoopStack::DbgLoopStack()
52 void DbgLoopStack::Reset()
56 for( USHORT i
= 0; i
< DBG_MAX_STACK
; ++i
)
60 /*************************************************************************
61 * DbgLoopStack::Push()
62 *************************************************************************/
64 void DbgLoopStack::Push( const void *pThis
)
66 // Wir muessen irgendwie mitbekommen, wann die erste Stackposition
67 // resettet werden soll, z.B. wenn wir einen Nullpointer uebergeben
68 if( !nPtr
&& ( pDbg
!= pThis
|| !pThis
) )
75 if( DBG_MAX_STACK
> nPtr
)
77 // Wenn eine loop entdeckt wird, wird der counter wieder zurueckgesetzt.
78 ASSERT( DBG_MAX_LOOP
> aCount
[nPtr
], "DbgLoopStack::Push: loop detected" );
79 if( DBG_MAX_LOOP
> aCount
[nPtr
] )
86 /*************************************************************************
88 *************************************************************************/
90 void DbgLoopStack::Pop()
92 if( DBG_MAX_STACK
> nPtr
)
94 ASSERT( nPtr
, "DbgLoopStack::Pop: can't pop the stack" );
96 ASSERT( aCount
[nPtr
], "DbgLoopStack::Pop: can't dec the count" );
97 if( DBG_MAX_STACK
> nPtr
+ 1 )
103 /*************************************************************************
104 * DbgLoopStack::Print()
105 *************************************************************************/
107 void DbgLoopStack::Print( SvStream
&rOS
) const
109 rOS
<< "POS: " << nPtr
<< '\n';
111 for( i
= 0; i
< DBG_MAX_STACK
; ++i
)
114 for( i
= 0; i
< DBG_MAX_STACK
; ++i
)
115 rOS
<< aCount
[i
] << " ";
120 // compile with: cl /AL /DSTAND_ALONE dbgloop.cxx
122 /*************************************************************************
124 *************************************************************************/
128 void AssertFail( const char *pErr
, const char *pFile
, USHORT nLine
)
130 cout
<< pErr
<< '\n';
131 PrintLoopStack( cout
);
141 void Test::Run() const
143 cout
<< "---" << '\n';
144 for( USHORT i
= 0; i
< 10; ++i
)
148 PrintLoopStack( cout
);
149 for( USHORT j
= 0; j
< 10; ++j
)
153 PrintLoopStack( cout
);
157 PrintLoopStack( cout
);
162 // unterschiedliche Instanzen waehlen wg. pDbg != pThis