1 /*
2  * Copyright (C) 2023 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 
17 package android.os.cts;
18 
19 import static org.junit.Assert.assertEquals;
20 
21 import android.os.Parcel;
22 import android.os.ParcelUuid;
23 import android.platform.test.annotations.AppModeSdkSandbox;
24 
25 import org.junit.Test;
26 
27 import java.util.UUID;
28 
29 @AppModeSdkSandbox(reason = "Allow test in the SDK sandbox (does not prevent other modes).")
30 public class ParcelUuidTest {
31     private static final String TEST_UUID = "41217664-9172-527a-b3d5-edabb50a7d69";
32 
33     @Test
testTypical()34     public void testTypical() {
35         UUID uuid = UUID.fromString(TEST_UUID);
36         assertEquals(uuid, new ParcelUuid(uuid).getUuid());
37         assertEquals(uuid, ParcelUuid.fromString(TEST_UUID).getUuid());
38     }
39 
40     @Test
testSymmetry()41     public void testSymmetry() {
42         UUID uuid = UUID.fromString(TEST_UUID);
43         ParcelUuid before = new ParcelUuid(uuid);
44 
45         Parcel p = Parcel.obtain();
46         p.writeParcelable(before, 0);
47         p.setDataPosition(0);
48 
49         ParcelUuid after = p.readParcelable(null, ParcelUuid.class);
50         assertEquals(before, after);
51         p.recycle();
52     }
53 }
54