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.
 
 

56 lines
1.3 KiB

#include <gtest/gtest.h>
#include "../src/types.hh"
TEST( StringList, Simple )
{
pEp::StringList sl;
EXPECT_TRUE(sl.empty());
EXPECT_EQ(sl.size(), 0);
}
TEST( StringList, InitList )
{
pEp::StringList sl( {"Hello", "world"} );
EXPECT_EQ( sl.size(), 2);
sl.clear();
EXPECT_EQ(sl.size(), 0);
EXPECT_TRUE( sl.empty() );
}
TEST( StringList, Dynamic )
{
static const unsigned NumberOfElements = 17;
pEp::StringList sl;
EXPECT_EQ(sl.size(), 0);
EXPECT_TRUE( sl.empty() );
char buffer[16];
for(unsigned u=0; u<NumberOfElements; ++u)
{
EXPECT_EQ(sl.size(), u);
snprintf(buffer, 15, "k%u", u);
sl.push_back( buffer );
}
auto find_value = [&buffer](const char* v){ return strcmp(v, buffer)==0; };
// delete random elements.
for(unsigned u=0; u<NumberOfElements; ++u)
{
EXPECT_EQ(sl.size(), NumberOfElements-u);
snprintf(buffer, 15, "k%u", (u*7) % NumberOfElements); // permutate keys order
auto q = std::find_if( sl.begin(), sl.end(), find_value );
ASSERT_NE( q, sl.end() ); // element with key is found
EXPECT_STREQ( *q, buffer);
sl.erase(q);
q = std::find_if( sl.begin(), sl.end(), find_value );
EXPECT_EQ( q, sl.end() ); // element with that key is no longer found
}
}