//--------------------------------------------------------------------------- // @function: // CStackTest::EresUnittest_Basic // // @doc: // Basic stack test // //--------------------------------------------------------------------------- GPOS_RESULT CStackTest::EresUnittest_Basic() { // create memory pool CAutoMemoryPool amp; IMemoryPool *pmp = amp.Pmp(); // test with CHAR array CHAR rgsz[][9] = {"abc", "def", "ghi", "qwe", "wer", "wert", "dfg", "xcv", "zxc"}; CStack<CHAR> *pstk = GPOS_NEW(pmp) CStack<CHAR> (pmp, 4); // add elements incl trigger resize of array for (ULONG i = 0; i < 9; i++) { pstk->Push(rgsz[i]); } ULONG idx = 0; while (!pstk->FEmpty()) { GPOS_ASSERT(idx <= 8 && "Index out of range. Problem with FEmpty."); #ifdef GPOS_DEBUG GPOS_ASSERT(pstk->Pop() == rgsz[8 - idx] && "Incorrect pop value"); #else pstk->Pop(); #endif idx++; } GPOS_ASSERT(idx == 9 && "Stack is not empty!"); GPOS_DELETE(pstk); return GPOS_OK; }