1 /*
2 * Copyright (C) 2022 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 #include "napi_remote_object.h"
18 #include <unistd.h>
19 #include <securec.h>
20
21 using namespace testing::ext;
22
23 class IPCNapiTest : public testing::Test {
24 public:
25 static void SetUpTestCase(void);
26 static void TearDownTestCase(void);
27 void SetUp();
28 void TearDown();
29 };
30
SetUpTestCase(void)31 void IPCNapiTest::SetUpTestCase(void)
32 {
33 // input testsuit setup step,setup invoked before all testcases
34 }
35
TearDownTestCase(void)36 void IPCNapiTest::TearDownTestCase(void)
37 {
38 // input testsuit teardown step,teardown invoked after all testcases
39 }
40
SetUp(void)41 void IPCNapiTest::SetUp(void)
42 {
43 // input testcase setup step,setup invoked before each testcases
44 }
45
TearDown(void)46 void IPCNapiTest::TearDown(void)
47 {
48 // input testcase teardown step,teardown invoked after each testcases
49 }
50
51 /**
52 * @tc.name: ipc_napi_001
53 * @tc.desc: Verify the sub function.
54 * @tc.type: FUNC
55 * @tc.require: issueNumber
56 */
57 HWTEST_F(IPCNapiTest, IPC_NAPI_TEST_001, TestSize.Level1)
58 {
59 napi_env env_ = nullptr;
60 OHOS::NAPI_CallingInfo oldCallingInfo;
61 OHOS::CallingInfo callingInfo;
62
63 (void)memset_s(&oldCallingInfo, sizeof(oldCallingInfo), 0, sizeof(oldCallingInfo));
64 (void)memset_s(&callingInfo, sizeof(callingInfo), 0, sizeof(callingInfo));
65 OHOS::NAPI_RemoteObject_getCallingInfo(callingInfo);
66 OHOS::NAPI_RemoteObject_saveOldCallingInfo(env_, oldCallingInfo);
67 OHOS::NAPI_RemoteObject_setNewCallingInfo(env_, callingInfo);
68 OHOS::NAPI_RemoteObject_resetOldCallingInfo(env_, oldCallingInfo);
69 EXPECT_EQ(callingInfo.callingPid, getpid());
70 EXPECT_EQ(callingInfo.callingUid, 0);
71 }