os_compat_android_unittest.cc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "base/os_compat_android.h"
  5. #include "base/files/file_util.h"
  6. #include "testing/gtest/include/gtest/gtest.h"
  7. namespace base {
  8. typedef testing::Test OsCompatAndroidTest;
  9. // Keep this Unittest DISABLED_ , because it actually creates a directory in the
  10. // device and it may be source of flakyness. For any changes in the mkdtemp
  11. // function, you should run this unittest in your local machine to check if it
  12. // passes.
  13. TEST_F(OsCompatAndroidTest, DISABLED_TestMkdTemp) {
  14. FilePath tmp_dir;
  15. EXPECT_TRUE(base::GetTempDir(&tmp_dir));
  16. // Not six XXXXXX at the suffix of the path.
  17. FilePath sub_dir = tmp_dir.Append("XX");
  18. std::string sub_dir_string = sub_dir.value();
  19. // this should be OK since mkdtemp just replaces characters in place
  20. char* buffer = const_cast<char*>(sub_dir_string.c_str());
  21. EXPECT_EQ(NULL, mkdtemp(buffer));
  22. // Directory does not exist
  23. char invalid_path2[] = "doesntoexist/foobarXXXXXX";
  24. EXPECT_EQ(NULL, mkdtemp(invalid_path2));
  25. // Successfully create a tmp dir.
  26. FilePath sub_dir2 = tmp_dir.Append("XXXXXX");
  27. std::string sub_dir2_string = sub_dir2.value();
  28. // this should be OK since mkdtemp just replaces characters in place
  29. char* buffer2 = const_cast<char*>(sub_dir2_string.c_str());
  30. EXPECT_TRUE(mkdtemp(buffer2) != NULL);
  31. }
  32. } // namespace base