1/* 2 * Copyright (c) 2021 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#ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TEST_ACTIONS_H 17#define ECMASCRIPT_TOOLING_TEST_UTILS_TEST_ACTIONS_H 18 19#include <functional> 20#include <string> 21#include <vector> 22 23namespace panda::ecmascript::tooling::test { 24/* 25 * Socket action. 26 * {SEND} Send a message to server. 27 * {RECV} Should recv a message from server. 28 */ 29enum class SocketAction { 30 SEND = 0U, 31 RECV = 1U, 32}; 33 34/* 35 * Action matching rules. 36 * {STRING_EQUAL} Expect string should equal recv string. 37 * {STRING_CONTAIN} Expect string should a substring of recv string. 38 * {CUSTOM_RULE} Recv string should match custom rule. 39 */ 40enum class ActionRule { 41 STRING_EQUAL, 42 STRING_CONTAIN, 43 CUSTOM_RULE, 44}; 45std::ostream &operator<<(std::ostream &out, ActionRule value); 46 47using MatchFunc = std::function<bool(const std::string&, const std::string&, bool&)>; 48 49enum class TestCase { 50 COMMON, 51 SOURCE, 52 WATCH, 53 WATCH_OBJECT, 54}; 55 56/* 57 * Add some common match func here 58 */ 59struct MatchRule { 60 static MatchFunc replySuccess; 61}; 62 63/* 64 * Action information. 65 * @param action Socket action. 66 * @param rule Action matching rules. 67 * @param message Expect message or send message 68 * @param matchFunc Custom matching rule 69 */ 70struct ActionInfo { 71 SocketAction action; 72 std::string message; 73 ActionRule rule = ActionRule::STRING_CONTAIN; 74 MatchFunc matchFunc = [] (auto, auto, auto) -> auto { 75 return true; 76 }; 77 TestCase event = TestCase::COMMON; 78 79 ActionInfo(const ActionInfo&) = default; 80 ActionInfo& operator=(const ActionInfo&) = default; 81}; 82 83struct TestActions { 84 std::vector<ActionInfo> testAction; 85 86 TestActions() = default; 87 virtual ~TestActions() = default; 88 89 virtual std::pair<std::string, std::string> GetEntryPoint() = 0; 90}; 91} // namespace panda::ecmascript::tooling::test 92 93#endif // ECMASCRIPT_TOOLING_TEST_UTILS_TEST_ACTIONS_H 94