2006-02-17 13:35:04 +00:00
|
|
|
#include "Option.h"
|
|
|
|
#include <string>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
2006-02-17 13:35:04 +00:00
|
|
|
|
|
|
|
class OptionTest:public CppUnit::TestFixture {
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(OptionTest);
|
|
|
|
CPPUNIT_TEST(testPutAndGet);
|
|
|
|
CPPUNIT_TEST(testPutAndGetAsInt);
|
2006-08-28 12:40:41 +00:00
|
|
|
CPPUNIT_TEST(testPutAndGetAsDouble);
|
2008-12-04 13:05:05 +00:00
|
|
|
CPPUNIT_TEST(testDefined);
|
|
|
|
CPPUNIT_TEST(testBlank);
|
2006-02-17 13:35:04 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
private:
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void testPutAndGet();
|
|
|
|
void testPutAndGetAsInt();
|
2006-08-28 12:40:41 +00:00
|
|
|
void testPutAndGetAsDouble();
|
2008-12-04 13:05:05 +00:00
|
|
|
void testDefined();
|
|
|
|
void testBlank();
|
2006-02-17 13:35:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION( OptionTest );
|
|
|
|
|
|
|
|
void OptionTest::testPutAndGet() {
|
|
|
|
Option op;
|
|
|
|
op.put("key", "value");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(op.defined("key"));
|
2008-02-08 15:53:45 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL(std::string("value"), op.get("key"));
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionTest::testPutAndGetAsInt() {
|
|
|
|
Option op;
|
|
|
|
op.put("key", "1000");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT(op.defined("key"));
|
2007-08-15 15:11:01 +00:00
|
|
|
CPPUNIT_ASSERT_EQUAL((int32_t)1000, op.getAsInt("key"));
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-08-28 12:40:41 +00:00
|
|
|
|
|
|
|
void OptionTest::testPutAndGetAsDouble() {
|
|
|
|
Option op;
|
|
|
|
op.put("key", "10.0");
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT_EQUAL(10.0, op.getAsDouble("key"));
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-12-04 13:05:05 +00:00
|
|
|
void OptionTest::testDefined()
|
|
|
|
{
|
|
|
|
Option op;
|
|
|
|
op.put("k", "v");
|
|
|
|
op.put("k1", "");
|
|
|
|
CPPUNIT_ASSERT(op.defined("k"));
|
|
|
|
CPPUNIT_ASSERT(op.defined("k1"));
|
|
|
|
CPPUNIT_ASSERT(!op.defined("undefined"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionTest::testBlank()
|
|
|
|
{
|
|
|
|
Option op;
|
|
|
|
op.put("k", "v");
|
|
|
|
op.put("k1", "");
|
|
|
|
CPPUNIT_ASSERT(!op.blank("k"));
|
|
|
|
CPPUNIT_ASSERT(op.blank("k1"));
|
|
|
|
CPPUNIT_ASSERT(op.blank("undefined"));
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|