1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 
18 #include "cj_utils_ffi.h"
19 
20 #include "securec.h"
21 #include <cstdlib>
22 
23 using namespace testing;
24 using namespace testing::ext;
25 
26 class CjUtilsFfiTest : public testing::Test {
27 public:
CjUtilsFfiTest()28     CjUtilsFfiTest()
29     {}
~CjUtilsFfiTest()30     ~CjUtilsFfiTest()
31     {}
32     static void SetUpTestCase();
33     static void TearDownTestCase();
34     void SetUp() override;
35     void TearDown() override;
36 };
37 
SetUpTestCase()38 void CjUtilsFfiTest::SetUpTestCase()
39 {}
40 
TearDownTestCase()41 void CjUtilsFfiTest::TearDownTestCase()
42 {}
43 
SetUp()44 void CjUtilsFfiTest::SetUp()
45 {}
46 
TearDown()47 void CjUtilsFfiTest::TearDown()
48 {}
49 
50 /**
51  * @tc.name: CjElementNameFfiTestContext_0100
52  * @tc.desc: CjUtilsFfiTest test for CreateCStringFromString.
53  * @tc.type: FUNC
54  */
55 HWTEST_F(CjUtilsFfiTest, CjUtilsFfiTestCreateCStringFromString_0100, TestSize.Level1)
56 {
57     // 测试用例1:空字符串
58     std::string emptyStr = "";
59     const char* result1 = CreateCStringFromString(emptyStr);
60     EXPECT_TRUE(result1 == nullptr);
61 
62     // 测试用例2:正常字符串
63     std::string normalStr = "Hello, world!";
64     const char* result2 = CreateCStringFromString(normalStr);
65     EXPECT_TRUE(result2 != nullptr);
66 
67     // 测试用例3:包含特殊字符的字符串
68     std::string specialStr = "Hello, \0world!";
69     const char* result3 = CreateCStringFromString(specialStr);
70     EXPECT_TRUE(result3 != nullptr);
71 }