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 "ecmascript/global_env.h"
17 #include "ecmascript/js_async_generator_object.h"
18 #include "ecmascript/interpreter/slow_runtime_stub.h"
19 #include "ecmascript/tests/test_helper.h"
20
21 using namespace panda;
22 using namespace panda::ecmascript;
23
24 namespace panda::test {
25 class JSAsyncGeneratorObjectTest : public testing::Test {
26 public:
SetUpTestCase()27 static void SetUpTestCase()
28 {
29 GTEST_LOG_(INFO) << "SetUpTestCase";
30 }
31
TearDownTestCase()32 static void TearDownTestCase()
33 {
34 GTEST_LOG_(INFO) << "TearDownCase";
35 }
36
SetUp()37 void SetUp() override
38 {
39 TestHelper::CreateEcmaVMWithScope(instance, thread, scope);
40 }
41
TearDown()42 void TearDown() override
43 {
44 TestHelper::DestroyEcmaVMWithScope(instance, scope);
45 }
46
47 EcmaVM *instance {nullptr};
48 ecmascript::EcmaHandleScope *scope {nullptr};
49 JSThread *thread {nullptr};
50 };
51
52 /**
53 * @tc.name: GeneratorValidate
54 * @tc.desc: Get the current status of the AsyncGenerator.
55 * @tc.type: FUNC
56 * @tc.require:issueI5JIGT
57 */
HWTEST_F_L0(JSAsyncGeneratorObjectTest,AsyncGeneratorValidate_001)58 HWTEST_F_L0(JSAsyncGeneratorObjectTest, AsyncGeneratorValidate_001)
59 {
60 auto vm = thread->GetEcmaVM();
61 auto factory = vm->GetFactory();
62 auto env = vm->GetGlobalEnv();
63 JSHandle<JSAsyncGeneratorObject> asyncGenObj =
64 factory->NewJSAsyncGeneratorObject(env->GetAsyncGeneratorFunctionFunction());
65 JSAsyncGeneratorState state = asyncGenObj->GetAsyncGeneratorState();
66 EXPECT_EQ(state, JSAsyncGeneratorState::UNDEFINED);
67 }
68 } // namespace panda::test