mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
Self test JSONDB.
This commit is contained in:
parent
a78d7311a6
commit
a454a37a6e
2 changed files with 20 additions and 2 deletions
|
@ -147,8 +147,6 @@ std::string JSONDB::_genPath(const std::string &n,bool create)
|
||||||
std::vector<std::string> pt(Utils::split(n.c_str(),"/","",""));
|
std::vector<std::string> pt(Utils::split(n.c_str(),"/","",""));
|
||||||
if (pt.size() == 0)
|
if (pt.size() == 0)
|
||||||
return std::string();
|
return std::string();
|
||||||
if (pt.size() == 1)
|
|
||||||
return pt[0];
|
|
||||||
|
|
||||||
std::string p(_basePath);
|
std::string p(_basePath);
|
||||||
if (create) OSUtils::mkdir(p.c_str());
|
if (create) OSUtils::mkdir(p.c_str());
|
||||||
|
|
20
selftest.cpp
20
selftest.cpp
|
@ -53,6 +53,8 @@
|
||||||
#include "osdep/PortMapper.hpp"
|
#include "osdep/PortMapper.hpp"
|
||||||
#include "osdep/Thread.hpp"
|
#include "osdep/Thread.hpp"
|
||||||
|
|
||||||
|
#include "controller/JSONDB.hpp"
|
||||||
|
|
||||||
#ifdef __WINDOWS__
|
#ifdef __WINDOWS__
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -807,6 +809,24 @@ static int testOther()
|
||||||
}
|
}
|
||||||
std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" << std::endl;
|
std::cout << "PASS (junk value to prevent optimization-out of test: " << foo << ")" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "[other] Testing controller/JSONDB..."; std::cout.flush();
|
||||||
|
{
|
||||||
|
JSONDB db1("jsondb-test");
|
||||||
|
std::map<std::string,nlohmann::json> db1data;
|
||||||
|
for(unsigned int i=0;i<256;++i) {
|
||||||
|
std::string n;
|
||||||
|
for(unsigned int j=0,k=rand() % 4;j<=k;++j) {
|
||||||
|
if (j > 0) n.push_back('/');
|
||||||
|
char foo[24];
|
||||||
|
Utils::snprintf(foo,sizeof(foo),"%lx",rand());
|
||||||
|
n.append(foo);
|
||||||
|
}
|
||||||
|
db1data[n] = {{"i",i}};
|
||||||
|
db1.put(n,db1data[n]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << "PASS" << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue