-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_native_subprocess.py
More file actions
108 lines (100 loc) · 3.26 KB
/
Copy pathtest_native_subprocess.py
File metadata and controls
108 lines (100 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"""
GUIと同じ環境でNativeStreamerWrapperをテストするスクリプト
subprocess を使用してクリーンな環境でテスト
"""
import subprocess
import sys
def run_test(test_name, code):
"""新しいPythonプロセスでテストを実行"""
print(f"\n[{test_name}]")
env = {"PYTHONIOENCODING": "utf-8"}
env.update(__import__("os").environ)
result = subprocess.run(
[sys.executable, "-c", code],
capture_output=True,
text=True,
cwd="F:\\ytdlpSpout",
env=env,
encoding="utf-8",
errors="replace"
)
print(result.stdout)
if result.stderr:
print("STDERR:", result.stderr)
return result.returncode == 0
# Test 1: DLL単体ロード
run_test("Test 1: DLL単体ロード", '''
import ctypes
import os
os.add_dll_directory("F:/ytdlpSpout/cpp/build/vs2022/bin/Release")
lib = ctypes.CDLL("F:/ytdlpSpout/cpp/build/vs2022/bin/Release/ytdlpspout.dll")
lib.ytdlpspout_version.restype = ctypes.c_char_p
print("SUCCESS: Version =", lib.ytdlpspout_version().decode())
''')
# Test 2: SpoutGL -> DLL
run_test("Test 2: SpoutGL後にDLLロード", '''
import SpoutGL
print("SpoutGL imported")
import ctypes
import os
os.add_dll_directory("F:/ytdlpSpout/cpp/build/vs2022/bin/Release")
try:
lib = ctypes.CDLL("F:/ytdlpSpout/cpp/build/vs2022/bin/Release/ytdlpspout.dll")
lib.ytdlpspout_version.restype = ctypes.c_char_p
print("SUCCESS: Version =", lib.ytdlpspout_version().decode())
except Exception as e:
print("FAILED:", e)
''')
# Test 3: DLL -> SpoutGL
run_test("Test 3: DLL後にSpoutGLロード", '''
import ctypes
import os
os.add_dll_directory("F:/ytdlpSpout/cpp/build/vs2022/bin/Release")
lib = ctypes.CDLL("F:/ytdlpSpout/cpp/build/vs2022/bin/Release/ytdlpspout.dll")
lib.ytdlpspout_version.restype = ctypes.c_char_p
print("DLL loaded: Version =", lib.ytdlpspout_version().decode())
import SpoutGL
print("SpoutGL imported after DLL - SUCCESS")
''')
# Test 4: SpoutSender作成 -> DLL
run_test("Test 4: SpoutSender作成後にDLLロード", '''
import SpoutGL
sender = SpoutGL.SpoutSender()
sender.setSenderName("TestSender")
print("SpoutSender created")
import ctypes
import os
os.add_dll_directory("F:/ytdlpSpout/cpp/build/vs2022/bin/Release")
try:
lib = ctypes.CDLL("F:/ytdlpSpout/cpp/build/vs2022/bin/Release/ytdlpspout.dll")
lib.ytdlpspout_version.restype = ctypes.c_char_p
print("SUCCESS: Version =", lib.ytdlpspout_version().decode())
except Exception as e:
print("FAILED:", e)
finally:
sender.releaseSender()
''')
# Test 5: YtdlpSpoutNative
run_test("Test 5: YtdlpSpoutNative初期化", '''
import sys
sys.path.insert(0, ".")
from python.ytdlpspout_native import YtdlpSpoutNative
native = YtdlpSpoutNative()
print("SUCCESS: Version =", native.version)
''')
# Test 6: SpoutGL + YtdlpSpoutNative
run_test("Test 6: SpoutGL + YtdlpSpoutNative", '''
import SpoutGL
print("SpoutGL imported")
import sys
sys.path.insert(0, ".")
try:
from python.ytdlpspout_native import YtdlpSpoutNative
native = YtdlpSpoutNative()
print("SUCCESS: Version =", native.version)
except Exception as e:
print("FAILED:", e)
''')
print("\n" + "=" * 60)
print("テスト完了")
print("=" * 60)