Browse Source

add unittest for identity & identity_list

master
roker 6 months ago
parent
commit
9278dd9e9b
1 changed files with 69 additions and 0 deletions
  1. +69
    -0
      test/unittest_identity.cc

+ 69
- 0
test/unittest_identity.cc View File

@ -0,0 +1,69 @@
#include <gtest/gtest.h>
#include "../src/types.hh"
TEST( PepIdentity, Simple )
{
pEp::Identity id{"test1@pEpdatatypes.lol", "FF00112233445566778899AABBCCDDEEFF001122", "Test User ID", "Test User Name"};
}
TEST( IdentityList, Simple )
{
pEp::IdentityList il;
EXPECT_TRUE(il.empty());
EXPECT_EQ(il.size(), 0);
}
TEST( IdentityList, InitList )
{
pEp::IdentityList il(
{
pEp::Identity{"test-init1@pEpdatatypes.lol", "0100112233445566778899AABBCCDDEEFF001122", "Test User ID1", "Test User 1 Name"},
pEp::Identity{"test-init2@pEpdatatypes.lol", "0200112233445566778899AABBCCDDEEFF001122", "Test User ID2", "Test User 2 Name"}
} );
EXPECT_EQ( il.size(), 2);
il.clear();
EXPECT_EQ(il.size(), 0);
EXPECT_TRUE( il.empty() );
}
/*
TEST( IdentityList, Dynamic )
{
static const unsigned NumberOfElements = 17;
pEp::IdentityList il;
EXPECT_EQ(il.size(), 0);
EXPECT_TRUE( il.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
}
}
*/

Loading…
Cancel
Save