001/*
002 * Copyright (c) 2015, 2015, 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 com.oracle.graal.lir.test;
024
025import static org.junit.Assert.*;
026import jdk.internal.jvmci.code.*;
027import jdk.internal.jvmci.code.Register.RegisterCategory;
028import jdk.internal.jvmci.meta.*;
029
030import org.junit.*;
031
032import com.oracle.graal.lir.*;
033import com.oracle.graal.lir.util.*;
034
035public class GenericValueMapTest {
036
037    @Test
038    public void run0() {
039        RegisterCategory cat = new RegisterCategory("regs");
040
041        RegisterValue reg = new Register(0, 0, "reg0", cat).asValue();
042        Variable var = new Variable(LIRKind.value(Kind.Long), 0);
043        Object obj0 = new Object();
044        Object obj1 = new Object();
045
046        GenericValueMap<Object> map = new GenericValueMap<>();
047
048        assertNull(map.get(reg));
049        assertNull(map.get(var));
050
051        map.put(reg, obj0);
052        map.put(var, obj1);
053
054        assertEquals(obj0, map.get(reg));
055        assertEquals(obj1, map.get(var));
056
057        map.remove(reg);
058        map.remove(var);
059
060        assertNull(map.get(reg));
061        assertNull(map.get(var));
062
063        map.put(reg, obj0);
064        map.put(var, obj1);
065
066        map.put(var, obj0);
067        map.put(reg, obj1);
068
069        assertEquals(obj1, map.get(reg));
070        assertEquals(obj0, map.get(var));
071
072        map.put(reg, null);
073        map.put(var, null);
074
075        assertNull(map.get(reg));
076        assertNull(map.get(var));
077    }
078}