From c345c699fd90cbad1ceda6226475d9a27ae47072 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 18 Jul 2013 13:27:46 -0400 Subject: Self test for command bus encode/decode. --- selftest.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'selftest.cpp') diff --git a/selftest.cpp b/selftest.cpp index d5a2bc45..dffd22cd 100644 --- a/selftest.cpp +++ b/selftest.cpp @@ -45,6 +45,7 @@ #include "node/Peer.hpp" #include "node/Http.hpp" #include "node/Condition.hpp" +#include "node/NodeConfig.hpp" using namespace ZeroTier; @@ -266,6 +267,38 @@ static int testOther() } std::cout << "PASS" << std::endl; + std::cout << "[other] Testing command bus encode/decode... "; std::cout.flush(); + try { + static char key[32] = { 0 }; + for(unsigned int k=0;k<1000;++k) { + std::vector original; + for(unsigned int i=0,j=rand() % 256,l=(rand() % 1024)+1;i > packets(NodeConfig::encodeControlMessage(key,1,original)); + //std::cout << packets.size() << ' '; std::cout.flush(); + std::vector after; + for(std::vector< Buffer >::iterator i(packets.begin());i!=packets.end();++i) { + unsigned long convId = 9999; + if (!NodeConfig::decodeControlMessagePacket(key,i->data(),i->size(),convId,after)) { + std::cout << "FAIL (decode)" << std::endl; + return -1; + } + if (convId != 1) { + std::cout << "FAIL (conversation ID)" << std::endl; + return -1; + } + } + if (after != original) { + std::cout << "FAIL (compare)" << std::endl; + return -1; + } + } + } catch (std::exception &exc) { + std::cout << "FAIL (" << exc.what() << ")" << std::endl; + return -1; + } + std::cout << "PASS" << std::endl; + return 0; } -- cgit v1.2.3