This repository was archived by the owner on Jan 31, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathOtherUserDialogTest.cpp
More file actions
87 lines (69 loc) · 2.31 KB
/
Copy pathOtherUserDialogTest.cpp
File metadata and controls
87 lines (69 loc) · 2.31 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2021 The Orbit Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <QCheckBox>
#include <QCoreApplication>
#include <QMetaObject>
#include <QSettings>
#include <Qt>
#include <memory>
#include "SessionSetup/OtherUserDialog.h"
#include "TestUtils/TestUtils.h"
namespace {
constexpr const char* kOrganizationName = "The Orbit Authors";
constexpr const char* kRememberKey = "OtherUserDialog.RememberKey";
} // namespace
namespace orbit_session_setup {
using orbit_test_utils::HasErrorWithMessage;
using orbit_test_utils::HasValue;
TEST(OtherUserDialog, ExecAccept) {
QCoreApplication::setOrganizationDomain(kOrganizationName);
QCoreApplication::setApplicationName("OtherUserDialog.ExecAccept");
QSettings settings;
settings.clear();
OtherUserDialog dialog{"username"};
QMetaObject::invokeMethod(
&dialog, [&]() { dialog.accept(); }, Qt::QueuedConnection);
auto result = dialog.Exec();
EXPECT_THAT(result, HasValue());
}
TEST(OtherUserDialog, ExecReject) {
QCoreApplication::setOrganizationDomain(kOrganizationName);
QCoreApplication::setApplicationName("OtherUserDialog.ExecReject");
QSettings settings;
settings.clear();
OtherUserDialog dialog{"username"};
QMetaObject::invokeMethod(
&dialog, [&]() { dialog.reject(); }, Qt::QueuedConnection);
auto result = dialog.Exec();
EXPECT_THAT(result, HasErrorWithMessage("user rejected"));
}
TEST(OtherUserDialog, Remember) {
QCoreApplication::setOrganizationDomain(kOrganizationName);
QCoreApplication::setApplicationName("OtherUserDialog.WillRemember");
QSettings settings;
settings.clear();
{
OtherUserDialog dialog{"username"};
QMetaObject::invokeMethod(
&dialog,
[&]() {
auto* check_box = dialog.findChild<QCheckBox*>();
ASSERT_TRUE(check_box != nullptr);
check_box->setChecked(true);
dialog.accept();
},
Qt::QueuedConnection);
auto result = dialog.Exec();
EXPECT_THAT(result, HasValue());
EXPECT_TRUE(settings.contains(kRememberKey));
}
{
OtherUserDialog dialog{"username"};
auto result = dialog.Exec();
EXPECT_THAT(result, HasValue());
}
}
} // namespace orbit_session_setup