Skip to content

Commit 4eba77b

Browse files
committed
More test tweaks
1 parent 2e6f720 commit 4eba77b

File tree

5 files changed

+551
-7
lines changed

5 files changed

+551
-7
lines changed

tests/yup_core/yup_File.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,37 @@ TEST_F (FileTests, SpecialLocations)
7171
EXPECT_TRUE (File::getSpecialLocation (File::tempDirectory).isDirectory());
7272
}
7373

74+
TEST_F (FileTests, SpecialLocationComprehensive)
75+
{
76+
// Test all special locations mentioned in the requirements
77+
File userMusic = File::getSpecialLocation (File::userMusicDirectory);
78+
EXPECT_TRUE (userMusic.getFullPathName().isNotEmpty());
79+
80+
File userMovies = File::getSpecialLocation (File::userMoviesDirectory);
81+
EXPECT_TRUE (userMovies.getFullPathName().isNotEmpty());
82+
83+
File userPictures = File::getSpecialLocation (File::userPicturesDirectory);
84+
EXPECT_TRUE (userPictures.getFullPathName().isNotEmpty());
85+
86+
File userDesktop = File::getSpecialLocation (File::userDesktopDirectory);
87+
EXPECT_TRUE (userDesktop.isDirectory());
88+
89+
File commonDocuments = File::getSpecialLocation (File::commonDocumentsDirectory);
90+
EXPECT_TRUE (commonDocuments.getFullPathName().isNotEmpty());
91+
92+
File commonAppData = File::getSpecialLocation (File::commonApplicationDataDirectory);
93+
EXPECT_TRUE (commonAppData.getFullPathName().isNotEmpty());
94+
95+
File globalApps = File::getSpecialLocation (File::globalApplicationsDirectory);
96+
EXPECT_TRUE (globalApps.getFullPathName().isNotEmpty());
97+
98+
File tempDir = File::getSpecialLocation (File::tempDirectory);
99+
EXPECT_TRUE (tempDir.isDirectory());
100+
101+
File hostAppPath = File::getSpecialLocation (File::hostApplicationPath);
102+
EXPECT_TRUE (hostAppPath.getFullPathName().isNotEmpty());
103+
}
104+
74105
TEST_F (FileTests, RootDirectory)
75106
{
76107
#if ! YUP_WINDOWS
@@ -1075,3 +1106,23 @@ TEST_F (FileTests, FileOutputStreamFlush)
10751106
EXPECT_EQ (testFile.loadFileAsString(), "testdata");
10761107
}
10771108
#endif
1109+
1110+
TEST_F (FileTests, RevealToUser)
1111+
{
1112+
// Test File::revealToUser() - this method shows the file in the OS file browser
1113+
tempFolder.createDirectory();
1114+
File fileToReveal = tempFolder.getChildFile ("reveal_test.txt");
1115+
fileToReveal.replaceWithText ("Test content for reveal");
1116+
1117+
ASSERT_TRUE (fileToReveal.exists());
1118+
1119+
// revealToUser() doesn't return a value, just verify it doesn't crash
1120+
EXPECT_NO_THROW (fileToReveal.revealToUser());
1121+
1122+
// Also test with a directory
1123+
EXPECT_NO_THROW (tempFolder.revealToUser());
1124+
1125+
// Test with non-existent file (should not crash)
1126+
File nonExistent = tempFolder.getChildFile ("does_not_exist.txt");
1127+
EXPECT_NO_THROW (nonExistent.revealToUser());
1128+
}

tests/yup_core/yup_Process.cpp

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2025 - kunitoki@gmail.com
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+
class ProcessTests : public ::testing::Test
29+
{
30+
protected:
31+
void SetUp() override
32+
{
33+
testFile = File::getSpecialLocation (File::tempDirectory)
34+
.getChildFile ("YUP_ProcessTests_" + String::toHexString (Random::getSystemRandom().nextInt()))
35+
.getChildFile ("test_document.txt");
36+
37+
testFile.getParentDirectory().createDirectory();
38+
testFile.replaceWithText ("Test content for Process::openDocument");
39+
}
40+
41+
void TearDown() override
42+
{
43+
testFile.getParentDirectory().deleteRecursively();
44+
}
45+
46+
File testFile;
47+
};
48+
49+
TEST_F (ProcessTests, OpenDocumentWithFileName)
50+
{
51+
// Test Process::openDocument() with a file name
52+
// This attempts to open the file with the default application
53+
// It may fail if there's no default application or if running in CI
54+
55+
bool result = Process::openDocument (testFile.getFullPathName(), "");
56+
57+
// We don't assert the result because:
58+
// 1. It may fail in CI environments
59+
// 2. It requires a default application to be registered
60+
// 3. It's platform-dependent
61+
// Just verify it doesn't crash
62+
(void) result;
63+
}
64+
65+
TEST_F (ProcessTests, OpenDocumentWithUrl)
66+
{
67+
// Test opening a URL (this should be safer than opening a file)
68+
// Most systems have a default browser
69+
70+
// Use a safe, non-intrusive URL
71+
String testUrl = "about:blank";
72+
73+
bool result = Process::openDocument (testUrl, "");
74+
75+
// Again, don't assert the result for the same reasons as above
76+
(void) result;
77+
}
78+
79+
TEST_F (ProcessTests, OpenDocumentWithParameters)
80+
{
81+
// Test Process::openDocument() with parameters
82+
bool result = Process::openDocument (testFile.getFullPathName(), "--test-param");
83+
84+
// Don't assert success, just verify it doesn't crash
85+
(void) result;
86+
}
87+
88+
TEST_F (ProcessTests, OpenDocumentWithEnvironment)
89+
{
90+
// Test Process::openDocument() with custom environment variables
91+
StringPairArray environment;
92+
environment.set ("TEST_VAR", "test_value");
93+
94+
bool result = Process::openDocument (testFile.getFullPathName(), "", environment);
95+
96+
// Don't assert success, just verify it doesn't crash
97+
(void) result;
98+
}
99+
100+
TEST_F (ProcessTests, OpenDocumentWithEmptyPath)
101+
{
102+
// Test with empty path (should fail gracefully)
103+
bool result = Process::openDocument ("", "");
104+
105+
EXPECT_FALSE (result); // Empty path should fail
106+
}
107+
108+
TEST_F (ProcessTests, OpenDocumentWithNonExistentFile)
109+
{
110+
// Test with a file that doesn't exist
111+
File nonExistent = File::getSpecialLocation (File::tempDirectory)
112+
.getChildFile ("this_file_does_not_exist_12345.xyz");
113+
114+
bool result = Process::openDocument (nonExistent.getFullPathName(), "");
115+
116+
// Most systems will fail to open a non-existent file
117+
// but we don't assert because behavior is platform-dependent
118+
(void) result;
119+
}
120+
121+
TEST_F (ProcessTests, OpenDocumentWithSpecialCharacters)
122+
{
123+
// Create a file with special characters in the name
124+
File specialFile = testFile.getParentDirectory().getChildFile ("test file with spaces & special.txt");
125+
specialFile.replaceWithText ("Test content");
126+
127+
bool result = Process::openDocument (specialFile.getFullPathName(), "");
128+
129+
// Clean up
130+
specialFile.deleteFile();
131+
132+
// Don't assert success due to platform differences
133+
(void) result;
134+
}

tests/yup_core/yup_SystemStats.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
==============================================================================
33
44
This file is part of the YUP library.
5-
Copyright (c) 2024 - kunitoki@gmail.com
5+
Copyright (c) 2025 - kunitoki@gmail.com
66
77
YUP is an open source library subject to open-source licensing.
88
@@ -123,7 +123,7 @@ TEST (SystemStatsTests, GetEnvironmentVariables)
123123
EXPECT_GT (envVars.size(), 0);
124124
}
125125

126-
TEST (SystemStatsTests, DISABLED_UserAndComputerInfo)
126+
TEST (SystemStatsTests, UserAndComputerInfo)
127127
{
128128
String logonName = SystemStats::getLogonName();
129129
EXPECT_FALSE (logonName.isEmpty());
@@ -135,7 +135,7 @@ TEST (SystemStatsTests, DISABLED_UserAndComputerInfo)
135135
EXPECT_FALSE (computerName.isEmpty());
136136
}
137137

138-
TEST (SystemStatsTests, DISABLED_LocaleInfo)
138+
TEST (SystemStatsTests, LocaleInfo)
139139
{
140140
String userLanguage = SystemStats::getUserLanguage();
141141
EXPECT_FALSE (userLanguage.isEmpty());
@@ -150,7 +150,7 @@ TEST (SystemStatsTests, DISABLED_LocaleInfo)
150150
EXPECT_GE (displayLanguage.length(), 2);
151151
}
152152

153-
TEST (SystemStatsTests, DISABLED_DeviceInfo)
153+
TEST (SystemStatsTests, DeviceInfo)
154154
{
155155
String deviceDescription = SystemStats::getDeviceDescription();
156156
EXPECT_TRUE (deviceDescription.isNotEmpty());
@@ -176,7 +176,7 @@ TEST (SystemStatsTests, GetMachineIdentifiers)
176176
EXPECT_FALSE (identifiers.isEmpty());
177177
}
178178

179-
TEST (SystemStatsTests, DISABLED_CpuInfo)
179+
TEST (SystemStatsTests, CpuInfo)
180180
{
181181
int numCpus = SystemStats::getNumCpus();
182182
EXPECT_GT (numCpus, 0);

tests/yup_core/yup_Time.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,18 @@ TEST (TimeTests, GetCompilationDate)
311311

312312
TEST (TimeTests, DISABLED_SetSystemTimeToThisTime)
313313
{
314+
// This test is disabled as it requires elevated privileges and can disrupt the system
315+
// It may also fail or crash in CI environments
316+
// Manual testing should verify this functionality
317+
314318
Time now = Time::getCurrentTime();
315-
// This test may fail if the system does not have sufficient privileges
316-
EXPECT_TRUE (now.setSystemTimeToThisTime());
319+
320+
// Test would be: EXPECT_TRUE (now.setSystemTimeToThisTime());
321+
// But we keep it disabled to avoid system disruption
322+
323+
// Instead, just verify the method exists and can be called (will fail without privileges)
324+
bool result = now.setSystemTimeToThisTime();
325+
(void) result; // Suppress unused variable warning
317326
}
318327

319328
TEST (TimeTests, StockTests)

0 commit comments

Comments
 (0)