Browse Source

add docu, add tests. next try.....

master
roker 4 years ago
parent
commit
4e43ab01f2
  1. 16
      src/nfc.hh
  2. 12
      src/wrapper.hh
  3. 10
      test/unittest_message.cc
  4. 16
      test/unittest_stringlist.cc

16
src/nfc.hh

@ -13,16 +13,19 @@
namespace pEp {
/// Tri-sate return value of isNFC_quick_check()
enum class IsNFC
{
No=0, // contains a character that cannot occur in NFC
Maybe=1, // contains a character that is only allowed in certain positions in NFC
Yes=2 // contains no invalid or partially valid character
No=0, //!< string contains a character that cannot occur in NFC
Maybe=1, //!< string contains a character that is only allowed in certain positions in NFC
Yes=2 //!< string contains no invalid or partially valid character
};
std::ostream& operator<<(std::ostream& o, IsNFC is_nfc);
/// Exception class thrown whenever a string is parsed that is not a valid
/// UTF-8 or UTF-16 sequence.
class illegal_utf : public std::runtime_error
{
public:
@ -51,8 +54,9 @@ public:
static
bool is_safe_NFC_start(std::basic_string_view<CharT> s);
/// returns No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe"
/// might throw illegal_utf exception
/// returns No or Maybe, if at least one character with NFC_Quickcheck class is "No" or "Maybe".
/// use isNFC() for a comprehensive NFC check.
/// Might throw illegal_utf exception
static
IsNFC isNFC_quick_check(std::basic_string_view<CharT> s);
@ -129,6 +133,7 @@ public:
/// read-only: shares representation
operator const String&() const noexcept { return s; }
/// read-only: shares representation
const String& get() const noexcept { return s;}
/// read write: copy content
@ -185,6 +190,7 @@ public:
return *this;
}
/// more expensive, because 's' might not be in NFC.
nfc_string& operator+=(StringView s);
/// optimization possible to avoid re-normalization in most cases.

12
src/wrapper.hh

@ -10,6 +10,7 @@
namespace pEp
{
/// A generalized wrapper around pEpEngine's datatypes.
template<class T>
class Wrapper
{
@ -104,13 +105,17 @@ public:
return value!=b.value;
}
// Get read-only access to the value itself
// Beware: 'const' is not transitive in C, so the 2nd indirect data
// allows r/w access!
const T* operator->() const { return value; }
const T* get() const { return value; }
// dangerous!
// Dangerous: Get R/W access to the value!
T* operator->() { return value; }
T* get() { return value;}
// Releases ownership of the value. Wrapper becomes valueless.
T* move_out() { T* r = value; value=nullptr; return r;}
// only implemented for the datatypes where necessay.
@ -166,6 +171,8 @@ public:
friend class ListWrapper<T*, Element>;
};
typedef const iterator const_iterator;
using Base::value;
@ -176,6 +183,9 @@ public:
iterator begin() { return iterator{value}; }
iterator end() const { return iterator{}; }
const_iterator cbegin() const { return const_iterator{value}; }
const_iterator cend() const { return const_iterator{}; }
int size() const;
bool empty() const;

10
test/unittest_message.cc

@ -110,6 +110,13 @@ namespace
"--==pEp_01==--\r\n"
"\r\n";
PEP_STATUS dummy_message(::message* msg)
{
msg->shortmsg = strdup("Hello World");
return PEP_STATUS_OK;
}
} // end of anonymous namespace
@ -127,4 +134,7 @@ TEST( MessageTest, Simple )
ASSERT_NE(msg->from, nullptr);
EXPECT_STREQ( msg->from->username, "Alice");
EXPECT_EQ( dummy_message(msg.get()), PEP_STATUS_OK);
EXPECT_STREQ( msg->shortmsg, "Hello World");
}

16
test/unittest_stringlist.cc

@ -21,6 +21,22 @@ TEST( StringList, InitList )
}
TEST( StringList, Algorithm )
{
pEp::StringList sl( {"Alice", "Bob", "Carol", "Dave", "Eve", "Frank", "George", "Harry"} );
auto qe = std::find(sl.begin(), sl.end(), std::string("Santa Claus")); // not there!
EXPECT_EQ( qe, sl.end() );
// BEWARE: DOES NOT WORK, because find() uses operator== on char* pointers. :-(
// auto q = std::find(sl.begin(), sl.end(), "Eve");
auto q = std::find(sl.begin(), sl.end(), std::string("Eve"));
EXPECT_NE( q, sl.end() );
EXPECT_STREQ( *q, "Eve" );
}
TEST( StringList, Dynamic )
{
static const unsigned NumberOfElements = 17;

Loading…
Cancel
Save