protocol/Ack: add exception class wrapping enum ack

This commit is contained in:
Max Kellermann
2015-12-18 09:50:48 +01:00
parent 8bb5a565cd
commit e939d667d9
13 changed files with 289 additions and 377 deletions

View File

@@ -1,6 +1,6 @@
#include "config.h"
#include "protocol/ArgParser.hxx"
#include "client/Response.hxx"
#include "protocol/Ack.hxx"
#include "Compiler.h"
#include <cppunit/TestFixture.h>
@@ -10,20 +10,6 @@
#include <stdlib.h>
static enum ack last_error = ack(-1);
void
Response::Error(enum ack code, gcc_unused const char *msg)
{
last_error = code;
}
void
Response::FormatError(enum ack code, gcc_unused const char *fmt, ...)
{
last_error = code;
}
class ArgParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ArgParserTest);
CPPUNIT_TEST(TestRange);
@@ -36,25 +22,24 @@ public:
void
ArgParserTest::TestRange()
{
Client &client = *(Client *)nullptr;
Response r(client, 0);
RangeArg range;
CPPUNIT_ASSERT(ParseCommandArg(r, range, "1"));
RangeArg range = ParseCommandArgRange("1");
CPPUNIT_ASSERT_EQUAL(1u, range.start);
CPPUNIT_ASSERT_EQUAL(2u, range.end);
CPPUNIT_ASSERT(ParseCommandArg(r, range, "1:5"));
range = ParseCommandArgRange("1:5");
CPPUNIT_ASSERT_EQUAL(1u, range.start);
CPPUNIT_ASSERT_EQUAL(5u, range.end);
CPPUNIT_ASSERT(ParseCommandArg(r, range, "1:"));
range = ParseCommandArgRange("1:");
CPPUNIT_ASSERT_EQUAL(1u, range.start);
CPPUNIT_ASSERT(range.end >= 999999u);
CPPUNIT_ASSERT(!ParseCommandArg(r, range, "-2"));
CPPUNIT_ASSERT_EQUAL(ACK_ERROR_ARG, last_error);
try {
range = ParseCommandArgRange("-2");
CPPUNIT_ASSERT(false);
} catch (ProtocolError) {
CPPUNIT_ASSERT(true);
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(ArgParserTest);