| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from unittest import mock |
| 19 |
import jpype |
| 20 |
import common |
| 21 |
from jpype.types import * |
| 22 |
|
| 23 |
|
| 24 |
class JCharTestCase(common.JPypeTestCase): |
| 25 |
def setUp(self): |
| 26 |
common.JPypeTestCase.setUp(self) |
| 27 |
|
| 28 |
def testShutdownHook(self): |
| 29 |
Thread = JClass("java.lang.Thread") |
| 30 |
Runnable = JClass("java.lang.Runnable") |
| 31 |
Runtime = JClass("java.lang.Runtime") |
| 32 |
@jpype.JImplements(Runnable) |
| 33 |
class Run: |
| 34 |
@jpype.JOverride |
| 35 |
def run(self): |
| 36 |
pass |
| 37 |
th = Thread(Run()) |
| 38 |
Runtime.getRuntime().addShutdownHook(th) |
| 39 |
self.assertTrue(Runtime.getRuntime().removeShutdownHook(th)) |
| 40 |
|
| 41 |
def testShutdownWrongThread(self): |
| 42 |
Thread = JClass("java.lang.Thread") |
| 43 |
Runnable = JClass("java.lang.Runnable") |
| 44 |
@jpype.JImplements(Runnable) |
| 45 |
class Run: |
| 46 |
def __init__(self): |
| 47 |
self.rc = False |
| 48 |
|
| 49 |
@jpype.JOverride |
| 50 |
def run(self): |
| 51 |
try: |
| 52 |
jpype.shutdownJVM() |
| 53 |
except: |
| 54 |
self.rc = True |
| 55 |
run = Run() |
| 56 |
th = Thread(run) |
| 57 |
th.start() |
| 58 |
th.join() |
| 59 |
self.assertTrue(run.rc) |