Browse Source

new tests added

cl-refactor
Vlad Gluhovsky 10 years ago
parent
commit
f4eb948c15
  1. 68
      test/libwhisper/whisperDB.cpp

68
test/libwhisper/whisperDB.cpp

@ -19,6 +19,7 @@ along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
* @date July 2015
*/
#include <thread>
#include <boost/test/unit_test.hpp>
#include <libwhisper/WhisperDB.h>
@ -28,23 +29,24 @@ using namespace dev::shh;
BOOST_AUTO_TEST_SUITE(whisperDB)
BOOST_AUTO_TEST_CASE(first)
BOOST_AUTO_TEST_CASE(basic)
{
VerbosityHolder setTemporaryLevel(10);
cnote << "Testing Whisper DB...";
WhisperDB db;
h256 h1(0x12345678);
h256 h2(0xBADD00DE);
string s;
string const text1 = "lorem_ipsum";
string const text2 = "dolor_sit_amet";
string const text1 = "lorem";
string const text2 = "ipsum";
h256 h1(0xBEEF);
h256 h2(0xC0FFEE);
WhisperDB db;
db.kill(h1);
db.kill(h2);
s = db.lookup(h1);
BOOST_REQUIRE(s.empty());
db.insert(h1, text2);
s = db.lookup(h2);
BOOST_REQUIRE(s.empty());
@ -65,6 +67,56 @@ BOOST_AUTO_TEST_CASE(first)
db.kill(h1);
db.kill(h2);
s = db.lookup(h2);
BOOST_REQUIRE(s.empty());
s = db.lookup(h1);
BOOST_REQUIRE(s.empty());
}
BOOST_AUTO_TEST_CASE(persistence)
{
VerbosityHolder setTemporaryLevel(10);
cnote << "Testing persistence of Whisper DB...";
string s;
string const text1 = "sator";
string const text2 = "arepo";
h256 const h1(0x12345678);
h256 const h2(0xBADD00DE);
{
WhisperDB db;
db.kill(h1);
db.kill(h2);
s = db.lookup(h1);
BOOST_REQUIRE(s.empty());
db.insert(h1, text2);
s = db.lookup(h2);
BOOST_REQUIRE(s.empty());
s = db.lookup(h1);
BOOST_REQUIRE(!s.compare(text2));
}
this_thread::sleep_for(chrono::milliseconds(20));
{
WhisperDB db;
db.insert(h1, text1);
db.insert(h2, text2);
}
this_thread::sleep_for(chrono::milliseconds(20));
{
WhisperDB db;
s = db.lookup(h2);
BOOST_REQUIRE(!s.compare(text2));
s = db.lookup(h1);
BOOST_REQUIRE(!s.compare(text1));
db.kill(h1);
db.kill(h2);
}
}
BOOST_AUTO_TEST_SUITE_END()

Loading…
Cancel
Save