OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.mojo.bindings; |
| 6 |
| 7 import android.test.suitebuilder.annotation.SmallTest; |
| 8 |
| 9 import org.chromium.mojo.MojoTestCase; |
| 10 import org.chromium.mojo.system.impl.CoreImpl; |
| 11 import org.chromium.mojom.mojo.test.AnEnum; |
| 12 import org.chromium.mojom.mojo.test.ObjectUnion; |
| 13 import org.chromium.mojom.mojo.test.PodUnion; |
| 14 |
| 15 import java.util.HashSet; |
| 16 import java.util.Set; |
| 17 |
| 18 /** |
| 19 * Testing union generation. Generated classes are defined in |
| 20 * mojo/public/interfaces/bindings/tests/test_unions.mojom |
| 21 */ |
| 22 public class UnionTest extends MojoTestCase { |
| 23 @SmallTest |
| 24 public void testTagGeneration() { |
| 25 // Check that all tag are different. |
| 26 Set<Integer> tags = new HashSet<>(); |
| 27 tags.add(PodUnion.Tag.FInt8); |
| 28 tags.add(PodUnion.Tag.FInt8Other); |
| 29 tags.add(PodUnion.Tag.FUint8); |
| 30 tags.add(PodUnion.Tag.FInt16); |
| 31 tags.add(PodUnion.Tag.FUint16); |
| 32 tags.add(PodUnion.Tag.FInt32); |
| 33 tags.add(PodUnion.Tag.FUint32); |
| 34 tags.add(PodUnion.Tag.FInt64); |
| 35 tags.add(PodUnion.Tag.FUint64); |
| 36 tags.add(PodUnion.Tag.FFloat); |
| 37 tags.add(PodUnion.Tag.FDouble); |
| 38 tags.add(PodUnion.Tag.FBool); |
| 39 tags.add(PodUnion.Tag.FEnum); |
| 40 assertEquals(13, tags.size()); |
| 41 } |
| 42 |
| 43 @SmallTest |
| 44 public void testPlainOldDataGetterSetter() { |
| 45 PodUnion pod = new PodUnion(); |
| 46 |
| 47 pod.setFInt8((byte) 10); |
| 48 assertEquals((byte) 10, pod.getFInt8()); |
| 49 assertEquals(PodUnion.Tag.FInt8, pod.which()); |
| 50 |
| 51 pod.setFUint8((byte) 11); |
| 52 assertEquals((byte) 11, pod.getFUint8()); |
| 53 assertEquals(PodUnion.Tag.FUint8, pod.which()); |
| 54 |
| 55 pod.setFInt16((short) 12); |
| 56 assertEquals((short) 12, pod.getFInt16()); |
| 57 assertEquals(PodUnion.Tag.FInt16, pod.which()); |
| 58 |
| 59 pod.setFUint16((short) 13); |
| 60 assertEquals((short) 13, pod.getFUint16()); |
| 61 assertEquals(PodUnion.Tag.FUint16, pod.which()); |
| 62 |
| 63 pod.setFInt32(14); |
| 64 assertEquals(14, pod.getFInt32()); |
| 65 assertEquals(PodUnion.Tag.FInt32, pod.which()); |
| 66 |
| 67 pod.setFUint32(15); |
| 68 assertEquals(15, pod.getFUint32()); |
| 69 assertEquals(PodUnion.Tag.FUint32, pod.which()); |
| 70 |
| 71 pod.setFInt64(16); |
| 72 assertEquals(16, pod.getFInt64()); |
| 73 assertEquals(PodUnion.Tag.FInt64, pod.which()); |
| 74 |
| 75 pod.setFUint64(17); |
| 76 assertEquals(17, pod.getFUint64()); |
| 77 assertEquals(PodUnion.Tag.FUint64, pod.which()); |
| 78 |
| 79 pod.setFFloat(1.5f); |
| 80 assertEquals(1.5f, pod.getFFloat()); |
| 81 assertEquals(PodUnion.Tag.FFloat, pod.which()); |
| 82 |
| 83 pod.setFDouble(1.9); |
| 84 assertEquals(1.9, pod.getFDouble()); |
| 85 assertEquals(PodUnion.Tag.FDouble, pod.which()); |
| 86 |
| 87 pod.setFBool(true); |
| 88 assertTrue(pod.getFBool()); |
| 89 pod.setFBool(false); |
| 90 assertFalse(pod.getFBool()); |
| 91 assertEquals(PodUnion.Tag.FBool, pod.which()); |
| 92 |
| 93 pod.setFEnum(AnEnum.SECOND); |
| 94 assertEquals(AnEnum.SECOND, pod.getFEnum()); |
| 95 assertEquals(PodUnion.Tag.FEnum, pod.which()); |
| 96 } |
| 97 |
| 98 @SmallTest |
| 99 public void testEquals() { |
| 100 PodUnion pod1 = new PodUnion(); |
| 101 PodUnion pod2 = new PodUnion(); |
| 102 |
| 103 pod1.setFInt8((byte) 10); |
| 104 pod2.setFInt8((byte) 10); |
| 105 assertEquals(pod1, pod2); |
| 106 |
| 107 pod2.setFInt8((byte) 11); |
| 108 assertFalse(pod1.equals(pod2)); |
| 109 |
| 110 pod2.setFInt8Other((byte) 10); |
| 111 assertFalse(pod1.equals(pod2)); |
| 112 } |
| 113 |
| 114 @SmallTest |
| 115 public void testPodSerialization() { |
| 116 PodUnion pod1 = new PodUnion(); |
| 117 pod1.setFInt8((byte) 10); |
| 118 |
| 119 PodUnion pod2 = PodUnion.deserialize(pod1.serialize(CoreImpl.getInstance
())); |
| 120 |
| 121 assertEquals((byte) 10, pod2.getFInt8()); |
| 122 assertEquals(PodUnion.Tag.FInt8, pod2.which()); |
| 123 } |
| 124 |
| 125 @SmallTest |
| 126 public void testEnumSerialization() { |
| 127 PodUnion pod1 = new PodUnion(); |
| 128 pod1.setFEnum(AnEnum.SECOND); |
| 129 |
| 130 PodUnion pod2 = PodUnion.deserialize(pod1.serialize(CoreImpl.getInstance
())); |
| 131 |
| 132 assertEquals(AnEnum.SECOND, pod2.getFEnum()); |
| 133 assertEquals(PodUnion.Tag.FEnum, pod2.which()); |
| 134 } |
| 135 |
| 136 @SmallTest |
| 137 public void testStringGetterSetter() { |
| 138 ObjectUnion ou = new ObjectUnion(); |
| 139 ou.setFString("hello world"); |
| 140 |
| 141 assertEquals("hello world", ou.getFString()); |
| 142 assertEquals(ObjectUnion.Tag.FString, ou.which()); |
| 143 } |
| 144 |
| 145 @SmallTest |
| 146 public void testStringEquals() { |
| 147 ObjectUnion ou1 = new ObjectUnion(); |
| 148 ObjectUnion ou2 = new ObjectUnion(); |
| 149 |
| 150 ou1.setFString("hello world"); |
| 151 ou2.setFString("hello world"); |
| 152 assertEquals(ou1, ou2); |
| 153 |
| 154 ou2.setFString("hello universe"); |
| 155 assertFalse(ou1.equals(ou2)); |
| 156 } |
| 157 |
| 158 @SmallTest |
| 159 public void testStringSerialization() { |
| 160 ObjectUnion ou1 = new ObjectUnion(); |
| 161 ou1.setFString("hello world"); |
| 162 |
| 163 ObjectUnion ou2 = ObjectUnion.deserialize(ou1.serialize(CoreImpl.getInst
ance())); |
| 164 |
| 165 assertEquals("hello world", ou2.getFString()); |
| 166 assertEquals(ObjectUnion.Tag.FString, ou2.which()); |
| 167 } |
| 168 } |
OLD | NEW |