00001 /* 00002 00003 Copyright (C) 2006-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #include "Qt.h" 00024 #include "../FifoQueue.h" 00025 #include "../BadPacket.h" 00026 #include "Imports.cpp" 00027 00028 namespace Protocols { 00029 namespace Generics { 00030 namespace Testing { 00031 00033 class FifoQueueTest : public CppUnit::TestFixture 00034 { 00035 CPPUNIT_TEST_SUITE (FifoQueueTest); 00036 CPPUNIT_TEST (testDefaultConstructedQueueIsEmpty); 00037 CPPUNIT_TEST (testQueueWithMultipleElementsIsNotEmpty); 00038 CPPUNIT_TEST (testOneInOneOut); 00039 CPPUNIT_TEST (testMoreInMoreOut); 00040 CPPUNIT_TEST_SUITE_END(); 00041 00042 auto_ptr <FifoQueue> queue; 00043 00044 public: 00045 FifoQueueTest() : queue() {} 00046 00047 void setUp() 00048 { 00049 queue.reset (new FifoQueue); 00050 } 00051 00052 void tearDown() 00053 { 00054 queue.reset(); 00055 } 00056 00057 void testDefaultConstructedQueueIsEmpty() 00058 { 00059 willBeEqual (queue->isEmpty(), true); 00060 } 00061 00062 void testQueueWithMultipleElementsIsNotEmpty() 00063 { 00064 queue->enqueue (Data()); 00065 willBeEqual (queue->isEmpty(), false); 00066 } 00067 00068 void testOneInOneOut() 00069 { 00070 Data data (BadPacket ("aa")); 00071 queue->enqueue (data); 00072 willBeEqual (queue->next(), data); 00073 queue->dequeue(); 00074 willBeEqual (queue->isEmpty(), true); 00075 } 00076 00077 void testMoreInMoreOut() 00078 { 00079 Data data1 (BadPacket ("aa")); 00080 Data data2 (BadPacket ("bb")); 00081 Data data3 (BadPacket ("cc")); 00082 00083 queue->enqueue (data1); 00084 queue->enqueue (data2); 00085 queue->enqueue (data3); 00086 00087 willBeEqual (queue->next(), data1); 00088 queue->dequeue(); 00089 willBeEqual (queue->next(), data2); 00090 queue->dequeue(); 00091 willBeEqual (queue->next(), data3); 00092 queue->dequeue(); 00093 00094 willBeEqual (queue->isEmpty(), true); 00095 } 00096 }; 00097 00098 CPPUNIT_TEST_SUITE_REGISTRATION(FifoQueueTest); 00099 00100 } // namespace Testing 00101 } // namespace Generics 00102 } // namespace Protocols