Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TestQue.cpp
00001 /************************************************************************************** 00002 * Copyright (c) 2016, Tomoaki Yamaguchi 00003 * 00004 * All rights reserved. This program and the accompanying materials 00005 * are made available under the terms of the Eclipse Public License v1.0 00006 * and Eclipse Distribution License v1.0 which accompany this distribution. 00007 * 00008 * The Eclipse Public License is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * and the Eclipse Distribution License is available at 00011 * http://www.eclipse.org/org/documents/edl-v10.php. 00012 * 00013 * Contributors: 00014 * Tomoaki Yamaguchi - initial API and implementation 00015 **************************************************************************************/ 00016 #include <string.h> 00017 #include <tests/TestProcess.h> 00018 #include <cassert> 00019 #include "TestQue.h" 00020 using namespace std; 00021 using namespace MQTTSNGW; 00022 00023 TestQue::TestQue() 00024 { 00025 00026 } 00027 00028 TestQue::~TestQue() 00029 { 00030 00031 } 00032 00033 void TestQue::test(void) 00034 { 00035 int* v = 0; 00036 int i = 0; 00037 00038 for ( i = 0; i < 10; i++ ) 00039 { 00040 v = new int(i); 00041 this->post(v); 00042 } 00043 assert( 10 == this->size()); 00044 00045 for ( i = 0; i < 10; i++ ) 00046 { 00047 assert(i == *this->front()); 00048 int* p = this->front(); 00049 if ( p ) 00050 { 00051 assert(i == *p); 00052 this->pop(); 00053 delete p; 00054 } 00055 } 00056 assert(0 == this->front()); 00057 assert(0 == this->size()); 00058 00059 this->setMaxSize(5); 00060 for ( i = 0; i < 10; i++ ) 00061 { 00062 v = new int(i); 00063 this->post(v); 00064 assert( 5 >= this->size()); 00065 } 00066 for ( i = 0; i < 10; i++ ) 00067 { 00068 int* p = this->front(); 00069 if ( p ) 00070 { 00071 this->pop(); 00072 delete p; 00073 } 00074 } 00075 printf("[ OK ]\n"); 00076 } 00077 00078 int* TestQue::front(void) 00079 { 00080 return _que.front(); 00081 } 00082 void TestQue::pop(void) 00083 { 00084 _que.pop(); 00085 } 00086 int TestQue::size(void) 00087 { 00088 return _que.size(); 00089 } 00090 void TestQue::setMaxSize(int maxsize) 00091 { 00092 _que.setMaxSize(maxsize); 00093 } 00094 00095 void TestQue::post(int* val) 00096 { 00097 _que.post(val); 00098 } 00099 00100
Generated on Wed Jul 13 2022 10:46:03 by
1.7.2