91 lines
2.6 KiB
C++
91 lines
2.6 KiB
C++
#include <gmock/gmock.h>
|
|
|
|
#include "mocks/SessionMock.hpp"
|
|
#include "mocks/widgets/AuthPageMock.hpp"
|
|
#include "mocks/widgets/MainPageMock.hpp"
|
|
|
|
#include "utils/UniquePtrMockWrapper.hpp"
|
|
#include <Wt/Auth/Login.h>
|
|
#include <Wt/Test/WTestEnvironment.h>
|
|
|
|
#include <eedb/EEDB.hpp>
|
|
#include <eedb/Session.hpp>
|
|
#include <eedb/db/connection.hpp>
|
|
#include <eedb/widgets/Theme.hpp>
|
|
|
|
class AuthPageFactory {
|
|
public:
|
|
MOCK_METHOD0(impl, std::unique_ptr< eedb::AuthPage >());
|
|
auto operator()() {
|
|
return impl();
|
|
}
|
|
};
|
|
|
|
class HomePageFactory {
|
|
public:
|
|
MOCK_METHOD0(impl, std::unique_ptr< eedb::HomePage >());
|
|
auto operator()() {
|
|
return impl();
|
|
}
|
|
};
|
|
|
|
using namespace testing;
|
|
|
|
class EedbApplicationTest : public Test {
|
|
public:
|
|
EedbApplicationTest() {
|
|
createApp();
|
|
}
|
|
|
|
void createApp() {
|
|
expectCreateAuthPage();
|
|
|
|
auto session = std::make_unique< eedb::SessionMock >();
|
|
EXPECT_CALL(*session, enviroment()).WillOnce(ReturnRef(env));
|
|
|
|
// sut = new eedb::EEDB(std::move(session), [this]() { return authPageFactory(); }, [this]() { return homePageFactory(); });
|
|
}
|
|
void expectCreateAuthPage() {
|
|
EXPECT_CALL(authPageFactory, impl()).WillOnce(Return(ByMove(authPage.getPtr())));
|
|
|
|
EXPECT_CALL(*authPage, registerOnNeedVerification(_)).WillOnce(SaveArg< 0 >(&_needVerificationCB));
|
|
EXPECT_CALL(*authPage, registerOnUserWeakLogin(_)).WillOnce(SaveArg< 0 >(&_weakLoginCB));
|
|
EXPECT_CALL(*authPage, registerOnUserStrongLogin(_)).WillOnce(SaveArg< 0 >(&_stringLoginCB));
|
|
EXPECT_CALL(*authPage, registerOnUserLogout(_)).WillOnce(SaveArg< 0 >(&_userLogoutCB));
|
|
}
|
|
|
|
void expectCreateHomePage() {
|
|
EXPECT_CALL(homePageFactory, impl()).WillOnce(Return(ByMove(homePage.getPtr())));
|
|
// EXPECT_CALL(*authPage, detach());
|
|
EXPECT_CALL(*homePage, attachTo(_));
|
|
}
|
|
|
|
protected:
|
|
Wt::Test::WTestEnvironment env;
|
|
|
|
std::function< void() > _stringLoginCB;
|
|
std::function< void() > _weakLoginCB;
|
|
std::function< void() > _userLogoutCB;
|
|
std::function< void() > _needVerificationCB;
|
|
|
|
UniquePtrMockWrapper< eedb::AuthPageMock > authPage;
|
|
AuthPageFactory authPageFactory;
|
|
|
|
UniquePtrMockWrapper< eedb::HomePageMock > homePage;
|
|
HomePageFactory homePageFactory;
|
|
|
|
eedb::EEDB * sut;
|
|
};
|
|
|
|
//TEST_F(EedbApplicationTest, createApp) {}
|
|
|
|
//TEST_F(EedbApplicationTest, strongLoginCreatesMainPage) {
|
|
// expectCreateHomePage();
|
|
//// _stringLoginCB();
|
|
//}
|
|
|
|
//TEST_F(EedbApplicationTest, weakLoginCreatesMainPage) {
|
|
// expectCreateHomePage();
|
|
//// _weakLoginCB();
|
|
//}
|