1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include <gtest/gtest.h> 17f6603c60Sopenharmony_ci#include <stdlib.h> 18f6603c60Sopenharmony_ci#include "ActsLibuvTest.h" 19f6603c60Sopenharmony_ciextern "C"{ 20f6603c60Sopenharmony_ci#include "runner.h" 21f6603c60Sopenharmony_ci} 22f6603c60Sopenharmony_ci#include "uv.h" 23f6603c60Sopenharmony_ci 24f6603c60Sopenharmony_citypedef void (*init_plugin_function)(); 25f6603c60Sopenharmony_ci 26f6603c60Sopenharmony_cinamespace OHOS { 27f6603c60Sopenharmony_ci using namespace std; 28f6603c60Sopenharmony_ci using namespace testing::ext; 29f6603c60Sopenharmony_ci static const char TESTFILE[] = "foo.gz"; 30f6603c60Sopenharmony_ci 31f6603c60Sopenharmony_ci static uv_once_t once_only = UV_ONCE_INIT; 32f6603c60Sopenharmony_ci 33f6603c60Sopenharmony_ci int i = 0; 34f6603c60Sopenharmony_ci 35f6603c60Sopenharmony_ci void Increment() 36f6603c60Sopenharmony_ci { 37f6603c60Sopenharmony_ci i++; 38f6603c60Sopenharmony_ci } 39f6603c60Sopenharmony_ci // Preset action of the test suite, which is executed before the first test case 40f6603c60Sopenharmony_ci void ActsLibuvTest::SetUpTestCase(void) 41f6603c60Sopenharmony_ci { 42f6603c60Sopenharmony_ci } 43f6603c60Sopenharmony_ci // Test suite cleanup action, which is executed after the last test case 44f6603c60Sopenharmony_ci void ActsLibuvTest::TearDownTestCase(void) 45f6603c60Sopenharmony_ci { 46f6603c60Sopenharmony_ci } 47f6603c60Sopenharmony_ci // Preset action of the test case 48f6603c60Sopenharmony_ci void ActsLibuvTest::SetUp() 49f6603c60Sopenharmony_ci { 50f6603c60Sopenharmony_ci } 51f6603c60Sopenharmony_ci // Cleanup action of the test case 52f6603c60Sopenharmony_ci void ActsLibuvTest::TearDown() 53f6603c60Sopenharmony_ci { 54f6603c60Sopenharmony_ci } 55f6603c60Sopenharmony_ci 56f6603c60Sopenharmony_ci/** 57f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0100 58f6603c60Sopenharmony_ci * @tc.name : Test uv_version and uv_version_string test 59f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 60f6603c60Sopenharmony_ci*/ 61f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestUVVersion, Function | MediumTest | Level2) 62f6603c60Sopenharmony_ci{ 63f6603c60Sopenharmony_ci int version = uv_version(); 64f6603c60Sopenharmony_ci ASSERT_EQ(version, UV_VERSION_HEX); 65f6603c60Sopenharmony_ci fprintf(stderr, "uv_version error: %d\n", version); 66f6603c60Sopenharmony_ci 67f6603c60Sopenharmony_ci auto versionString = uv_version_string(); 68f6603c60Sopenharmony_ci fprintf(stderr, "uv_version_string error: %s\n", versionString); 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ci int replaceAllocator = uv_replace_allocator(nullptr, nullptr, nullptr, nullptr); 71f6603c60Sopenharmony_ci ASSERT_EQ(replaceAllocator, UV_EINVAL); 72f6603c60Sopenharmony_ci fprintf(stderr, "uv_replace_allocator error: %d\n", replaceAllocator); 73f6603c60Sopenharmony_ci 74f6603c60Sopenharmony_ci uv_loop_t* loop = uv_loop_new(); 75f6603c60Sopenharmony_ci ASSERT_TRUE(loop != nullptr); 76f6603c60Sopenharmony_ci} 77f6603c60Sopenharmony_ci 78f6603c60Sopenharmony_ci/** 79f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0200 80f6603c60Sopenharmony_ci * @tc.name : Test uv_loop_new 81f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 82f6603c60Sopenharmony_ci*/ 83f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestLoop, Function | MediumTest | Level2) 84f6603c60Sopenharmony_ci{ 85f6603c60Sopenharmony_ci uv_loop_t* newLoop; 86f6603c60Sopenharmony_ci newLoop = uv_loop_new(); 87f6603c60Sopenharmony_ci ASSERT_TRUE(newLoop != NULL); 88f6603c60Sopenharmony_ci uv_loop_delete(newLoop); 89f6603c60Sopenharmony_ci ASSERT_TRUE(true); 90f6603c60Sopenharmony_ci} 91f6603c60Sopenharmony_ci 92f6603c60Sopenharmony_ci/** 93f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0300 94f6603c60Sopenharmony_ci * @tc.name : Test uv_err_name_r 95f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 96f6603c60Sopenharmony_ci*/ 97f6603c60Sopenharmony_ci 98f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestErrName, Function | MediumTest | Level2) 99f6603c60Sopenharmony_ci{ 100f6603c60Sopenharmony_ci int err = 0; 101f6603c60Sopenharmony_ci char buf[40]; 102f6603c60Sopenharmony_ci size_t buflen = 40; 103f6603c60Sopenharmony_ci char* newBuf = uv_err_name_r(err, buf, buflen); 104f6603c60Sopenharmony_ci fprintf(stderr, "uv_err_name_r error: %s\n", newBuf); 105f6603c60Sopenharmony_ci ASSERT_STREQ(newBuf, "Unknown system error 0"); 106f6603c60Sopenharmony_ci} 107f6603c60Sopenharmony_ci 108f6603c60Sopenharmony_ci/** 109f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0400 110f6603c60Sopenharmony_ci * @tc.name : Test uv_req_get_data and uv_req_set_data and uv_req_get_type 111f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 112f6603c60Sopenharmony_ci*/ 113f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestReqGetData, Function | MediumTest | Level2) 114f6603c60Sopenharmony_ci{ 115f6603c60Sopenharmony_ci float f = 5.5f; 116f6603c60Sopenharmony_ci float* pf = &f; 117f6603c60Sopenharmony_ci uv_req_t* req = (uv_req_t *)malloc(sizeof(uv_req_t)); 118f6603c60Sopenharmony_ci uv_req_t* setReq = (uv_req_t *)malloc(sizeof(uv_req_t)); 119f6603c60Sopenharmony_ci req->data = pf; 120f6603c60Sopenharmony_ci req->type = UV_UNKNOWN_REQ; 121f6603c60Sopenharmony_ci fprintf(stderr, "uv_req_get_data: %f\n", *(float*)uv_req_get_data(req)); 122f6603c60Sopenharmony_ci fprintf(stderr, "uv_req_get_type: %d\n", uv_req_get_type(req)); 123f6603c60Sopenharmony_ci ASSERT_EQ(uv_req_get_data(req), pf); 124f6603c60Sopenharmony_ci ASSERT_EQ(uv_req_get_type(req), UV_UNKNOWN_REQ); 125f6603c60Sopenharmony_ci 126f6603c60Sopenharmony_ci uv_req_set_data(setReq, pf); 127f6603c60Sopenharmony_ci ASSERT_EQ(uv_req_get_data(setReq), pf); 128f6603c60Sopenharmony_ci} 129f6603c60Sopenharmony_ci 130f6603c60Sopenharmony_ci/** 131f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0500 132f6603c60Sopenharmony_ci * @tc.name : Test uv_print_all_handles and uv_print_active_handles 133f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 134f6603c60Sopenharmony_ci*/ 135f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestPrintHandles, Function | MediumTest | Level2) 136f6603c60Sopenharmony_ci{ 137f6603c60Sopenharmony_ci uv_loop_t* loop = nullptr; 138f6603c60Sopenharmony_ci FILE *fp = fopen(TESTFILE, "w"); 139f6603c60Sopenharmony_ci uv_print_all_handles(loop, fp); 140f6603c60Sopenharmony_ci uv_print_active_handles(loop, fp); 141f6603c60Sopenharmony_ci ASSERT_TRUE(true); 142f6603c60Sopenharmony_ci} 143f6603c60Sopenharmony_ci 144f6603c60Sopenharmony_ci/** 145f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0600 146f6603c60Sopenharmony_ci * @tc.name : Test uv_udp_get_send_queue_size and uv_udp_get_send_queue_count 147f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 148f6603c60Sopenharmony_ci*/ 149f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestUpdSendQueue, Function | MediumTest | Level2) 150f6603c60Sopenharmony_ci{ 151f6603c60Sopenharmony_ci size_t size, sizeC; 152f6603c60Sopenharmony_ci uv_udp_t* handle = (uv_udp_t *)malloc(sizeof(uv_udp_t)); 153f6603c60Sopenharmony_ci handle->send_queue_size = 5; 154f6603c60Sopenharmony_ci handle->send_queue_count = 5; 155f6603c60Sopenharmony_ci size = uv_udp_get_send_queue_size(handle); 156f6603c60Sopenharmony_ci ASSERT_TRUE(size == 5); 157f6603c60Sopenharmony_ci 158f6603c60Sopenharmony_ci sizeC = uv_udp_get_send_queue_count(handle); 159f6603c60Sopenharmony_ci ASSERT_TRUE(sizeC == 5); 160f6603c60Sopenharmony_ci} 161f6603c60Sopenharmony_ci 162f6603c60Sopenharmony_ci/** 163f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0700 164f6603c60Sopenharmony_ci * @tc.name : Test uv_fs_lchown 165f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 166f6603c60Sopenharmony_ci*/ 167f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestFsLchown, Function | MediumTest | Level2) 168f6603c60Sopenharmony_ci{ 169f6603c60Sopenharmony_ci int retC; 170f6603c60Sopenharmony_ci uv_loop_t loop; 171f6603c60Sopenharmony_ci uv_fs_t req; 172f6603c60Sopenharmony_ci const char *path = "/date/"; 173f6603c60Sopenharmony_ci uv_uid_t uid = 10000; 174f6603c60Sopenharmony_ci uv_gid_t gid = 2020; 175f6603c60Sopenharmony_ci retC = uv_fs_lchown(&loop, &req, path, uid, gid, nullptr); 176f6603c60Sopenharmony_ci fprintf(stderr, "uv_err_name_r error: %d\n", retC); 177f6603c60Sopenharmony_ci} 178f6603c60Sopenharmony_ci 179f6603c60Sopenharmony_ci/** 180f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0800 181f6603c60Sopenharmony_ci * @tc.name : Test uv_disable_stdio_inheritance 182f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 183f6603c60Sopenharmony_ci*/ 184f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestDisableStdioInheritance, Function | MediumTest | Level2) 185f6603c60Sopenharmony_ci{ 186f6603c60Sopenharmony_ci uv_disable_stdio_inheritance(); 187f6603c60Sopenharmony_ci ASSERT_TRUE(true); 188f6603c60Sopenharmony_ci} 189f6603c60Sopenharmony_ci 190f6603c60Sopenharmony_ci/** 191f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_0900 192f6603c60Sopenharmony_ci * @tc.name : Test uv_dlsym 193f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 194f6603c60Sopenharmony_ci */ 195f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestDlsym, Function | MediumTest | Level2) { 196f6603c60Sopenharmony_ci int argc = 3; 197f6603c60Sopenharmony_ci const char *tmp[] = {"aaaa", "bbbb", "cccc"}; 198f6603c60Sopenharmony_ci const char **argv = tmp; 199f6603c60Sopenharmony_ci uv_lib_t *lib = (uv_lib_t *)malloc(sizeof(uv_lib_t)); 200f6603c60Sopenharmony_ci while (--argc) { 201f6603c60Sopenharmony_ci uv_dlopen(argv[argc], lib); 202f6603c60Sopenharmony_ci ASSERT_TRUE(true); 203f6603c60Sopenharmony_ci 204f6603c60Sopenharmony_ci init_plugin_function init_plugin; 205f6603c60Sopenharmony_ci uv_dlsym(lib, "initialize", (void **)&init_plugin); 206f6603c60Sopenharmony_ci ASSERT_TRUE(true); 207f6603c60Sopenharmony_ci } 208f6603c60Sopenharmony_ci} 209f6603c60Sopenharmony_ci 210f6603c60Sopenharmony_ci/** 211f6603c60Sopenharmony_ci * @tc.number : ActsZlibTest_1000 212f6603c60Sopenharmony_ci * @tc.name : Test uv_once 213f6603c60Sopenharmony_ci * @tc.desc : [C- SOFTWARE -0200] 214f6603c60Sopenharmony_ci*/ 215f6603c60Sopenharmony_ciHWTEST_F(ActsLibuvTest, TestLibuvTestUvOnce, Function | MediumTest | Level2) 216f6603c60Sopenharmony_ci{ 217f6603c60Sopenharmony_ci uv_once(&once_only, Increment); 218f6603c60Sopenharmony_ci ASSERT_TRUE(true); 219f6603c60Sopenharmony_ci} 220f6603c60Sopenharmony_ci} 221