From 527af5122c22709774de454aeb44f91a7e85a6d8 Mon Sep 17 00:00:00 2001 From: zhanzeyi Date: Wed, 11 Sep 2024 14:48:59 +0800 Subject: [PATCH] update test case Signed-off-by: zhanzeyi --- .../unittest/byteBuffer/byte_buffer_test.cpp | 4 ++++ .../unittest/hapSign/sign_provider_test.cpp | 4 ++-- hapsigntool_cpp_test/unittest/utils/file_utils_test.cpp | 9 +++++---- hapsigntool_cpp_test/unittest/zip/zip_signer_test.cpp | 3 +++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hapsigntool_cpp_test/unittest/byteBuffer/byte_buffer_test.cpp b/hapsigntool_cpp_test/unittest/byteBuffer/byte_buffer_test.cpp index af2bf2c4..dc4471a8 100644 --- a/hapsigntool_cpp_test/unittest/byteBuffer/byte_buffer_test.cpp +++ b/hapsigntool_cpp_test/unittest/byteBuffer/byte_buffer_test.cpp @@ -156,6 +156,7 @@ HWTEST_F(ByteBufferTest, PutGetDataTest001, testing::ext::TestSize.Level1) empty.PutData("a", 2); empty.PutData(data, 1); empty.ClearData(); + EXPECT_EQ(empty.GetCapacity(), 0); } /** @@ -199,6 +200,7 @@ HWTEST_F(ByteBufferTest, GetIntAndPutOperation001, testing::ext::TestSize.Level1 */ ByteBuffer testBuffer2(TEST_HAPBYTEBUFFER_LENGTH); testBuffer2.PutByte(0, testChar); + ASSERT_TRUE(testBuffer2.GetUInt32(1, dataUInt32)); /* * @tc.steps: step5. Put data to buffer with type and get data from it. * @tc.expected: step5. The return data is same as which we put. @@ -206,9 +208,11 @@ HWTEST_F(ByteBufferTest, GetIntAndPutOperation001, testing::ext::TestSize.Level1 ByteBuffer testBuffer3(TEST_HAPBYTEBUFFER_LENGTH); testBuffer3.PutData(0, &testChar, sizeof(testChar), 1); testBuffer3.PutData(1, nullptr, 0, 1); + ASSERT_TRUE(testBuffer3.GetInt64(1, dataInt64)); ByteBuffer testBuffer4; testBuffer4.PutData(-1, &testChar, sizeof(testChar), 1); + ASSERT_FALSE(testBuffer4.GetUInt16(1, dataUInt16)); } /** diff --git a/hapsigntool_cpp_test/unittest/hapSign/sign_provider_test.cpp b/hapsigntool_cpp_test/unittest/hapSign/sign_provider_test.cpp index b149b22b..cf6ba5f3 100644 --- a/hapsigntool_cpp_test/unittest/hapSign/sign_provider_test.cpp +++ b/hapsigntool_cpp_test/unittest/hapSign/sign_provider_test.cpp @@ -963,7 +963,7 @@ HWTEST_F(SignProviderTest, SignElf_001, testing::ext::TestSize.Level1) (*params)["keystorePwd"] = keystorePwd; bool ret = signProvider->SignElf(params.get()); - EXPECT_NE(ret, -1); + EXPECT_EQ(ret, true); } /* @@ -1002,7 +1002,7 @@ HWTEST_F(SignProviderTest, SignElf_002, testing::ext::TestSize.Level1) (*params)["keyPwd"] = keyPwd; (*params)["keystorePwd"] = keystorePwd; bool ret = signProvider->SignElf(params.get()); - EXPECT_NE(ret, -1); + EXPECT_NE(ret, false); } /* diff --git a/hapsigntool_cpp_test/unittest/utils/file_utils_test.cpp b/hapsigntool_cpp_test/unittest/utils/file_utils_test.cpp index 739fedd8..b77c82dc 100644 --- a/hapsigntool_cpp_test/unittest/utils/file_utils_test.cpp +++ b/hapsigntool_cpp_test/unittest/utils/file_utils_test.cpp @@ -614,18 +614,19 @@ HWTEST_F(FileUtilsTest, WriteInputToOutPutMultithreadingTest, testing::ext::Test { CreateTestFile(); - std::vector threads; + std::vector> futures; for (int i = 1; i <= THREAD_NUMS; ++i) { std::string inputFile = "tmp/tmp-" + std::to_string(i) + ".txt"; std::string outputFile = "tmp/tmp-" + std::to_string(i) + "-copy.txt"; auto length = std::filesystem::file_size(inputFile); - threads.emplace_back(Worker, inputFile, outputFile, length); + futures.emplace_back(std::async(std::launch::async, Worker, inputFile, outputFile, length)); } - for (auto& thread : threads) { - thread.join(); + for (auto& f : futures) { + int ret = f.get(); + EXPECT_EQ(ret, 0); } printf("All threads completed.\n"); diff --git a/hapsigntool_cpp_test/unittest/zip/zip_signer_test.cpp b/hapsigntool_cpp_test/unittest/zip/zip_signer_test.cpp index 7866fb3b..36b3eee5 100644 --- a/hapsigntool_cpp_test/unittest/zip/zip_signer_test.cpp +++ b/hapsigntool_cpp_test/unittest/zip/zip_signer_test.cpp @@ -830,8 +830,11 @@ HWTEST_F(ZipSignerTest, ZipSignerTest001, testing::ext::TestSize.Level1) signingBlock = zip.GetSigningBlock(); EXPECT_NE(signingBlock.size(), 0); zip.SetCDOffset(1); + EXPECT_EQ(zip.GetCDOffset(), 1); zip.SetEOCDOffset(1); + EXPECT_EQ(zip.GetEOCDOffset(), 1); zip.SetEndOfCentralDirectory(nullptr); + EXPECT_EQ(zip.GetEndOfCentralDirectory(), nullptr); } } // namespace SignatureTools } // namespace OHOS \ No newline at end of file -- Gitee