ScoredNetworkTest.java revision dc960e21ef1005fab5ef145773ddd6f40c802217
1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
15 */
16
17package android.net;
18
19import android.os.Parcel;
20
21import junit.framework.TestCase;
22
23import java.util.Arrays;
24
25public class ScoredNetworkTest extends TestCase {
26    private static final RssiCurve CURVE =
27            new RssiCurve(-110, 10, new byte[] {0, 1, 2, 3, 4, 5, 6, 7});
28
29    public void testInvalidCurve_nullBuckets() {
30        try {
31            new RssiCurve(-110, 10, null);
32            fail("Should have thrown IllegalArgumentException");
33        } catch (IllegalArgumentException e) {
34            // expected
35        }
36    }
37
38    public void testInvalidCurve_emptyBuckets() {
39        try {
40            new RssiCurve(-110, 10, new byte[] {});
41            fail("Should have thrown IllegalArgumentException");
42        } catch (IllegalArgumentException e) {
43            // expected
44        }
45    }
46
47    public void testParceling() {
48        NetworkKey key = new NetworkKey(new WifiKey("\"ssid\"", "00:00:00:00:00:00"));
49        ScoredNetwork network = new ScoredNetwork(key, CURVE);
50        Parcel parcel = null;
51        try {
52            parcel = Parcel.obtain();
53            parcel.writeParcelable(network, 0);
54            parcel.setDataPosition(0);
55            network = parcel.readParcelable(getClass().getClassLoader());
56        } finally {
57            if (parcel != null) {
58                parcel.recycle();
59            }
60        }
61        assertEquals(CURVE.start, network.rssiCurve.start);
62        assertEquals(CURVE.bucketWidth, network.rssiCurve.bucketWidth);
63        assertTrue(Arrays.equals(CURVE.rssiBuckets, network.rssiCurve.rssiBuckets));
64    }
65}
66