1/*
2 * Copyright (c) 2023 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 "web_socket_frame.h"
18
19using namespace OHOS::ArkCompiler::Toolchain;
20
21namespace panda::test {
22class WebSocketFrameTest : public testing::Test {
23public:
24    static constexpr uint8_t HEADER_RAW[WebSocketFrame::HEADER_LEN] = {0x01, 0x9a};
25    static constexpr uint8_t EXPECTED_FIN           = 0;
26    static constexpr uint8_t EXPECTED_OPCODE        = 0x1;
27    static constexpr uint8_t EXPECTED_MASK_BIT      = 1;
28    static constexpr uint8_t EXPECTED_PAYLOAD_LEN   = 0x1a;
29};
30
31HWTEST_F(WebSocketFrameTest, TestDecode, testing::ext::TestSize.Level0)
32{
33    WebSocketFrame wsFrame(HEADER_RAW);
34
35    ASSERT_EQ(wsFrame.fin, EXPECTED_FIN);
36    ASSERT_EQ(wsFrame.opcode, EXPECTED_OPCODE);
37    ASSERT_EQ(wsFrame.mask, EXPECTED_MASK_BIT);
38    ASSERT_EQ(wsFrame.payloadLen, EXPECTED_PAYLOAD_LEN);
39    // these fields must not be filled
40    ASSERT_TRUE(wsFrame.payload.empty());
41    for (size_t i = 0; i < WebSocketFrame::MASK_LEN; ++i) {
42        ASSERT_EQ(wsFrame.maskingKey[i], 0);
43    }
44}
45}  // namespace panda::test
46