15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/os_compat_android.h" 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/file_util.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)typedef testing::Test OsCompatAndroidTest; 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Keep this Unittest DISABLED_ , because it actually creates a directory in the 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// device and it may be source of flakyness. For any changes in the mkdtemp 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// function, you should run this unittest in your local machine to check if it 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// passes. 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(OsCompatAndroidTest, DISABLED_TestMkdTemp) { 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FilePath tmp_dir; 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_TRUE(base::GetTempDir(&tmp_dir)); 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Not six XXXXXX at the suffix of the path. 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FilePath sub_dir = tmp_dir.Append("XX"); 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string sub_dir_string = sub_dir.value(); 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this should be OK since mkdtemp just replaces characters in place 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char* buffer = const_cast<char*>(sub_dir_string.c_str()); 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(NULL, mkdtemp(buffer)); 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Directory does not exist 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char invalid_path2[] = "doesntoexist/foobarXXXXXX"; 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(NULL, mkdtemp(invalid_path2)); 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Successfully create a tmp dir. 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FilePath sub_dir2 = tmp_dir.Append("XXXXXX"); 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string sub_dir2_string = sub_dir2.value(); 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this should be OK since mkdtemp just replaces characters in place 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) char* buffer2 = const_cast<char*>(sub_dir2_string.c_str()); 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(mkdtemp(buffer2) != NULL); 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace base 42