001/*
002 * Copyright (c) 2014, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package jdk.internal.jvmci.runtime.test;
024
025import jdk.internal.jvmci.meta.*;
026
027import org.junit.*;
028
029public class ConstantTest extends FieldUniverse {
030
031    @Test
032    public void testNegativeZero() {
033        Assert.assertTrue("Constant for 0.0f must be different from -0.0f", JavaConstant.FLOAT_0 != JavaConstant.forFloat(-0.0F));
034        Assert.assertTrue("Constant for 0.0d must be different from -0.0d", JavaConstant.DOUBLE_0 != JavaConstant.forDouble(-0.0d));
035    }
036
037    @Test
038    public void testNullIsNull() {
039        Assert.assertTrue(JavaConstant.NULL_POINTER.isNull());
040    }
041
042    @Test
043    public void testOne() {
044        for (Kind kind : Kind.values()) {
045            if (kind.isNumericInteger() || kind.isNumericFloat()) {
046                Assert.assertTrue(JavaConstant.one(kind).getKind() == kind);
047            }
048        }
049        Assert.assertEquals(1, JavaConstant.one(Kind.Int).asInt());
050        Assert.assertEquals(1L, JavaConstant.one(Kind.Long).asLong());
051        Assert.assertEquals(1, JavaConstant.one(Kind.Byte).asInt());
052        Assert.assertEquals(1, JavaConstant.one(Kind.Short).asInt());
053        Assert.assertEquals(1, JavaConstant.one(Kind.Char).asInt());
054        Assert.assertTrue(1F == JavaConstant.one(Kind.Float).asFloat());
055        Assert.assertTrue(1D == JavaConstant.one(Kind.Double).asDouble());
056    }
057
058    @Test(expected = IllegalArgumentException.class)
059    public void testIllegalOne() {
060        JavaConstant.one(Kind.Illegal);
061    }
062
063    @Test(expected = IllegalArgumentException.class)
064    public void testVoidOne() {
065        JavaConstant.one(Kind.Void);
066    }
067}