summaryrefslogtreecommitdiffstats
path: root/src/deps_log_test.cc
diff options
context:
space:
mode:
authorEvan Martin <martine@danga.com>2012-12-17 17:08:15 (GMT)
committerEvan Martin <martine@danga.com>2013-04-08 21:45:06 (GMT)
commitb6a9a1c8adbb444c2489d884f06e5bd39627c3e9 (patch)
tree61a7e8e06a57e1ef054a48e6febe061ac51635a5 /src/deps_log_test.cc
parent9f1852fa3c97197e1876f1d47ca45e66b5e6cd28 (diff)
downloadNinja-b6a9a1c8adbb444c2489d884f06e5bd39627c3e9.zip
Ninja-b6a9a1c8adbb444c2489d884f06e5bd39627c3e9.tar.gz
Ninja-b6a9a1c8adbb444c2489d884f06e5bd39627c3e9.tar.bz2
add DepsLog, a new data structure for dependency information
DepsLog is a compact serialization of dependency information. It can be used to replace depfiles for faster loading.
Diffstat (limited to 'src/deps_log_test.cc')
-rw-r--r--src/deps_log_test.cc63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/deps_log_test.cc b/src/deps_log_test.cc
new file mode 100644
index 0000000..540865b
--- /dev/null
+++ b/src/deps_log_test.cc
@@ -0,0 +1,63 @@
+// Copyright 2012 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "deps_log.h"
+
+#include "graph.h"
+#include "util.h"
+#include "test.h"
+
+namespace {
+
+const char kTestFilename[] = "DepsLogTest-tempfile";
+
+struct DepsLogTest : public testing::Test {
+ virtual void SetUp() {
+ // In case a crashing test left a stale file behind.
+ unlink(kTestFilename);
+ }
+ virtual void TearDown() {
+ //unlink(kTestFilename);
+ }
+};
+
+TEST_F(DepsLogTest, WriteRead) {
+ State state1;
+ DepsLog log1;
+ string err;
+ EXPECT_TRUE(log1.OpenForWrite(kTestFilename, &err));
+ ASSERT_EQ("", err);
+
+ vector<Node*> deps;
+ deps.push_back(state1.GetNode("foo.h"));
+ deps.push_back(state1.GetNode("bar.h"));
+ log1.RecordDeps(state1.GetNode("out.o"), 1, deps);
+
+ deps.clear();
+ deps.push_back(state1.GetNode("foo.h"));
+ deps.push_back(state1.GetNode("bar2.h"));
+ log1.RecordDeps(state1.GetNode("out2.o"), 2, deps);
+
+ log1.Close();
+
+ State state2;
+ DepsLog log2;
+ EXPECT_TRUE(log1.Load(kTestFilename, &state2, &err));
+ ASSERT_EQ("", err);
+ state2.Dump();
+
+ state2.GetNode("out2.o")->Dump();
+}
+
+} // anonymous namespace