183N/A/*
3261N/A * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
183N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
183N/A *
183N/A * This code is free software; you can redistribute it and/or modify it
183N/A * under the terms of the GNU General Public License version 2 only, as
183N/A * published by the Free Software Foundation.
183N/A *
183N/A * This code is distributed in the hope that it will be useful, but WITHOUT
183N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
183N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
183N/A * version 2 for more details (a copy is included in the LICENSE file that
183N/A * accompanied this code).
183N/A *
183N/A * You should have received a copy of the GNU General Public License version
183N/A * 2 along with this work; if not, write to the Free Software Foundation,
183N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
183N/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.
183N/A */
183N/A
183N/A/**
183N/A * @test
183N/A * @bug 6537506
2500N/A * @ignore 6962535
183N/A * @summary Basic unit test for tracing framework
183N/A */
183N/A
183N/Aimport com.sun.tracing.*;
183N/Aimport java.lang.reflect.Method;
183N/A
183N/A@ProviderName("NamedProvider")
183N/Ainterface BasicProvider extends Provider {
183N/A void plainProbe();
183N/A void probeWithArgs(int a, float f, String s, Long l);
183N/A @ProbeName("namedProbe") void probeWithName();
183N/A void overloadedProbe();
183N/A void overloadedProbe(int i);
183N/A}
183N/A
183N/Ainterface InvalidProvider extends Provider {
183N/A int nonVoidProbe();
183N/A}
183N/A
183N/Apublic class BasicFunctionality {
183N/A
183N/A public static ProviderFactory factory;
183N/A public static BasicProvider bp;
183N/A
183N/A public static void main(String[] args) throws Exception {
183N/A
183N/A factory = ProviderFactory.getDefaultFactory();
183N/A if (factory != null) {
183N/A bp = factory.createProvider(BasicProvider.class);
183N/A }
183N/A
183N/A testProviderFactory();
183N/A testProbe();
183N/A testProvider();
183N/A }
183N/A
183N/A static void fail(String s) throws Exception {
183N/A throw new Exception(s);
183N/A }
183N/A
183N/A static void testProviderFactory() throws Exception {
183N/A if (factory == null) {
183N/A fail("ProviderFactory.getDefaultFactory: Did not create factory");
183N/A }
183N/A if (bp == null) {
183N/A fail("ProviderFactory.createProvider: Did not create provider");
183N/A }
183N/A try {
183N/A factory.createProvider(null);
183N/A fail("ProviderFactory.createProvider: Did not throw NPE for null");
183N/A } catch (NullPointerException e) {}
183N/A
183N/A try {
183N/A factory.createProvider(InvalidProvider.class);
183N/A fail("Factory.createProvider: Should error with non-void probes");
183N/A } catch (IllegalArgumentException e) {}
183N/A }
183N/A
183N/A public static void testProvider() throws Exception {
183N/A
183N/A // These just shouldn't throw any exeptions:
183N/A bp.plainProbe();
183N/A bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L));
183N/A bp.probeWithArgs(42, (float)3.14, null, null);
183N/A bp.probeWithName();
183N/A bp.overloadedProbe();
183N/A bp.overloadedProbe(42);
183N/A
183N/A Method m = BasicProvider.class.getMethod("plainProbe");
183N/A Probe p = bp.getProbe(m);
183N/A if (p == null) {
183N/A fail("Provider.getProbe: Did not return probe");
183N/A }
183N/A
183N/A Method m2 = BasicFunctionality.class.getMethod("testProvider");
183N/A p = bp.getProbe(m2);
183N/A if (p != null) {
183N/A fail("Provider.getProbe: Got probe with invalid spec");
183N/A }
183N/A
183N/A bp.dispose();
183N/A // These just shouldn't throw any exeptions:
183N/A bp.plainProbe();
183N/A bp.probeWithArgs(42, (float)3.14, "spam", new Long(2L));
183N/A bp.probeWithArgs(42, (float)3.14, null, null);
183N/A bp.probeWithName();
183N/A bp.overloadedProbe();
183N/A bp.overloadedProbe(42);
183N/A
183N/A if (bp.getProbe(m) != null) {
183N/A fail("Provider.getProbe: Should return null after dispose()");
183N/A }
183N/A
183N/A bp.dispose(); // just to make sure nothing bad happens
183N/A }
183N/A
183N/A static void testProbe() throws Exception {
183N/A Method m = BasicProvider.class.getMethod("plainProbe");
183N/A Probe p = bp.getProbe(m);
183N/A p.isEnabled(); // just make sure it doesn't do anything bad
183N/A p.trigger();
183N/A
183N/A try {
183N/A p.trigger(0);
183N/A fail("Probe.trigger: too many arguments not caught");
183N/A } catch (IllegalArgumentException e) {}
183N/A
183N/A p = bp.getProbe(BasicProvider.class.getMethod(
183N/A "probeWithArgs", int.class, float.class, String.class, Long.class));
183N/A try {
183N/A p.trigger();
183N/A fail("Probe.trigger: too few arguments not caught");
183N/A } catch (IllegalArgumentException e) {}
183N/A
183N/A try {
183N/A p.trigger((float)3.14, (float)3.14, "", new Long(0L));
183N/A fail("Probe.trigger: wrong type primitive arguments not caught");
183N/A } catch (IllegalArgumentException e) {}
183N/A }
183N/A}