756N/A/*
2362N/A * Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved.
756N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
756N/A *
756N/A * This code is free software; you can redistribute it and/or modify it
756N/A * under the terms of the GNU General Public License version 2 only, as
756N/A * published by the Free Software Foundation.
756N/A *
756N/A * This code is distributed in the hope that it will be useful, but WITHOUT
756N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
756N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
756N/A * version 2 for more details (a copy is included in the LICENSE file that
756N/A * accompanied this code).
756N/A *
756N/A * You should have received a copy of the GNU General Public License version
756N/A * 2 along with this work; if not, write to the Free Software Foundation,
756N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
756N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
756N/A */
756N/A
756N/A/*
756N/A * @test
756N/A * @bug 4996318 6731937
756N/A * @summary There should be no duplicates returned by getSupportedDocFlavors.
756N/A * @run main CheckDupFlavor
756N/A */
756N/Aimport javax.print.*;
756N/Aimport javax.print.attribute.*;
756N/Aimport javax.print.attribute.standard.*;
756N/Aimport java.util.ArrayList;
756N/A
756N/A
756N/Apublic class CheckDupFlavor {
756N/A public static void main(String[] args){
1183N/A PrintService defService = PrintServiceLookup.lookupDefaultPrintService();
1183N/A PrintService[] pservice;
1183N/A if (defService == null) {
1183N/A pservice = PrintServiceLookup.lookupPrintServices(null, null);
1183N/A if (pservice.length == 0) {
1183N/A throw new RuntimeException("No printer found. TEST ABORTED");
1183N/A }
1183N/A defService = pservice[0];
756N/A }
756N/A
1183N/A System.out.println("PrintService = "+defService);
756N/A
1183N/A DocFlavor[] flavors = defService.getSupportedDocFlavors();
756N/A if (flavors==null) {
756N/A System.out.println("No flavors supported. Test PASSED.");
756N/A return;
756N/A }
756N/A
756N/A
756N/A ArrayList flavorList = new ArrayList();
756N/A for (int i=0; i<flavors.length; i++) {
1183N/A if (flavors[i] == null) {
1183N/A throw new RuntimeException("Null flavor. Test FAILED.");
1183N/A } else if (flavorList.contains(flavors[i])) {
1183N/A throw new RuntimeException("\n\tDuplicate flavor found : "+flavors[i]+" : Test FAILED.");
1183N/A } else {
1183N/A flavorList.add(flavors[i]);
1183N/A }
756N/A }
756N/A System.out.println("No duplicate found. Test PASSED.");
756N/A }
756N/A}