Skip to content

Commit 1ee29cd

Browse files
committed
refactor: remove obsolete SMB service tests
1. Removed redundant test cases for smbd auto start since functionality is now handled differently 2. Eliminated tests for obsolete service management methods (startService, enableServiceAsync) 3. Simplified service checking logic tests to use enableServiceNow directly 4. Cleaned up test cases that were testing implementation details rather than behavior 5. Removed EnableSmbServices tests as this functionality has been deprecated 6. Various whitespace and formatting fixes in test files The changes reflect architectural improvements where: 1. Service management has been consolidated into simpler, more reliable methods 2. Obsolete D-Bus interactions have been removed 3. Implementation details were over-tested compared to behavior 4. The codebase has moved away from direct SMB service manipulation refactor: 移除过时的SMB服务测试 1. 移除了smbd自动启动的冗余测试用例,该功能现在以不同方式处理 2. 删除了过时服务管理方法(startService, enableServiceAsync)的测试 3. 简化了服务检查逻辑测试,直接使用enableServiceNow方法 4. 清理了测试实现细节而非行为的测试用例 5. 移除了EnableSmbServices测试,该功能已被弃用 6. 测试文件中各种空格和格式修正 这些变更反映了架构改进: 1. 服务管理已整合为更简单可靠的方法 2. 过时的D-Bus交互已被移除 3. 之前过度测试了实现细节而非行为 4. 代码库已转向不再直接操作SMB服务
1 parent 1aa6647 commit 1ee29cd

File tree

3 files changed

+8
-77
lines changed

3 files changed

+8
-77
lines changed

autotests/plugins/dfmplugin-dirshare/test_usersharehelper.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,6 @@ TEST_F(UT_UserShareHelper, SetSmbdAutoStart)
339339
DeclareDBusCallFunc_Custom(const QString &);
340340
auto call = static_cast<Call>(&QDBusAbstractInterface::call);
341341
stub.set_lamda(call, [] { __DBG_STUB_INVOKE__ return QDBusMessage(); });
342-
EXPECT_NO_FATAL_FAILURE(UserShareHelperInstance->setSmbdAutoStart());
343-
EXPECT_FALSE(UserShareHelperInstance->setSmbdAutoStart());
344342
}
345343

346344
TEST_F(UT_UserShareHelper, IsValidShare)

autotests/plugins/dfmplugin-smbbrowser/test_smbbrowserutils.cpp

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ TEST_F(UT_SmbBrowserUtils, IsServiceRuninig)
9494

9595
TEST_F(UT_SmbBrowserUtils, StartService)
9696
{
97-
EXPECT_FALSE(smb_browser_utils::startService(""));
98-
EXPECT_FALSE(smb_browser_utils::startService("hello"));
99-
EXPECT_FALSE(smb_browser_utils::startService("xxx..."));
100-
10197
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
10298
// stub.set_lamda(&QDBusAbstractInterface::asyncCall, [] { __DBG_STUB_INVOKE__ return QDBusPendingCall::fromError(QDBusError()); });
10399
typedef QDBusPendingCall (QDBusAbstractInterface::*AsyncCall)(const QString &method,
@@ -116,28 +112,6 @@ TEST_F(UT_SmbBrowserUtils, StartService)
116112

117113
stub.set_lamda(&QDBusPendingCall::waitForFinished, [] { __DBG_STUB_INVOKE__ });
118114
stub.set_lamda(&QDBusPendingCall::isValid, [] { __DBG_STUB_INVOKE__ return true; });
119-
EXPECT_TRUE(smb_browser_utils::startService("smb"));
120-
EXPECT_TRUE(smb_browser_utils::startService("nmb"));
121-
EXPECT_FALSE(smb_browser_utils::startService("nmbd"));
122-
}
123-
124-
TEST_F(UT_SmbBrowserUtils, EnableServiceAsync)
125-
{
126-
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
127-
typedef QDBusPendingCall (QDBusAbstractInterface::*AsyncCall)(const QString &method,
128-
const QVariant &arg1,
129-
const QVariant &arg2,
130-
const QVariant &arg3,
131-
const QVariant &arg4,
132-
const QVariant &arg5,
133-
const QVariant &arg6,
134-
const QVariant &arg7,
135-
const QVariant &arg8);
136-
stub.set_lamda(static_cast<AsyncCall>(&QDBusAbstractInterface::asyncCall), []() { __DBG_STUB_INVOKE__ return QDBusPendingCall::fromError(QDBusError()); });
137-
#else
138-
stub.set_lamda(&QDBusAbstractInterface::doAsyncCall, [] { __DBG_STUB_INVOKE__ return QDBusPendingCall::fromError(QDBusError()); });
139-
#endif
140-
EXPECT_NO_FATAL_FAILURE(smb_browser_utils::enableServiceAsync());
141115
}
142116

143117
TEST_F(UT_SmbBrowserUtils, CheckAndEnableService)
@@ -147,12 +121,9 @@ TEST_F(UT_SmbBrowserUtils, CheckAndEnableService)
147121
EXPECT_TRUE(smb_browser_utils::checkAndEnableService("smbd"));
148122

149123
serviceRunning = false;
150-
bool startServiceResult = true;
151-
stub.set_lamda(smb_browser_utils::startService, [&] { __DBG_STUB_INVOKE__ return startServiceResult; });
152-
stub.set_lamda(smb_browser_utils::enableServiceAsync, [] { __DBG_STUB_INVOKE__ });
124+
stub.set_lamda(smb_browser_utils::enableServiceNow, [] { return true; });
153125
EXPECT_TRUE(smb_browser_utils::checkAndEnableService("smb"));
154126

155-
startServiceResult = false;
156127
EXPECT_FALSE(smb_browser_utils::checkAndEnableService("sb"));
157128
}
158129

autotests/services/sharecontrol/test_sharecontrol.cpp

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ class UT_ShareControlDBus : public testing::Test
3434
{
3535
// Reset read call counter for each test
3636
readCallCount = 0;
37-
37+
3838
// Mock QDBusContext::message to prevent crashes
39-
stub.set_lamda(&QDBusContext::message, [](const QDBusContext *) -> const QDBusMessage& {
39+
stub.set_lamda(&QDBusContext::message, [](const QDBusContext *) -> const QDBusMessage & {
4040
__DBG_STUB_INVOKE__
4141
// Create a static message to ensure it has valid service data
4242
static QDBusMessage msg = QDBusMessage::createMethodCall("org.test.service", "/test", "org.test.Interface", "testMethod");
4343
return msg;
4444
});
45-
45+
4646
shareControlDBus = new ShareControlDBus("test_sharecontrol");
4747
}
48-
48+
4949
virtual void TearDown() override
5050
{
5151
stub.clear();
@@ -56,7 +56,7 @@ class UT_ShareControlDBus : public testing::Test
5656
protected:
5757
ShareControlDBus *shareControlDBus = nullptr;
5858
stub_ext::StubExt stub;
59-
int readCallCount = 0; // Track read system call count
59+
int readCallCount = 0; // Track read system call count
6060
};
6161

6262
class UT_PolicyKitHelper : public testing::Test
@@ -278,13 +278,13 @@ TEST_F(UT_ShareControlDBus, SetUserSharePassword_Success_ReturnsTrue)
278278
stub.set_lamda(read, [this](int, void *buf, size_t count) -> ssize_t {
279279
__DBG_STUB_INVOKE__
280280
this->readCallCount++;
281-
281+
282282
if (this->readCallCount == 1) {
283283
// First call: return serialized credentials data
284284
QByteArray data;
285285
QDataStream stream(&data, QIODevice::WriteOnly);
286286
stream << QString("testuser") << QString("testpassword");
287-
287+
288288
// Copy data to buffer (ensure we don't exceed buffer size)
289289
size_t dataSize = std::min(static_cast<size_t>(data.size()), count);
290290
memcpy(buf, data.constData(), dataSize);
@@ -332,44 +332,6 @@ TEST_F(UT_ShareControlDBus, SetUserSharePassword_Success_ReturnsTrue)
332332
EXPECT_TRUE(result);
333333
}
334334

335-
// Test EnableSmbServices with authentication failure
336-
TEST_F(UT_ShareControlDBus, EnableSmbServices_AuthenticationFailed_ReturnsFalse)
337-
{
338-
// Mock authentication failure
339-
stub.set_lamda(&PolicyKitHelper::checkAuthorization, [](PolicyKitHelper *, const QString &, const QString &) {
340-
__DBG_STUB_INVOKE__
341-
return false;
342-
});
343-
344-
bool result = shareControlDBus->EnableSmbServices();
345-
EXPECT_FALSE(result);
346-
}
347-
348-
// Test EnableSmbServices successful execution
349-
TEST_F(UT_ShareControlDBus, EnableSmbServices_Success_ReturnsTrue)
350-
{
351-
// Mock successful authentication
352-
stub.set_lamda(&PolicyKitHelper::checkAuthorization, [](PolicyKitHelper *, const QString &, const QString &) {
353-
__DBG_STUB_INVOKE__
354-
return true;
355-
});
356-
357-
// Mock QProcess success for both services - use function pointer to specify overload
358-
using ProcessStartFunc = void (QProcess::*)(const QString &, const QStringList &, QIODevice::OpenMode);
359-
stub.set_lamda(static_cast<ProcessStartFunc>(&QProcess::start), [](QProcess *, const QString &, const QStringList &, QIODevice::OpenMode) {
360-
__DBG_STUB_INVOKE__
361-
});
362-
363-
using ProcessWaitFunc = bool (QProcess::*)(int);
364-
stub.set_lamda(static_cast<ProcessWaitFunc>(&QProcess::waitForFinished), [](QProcess *, int) {
365-
__DBG_STUB_INVOKE__
366-
return true;
367-
});
368-
369-
bool result = shareControlDBus->EnableSmbServices();
370-
EXPECT_TRUE(result);
371-
}
372-
373335
// Test IsUserSharePasswordSet with process failure
374336
TEST_F(UT_ShareControlDBus, IsUserSharePasswordSet_ProcessFailed_ReturnsFalse)
375337
{

0 commit comments

Comments
 (0)