Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: tools/gn/function_write_file_unittest.cc

Issue 1549203002: Switch to standard integer types in tools/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gn/function_write_file.cc ('k') | tools/gn/functions.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h>
6
5 #include "base/files/file.h" 7 #include "base/files/file.h"
6 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
7 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
8 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
9 #include "tools/gn/functions.h" 11 #include "tools/gn/functions.h"
10 #include "tools/gn/scheduler.h" 12 #include "tools/gn/scheduler.h"
11 #include "tools/gn/test_with_scope.h" 13 #include "tools/gn/test_with_scope.h"
12 14
13 namespace { 15 namespace {
14 16
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_string)); 54 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_string));
53 base::FilePath foo_name = temp_dir.path().Append(FILE_PATH_LITERAL("out")) 55 base::FilePath foo_name = temp_dir.path().Append(FILE_PATH_LITERAL("out"))
54 .Append(FILE_PATH_LITERAL("foo.txt")); 56 .Append(FILE_PATH_LITERAL("foo.txt"));
55 std::string result_contents; 57 std::string result_contents;
56 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents)); 58 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents));
57 EXPECT_EQ(some_string.string_value(), result_contents); 59 EXPECT_EQ(some_string.string_value(), result_contents);
58 60
59 // Update the contents with a list of a string and a number. 61 // Update the contents with a list of a string and a number.
60 Value some_list(nullptr, Value::LIST); 62 Value some_list(nullptr, Value::LIST);
61 some_list.list_value().push_back(Value(nullptr, "line 1")); 63 some_list.list_value().push_back(Value(nullptr, "line 1"));
62 some_list.list_value().push_back(Value(nullptr, static_cast<int64>(2))); 64 some_list.list_value().push_back(Value(nullptr, static_cast<int64_t>(2)));
63 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); 65 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list));
64 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents)); 66 EXPECT_TRUE(base::ReadFileToString(foo_name, &result_contents));
65 EXPECT_EQ("line 1\n2\n", result_contents); 67 EXPECT_EQ("line 1\n2\n", result_contents);
66 68
67 // Test that the file is not rewritten if the contents are not changed. 69 // Test that the file is not rewritten if the contents are not changed.
68 // Start by setting the modified time to something old to avoid clock 70 // Start by setting the modified time to something old to avoid clock
69 // resolution issues. 71 // resolution issues.
70 base::Time old_time = base::Time::Now() - base::TimeDelta::FromDays(1); 72 base::Time old_time = base::Time::Now() - base::TimeDelta::FromDays(1);
71 base::File foo_file(foo_name, 73 base::File foo_file(foo_name,
72 base::File::FLAG_OPEN | 74 base::File::FLAG_OPEN |
73 base::File::FLAG_READ | base::File::FLAG_WRITE); 75 base::File::FLAG_READ | base::File::FLAG_WRITE);
74 ASSERT_TRUE(foo_file.IsValid()); 76 ASSERT_TRUE(foo_file.IsValid());
75 foo_file.SetTimes(old_time, old_time); 77 foo_file.SetTimes(old_time, old_time);
76 78
77 // Read the current time to avoid timer resolution issues when comparing 79 // Read the current time to avoid timer resolution issues when comparing
78 // below. 80 // below.
79 base::File::Info original_info; 81 base::File::Info original_info;
80 foo_file.GetInfo(&original_info); 82 foo_file.GetInfo(&original_info);
81 83
82 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list)); 84 EXPECT_TRUE(CallWriteFile(setup.scope(), "//out/foo.txt", some_list));
83 85
84 // Verify that the last modified time is the same as before. 86 // Verify that the last modified time is the same as before.
85 base::File::Info new_info; 87 base::File::Info new_info;
86 foo_file.GetInfo(&new_info); 88 foo_file.GetInfo(&new_info);
87 EXPECT_EQ(original_info.last_modified, new_info.last_modified); 89 EXPECT_EQ(original_info.last_modified, new_info.last_modified);
88 } 90 }
OLDNEW
« no previous file with comments | « tools/gn/function_write_file.cc ('k') | tools/gn/functions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698