A C++ wrapper for the basic C datatypes defined by the pEpEngine.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

62 lines
1.6 KiB

#include <gtest/gtest.h>
#include "../src/types.hh"
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
}
}