
#include "MyString.h"
#include "Title.h"
#include "Name.h"

#include <iostream>
#include <stdexcept>

void runNameTests();

int main(int argc, char** argv)
{

	Title* t = new Title();
	t->setTitle(1);

	MyString *ts;
    ts = t->getTitleAsMyString();
	ts->print();
	delete ts;

	Title* t2 = new Title();
	t2->setTitle(Title::MRS);
    std::string s = t2->getTitleAsString(); /* This actually uses the copy constructor of string */
    std::cout << "Title as a std::string" << s << std::endl;

    try
    {
        Title* t3 = new Title();
        t3->setTitle(99);
        std:: cout << t3->getTitleAsString() << std::endl;
    }
    catch(std::out_of_range oor)
    {
         std::cout << "Error message: " << oor.what() << std::endl;
    }
    catch(std::exception e) //catch an exception or any children of
    {
        std::cout << "Error message: " << e.what() << std::endl;
    }

    try
    {
        Title* t4 = new Title();
        t4->setTitle(0);
        std:: cout << t4->getTitleAsString() << std::endl;
    }
    catch(std::out_of_range oor)
    {
         std::cout << "Error message: " << oor.what() << std::endl;
    }
    catch(std::exception e) //catch an exception or any children of
    {
        std::cout << "Error message: " << e.what() << std::endl;
    }

    printf("\n\t\t Running Name Tests \n");
    runNameTests();
    printf("\n\t\t Name Tests Done \n");

}

void runNameTests()
{
    Name* good = new Name("Hello");

    std::cout << "Testing with : " << (*good) << std::endl;

    if(good->validate())
        std::cout << "Validation pass - expected" << std::endl;
    else
        std::cout << "Valdiation fail" << std::endl;

    std::cout << std::endl << " ************************** " << std::endl;

    Name* good1 = new Name("Hel-oo");

    std::cout << "Testing with : " << (*good1) << std::endl;

    if(good1->validate())
        std::cout << "Validation pass - expected" << std::endl;
    else
        std::cout << "Valdiation fail" << std::endl;

    std::cout << std::endl << " ************************** " << std::endl;

    Name* good2 = new Name("Hello Jr.");

    std::cout << "Testing with : " << (*good2) << std::endl;

    if(good2->validate())
        std::cout << "Validation pass - expected" << std::endl;
    else
        std::cout << "Valdiation fail" << std::endl;

    std::cout << std::endl << " ************************** " << std::endl;

    Name* bad1 = new Name("Fred55Dog");

    std::cout << "Testing with : " << (*bad1) << std::endl;

    if(bad1->validate())
        std::cout << "Validation pass" << std::endl;
    else
        std::cout << "Valdiation fail - expected" << std::endl;

    std::cout << std::endl << " ************************** " << std::endl;

    Name* bad2 = new Name("Fred!!Dog");

   std::cout << "Testing with : " << (*bad2) << std::endl;

    if(bad2->validate())
        std::cout << "Validation pass" << std::endl;
    else
        std::cout << "Valdiation fail - expected" << std::endl;

    std::cout << std::endl << " ************************** " << std::endl;

    delete good;
    delete good1;
    delete good2;
    delete bad2;
    delete bad1;
}
