1 /* 2 * Copyright (c) 2012, 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 /* 25 * @test 26 * @summary Basic test for ModuleArchitecture matching 27 */ 28 29 import java.util.ArrayList; 30 import java.util.Arrays; 31 import java.util.List; 32 import org.openjdk.jigsaw.ModuleArchitecture; 33 34 public class ModuleArchitectureTest { 35 36 static List<ModuleArchitecture> oses = new ArrayList<>( Arrays.asList( 37 ModuleArchitecture.createFromOS("solaris"), 38 ModuleArchitecture.createFromOS("linux"), 39 ModuleArchitecture.createFromOS("windows"), 40 ModuleArchitecture.createFromOS("macosx"), 41 ModuleArchitecture.createFromOS("freebsd"), 42 ModuleArchitecture.createFromOS("hp-ux") )); 43 44 static List<ModuleArchitecture> archs = new ArrayList<>( Arrays.asList( 45 ModuleArchitecture.createFromArch("sparc"), 46 ModuleArchitecture.createFromArch("sparcv9"), 47 ModuleArchitecture.createFromArch("i386"), 48 ModuleArchitecture.createFromArch("x86"), 49 ModuleArchitecture.createFromArch("amd64"), 50 ModuleArchitecture.createFromArch("x86_64"), 51 ModuleArchitecture.createFromArch("ia64"), 52 ModuleArchitecture.createFromArch("arm"), 53 ModuleArchitecture.createFromArch("ppc"), 54 ModuleArchitecture.createFromArch("pa_risc2.0") )); 55 56 static List<ModuleArchitecture> platforms = new ArrayList<>( Arrays.asList( 57 ModuleArchitecture.create("solaris", "sparc"), 58 ModuleArchitecture.create("solaris", "sparcv9"), 59 ModuleArchitecture.create("solaris", "x86"), 60 ModuleArchitecture.create("solaris", "amd64"), 61 ModuleArchitecture.create("linux", "i386"), 62 ModuleArchitecture.create("linux", "arm"), 63 ModuleArchitecture.create("linux", "ppc"), 64 ModuleArchitecture.create("linux", "amd64"), 65 ModuleArchitecture.create("linux", "x86_64"), 66 ModuleArchitecture.create("linux", "ia64"), 67 ModuleArchitecture.create("windows", "x86"), 68 ModuleArchitecture.create("windows", "amd64"), 69 ModuleArchitecture.create("macosx", "i386"), 70 ModuleArchitecture.create("macosx", "ppc"), 71 ModuleArchitecture.create("macosx", "x86_64"), 72 ModuleArchitecture.create("freebsd", "i386"), 73 ModuleArchitecture.create("hp-ux", "pa_risc2.0") )); 74 75 static int failed; 76 77 public static void main(String[] args) { 78 for (ModuleArchitecture os : oses) { 79 for (ModuleArchitecture platform : platforms) { 80 if (platform.os().equals(os.os())) 81 matches(platform, os); 82 matches(ModuleArchitecture.ANY, platform); 83 matches(ModuleArchitecture.ANY, os); 84 } 85 } 86 for (ModuleArchitecture arch : archs) { 87 for (ModuleArchitecture platform : platforms) { 88 if (platform.arch().equals(arch.arch())) 89 matches(platform, arch); 90 matches(ModuleArchitecture.ANY, platform); 91 matches(ModuleArchitecture.ANY, arch); 92 } 93 } 94 95 ModuleArchitecture sunos = ModuleArchitecture.createFromOS("SunOS"); 96 ModuleArchitecture sparc = ModuleArchitecture.createFromArch("sparc"); 97 matches(sunos, sparc); 98 99 if (failed > 0) 100 throw new RuntimeException("Failed " + failed + " tests: check output"); 101 } 102 103 static void matches(ModuleArchitecture ma1, ModuleArchitecture ma2) { 104 if (! (ma1.matches(ma2) && ma2.matches(ma1)) ) { 105 failed++; 106 System.out.printf("[%s] should match to [%s]%n", ma1, ma2); 107 } 108 } 109 }