Skip to content

Commit 2e6f720

Browse files
committed
More testing
1 parent 40815df commit 2e6f720

14 files changed

+802
-12
lines changed

cmake/platforms/yup_emscripten.cmake

Whitespace-only changes.

cmake/platforms/yup_ios.cmake

Whitespace-only changes.

cmake/platforms/yup_linux.cmake

Whitespace-only changes.

cmake/platforms/yup_mac.cmake

Whitespace-only changes.

cmake/platforms/yup_uwp.cmake

Whitespace-only changes.

cmake/platforms/yup_windows.cmake

Whitespace-only changes.

cmake/yup.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ include (${CMAKE_CURRENT_LIST_DIR}/yup_modules.cmake)
9797
include (${CMAKE_CURRENT_LIST_DIR}/yup_standalone.cmake)
9898
include (${CMAKE_CURRENT_LIST_DIR}/yup_audio_plugin.cmake)
9999
include (${CMAKE_CURRENT_LIST_DIR}/yup_embed_binary.cmake)
100-
include (${CMAKE_CURRENT_LIST_DIR}/yup_android_java.cmake)
101100
include (${CMAKE_CURRENT_LIST_DIR}/yup_python.cmake)
102101

103102
# Platform specific includes

tests/yup_core/yup_ChildProcess.cpp

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,120 @@ TEST (ChildProcessTests, ReadAllProcesOutput)
5858
EXPECT_TRUE (output.isNotEmpty());
5959
#endif
6060
}
61+
62+
TEST (ChildProcessTests, StartWithEnvironment)
63+
{
64+
#if YUP_WINDOWS || YUP_MAC || YUP_LINUX || YUP_BSD
65+
ChildProcess p;
66+
StringPairArray env;
67+
env.set ("YUP_TEST_VAR", "test_value");
68+
env.set ("PATH", SystemStats::getEnvironmentVariable ("PATH", ""));
69+
70+
#if YUP_WINDOWS
71+
EXPECT_TRUE (p.start ("cmd /c echo %YUP_TEST_VAR%", env));
72+
#else
73+
EXPECT_TRUE (p.start ("printenv YUP_TEST_VAR", env));
74+
#endif
75+
76+
auto output = p.readAllProcessOutput().trim();
77+
EXPECT_TRUE (output.contains ("test_value"));
78+
#endif
79+
}
80+
81+
TEST (ChildProcessTests, IsRunning)
82+
{
83+
#if YUP_WINDOWS || YUP_MAC || YUP_LINUX || YUP_BSD
84+
ChildProcess p;
85+
86+
#if YUP_WINDOWS
87+
EXPECT_TRUE (p.start ("cmd /c timeout /t 1"));
88+
#else
89+
EXPECT_TRUE (p.start ("sleep 1"));
90+
#endif
91+
92+
// Should be running initially
93+
EXPECT_TRUE (p.isRunning());
94+
95+
// Wait for completion
96+
p.waitForProcessToFinish (2000);
97+
98+
// Should not be running after completion
99+
EXPECT_FALSE (p.isRunning());
100+
#endif
101+
}
102+
103+
TEST (ChildProcessTests, Kill)
104+
{
105+
#if YUP_WINDOWS || YUP_MAC || YUP_LINUX || YUP_BSD
106+
ChildProcess p;
107+
108+
#if YUP_WINDOWS
109+
EXPECT_TRUE (p.start ("cmd /c timeout /t 30"));
110+
#else
111+
EXPECT_TRUE (p.start ("sleep 30"));
112+
#endif
113+
114+
EXPECT_TRUE (p.isRunning());
115+
116+
// Kill the process
117+
EXPECT_TRUE (p.kill());
118+
119+
// Give it a moment to terminate
120+
Thread::sleep (100);
121+
122+
// Should not be running after kill
123+
EXPECT_FALSE (p.isRunning());
124+
#endif
125+
}
126+
127+
TEST (ChildProcessTests, GetExitCode)
128+
{
129+
#if YUP_WINDOWS || YUP_MAC || YUP_LINUX || YUP_BSD
130+
ChildProcess p;
131+
132+
#if YUP_WINDOWS
133+
EXPECT_TRUE (p.start ("cmd /c exit 42"));
134+
p.waitForProcessToFinish (1000);
135+
auto exitCode = p.getExitCode();
136+
EXPECT_EQ (exitCode, 42);
137+
#else
138+
// On POSIX, use 'true' command which exits with 0
139+
EXPECT_TRUE (p.start ("true"));
140+
p.waitForProcessToFinish (1000);
141+
auto exitCode = p.getExitCode();
142+
EXPECT_EQ (exitCode, 0);
143+
144+
// Test non-zero exit using 'false' command which exits with 1
145+
ChildProcess p2;
146+
EXPECT_TRUE (p2.start ("false"));
147+
p2.waitForProcessToFinish (1000);
148+
EXPECT_EQ (p2.getExitCode(), 1);
149+
#endif
150+
#endif
151+
}
152+
153+
TEST (ChildProcessTests, StartWithStringArray)
154+
{
155+
#if YUP_WINDOWS || YUP_MAC || YUP_LINUX || YUP_BSD
156+
ChildProcess p;
157+
StringArray args;
158+
159+
#if YUP_WINDOWS
160+
args.add ("cmd");
161+
args.add ("/c");
162+
args.add ("echo");
163+
args.add ("test");
164+
#else
165+
args.add ("echo");
166+
args.add ("test");
167+
#endif
168+
169+
EXPECT_TRUE (p.start (args));
170+
171+
auto output = p.readAllProcessOutput().trim();
172+
EXPECT_TRUE (output.contains ("test"));
173+
#endif
174+
}
175+
176+
// Note: yup_runSystemCommand and yup_getOutputFromCommand are internal POSIX functions
177+
// not exposed in the public API. They are tested indirectly through ChildProcess and File operations.
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - [email protected]
6+
7+
YUP is an open source library subject to open-source licensing.
8+
9+
The code included in this file is provided under the terms of the ISC license
10+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
11+
to use, copy, modify, and/or distribute this software for any purpose with or
12+
without fee is hereby granted provided that the above copyright notice and
13+
this permission notice appear in all copies.
14+
15+
YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
16+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
17+
DISCLAIMED.
18+
19+
==============================================================================
20+
*/
21+
22+
#include <gtest/gtest.h>
23+
24+
#include <yup_core/yup_core.h>
25+
26+
using namespace yup;
27+
28+
#if ! YUP_WASM
29+
30+
TEST (DynamicLibraryTests, OpenSystemLibrary)
31+
{
32+
DynamicLibrary lib;
33+
34+
// Try to open a system library
35+
#if YUP_MAC || YUP_IOS
36+
EXPECT_TRUE (lib.open ("/usr/lib/libSystem.dylib"));
37+
#elif YUP_LINUX || YUP_ANDROID
38+
EXPECT_TRUE (lib.open ("libc.so.6") || lib.open ("libc.so"));
39+
#elif YUP_WINDOWS
40+
EXPECT_TRUE (lib.open ("kernel32.dll"));
41+
#endif
42+
}
43+
44+
TEST (DynamicLibraryTests, OpenNonExistent)
45+
{
46+
DynamicLibrary lib;
47+
48+
// Should fail to open non-existent library
49+
EXPECT_FALSE (lib.open ("/nonexistent/library.so"));
50+
}
51+
52+
TEST (DynamicLibraryTests, Close)
53+
{
54+
DynamicLibrary lib;
55+
56+
// Close without opening should not crash
57+
EXPECT_NO_THROW (lib.close());
58+
59+
#if YUP_MAC || YUP_IOS
60+
lib.open ("/usr/lib/libSystem.dylib");
61+
#elif YUP_LINUX || YUP_ANDROID
62+
lib.open ("libc.so.6");
63+
#endif
64+
65+
// Close after opening
66+
EXPECT_NO_THROW (lib.close());
67+
68+
// Close again should not crash
69+
EXPECT_NO_THROW (lib.close());
70+
}
71+
72+
TEST (DynamicLibraryTests, GetFunction)
73+
{
74+
DynamicLibrary lib;
75+
76+
// Getting function from unopened library should return nullptr
77+
EXPECT_EQ (lib.getFunction ("some_function"), nullptr);
78+
79+
#if YUP_MAC || YUP_IOS
80+
if (lib.open ("/usr/lib/libSystem.dylib"))
81+
{
82+
// Try to get a known function
83+
auto func = lib.getFunction ("malloc");
84+
EXPECT_NE (func, nullptr);
85+
86+
// Try to get non-existent function
87+
func = lib.getFunction ("nonexistent_function_12345");
88+
EXPECT_EQ (func, nullptr);
89+
}
90+
#elif YUP_LINUX || YUP_ANDROID
91+
if (lib.open ("libc.so.6") || lib.open ("libc.so"))
92+
{
93+
// Try to get a known function
94+
auto func = lib.getFunction ("malloc");
95+
EXPECT_NE (func, nullptr);
96+
97+
// Try to get non-existent function
98+
func = lib.getFunction ("nonexistent_function_12345");
99+
EXPECT_EQ (func, nullptr);
100+
}
101+
#endif
102+
}
103+
104+
TEST (DynamicLibraryTests, ReopenAfterClose)
105+
{
106+
DynamicLibrary lib;
107+
108+
#if YUP_MAC || YUP_IOS
109+
EXPECT_TRUE (lib.open ("/usr/lib/libSystem.dylib"));
110+
lib.close();
111+
EXPECT_TRUE (lib.open ("/usr/lib/libSystem.dylib"));
112+
#elif YUP_LINUX || YUP_ANDROID
113+
if (lib.open ("libc.so.6") || lib.open ("libc.so"))
114+
{
115+
lib.close();
116+
EXPECT_TRUE (lib.open ("libc.so.6") || lib.open ("libc.so"));
117+
}
118+
#endif
119+
}
120+
121+
TEST (DynamicLibraryTests, OpenEmptyString)
122+
{
123+
DynamicLibrary lib;
124+
125+
// Opening with empty string loads current process symbols
126+
EXPECT_TRUE (lib.open (""));
127+
128+
// Should be able to get functions from current process
129+
auto func = lib.getFunction ("malloc");
130+
EXPECT_NE (func, nullptr);
131+
}
132+
133+
#endif // ! YUP_WASM

0 commit comments

Comments
 (0)