1 /**
2 * Copyright (c) 2025 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 "ani.h"
18 #include "ani_option_logger_callback.h"
19
20 namespace ark::ets::ani::testing {
21
TEST(AniOptionLoggerTest,logger_parser_success)22 TEST(AniOptionLoggerTest, logger_parser_success)
23 {
24 ASSERT_EQ(g_msgs.size(), 0);
25
26 const char *stdlib = std::getenv("ARK_ETS_STDLIB_PATH");
27 ASSERT_NE(stdlib, nullptr);
28 std::string bootFileString = "--ext:boot-panda-files=" + std::string(stdlib);
29
30 std::array optionsArray {
31 ani_option {"--ext:log-level=info", nullptr},
32 ani_option {"--ext:log-components=ani", nullptr},
33 ani_option {bootFileString.c_str(), nullptr},
34 ani_option {"--logger", reinterpret_cast<void *>(LoggerCallback)},
35 };
36
37 ani_options options = {optionsArray.size(), optionsArray.data()};
38 ani_vm *vm;
39 ASSERT_EQ(ANI_CreateVM(&options, ANI_VERSION_1, &vm), ANI_OK);
40
41 ASSERT_EQ(g_msgs.size(), 1);
42 ASSERT_EQ(g_msgs[0].level, ANI_LOGLEVEL_INFO);
43 ASSERT_STREQ(g_msgs[0].component.c_str(), "ani");
44 ASSERT_STREQ(g_msgs[0].message.c_str(), "ani_vm has been created"); // The log message from ani_vm_api.cpp
45
46 ASSERT_EQ(vm->DestroyVM(), ANI_OK);
47 }
48
49 } // namespace ark::ets::ani::testing
50