| Index: mojo/android/javatests/src/org/chromium/mojo/bindings/UnionTest.java
|
| diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/UnionTest.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/UnionTest.java
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3b09e5a1ca8a4eeb7306aa15769f8d6f17e5cc50
|
| --- /dev/null
|
| +++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/UnionTest.java
|
| @@ -0,0 +1,168 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +package org.chromium.mojo.bindings;
|
| +
|
| +import android.test.suitebuilder.annotation.SmallTest;
|
| +
|
| +import org.chromium.mojo.MojoTestCase;
|
| +import org.chromium.mojo.system.impl.CoreImpl;
|
| +import org.chromium.mojom.mojo.test.AnEnum;
|
| +import org.chromium.mojom.mojo.test.ObjectUnion;
|
| +import org.chromium.mojom.mojo.test.PodUnion;
|
| +
|
| +import java.util.HashSet;
|
| +import java.util.Set;
|
| +
|
| +/**
|
| + * Testing union generation. Generated classes are defined in
|
| + * mojo/public/interfaces/bindings/tests/test_unions.mojom
|
| + */
|
| +public class UnionTest extends MojoTestCase {
|
| + @SmallTest
|
| + public void testTagGeneration() {
|
| + // Check that all tag are different.
|
| + Set<Integer> tags = new HashSet<>();
|
| + tags.add(PodUnion.Tag.FInt8);
|
| + tags.add(PodUnion.Tag.FInt8Other);
|
| + tags.add(PodUnion.Tag.FUint8);
|
| + tags.add(PodUnion.Tag.FInt16);
|
| + tags.add(PodUnion.Tag.FUint16);
|
| + tags.add(PodUnion.Tag.FInt32);
|
| + tags.add(PodUnion.Tag.FUint32);
|
| + tags.add(PodUnion.Tag.FInt64);
|
| + tags.add(PodUnion.Tag.FUint64);
|
| + tags.add(PodUnion.Tag.FFloat);
|
| + tags.add(PodUnion.Tag.FDouble);
|
| + tags.add(PodUnion.Tag.FBool);
|
| + tags.add(PodUnion.Tag.FEnum);
|
| + assertEquals(13, tags.size());
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testPlainOldDataGetterSetter() {
|
| + PodUnion pod = new PodUnion();
|
| +
|
| + pod.setFInt8((byte) 10);
|
| + assertEquals((byte) 10, pod.getFInt8());
|
| + assertEquals(PodUnion.Tag.FInt8, pod.which());
|
| +
|
| + pod.setFUint8((byte) 11);
|
| + assertEquals((byte) 11, pod.getFUint8());
|
| + assertEquals(PodUnion.Tag.FUint8, pod.which());
|
| +
|
| + pod.setFInt16((short) 12);
|
| + assertEquals((short) 12, pod.getFInt16());
|
| + assertEquals(PodUnion.Tag.FInt16, pod.which());
|
| +
|
| + pod.setFUint16((short) 13);
|
| + assertEquals((short) 13, pod.getFUint16());
|
| + assertEquals(PodUnion.Tag.FUint16, pod.which());
|
| +
|
| + pod.setFInt32(14);
|
| + assertEquals(14, pod.getFInt32());
|
| + assertEquals(PodUnion.Tag.FInt32, pod.which());
|
| +
|
| + pod.setFUint32(15);
|
| + assertEquals(15, pod.getFUint32());
|
| + assertEquals(PodUnion.Tag.FUint32, pod.which());
|
| +
|
| + pod.setFInt64(16);
|
| + assertEquals(16, pod.getFInt64());
|
| + assertEquals(PodUnion.Tag.FInt64, pod.which());
|
| +
|
| + pod.setFUint64(17);
|
| + assertEquals(17, pod.getFUint64());
|
| + assertEquals(PodUnion.Tag.FUint64, pod.which());
|
| +
|
| + pod.setFFloat(1.5f);
|
| + assertEquals(1.5f, pod.getFFloat());
|
| + assertEquals(PodUnion.Tag.FFloat, pod.which());
|
| +
|
| + pod.setFDouble(1.9);
|
| + assertEquals(1.9, pod.getFDouble());
|
| + assertEquals(PodUnion.Tag.FDouble, pod.which());
|
| +
|
| + pod.setFBool(true);
|
| + assertTrue(pod.getFBool());
|
| + pod.setFBool(false);
|
| + assertFalse(pod.getFBool());
|
| + assertEquals(PodUnion.Tag.FBool, pod.which());
|
| +
|
| + pod.setFEnum(AnEnum.SECOND);
|
| + assertEquals(AnEnum.SECOND, pod.getFEnum());
|
| + assertEquals(PodUnion.Tag.FEnum, pod.which());
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testEquals() {
|
| + PodUnion pod1 = new PodUnion();
|
| + PodUnion pod2 = new PodUnion();
|
| +
|
| + pod1.setFInt8((byte) 10);
|
| + pod2.setFInt8((byte) 10);
|
| + assertEquals(pod1, pod2);
|
| +
|
| + pod2.setFInt8((byte) 11);
|
| + assertFalse(pod1.equals(pod2));
|
| +
|
| + pod2.setFInt8Other((byte) 10);
|
| + assertFalse(pod1.equals(pod2));
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testPodSerialization() {
|
| + PodUnion pod1 = new PodUnion();
|
| + pod1.setFInt8((byte) 10);
|
| +
|
| + PodUnion pod2 = PodUnion.deserialize(pod1.serialize(CoreImpl.getInstance()));
|
| +
|
| + assertEquals((byte) 10, pod2.getFInt8());
|
| + assertEquals(PodUnion.Tag.FInt8, pod2.which());
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testEnumSerialization() {
|
| + PodUnion pod1 = new PodUnion();
|
| + pod1.setFEnum(AnEnum.SECOND);
|
| +
|
| + PodUnion pod2 = PodUnion.deserialize(pod1.serialize(CoreImpl.getInstance()));
|
| +
|
| + assertEquals(AnEnum.SECOND, pod2.getFEnum());
|
| + assertEquals(PodUnion.Tag.FEnum, pod2.which());
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testStringGetterSetter() {
|
| + ObjectUnion ou = new ObjectUnion();
|
| + ou.setFString("hello world");
|
| +
|
| + assertEquals("hello world", ou.getFString());
|
| + assertEquals(ObjectUnion.Tag.FString, ou.which());
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testStringEquals() {
|
| + ObjectUnion ou1 = new ObjectUnion();
|
| + ObjectUnion ou2 = new ObjectUnion();
|
| +
|
| + ou1.setFString("hello world");
|
| + ou2.setFString("hello world");
|
| + assertEquals(ou1, ou2);
|
| +
|
| + ou2.setFString("hello universe");
|
| + assertFalse(ou1.equals(ou2));
|
| + }
|
| +
|
| + @SmallTest
|
| + public void testStringSerialization() {
|
| + ObjectUnion ou1 = new ObjectUnion();
|
| + ou1.setFString("hello world");
|
| +
|
| + ObjectUnion ou2 = ObjectUnion.deserialize(ou1.serialize(CoreImpl.getInstance()));
|
| +
|
| + assertEquals("hello world", ou2.getFString());
|
| + assertEquals(ObjectUnion.Tag.FString, ou2.which());
|
| + }
|
| +}
|
|
|