1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#include "DefaultAuthResolver.h"
#include "prefs.h"
#include "AuthConfig.h"
#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
class DefaultAuthResolverTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DefaultAuthResolverTest);
CPPUNIT_TEST(testResolveAuthConfig_without_userDefined);
CPPUNIT_TEST(testResolveAuthConfig_with_userDefined);
CPPUNIT_TEST_SUITE_END();
private:
//NetrcHandle _netrc;
//SharedHandle<Option> _option;
SharedHandle<DefaultAuthResolver> resolver_;
public:
void setUp()
{
//_netrc = new Netrc();
//_option = new Option();
resolver_.reset(new DefaultAuthResolver());
//_factory->setOption(_option.get());
resolver_->setDefaultAuthConfig
(SharedHandle<AuthConfig>(new AuthConfig("foo", "bar")));
}
void testResolveAuthConfig_without_userDefined();
void testResolveAuthConfig_with_userDefined();
};
CPPUNIT_TEST_SUITE_REGISTRATION( DefaultAuthResolverTest );
void DefaultAuthResolverTest::testResolveAuthConfig_without_userDefined()
{
SharedHandle<AuthConfig> authConfig = resolver_->resolveAuthConfig("localhost");
CPPUNIT_ASSERT_EQUAL(std::string("foo:bar"), authConfig->getAuthText());
}
void DefaultAuthResolverTest::testResolveAuthConfig_with_userDefined()
{
resolver_->setUserDefinedAuthConfig
(SharedHandle<AuthConfig>(new AuthConfig("myname", "mypasswd")));
SharedHandle<AuthConfig> authConfig = resolver_->resolveAuthConfig("localhost");
CPPUNIT_ASSERT_EQUAL(std::string("myname:mypasswd"), authConfig->getAuthText());
}
} // namespace aria2
|