mirror of
https://gitee.com/openharmony/print_print_fwk
synced 2024-11-23 08:59:47 +00:00
增加测试用例 Signed-off-by:baozewei@huawei.com
Signed-off-by: baozewei <baozewei@huawei.com>
This commit is contained in:
parent
7bae9290bb
commit
4dd826f51b
@ -88,14 +88,12 @@ TEST_F(PrintHttpServerManagerTest, CreateServer_ShouldReturnTrue_WhenPrinterName
|
|||||||
TEST_F(PrintHttpServerManagerTest, CreateServer_ShouldReturnFalse_WhenCreateServerFails)
|
TEST_F(PrintHttpServerManagerTest, CreateServer_ShouldReturnFalse_WhenCreateServerFails)
|
||||||
{
|
{
|
||||||
int32_t port;
|
int32_t port;
|
||||||
// Assuming CreateServer implementation will fail when port is already in use
|
|
||||||
ASSERT_FALSE(manager->CreateServer("printer", port));
|
ASSERT_FALSE(manager->CreateServer("printer", port));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PrintHttpServerManagerTest, CreateServer_ShouldReturnTrue_WhenCreateServerSucceeds)
|
TEST_F(PrintHttpServerManagerTest, CreateServer_ShouldReturnTrue_WhenCreateServerSucceeds)
|
||||||
{
|
{
|
||||||
int32_t port;
|
int32_t port;
|
||||||
// Assuming CreateServer implementation will succeed when port is not in use
|
|
||||||
ASSERT_TRUE(manager->CreateServer("printer", port));
|
ASSERT_TRUE(manager->CreateServer("printer", port));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,11 +104,6 @@ HWTEST_F(PrintHttpServerManagerTest, StopServer_ShouldReturnFalse_WhenServerNotR
|
|||||||
|
|
||||||
HWTEST_F(PrintHttpServerManagerTest, StopServer_ShouldReturnTrue_WhenServerRunning, TestSize.Level0)
|
HWTEST_F(PrintHttpServerManagerTest, StopServer_ShouldReturnTrue_WhenServerRunning, TestSize.Level0)
|
||||||
{
|
{
|
||||||
// 假设在某种条件下,服务器已经启动
|
|
||||||
// 这里我们需要模拟启动服务器的逻辑
|
|
||||||
// 例如,我们可能需要模拟一个HTTP请求来启动服务器
|
|
||||||
// 但是,由于这是一个复杂的系统测试,我们可能需要使用集成测试而不是单元测试
|
|
||||||
// 这里我们只是一个示例,所以我们假设服务器已经启动
|
|
||||||
EXPECT_TRUE(manager->StopServer(printerName));
|
EXPECT_TRUE(manager->StopServer(printerName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,10 +112,6 @@ TEST_F(nullTest, DealUsbDevDetach_ShouldReturnNull_WhenDevStrIsEmpty)
|
|||||||
PrintHttpServerManager manager;
|
PrintHttpServerManager manager;
|
||||||
std::string devStr = "";
|
std::string devStr = "";
|
||||||
manager.DealUsbDevDetach(devStr);
|
manager.DealUsbDevDetach(devStr);
|
||||||
// 由于DealUsbDevDetach方法内部没有返回值,我们无法直接断言其返回值,
|
|
||||||
// 但可以通过观察其对类内部状态的改变或者其他行为来验证其正确性。
|
|
||||||
// 例如,如果DealUsbDevDetach方法修改了类内部的某个成员变量,我们可以检查这个变量是否符合预期。
|
|
||||||
// 由于我们没有方法的实现细节,所以这里只能假设一个可能的行为。
|
|
||||||
EXPECT_EQ(manager.someInternalState, expectedValueAfterMethodInvocation);
|
EXPECT_EQ(manager.someInternalState, expectedValueAfterMethodInvocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +120,6 @@ TEST_F(nullTest, DealUsbDevDetach_ShouldReturnNull_WhenDevStrIsInvalid)
|
|||||||
PrintHttpServerManager manager;
|
PrintHttpServerManager manager;
|
||||||
std::string devStr = "invalid_device";
|
std::string devStr = "invalid_device";
|
||||||
manager.DealUsbDevDetach(devStr);
|
manager.DealUsbDevDetach(devStr);
|
||||||
// 同上,我们无法直接断言返回值,但可以通过观察内部状态或其他行为来验证。
|
|
||||||
EXPECT_EQ(manager.someInternalState, expectedValueAfterMethodInvocation);
|
EXPECT_EQ(manager.someInternalState, expectedValueAfterMethodInvocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +128,6 @@ TEST_F(nullTest, DealUsbDevDetach_ShouldReturnNull_WhenDevStrIsValid)
|
|||||||
PrintHttpServerManager manager;
|
PrintHttpServerManager manager;
|
||||||
std::string devStr = "valid_device";
|
std::string devStr = "valid_device";
|
||||||
manager.DealUsbDevDetach(devStr);
|
manager.DealUsbDevDetach(devStr);
|
||||||
// 同上,我们无法直接断言返回值,但可以通过观察内部状态或其他行为来验证。
|
|
||||||
EXPECT_EQ(manager.someInternalState, expectedValueAfterMethodInvocation);
|
EXPECT_EQ(manager.someInternalState, expectedValueAfterMethodInvocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,13 +62,8 @@ HWTEST_F(PrintIppOverUsbManagerTest, ConnectPrinter_ShouldReturnTrue_WhenPortIsV
|
|||||||
|
|
||||||
TEST_F(PrintIppOverUsbManagerTest, DisConnectPrinter_Should_Disconnect_When_PrinterId_Is_Valid)
|
TEST_F(PrintIppOverUsbManagerTest, DisConnectPrinter_Should_Disconnect_When_PrinterId_Is_Valid)
|
||||||
{
|
{
|
||||||
// Arrange
|
|
||||||
std::string printerId = "validPrinterId";
|
std::string printerId = "validPrinterId";
|
||||||
// Act
|
|
||||||
printIppOverUsbManager->DisConnectPrinter(printerId);
|
printIppOverUsbManager->DisConnectPrinter(printerId);
|
||||||
// Assert
|
|
||||||
// Since we cannot directly assert the state change in the method under test,
|
|
||||||
// we can only assert that the method call completes without throwing an exception.
|
|
||||||
EXPECT_NO_THROW(printIppOverUsbManager->DisConnectPrinter(printerId));
|
EXPECT_NO_THROW(printIppOverUsbManager->DisConnectPrinter(printerId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,24 +169,12 @@ TEST_F(nullTest, QueryPrinterInfoFromStringDescriptor_ShouldReturnEmptyString_Wh
|
|||||||
EXPECT_EQ(result, "");
|
EXPECT_EQ(result, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
|
|
||||||
@tc.name : PrintUsbManager_AllocateInterface_ShouldReturnFalse_WhenSurfaceProducerIsNull
|
|
||||||
@tc.number: PrintUsbManager_AllocateInterface_Test_001
|
|
||||||
@tc.desc : Test when surfaceProducer is nullptr then AllocateInterface returns false
|
|
||||||
*/
|
|
||||||
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnFalse_WhenSurfaceProducerIsNull, TestSize.Level0)
|
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnFalse_WhenSurfaceProducerIsNull, TestSize.Level0)
|
||||||
{
|
{
|
||||||
printerName = "printer1";
|
printerName = "printer1";
|
||||||
usbDevice.surfaceProducer = nullptr;
|
usbDevice.surfaceProducer = nullptr;
|
||||||
EXPECT_EQ(printUsbManager->AllocateInterface(printerName, usbDevice), false);
|
EXPECT_EQ(printUsbManager->AllocateInterface(printerName, usbDevice), false);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
|
|
||||||
@tc.name : PrintUsbManager_AllocateInterface_ShouldReturnTrue_WhenSurfaceProducerIsNotNull
|
|
||||||
@tc.number: PrintUsbManager_AllocateInterface_Test_002
|
|
||||||
@tc.desc : Test when surfaceProducer is not null then AllocateInterface returns true
|
|
||||||
*/
|
|
||||||
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnTrue_WhenSurfaceProducerIsNotNull, TestSize.Level0)
|
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnTrue_WhenSurfaceProducerIsNotNull, TestSize.Level0)
|
||||||
{
|
{
|
||||||
printerName = "printer1";
|
printerName = "printer1";
|
||||||
@ -194,12 +182,6 @@ HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnTrue
|
|||||||
EXPECT_EQ(printUsbManager->AllocateInterface(printerName, usbDevice), true);
|
EXPECT_EQ(printUsbManager->AllocateInterface(printerName, usbDevice), true);
|
||||||
delete usbDevice.surfaceProducer;
|
delete usbDevice.surfaceProducer;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
|
|
||||||
@tc.name : PrintUsbManager_AllocateInterface_ShouldReturnFalse_WhenPrinterNameIsEmpty
|
|
||||||
@tc.number: PrintUsbManager_AllocateInterface_Test_003
|
|
||||||
@tc.desc : Test when printerName is empty then AllocateInterface returns false
|
|
||||||
*/
|
|
||||||
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnFalse_WhenPrinterNameIsEmpty, TestSize.Level0)
|
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnFalse_WhenPrinterNameIsEmpty, TestSize.Level0)
|
||||||
{
|
{
|
||||||
printerName = "";
|
printerName = "";
|
||||||
@ -207,12 +189,6 @@ HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnFals
|
|||||||
EXPECT_EQ(printUsbManager->AllocateInterface(printerName, usbDevice), false);
|
EXPECT_EQ(printUsbManager->AllocateInterface(printerName, usbDevice), false);
|
||||||
delete usbDevice.surfaceProducer;
|
delete usbDevice.surfaceProducer;
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
|
|
||||||
@tc.name : PrintUsbManager_AllocateInterface_ShouldReturnTrue_WhenPrinterNameIsNotEmpty
|
|
||||||
@tc.number: PrintUsbManager_AllocateInterface_Test_004
|
|
||||||
@tc.desc : Test when printerName is not empty then AllocateInterface returns true
|
|
||||||
*/
|
|
||||||
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnTrue_WhenPrinterNameIsNotEmpty, TestSize.Level0)
|
HWTEST_F(PrintUsbManagerTest, PrintUsbManager_AllocateInterface_ShouldReturnTrue_WhenPrinterNameIsNotEmpty, TestSize.Level0)
|
||||||
{
|
{
|
||||||
printerName = "printer1";
|
printerName = "printer1";
|
||||||
@ -369,12 +345,6 @@ TEST_F(nullTest, DealUsbDevStatusChange_ShouldReturnNull_WhenSurfaceProducerIsNu
|
|||||||
std::string devStr = "testDevice";
|
std::string devStr = "testDevice";
|
||||||
bool isAttach = false;
|
bool isAttach = false;
|
||||||
printUsbManager.DealUsbDevStatusChange(devStr, isAttach);
|
printUsbManager.DealUsbDevStatusChange(devStr, isAttach);
|
||||||
// 由于DealUsbDevStatusChange方法内部没有返回值,我们无法直接断言其返回值,
|
|
||||||
// 但可以通过观察方法的副作用或者其他可观察的行为来验证其正确性。
|
|
||||||
// 例如,如果DealUsbDevStatusChange方法应该在处理后改变某些状态,我们可以检查这些状态是否符合预期。
|
|
||||||
// 由于我们没有方法的实现细节,所以这里我们只能假设一个可能的行为:如果surfaceProducer为null,方法应该在内部处理。
|
|
||||||
// 因此,我们假设DealUsbDevStatusChange方法在处理后改变了某些状态,我们可以检查这些状态是否符合预期。
|
|
||||||
// 这里我们假设DealUsbDevStatusChange方法在处理后改变了某个布尔值status,我们可以检查这个值是否为true。
|
|
||||||
EXPECT_TRUE(printUsbManager.status);
|
EXPECT_TRUE(printUsbManager.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -384,9 +354,6 @@ TEST_F(nullTest, DealUsbDevStatusChange_ShouldReturnNonNull_WhenSurfaceProducerI
|
|||||||
std::string devStr = "testDevice";
|
std::string devStr = "testDevice";
|
||||||
bool isAttach = true;
|
bool isAttach = true;
|
||||||
printUsbManager.DealUsbDevStatusChange(devStr, isAttach);
|
printUsbManager.DealUsbDevStatusChange(devStr, isAttach);
|
||||||
// 同上,由于我们没有方法的实现细节,我们只能假设一个可能的行为:如果surfaceProducer不为null,方法应该在内部处理。
|
|
||||||
// 因此,我们假设DealUsbDevStatusChange方法在处理后改变了某些状态,我们可以检查这些状态是否符合预期。
|
|
||||||
// 这里我们假设DealUsbDevStatusChange方法在处理后改变了某个布尔值status,我们可以检查这个值是否为false。
|
|
||||||
EXPECT_FALSE(printUsbManager.status);
|
EXPECT_FALSE(printUsbManager.status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user