--- /dev/null 2018-04-02 14:03:43.000000000 -0700 +++ new/test/jdk/java/awt/Window/MainKeyWindowTest/libtest8194327.c 2018-04-02 14:03:42.000000000 -0700 @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +#import +#import + +static NSWindow *testWindow; +static NSColorPanel *colorPanel; + +/* + * Class: Test + * Method: setup + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_Test_setup(JNIEnv *env, jclass cl) +{ + JNF_COCOA_ENTER(env); + + void (^block)() = ^(){ + NSScreen *mainScreen = [NSScreen mainScreen]; + NSRect screenFrame = [mainScreen frame]; + NSRect frame = NSMakeRect(100, screenFrame.size.height - 350, 150, 150); + NSWindowStyleMask style = NSWindowStyleMaskTitled; + NSRect rect = [NSWindow contentRectForFrameRect:frame styleMask:style]; + NSBackingStoreType bt = NSBackingStoreBuffered; + testWindow = [[[NSWindow alloc] initWithContentRect:rect styleMask:style backing:bt defer:NO] retain]; + testWindow.title = @"NSWindow"; + [testWindow setBackgroundColor:[NSColor blueColor]]; + [testWindow makeKeyAndOrderFront:nil]; + // Java coordinates are 100, 200 + + colorPanel = [[NSColorPanel sharedColorPanel] retain]; + [colorPanel setReleasedWhenClosed: NO]; + [colorPanel makeKeyAndOrderFront: nil]; + [colorPanel setFrameTopLeftPoint: NSMakePoint(100, screenFrame.size.height - 400)]; + // Java coordinates are 100, 400 + }; + + if ([NSThread isMainThread]) { + block(); + } else { + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block]; + } + + JNF_COCOA_EXIT(env); +} + +/* + * Class: Test + * Method: takedown + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_Test_takedown(JNIEnv *env, jclass cl) +{ + JNF_COCOA_ENTER(env); + + void (^block)() = ^(){ + if (testWindow != nil) { + [testWindow close]; + testWindow = nil; + } + if (colorPanel != nil) { + [colorPanel close]; + colorPanel = nil; + } + }; + + if ([NSThread isMainThread]) { + block(); + } else { + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block]; + } + + JNF_COCOA_EXIT(env); +} + +/* + * Class: Test + * Method: activateApplication + * Signature: ()V + */ +JNIEXPORT void JNICALL Java_Test_activateApplication + (JNIEnv *env, jclass cl) +{ + JNF_COCOA_ENTER(env); + + void (^block)() = ^(){ + [NSApp activateIgnoringOtherApps:YES]; + }; + + [JNFRunLoop performOnMainThreadWaiting:YES withBlock:block]; + + JNF_COCOA_EXIT(env); +}