1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 import java.foreign.Libraries;
  25 import java.foreign.Library;
  26 import java.foreign.NativeTypes;
  27 import java.foreign.Scope;
  28 import java.foreign.memory.LayoutType;
  29 import java.foreign.memory.Pointer;
  30 import java.lang.invoke.MethodHandles;
  31 import org.testng.annotations.Test;
  32 
  33 import static org.testng.Assert.assertEquals;
  34 import static org.testng.Assert.fail;
  35 import test.jextract.enums.enums;
  36 
  37 /*
  38  * @test
  39  * @bug 8210935
  40  * @summary C enum constants should be mapped to interface methods instead of static final int constants
  41  * @library ..
  42  * @run driver JtregJextract -t test.jextract.enums -- enums.h
  43  * @run testng LibEnumsTest
  44  */
  45 public class LibEnumsTest {
  46     static final enums libEnums;
  47 
  48     static {
  49         Library lib = Libraries.loadLibrary(MethodHandles.lookup(), "Enums");
  50         libEnums = Libraries.bind(enums.class, lib);
  51     }
  52 
  53     @Test
  54     public void testEnumConstants() {
  55         assertEquals(libEnums.R(), 0xFF0000);
  56         assertEquals(libEnums.G(), 0x00FF00);
  57         assertEquals(libEnums.B(), 0x0000FF);
  58 
  59         assertEquals(libEnums.R() | libEnums.G(), libEnums.red_green());
  60         assertEquals(libEnums.G() | libEnums.B(), libEnums.green_blue());
  61         assertEquals(libEnums.R() | libEnums.G() | libEnums.B(), libEnums.red_green_blue());
  62 
  63         assertEquals(libEnums.iminfunc(), libEnums.I_MIN());
  64         assertEquals(libEnums.imaxfunc(), libEnums.I_MAX());
  65         assertEquals(libEnums.lminfunc(), libEnums.L_MIN());
  66         assertEquals(libEnums.lmaxfunc(), libEnums.L_MAX());
  67     }
  68 }