• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdlib>
17 #include <string>
18 #include "extension_c_api.h"
19 
20 using namespace std;
21 using namespace OHOS::uitest;
22 
23 static uintptr_t g_onInitImplAddr = 0;
24 static uintptr_t g_onRunImplAddr = 0;
25 
UiTestExtension_OnInit(UiTestPort port,size_t argc,char ** argv)26 extern "C" RetCode UiTestExtension_OnInit(UiTestPort port, size_t argc, char **argv)
27 {
28     constexpr int32_t INTERAL_ERROR_CODE = RETCODE_FAIL - 1;
29     auto envOnInitImplAddr = getenv("OnInitImplAddr");
30     auto envOnRunImplAddr = getenv("OnRunImplAddr");
31     if (envOnInitImplAddr == nullptr || envOnRunImplAddr == nullptr) {
32         return INTERAL_ERROR_CODE;
33     }
34     g_onInitImplAddr = std::stoul(envOnInitImplAddr);
35     g_onRunImplAddr = std::stoul(envOnRunImplAddr);
36     if (g_onInitImplAddr <= 0 || g_onRunImplAddr <= 0) {
37         return INTERAL_ERROR_CODE;
38     }
39     auto impl = reinterpret_cast<UiTestExtensionOnInitCallback>(g_onInitImplAddr);
40     return impl(port, argc, argv);
41 }
42 
UiTestExtension_OnRun()43 extern "C" RetCode UiTestExtension_OnRun()
44 {
45     auto impl = reinterpret_cast<UiTestExtensionOnRunCallback>(g_onRunImplAddr);
46     return impl();
47 }