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 "cj_context.h" 18 #include "context.h" 19 #include "context_impl.h" 20 #include "cj_utils_ffi.h" 21 #include "cj_macro.h" 22 #include "cj_application_context.h" 23 24 using namespace OHOS::FFI; 25 using namespace OHOS::AbilityRuntime; 26 27 using namespace testing; 28 using namespace testing::ext; 29 using namespace OHOS::FfiContext; 30 31 extern "C" { 32 void FfiContextSwitchArea(int64_t id, int32_t mode); 33 int32_t FfiContextGetArea(int64_t id, int32_t type); 34 } 35 36 class FfiContextSwitchAreaTest : public ::testing::Test {}; 37 38 /** 39 * @tc.name : FfiContextSwitchArea_ShouldLogError_WhenContextIsNull 40 * @tc.number: FfiContextSwitchAreaTest_001 41 */ 42 HWTEST_F(FfiContextSwitchAreaTest, ATC_FfiContextSwitchArea_ShouldLogError_WhenContextIsNull, TestSize.Level0) { 43 int64_t id = 123; 44 int32_t mode = 4; 45 FfiContextSwitchArea(id, mode); 46 } 47 48 /** 49 * @tc.name : FfiContextSwitchArea_ShouldCallSwitchArea_WhenContextIsNotNull 50 * @tc.number: FfiContextSwitchAreaTest_002 51 */ 52 HWTEST_F(FfiContextSwitchAreaTest, ATC_FfiContextSwitchArea_ShouldCallSwitchArea_WhenContextIsNotNull, 53 TestSize.Level0) { 54 int32_t mode = 4; 55 std::shared_ptr<ContextImpl> mockContext = std::make_shared<ContextImpl>(); 56 EXPECT_NE(mockContext, nullptr); 57 auto cjContext = FFIData::Create<CJContext>(mockContext); 58 EXPECT_NE(cjContext, nullptr); 59 FfiContextSwitchArea(cjContext->GetID(), mode); 60 auto modeGet = FfiContextGetArea(cjContext->GetID(), 0); 61 EXPECT_EQ(modeGet, mode); 62 }