#include "Test.h"
#include <iostream>
#include "../../TestWalker/MSClient.h"

ConnectTest::ConnectTest()
{
    ok = 0;
}

void ConnectTest::init()
{
    std::cout << "starting connection Test\n";
}

void ConnectTest::run()
{
    bool ok = 1;
    MSClient msc;
    std::cout << "\x1...Main Server...\x1\n";
    if( !msc.registerSSL() )
    {
        ok = 0;
        std::cerr << "client registration failed " __FILE__ ":" << __LINE__ << "\n";
        return;
    }
    std::cout << "\x1...Erhaltung Server...\x1\n";
    ESClient *esc = msc.createErhaltungServerClient();
    if( !esc )
    {
        ok = 0;
        std::cerr << "no Erhaltung Server available " __FILE__ ":" << __LINE__ << "\n";
    }
    else
    {
        if( !esc->verbinden() )
        {
            ok = 0;
            std::cerr << "no connection to Erhaltung Server " __FILE__ ":" << __LINE__ << "\n";
        }
    }

    // TODO
    std::cout << "\x1...Abmeldung beim Server...\x1\n";
    esc->release();
    if( !msc.unregister() )
    {
        ok = 0;
        std::cerr << "client unregistration failed " __FILE__ ":" << __LINE__ << "\n";
    }
    this->ok = ok;
}

bool ConnectTest::failed()
{
    return !ok;
}

void ConnectTest::destroy()
{
    delete this;
}