1 // Copyright 2012 Google Inc. All Rights Reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
23 const char kTestFilename[] = "DepsLogTest-tempfile";
25 struct DepsLogTest : public testing::Test {
26 virtual void SetUp() {
27 // In case a crashing test left a stale file behind.
28 unlink(kTestFilename);
30 virtual void TearDown() {
31 //unlink(kTestFilename);
35 TEST_F(DepsLogTest, WriteRead) {
39 EXPECT_TRUE(log1.OpenForWrite(kTestFilename, &err));
44 deps.push_back(state1.GetNode("foo.h"));
45 deps.push_back(state1.GetNode("bar.h"));
46 log1.RecordDeps(state1.GetNode("out.o"), 1, deps);
49 deps.push_back(state1.GetNode("foo.h"));
50 deps.push_back(state1.GetNode("bar2.h"));
51 log1.RecordDeps(state1.GetNode("out2.o"), 2, deps);
58 EXPECT_TRUE(log2.Load(kTestFilename, &state2, &err));
61 ASSERT_EQ(log1.nodes().size(), log2.nodes().size());
62 for (int i = 0; i < (int)log1.nodes().size(); ++i) {
63 Node* node1 = log1.nodes()[i];
64 Node* node2 = log2.nodes()[i];
65 ASSERT_EQ(i, node1->id());
66 ASSERT_EQ(node1->id(), node2->id());
69 // log1 has no deps entries, as it was only used for writing.
70 // Manually check the entries in log2.
71 DepsLog::Deps* deps = log2.GetDeps(state2.GetNode("out.o"));
73 ASSERT_EQ(1, deps->mtime);
74 ASSERT_EQ(2, deps->node_count);
75 ASSERT_EQ("foo.h", deps->nodes[0]->path());
76 ASSERT_EQ("bar.h", deps->nodes[1]->path());
79 } // anonymous namespace