mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-18 17:56:52 +01:00
Update: Add Tree23 and List template classes
Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "TestProcess.h"
|
||||
#include "TestTopics.h"
|
||||
#include "TestQue.h"
|
||||
#include "TestTree23.h"
|
||||
#include "TestTopicIdMap.h"
|
||||
#include "MQTTSNGWProcess.h"
|
||||
#include "MQTTSNGWClient.h"
|
||||
@@ -90,6 +91,11 @@ void TestProcess::run(void)
|
||||
tque->test();
|
||||
delete tque;
|
||||
|
||||
/* Test Tree23 */
|
||||
TestTree23* tree23 = new TestTree23();
|
||||
tree23->test();
|
||||
delete tree23;
|
||||
|
||||
/* Test TopicTable */
|
||||
TestTopics* testTopic = new TestTopics();
|
||||
testTopic->test();
|
||||
@@ -103,7 +109,7 @@ void TestProcess::run(void)
|
||||
|
||||
|
||||
/* Test EventQue */
|
||||
printf("EventQue test start.\n");
|
||||
printf("Test EventQue ");
|
||||
Client* client = new Client();
|
||||
_evQue.setMaxSize(EVENT_CNT);
|
||||
for ( int i = 0; i < EVENT_CNT + 4; i++ )
|
||||
@@ -116,6 +122,4 @@ void TestProcess::run(void)
|
||||
}
|
||||
|
||||
MultiTaskProcess::run();
|
||||
|
||||
printf("\n\nAll Tests completed.\n");
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ void TestQue::test(void)
|
||||
int* v = 0;
|
||||
int i = 0;
|
||||
|
||||
printf("Que Test start.\n");
|
||||
printf("Test Que ");
|
||||
for ( i = 0; i < 10; i++ )
|
||||
{
|
||||
v = new int(i);
|
||||
@@ -73,7 +73,7 @@ void TestQue::test(void)
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
printf("Que test completed.\n\n");
|
||||
printf("[ OK ]\n");
|
||||
}
|
||||
|
||||
int* TestQue::front(void)
|
||||
|
||||
@@ -52,7 +52,7 @@ void TestTask::run(void)
|
||||
{
|
||||
assert(EVENT_CNT + 1 == evcnt);
|
||||
delete ev;
|
||||
printf("EventQue test complete.\n\n");
|
||||
printf("[ OK ]\n");
|
||||
break;
|
||||
}
|
||||
MQTTSNPacket* packet = ev->getMQTTSNPacket();
|
||||
@@ -64,10 +64,10 @@ void TestTask::run(void)
|
||||
{
|
||||
if ( CHK_SIGINT)
|
||||
{
|
||||
printf("Task stopped.\n");
|
||||
printf("\nTest Task [ OK ]\n");
|
||||
return;
|
||||
}
|
||||
printf("Task is running. Enter CTRL+C\n");
|
||||
printf("Enter CTRL+C\n");
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ TestTopicIdMap::~TestTopicIdMap()
|
||||
void TestTopicIdMap::test(void)
|
||||
{
|
||||
uint16_t id[MAXID];
|
||||
printf("Test TopicIdMat start.\n");
|
||||
printf("Test TopicIdMat ");
|
||||
|
||||
for ( int i = 0; i < MAXID; i++ )
|
||||
{
|
||||
@@ -120,6 +120,6 @@ void TestTopicIdMap::test(void)
|
||||
//printf("TopicId=%d msgId=%d type=%d\n", topicId, i, type);
|
||||
assert( topicId == 0 );
|
||||
}
|
||||
printf("Test TopicIdMat completed.\n\n");
|
||||
printf("[ OK ]\n");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ TestTopics::~TestTopics()
|
||||
|
||||
void TestTopics::test(void)
|
||||
{
|
||||
printf("Topics Test start.\n");
|
||||
printf("Test Topics ");
|
||||
|
||||
MQTTSN_topicid topic[12];
|
||||
char tp[12][10];
|
||||
@@ -179,5 +179,5 @@ void TestTopics::test(void)
|
||||
*/
|
||||
assert( t != 0);
|
||||
}
|
||||
printf("Topics Test complete.\n\n");
|
||||
printf("[ OK ]\n");
|
||||
}
|
||||
|
||||
93
MQTTSNGateway/src/tests/TestTree23.cpp
Normal file
93
MQTTSNGateway/src/tests/TestTree23.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/**************************************************************************************
|
||||
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Tomoaki Yamaguchi - initial API and implementation
|
||||
**************************************************************************************/
|
||||
#include "TestTree23.h"
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
using namespace std;
|
||||
using namespace MQTTSNGW;
|
||||
|
||||
TestTree23::TestTree23()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TestTree23::~TestTree23()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TestTree23::test(void)
|
||||
{
|
||||
printf("Test Tree23 ");
|
||||
int N = 100;
|
||||
|
||||
Key* r1[100];
|
||||
Integer* r2[100];
|
||||
|
||||
for ( int i = 0; i < N; i++)
|
||||
{
|
||||
char buff[5];
|
||||
sprintf(buff,"%d", i);
|
||||
r1[i] = new Key(string(buff));
|
||||
r2[i] = new Integer(i);
|
||||
this->add(r1[i], r2[i]);
|
||||
}
|
||||
|
||||
for ( int i = 0; i < N; i++)
|
||||
{
|
||||
Integer* rc = this->getVal(r1[i]);
|
||||
//printf("key=%d val=%d\n", i, rc->_val);
|
||||
assert(i == rc->_val);
|
||||
}
|
||||
|
||||
for ( int i = 20; i < 50; i++)
|
||||
{
|
||||
this->remove(r1[i]);
|
||||
//printf("key=%d str=%s\n", i, r1[i]->_key.c_str());
|
||||
}
|
||||
|
||||
for ( int i = 0; i < 20; i++)
|
||||
{
|
||||
bool rc = this->find(r1[i]);
|
||||
assert(rc == true);
|
||||
//printf("key=%d find=%d\n", i, rc);
|
||||
Integer* val = this->getVal(r1[i]);
|
||||
//printf("key=%d val=%d\n", i, val->_val);
|
||||
assert(val->_val == i);
|
||||
}
|
||||
for ( int i = 20; i < 50; i++ )
|
||||
{
|
||||
bool rc = this->find(r1[i]);
|
||||
assert(rc == false);
|
||||
//printf("key=%d find=%d\n", i, rc);
|
||||
Integer* val = this->getVal(r1[i]);
|
||||
//printf("key=%d val=%d\n", i, val->_val);
|
||||
assert(val == 0);
|
||||
}
|
||||
for ( int i = 50; i < N; i++)
|
||||
{
|
||||
bool rc = this->find(r1[i]);
|
||||
assert(rc == true);
|
||||
//printf("key=%d find=%d\n", i, rc);
|
||||
Integer* val = this->getVal(r1[i]);
|
||||
//printf("key=%d val=%d\n", i, val->_val);
|
||||
assert(val->_val == i);
|
||||
}
|
||||
printf("[ OK ]\n");
|
||||
}
|
||||
|
||||
74
MQTTSNGateway/src/tests/TestTree23.h
Normal file
74
MQTTSNGateway/src/tests/TestTree23.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/**************************************************************************************
|
||||
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||
*
|
||||
* The Eclipse Public License is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
* and the Eclipse Distribution License is available at
|
||||
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||
*
|
||||
* Contributors:
|
||||
* Tomoaki Yamaguchi - initial API and implementation
|
||||
**************************************************************************************/
|
||||
#ifndef MQTTSNGATEWAY_SRC_TESTS_TESTTREE23_H_
|
||||
#define MQTTSNGATEWAY_SRC_TESTS_TESTTREE23_H_
|
||||
|
||||
#include "MQTTSNGWProcess.h"
|
||||
|
||||
namespace MQTTSNGW
|
||||
{
|
||||
|
||||
class Integer
|
||||
{
|
||||
public:
|
||||
int _val;
|
||||
Integer(){_val = 0;}
|
||||
Integer(int val){_val = val;}
|
||||
};
|
||||
|
||||
class Key
|
||||
{
|
||||
public:
|
||||
string _key;
|
||||
Key(){};
|
||||
Key(string key){_key = key;}
|
||||
int compare(Key* obj){
|
||||
if ( _key == obj->_key )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else if ( _key < obj->_key )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
class TestTree23
|
||||
{
|
||||
public:
|
||||
TestTree23();
|
||||
~TestTree23();
|
||||
void add(Key* key, Integer* val){_tree23.add(key, val);}
|
||||
Tree23Node<Key, Integer>* add(Tree23Node<Key, Integer>* n, Tree23Elm<Key, Integer>* elm){return _tree23.add(n, elm);}
|
||||
void remove(Key* k){_tree23.remove(k);}
|
||||
Tree23Node<Key, Integer>* remove(Tree23Node<Key, Integer>* node, Key* k){return _tree23.remove(node, k);}
|
||||
bool find(Key* key){return _tree23.find(key);}
|
||||
Integer* getVal(Key* key){return _tree23.getVal(key);}
|
||||
void test(void);
|
||||
private:
|
||||
Tree23<Key, Integer> _tree23;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* MQTTSNGATEWAY_SRC_TESTS_TESTTREE23_H_ */
|
||||
@@ -26,6 +26,7 @@ int main(int argc, char** argv)
|
||||
test->initialize(argc, argv);
|
||||
test->run();
|
||||
delete test;
|
||||
printf("\nPass all tests. \n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user