diff --git a/source/libs/transport/test/transportTests.cc b/source/libs/transport/test/transportTests.cc
index 468aeba8a9adad92d730bc251b3416eddea7e60f..151deaf29bfa183e40f3ad32d0ca9c8994ea6e39 100644
--- a/source/libs/transport/test/transportTests.cc
+++ b/source/libs/transport/test/transportTests.cc
@@ -13,23 +13,126 @@
* along with this program. If not, see .
*/
+#ifdef USE_UV
+
#include
#include
#include
#include
#include
+#include
#include "transportInt.h"
#include "trpc.h"
using namespace std;
-int main() {
- SRpcInit init = {.localPort = 6030, .label = "rpc", .numOfThreads = 5};
- void* p = rpcOpen(&init);
+struct QueueElem {
+ queue q;
+ int val;
+};
+class QueueObj {
+ public:
+ QueueObj() {
+ // avoid formate
+ QUEUE_INIT(&head);
+ }
+ void Push(QueueElem *el) {
+ // avoid formate
+ QUEUE_PUSH(&head, &el->q);
+ }
+ QueueElem *Pop() {
+ QueueElem *el = NULL;
+ if (!IsEmpty()) {
+ queue *h = QUEUE_HEAD(&head);
+ el = QUEUE_DATA(h, QueueElem, q);
+ QUEUE_REMOVE(&el->q);
+ }
+ return el;
+ }
+ bool IsEmpty() {
+ // avoid formate
+ return QUEUE_IS_EMPTY(&head);
+ }
+ void RmElem(QueueElem *el) {
+ // impl
+ QUEUE_REMOVE(&el->q);
+ }
+ void ForEach(std::vector &result) {
+ queue *h;
+ QUEUE_FOREACH(h, &head) {
+ // add more
+ QueueElem *el = QUEUE_DATA(h, QueueElem, q);
+ result.push_back(el->val);
+ }
+ }
+
+ private:
+ queue head;
+};
- while (1) {
- std::cout << "cron task" << std::endl;
- std::this_thread::sleep_for(std::chrono::milliseconds(10 * 1000));
+class QueueEnv : public ::testing::Test {
+ protected:
+ virtual void SetUp() {
+ // TODO
+ q = new QueueObj();
+ }
+ virtual void TearDown() {
+ delete q;
+ // formate
}
+ QueueObj *q;
+};
+
+TEST_F(QueueEnv, testPushAndPop) {
+ // add more test
+ assert(q->IsEmpty());
+
+ for (int i = 0; i < 100; i++) {
+ QueueElem *el = (QueueElem *)malloc(sizeof(QueueElem));
+ el->val = i;
+ q->Push(el);
+ }
+ int i = 0;
+ while (!q->IsEmpty()) {
+ QueueElem *el = q->Pop();
+ assert(el->val == i++);
+ free(el);
+ }
+ assert(q->IsEmpty());
+}
+TEST_F(QueueEnv, testRm) {
+ // add more test
+
+ std::vector set;
+ assert(q->IsEmpty());
+
+ for (int i = 0; i < 100; i++) {
+ QueueElem *el = (QueueElem *)malloc(sizeof(QueueElem));
+ el->val = i;
+ q->Push(el);
+ set.push_back(el);
+ }
+ for (int i = set.size() - 1; i >= 0; i--) {
+ QueueElem *el = set[i];
+ q->RmElem(el);
+ free(el);
+ }
+ assert(q->IsEmpty());
}
+TEST_F(QueueEnv, testIter) {
+ // add more test
+ assert(q->IsEmpty());
+ std::vector vals;
+ for (int i = 0; i < 100; i++) {
+ QueueElem *el = (QueueElem *)malloc(sizeof(QueueElem));
+ el->val = i;
+ q->Push(el);
+ vals.push_back(i);
+ }
+ std::vector result;
+ q->ForEach(result);
+ assert(result.size() == vals.size());
+}
+
+#endif