2014-09-04 15:15:58 +02:00
|
|
|
#include "config.h"
|
|
|
|
#include "protocol/ArgParser.hxx"
|
2015-08-06 22:10:25 +02:00
|
|
|
#include "client/Response.hxx"
|
2014-09-04 15:15:58 +02:00
|
|
|
#include "Compiler.h"
|
|
|
|
|
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/TestFactoryRegistry.h>
|
|
|
|
#include <cppunit/ui/text/TestRunner.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2014-09-24 23:03:28 +02:00
|
|
|
#include <stdlib.h>
|
2014-09-24 21:40:18 +02:00
|
|
|
|
2014-09-04 15:15:58 +02:00
|
|
|
static enum ack last_error = ack(-1);
|
|
|
|
|
|
|
|
void
|
2015-08-06 22:10:25 +02:00
|
|
|
Response::Error(enum ack code, gcc_unused const char *msg)
|
2014-09-04 15:15:58 +02:00
|
|
|
{
|
2015-08-06 22:10:25 +02:00
|
|
|
last_error = code;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Response::FormatError(enum ack code, gcc_unused const char *fmt, ...)
|
|
|
|
{
|
|
|
|
last_error = code;
|
2014-09-04 15:15:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ArgParserTest : public CppUnit::TestFixture {
|
|
|
|
CPPUNIT_TEST_SUITE(ArgParserTest);
|
|
|
|
CPPUNIT_TEST(TestRange);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void TestRange();
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
ArgParserTest::TestRange()
|
|
|
|
{
|
|
|
|
Client &client = *(Client *)nullptr;
|
2015-08-06 22:10:25 +02:00
|
|
|
Response r(client);
|
2014-09-04 15:15:58 +02:00
|
|
|
|
2015-08-11 21:35:52 +02:00
|
|
|
RangeArg range;
|
2014-09-04 15:15:58 +02:00
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
CPPUNIT_ASSERT(ParseCommandArg(r, range, "1"));
|
2015-08-11 21:35:52 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1u, range.start);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(2u, range.end);
|
2014-09-04 15:15:58 +02:00
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
CPPUNIT_ASSERT(ParseCommandArg(r, range, "1:5"));
|
2015-08-11 21:35:52 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1u, range.start);
|
|
|
|
CPPUNIT_ASSERT_EQUAL(5u, range.end);
|
2014-09-04 15:15:58 +02:00
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
CPPUNIT_ASSERT(ParseCommandArg(r, range, "1:"));
|
2015-08-11 21:35:52 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(1u, range.start);
|
|
|
|
CPPUNIT_ASSERT(range.end >= 999999u);
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
CPPUNIT_ASSERT(!ParseCommandArg(r, range, "-2"));
|
2014-09-04 15:15:58 +02:00
|
|
|
CPPUNIT_ASSERT_EQUAL(ACK_ERROR_ARG, last_error);
|
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(ArgParserTest);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(gcc_unused int argc, gcc_unused char **argv)
|
|
|
|
{
|
|
|
|
CppUnit::TextUi::TestRunner runner;
|
|
|
|
auto ®istry = CppUnit::TestFactoryRegistry::getRegistry();
|
|
|
|
runner.addTest(registry.makeTest());
|
|
|
|
return runner.run() ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|