DRDE/ACTK1_0/session/SessionTest.cpp

87 lines
2.1 KiB
C++
Raw Normal View History

#include "session/SessionFactory.hpp"
#include "session/SessionManagerProperties.hpp"
#include "common/SystemProperties.hpp"
#include "common/init.hpp"
#include "session/Session.hpp"
#include "session/StatsManager.hpp"
#include "session/TestEnvironment.hpp"
#include "common/Test.hpp"
#include <string>
#include <iostream>
#include <memory>
using namespace std;
static std::string TEST_SE =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><epp xmlns=\"urn:ietf:params:xml:ns:epp-1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd\"><hello/></epp>";
2014-01-10 21:25:13 +00:00
extern int tkScenario;
void doWork()
{
2014-01-10 20:19:20 +00:00
if (!tkScenario)
2014-01-16 20:28:52 +00:00
init("./etc/toolkit2.conf");
2014-01-10 20:19:20 +00:00
else
2014-01-16 20:28:52 +00:00
scenario(tkScenario,"./etc/toolkit2.conf");
{
TestEnvironment props;
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
sess->open();
sess->close();
}
{
TestEnvironment props;
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
sess->open();
sess->writeXML(TEST_SE);
sess->read();
sess->close();
}
{
TestEnvironment props;
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
sess->open();
StatsManager* sm(sess->getStatsManager());
sm->incResultCounter(1000);
ASSERT_EQ(sm->getResultCodeCount(1000), 1);
sess->close();
}
{
TestEnvironment props;
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
sess->open();
StatsViewer* sv(sess->getStatsManager());
ASSERT_EQ(sv->getCommandCount(), 1);
ASSERT_EQ(sv->getCommandCount(StandardCommandType::LOGIN()), 1);
ASSERT_EQ(sv->getCommandCount(StandardCommandType::LOGOUT()), 0);
sess->close();
}
{
TestEnvironment props;
auto_ptr<Session> sess(SessionFactory::newInstance(&props));
sess->open();
StatsManager* sm(sess->getStatsManager());
ASSERT_EQ(sm->getResultCodeCount(1000), 0);
sess->close();
}
}
int main(int argc, char* argv[])
{
2014-01-10 20:19:20 +00:00
if (argc > 1)
tkScenario = atoi(argv[1]);
TEST_run(doWork);
return TEST_errorCount();
}