Fixed tests for macOS storage_apple.mm functions. #105000

Merged
Brecht Van Lommel merged 1 commits from CharlesWardlaw/blender:bugfix/apple_cwd_tests into main 2023-02-21 16:06:56 +01:00
2 changed files with 15 additions and 9 deletions

View File

@ -15,6 +15,7 @@
#include "BLI_path_util.h"
#include "BLI_string.h"
/* Extended file attribute used by OneDrive to mark placeholder files. */
static const char *ONEDRIVE_RECALLONOPEN_ATTRIBUTE = "com.microsoft.OneDrive.RecallOnOpen";
@ -187,8 +188,7 @@ const char *BLI_expand_tilde(const char *path_with_tilde)
return path_expanded;
}
char *BLI_current_working_dir(char *dir, const size_t maxncpy)
{
char *BLI_current_working_dir(char *dir, const size_t maxncpy) {
/* Can't just copy to the *dir pointer, as [path getCString gets grumpy.*/
static char path_expanded[PATH_MAX];
@autoreleasepool {
@ -200,15 +200,14 @@ char *BLI_current_working_dir(char *dir, const size_t maxncpy)
}
}
bool BLI_change_working_dir(const char *dir)
{
bool BLI_change_working_dir(const char* dir) {
@autoreleasepool {
NSString *path = [[NSString alloc] initWithUTF8String:dir];
if ([[NSFileManager defaultManager] changeCurrentDirectoryPath:path] == YES) {
return false;
NSString* path = [[NSString alloc] initWithUTF8String: dir];
if ([[NSFileManager defaultManager] changeCurrentDirectoryPath: path] == YES) {
return true;
}
else {
return true;
return false;
}
}
}

View File

@ -63,7 +63,7 @@ TEST_F(ChangeWorkingDirectoryTest, change_working_directory)
FAIL() << "unable to get the current working directory";
}
const std::string temp_file_name(std::tmpnam(nullptr));
std::string temp_file_name(std::tmpnam(nullptr));
test_temp_dir = temp_file_name + "овый";
if (BLI_exists(test_temp_dir.c_str())) {
@ -84,6 +84,13 @@ TEST_F(ChangeWorkingDirectoryTest, change_working_directory)
FAIL() << "unable to get the current working directory";
}
#ifdef __APPLE__
/* The name returned by std::tmpnam is fine but the Apple OS method
* picks the true var folder, not the alias, meaning the below
* comparison always fails unless we prepend with the correct value. */
test_temp_dir = "/private" + test_temp_dir;
#endif // #ifdef __APPLE__
ASSERT_EQ(BLI_path_cmp_normalized(cwd, test_temp_dir.c_str()), 0)
<< "the path of the current working directory should equal the path of the temporary "
"directory that was created.";