[go: nahoru, domu]

blob: 37608dfdc477e9c043751ebaa74f472336ba3680 [file] [log] [blame]
Avi Drissmane4622aa2022-09-08 20:36:061// Copyright 2012 The Chromium Authors
felipeg@chromium.org4870fe562012-07-16 16:12:162// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/os_compat_android.h"
6
brettw@chromium.orge3177dd52014-08-13 20:22:147#include "base/files/file_util.h"
felipeg@chromium.org4870fe562012-07-16 16:12:168#include "testing/gtest/include/gtest/gtest.h"
9
10namespace base {
11
12typedef testing::Test OsCompatAndroidTest;
13
14// Keep this Unittest DISABLED_ , because it actually creates a directory in the
15// device and it may be source of flakyness. For any changes in the mkdtemp
16// function, you should run this unittest in your local machine to check if it
17// passes.
18TEST_F(OsCompatAndroidTest, DISABLED_TestMkdTemp) {
19 FilePath tmp_dir;
brettw@chromium.orgfb4bcfa32013-12-02 18:55:4920 EXPECT_TRUE(base::GetTempDir(&tmp_dir));
felipeg@chromium.org4870fe562012-07-16 16:12:1621
22 // Not six XXXXXX at the suffix of the path.
23 FilePath sub_dir = tmp_dir.Append("XX");
24 std::string sub_dir_string = sub_dir.value();
25 // this should be OK since mkdtemp just replaces characters in place
26 char* buffer = const_cast<char*>(sub_dir_string.c_str());
27 EXPECT_EQ(NULL, mkdtemp(buffer));
28
29 // Directory does not exist
30 char invalid_path2[] = "doesntoexist/foobarXXXXXX";
31 EXPECT_EQ(NULL, mkdtemp(invalid_path2));
32
33 // Successfully create a tmp dir.
34 FilePath sub_dir2 = tmp_dir.Append("XXXXXX");
35 std::string sub_dir2_string = sub_dir2.value();
36 // this should be OK since mkdtemp just replaces characters in place
37 char* buffer2 = const_cast<char*>(sub_dir2_string.c_str());
38 EXPECT_TRUE(mkdtemp(buffer2) != NULL);
39}
40
41} // namespace base