libtld: /home/snapwebsites/snapcpp/contrib/libtld/tests/tld_test_emails.cpp File Reference

libtld  1.5.13
A library to determine the Top-Level Domain name of any URL.
tld_test_emails.cpp File Reference

Test the tld_email_list class. More...

#include "libtld/tld.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sstream>
Include dependency graph for tld_test_emails.cpp:

Go to the source code of this file.

Classes

struct  email_field_types
 Structure used to define a set of fields to test. More...
 
struct  invalid_email
 Define an invalid email. More...
 
struct  valid_email
 Define a valid email string. More...
 

Macros

#define EXPECTED_THROW(s, e)
 Macro to check that exceptions are raised without having to write the try/catch each time. More...
 

Functions

void contract_furfilled (tld_email_list::tld_email_t &e)
 
std::string email_to_vstring (const std::string &e)
 Transform an email string in a C-like string. More...
 
void error (const std::string &msg)
 Print an error. More...
 
int main (int argc, char *argv[])
 
void test_direct_email ()
 
void test_email_field_types ()
 
void test_invalid_emails ()
 
void test_valid_emails ()
 

Variables

int err_count = 0
 The number of errors encountered before exiting.
 
const email_field_types list_of_email_field_types []
 
const invalid_email list_of_invalid_emails []
 
const tld_email list_of_results []
 List of results to verify all the fields of the parser output. There is one entry per group and email.
 
const valid_email list_of_valid_emails []
 The list of valid emails used to check the parser out. More...
 
int verbose = 0
 Whether to be verbose, turned off by default.
 

Detailed Description

This file implements various tests to verify that the tld_email_list functions as expected.

Definition in file tld_test_emails.cpp.

Macro Definition Documentation

#define EXPECTED_THROW (   s,
 
)
Value:
try \
{ \
static_cast<void>(s); \
error("error: bad." #s "() of \"\" did not throw an error."); \
} \
catch(const e&) \
{ \
}
void error(const std::string &msg)
Print an error.

Definition at line 59 of file tld_test_emails.cpp.

Function Documentation

void error ( const std::string &  msg)

This function prints the specified msg in stderr and increases the error counter by one.

Parameters
[in]msgThe message to be printed.

Definition at line 51 of file tld_test_emails.cpp.

References err_count.

Referenced by email_to_vstring().

Variable Documentation

const valid_email list_of_valid_emails[]
Initial value:
=
{
{ "MAILER-DAEMON@mail.exdox.com (Mail Delivery System)", 1},
{ "alexis@m2osw.com", 1 },
{ "a@m2osw.com", 1 },
{ "b@c.com", 1 },
{ " \t alexis@m2osw.com\n \t", 1 },
{ "\"Wilke, Alexis\" <alexis@m2osw.com>", 1 },
{ " (* Pascal Comments *) \t alexis@m2osw.com\n (Just (kidding) he! he!) \t", 1 },
{ "(Start-Comment)alexis@ \t [ \t m2osw.com \t ] \n (More (comment) here) \r\n\t", 1 },
{ "(Test with dots in user name) al.ex.is@ \t [ \t m2osw.com \t ] \n (More (comments) there) \r\n\t", 1 },
{ "< (Test with dots in user name) al.ex.is@ \t [ \t m2osw.com \t ] \n (More (comments) there) > \r\n\t", 1 },
{ "(With full name) Alexis Wilke < (Test with dots in user name) al.ex.is@ \t [ \t m2osw.com \t ] \n (More (comments) there) > \r\n\t", 1 },
{ " (Now a group:) This Group: (With full name) Alexis Wilke < \n alexis \t @ \t [ \t m2osw.com \t ] \n (Less) >; \r\n\t", 2 },
{ "People: Alexis Wilke <alexis@m2osw.com>, John Smith <john@m2osw.com>; Lists: Contact <contact@m2osw.com>, Resume <resume@m2osw.com>; normal@m2osw.com, No-Reply: no-reply@m2osw.com;", 9 },
{ "\"Complex <name> for !a! \\\"USER\\\"\" <user@example.co.uk>", 1 },
{ "(Comment \n New-Line) alexis@m2osw.com", 1 },
{ "(Comment (Sub-Comment (Sub-Sub-Comment (Sub-Sub-Sub-Comment \\) This is still the Sub-Sub-Sub-Comment!!!)))) alexis@m2osw.com", 1 },
{ "Group with (Comment (Sub-Comment (Sub-Sub-Comment (Sub-Sub-Sub-Comment \\) This is still the Sub-Sub-Sub-Comment!!!)))) some sub-comments \t : alexis@m2osw.com;", 2 },
{ "\"Wilke, Alexis\" <\"alexis,wilke\"@[:special:.m2osw.com]>", 1 },
{ "alexis@m2osw.com (Simple Comment)", 1 },
{ nullptr, 0 }
}

Definition at line 166 of file tld_test_emails.cpp.

This document is part of the Snap! Websites Project.

Copyright by Made to Order Software Corp.

Syndicate content

Snap! Websites
An Open Source CMS System in C++

Contact Us Directly