Browse Source

add comprehensive test for pEp::StringPairList

master
roker 4 months ago
parent
commit
1a270a0106
1 changed files with 53 additions and 1 deletions
  1. +53
    -1
      test/unittest_stringpair.cc

+ 53
- 1
test/unittest_stringpair.cc View File

@ -3,8 +3,60 @@
#include "../src/types.hh"
TEST( StringPair, T1 )
TEST( StringPair, Simple )
{
pEp::StringPair s1{"key", "value"};
pEp::StringPairList spl;
EXPECT_TRUE(spl.empty());
EXPECT_EQUAL(spl.size(), 0);
// pEp::StringPair s2{ std::string{"key2"}, std::string{"value"} };
}
TEST( StringPair, InitList )
{
pEp::StringPairList spl{ {"key0", "value0"}, {"key1", "value1"} };
EXPECT_EQUAL( spl.size(), 2);
spl.clear();
EXPECT_EQUAL(spl.size(), 0);
EXPECT_TRUE( spl.empty() );
}
TEST( StringPair, Dynamic )
{
static const unsigned NumberOfElements = 17;
char key[16];
char value[16];
pEp::StringPairList spl;
EXPECT_EQUAL(spl.size(), 0);
EXPECT_TRUE( spl.empty() );
for(unsigned u=0; u<NumberOfElements; ++u)
{
EXPECT_EQUAL(spl.size(), u);
snprintf(key, 15, "k%u", u);
snprintf(value, 15, "v%u", u*91);
spl.push_back( pEp::StringPair{key, value} );
}
auto find_by_key = [key](const pEp::StringPair& sp){ return sp.key == key; };
// delete random elements.
for(unsigned u=0; u<NumberOfElements; ++u)
{
EXPECT_EQUAL(spl.size(), NumberOfElements-u);
snprintf(key, 15, "k%u", (u*7) % NumberOfElements); // permutate keys order
auto q = std::find( spl.begin(), spl.end(), find_by_keys );
EXPECT_NE( q, spl.end() ); // element with key is found
spl.erase(q);
q = std::find( spl.begin(), spl.end(), find_by_keys );
EXPECT_EQ( q, spl.end() ); // element with that key is no longer found
}
}

Loading…
Cancel
Save