summaryrefslogtreecommitdiffstats
path: root/tests/wifitests/src/com/android/server/wifi/wificond/NativeScanResultTest.java
blob: 08573e454812f92b1b53b63c70c5e4133c0401c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.wifi.wificond;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.os.Parcel;
import android.test.suitebuilder.annotation.SmallTest;

import org.junit.Test;

import java.util.BitSet;

/**
 * Unit tests for {@link com.android.server.wifi.wificond.NativeScanResult}.
 */
@SmallTest
public class NativeScanResultTest {

    private static final byte[] TEST_SSID =
            new byte[] {'G', 'o', 'o', 'g', 'l', 'e', 'G', 'u', 'e', 's', 't'};
    private static final byte[] TEST_BSSID =
            new byte[] {(byte) 0x12, (byte) 0xef, (byte) 0xa1,
                        (byte) 0x2c, (byte) 0x97, (byte) 0x8b};
    private static final byte[] TEST_INFO_ELEMENT =
            new byte[] {(byte) 0x01, (byte) 0x03, (byte) 0x12, (byte) 0xbe, (byte) 0xff};
    private static final int TEST_FREQUENCY = 2456;
    private static final int TEST_SIGNAL_MBM = -45;
    private static final long TEST_TSF = 34455441;
    private static final BitSet TEST_CAPABILITY = new BitSet(16) {{ set(2); set(5); }};
    private static final boolean TEST_ASSOCIATED = true;

    /**
     *  NativeScanResult object can be serialized and deserialized, while keeping the
     *  values unchanged.
     */
    @Test
    public void canSerializeAndDeserialize() throws Exception {
        NativeScanResult scanResult = new NativeScanResult();
        scanResult.ssid = TEST_SSID;
        scanResult.bssid = TEST_BSSID;
        scanResult.infoElement = TEST_INFO_ELEMENT;
        scanResult.frequency = TEST_FREQUENCY;
        scanResult.signalMbm = TEST_SIGNAL_MBM;
        scanResult.tsf = TEST_TSF;
        scanResult.capability = TEST_CAPABILITY;
        scanResult.associated = TEST_ASSOCIATED;
        Parcel parcel = Parcel.obtain();
        scanResult.writeToParcel(parcel, 0);
        // Rewind the pointer to the head of the parcel.
        parcel.setDataPosition(0);
        NativeScanResult scanResultDeserialized = NativeScanResult.CREATOR.createFromParcel(parcel);

        assertArrayEquals(scanResult.ssid, scanResultDeserialized.ssid);
        assertArrayEquals(scanResult.bssid, scanResultDeserialized.bssid);
        assertArrayEquals(scanResult.infoElement, scanResultDeserialized.infoElement);
        assertEquals(scanResult.frequency, scanResultDeserialized.frequency);
        assertEquals(scanResult.signalMbm, scanResultDeserialized.signalMbm);
        assertEquals(scanResult.tsf, scanResultDeserialized.tsf);
        assertTrue(scanResult.capability.equals(scanResultDeserialized.capability));
        assertEquals(scanResult.associated, scanResultDeserialized.associated);
    }
}