GCC Code Coverage Report


Directory: ./
File: qtpdcom/src/LoginManager.cpp
Date: 2023-11-12 04:06:57
Exec Total Coverage
Lines: 52 62 83.9%
Branches: 18 36 50.0%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * Copyright (C) 2009-2023 Bjarne von Horn <vh@igh.de>
4 *
5 * This file is part of the QtPdCom library.
6 *
7 * The QtPdCom library is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * The QtPdCom library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with the QtPdCom Library. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ****************************************************************************/
21
22 #include "LoginManager.h"
23
24 #include "LoginManager_p.h"
25 #include <pdcom5/Exception.h>
26 #include <QDebug>
27
28 using QtPdCom::LoginManager;
29 using QtPdCom::LoginManagerPrivate;
30
31 4 LoginManager::LoginManager(QString server_name, QObject *parent):
32 QObject(parent),
33
3/6
✓ Branch 6 taken 4 times.
✗ Branch 7 not taken.
✓ Branch 11 taken 4 times.
✗ Branch 12 not taken.
✓ Branch 15 taken 4 times.
✗ Branch 16 not taken.
4 d_ptr(new LoginManagerPrivate(server_name.toStdString().c_str(), this))
34 4 {}
35
36 LoginManager::~LoginManager() = default;
37
38 1 void LoginManager::InitLibrary(const char *plugin_path)
39 {
40 1 PdCom::SimpleLoginManager::InitLibrary(plugin_path);
41 1 }
42
43 void LoginManager::FinalizeLibrary()
44 {
45 PdCom::SimpleLoginManager::FinalizeLibrary();
46 }
47
48 4 void LoginManager::setAuthName(QString name)
49 {
50 4 Q_D(LoginManager);
51 4 d->username = name.toStdString();
52 4 d->username_set = true;
53 4 }
54
55 4 void LoginManager::setPassword(QString password)
56 {
57 4 Q_D(LoginManager);
58 4 d->password = password.toStdString();
59 4 d->password_set = true;
60 4 }
61
62 3 void LoginManager::login()
63 {
64 3 Q_D(LoginManager);
65 try {
66
1/2
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
3 d->login();
67 } catch (const PdCom::NotConnected&) {
68 qWarning() << "Login on not connected process!";
69 }
70 3 }
71
72 1 void LoginManager::logout()
73 {
74 1 Q_D(LoginManager);
75 try {
76
1/2
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 d->logout();
77 } catch (const PdCom::NotConnected&) {
78 }
79 1 }
80
81 6 std::string LoginManagerPrivate::getAuthname()
82 {
83
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 1 times.
✓ Branch 6 taken 5 times.
6 if (username_set)
84 1 return username;
85 5 Q_Q(LoginManager);
86 5 emit q->needCredentials();
87 // username can be set from non-queued signal
88
3/4
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 3 times.
✓ Branch 6 taken 2 times.
5 if (username_set)
89 3 return username;
90 2 throw Cancel();
91 }
92
93 4 std::string LoginManagerPrivate::getPassword()
94 {
95
2/4
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
✓ Branch 5 taken 4 times.
✗ Branch 6 not taken.
4 if (password_set)
96 4 return password;
97 Q_Q(LoginManager);
98 emit q->needCredentials();
99 // username can be set from non-queued signal
100 if (password_set)
101 return password;
102 throw Cancel();
103 }
104
105 6 void LoginManagerPrivate::completed(PdCom::SimpleLoginManager::LoginResult success)
106 {
107 6 Q_Q(LoginManager);
108
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if (success == LoginResult::Success) {
109 3 emit q->loginSuccessful();
110
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 } else if (success == LoginResult::Error) {
111 1 clearCredentials();
112 1 emit q->loginFailed();
113 }
114 6 }
115
116 2 void LoginManagerPrivate::clearCredentials()
117 {
118 2 username.clear();
119 2 password.clear();
120
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 2 times.
2 password_set = username_set = false;
121 2 }
122
123 1 void LoginManager::clearCredentials()
124 {
125 1 Q_D(LoginManager);
126 1 d->clearCredentials();
127 1 }
128