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

Unified Diff: tools/gn/visual_studio_writer_unittest.cc

Issue 1570113002: Visual Studio generators for GN (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests failing on non-Windows platforms 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 side-by-side diff with in-line comments
Download patch
Index: tools/gn/visual_studio_writer_unittest.cc
diff --git a/tools/gn/visual_studio_writer_unittest.cc b/tools/gn/visual_studio_writer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e7fe6def0a070071953fb3ee284fd926a57d804b
--- /dev/null
+++ b/tools/gn/visual_studio_writer_unittest.cc
@@ -0,0 +1,152 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "tools/gn/visual_studio_writer.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "tools/gn/test_with_scope.h"
+#include "tools/gn/visual_studio_utils.h"
+
+namespace {
+
+class VisualStudioWriterTest : public testing::Test {
+ protected:
+ TestWithScope setup_;
+};
+
+std::string MakeTestPath(const std::string& path) {
+#if defined(OS_WIN)
+ return "C:" + path;
+#else
+ return path;
+#endif
+}
+
+} // namespace
+
+TEST_F(VisualStudioWriterTest, ResolveSolutionFolders) {
+ VisualStudioWriter writer(setup_.build_settings());
+
+ std::string path =
+ MakeTestPath("/foo/chromium/src/out/Debug/obj/base/base.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "base", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path =
+ MakeTestPath("/foo/chromium/src/base");
+
+ path = MakeTestPath("/foo/chromium/src/out/Debug/obj/tools/gn/gn.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "gn", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path =
+ MakeTestPath("/foo/chromium/src/tools/gn");
+
+ path = MakeTestPath("/foo/chromium/src/out/Debug/obj/chrome/chrome.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "chrome", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path =
+ MakeTestPath("/foo/chromium/src/chrome");
+
+ path = MakeTestPath("/foo/chromium/src/out/Debug/obj/base/bar.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "bar", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path =
+ MakeTestPath("/foo/chromium/src/base");
+
+ writer.ResolveSolutionFolders();
+
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src"), writer.root_folder_path_);
+
+ ASSERT_EQ(4u, writer.folders_.size());
+
+ ASSERT_EQ("base", writer.folders_[0]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/base"), writer.folders_[0]->path);
+ ASSERT_EQ(nullptr, writer.folders_[0]->parent_folder);
+
+ ASSERT_EQ("chrome", writer.folders_[1]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/chrome"), writer.folders_[1]->path);
+ ASSERT_EQ(nullptr, writer.folders_[1]->parent_folder);
+
+ ASSERT_EQ("tools", writer.folders_[2]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/tools"), writer.folders_[2]->path);
+ ASSERT_EQ(nullptr, writer.folders_[2]->parent_folder);
+
+ ASSERT_EQ("gn", writer.folders_[3]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/tools/gn"),
+ writer.folders_[3]->path);
+ ASSERT_EQ(writer.folders_[2], writer.folders_[3]->parent_folder);
+
+ ASSERT_EQ(writer.folders_[0], writer.projects_[0]->parent_folder);
+ ASSERT_EQ(writer.folders_[3], writer.projects_[1]->parent_folder);
+ ASSERT_EQ(writer.folders_[1], writer.projects_[2]->parent_folder);
+ ASSERT_EQ(writer.folders_[0], writer.projects_[3]->parent_folder);
+}
+
+TEST_F(VisualStudioWriterTest, ResolveSolutionFolders_AbsPath) {
+ VisualStudioWriter writer(setup_.build_settings());
+
+ std::string path =
+ MakeTestPath("/foo/chromium/src/out/Debug/obj/base/base.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "base", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path =
+ MakeTestPath("/foo/chromium/src/base");
+
+ path = MakeTestPath("/foo/chromium/src/out/Debug/obj/tools/gn/gn.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "gn", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path =
+ MakeTestPath("/foo/chromium/src/tools/gn");
+
+ path = MakeTestPath(
+ "/foo/chromium/src/out/Debug/obj/ABS_PATH/C/foo/bar/bar.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "bar", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path = MakeTestPath("/foo/bar");
+
+ path = MakeTestPath(
+ "/foo/chromium/src/out/Debug/obj/ABS_PATH/C/foo/bar/baz/baz.vcxproj");
+ writer.projects_.push_back(new VisualStudioWriter::SolutionEntry(
+ "baz", path, MakeGuid(path, "project")));
+ writer.projects_.back()->label_dir_path = MakeTestPath("/foo/bar/baz");
+
+ writer.ResolveSolutionFolders();
+
+ ASSERT_EQ(MakeTestPath("/foo"), writer.root_folder_path_);
+
+ ASSERT_EQ(7u, writer.folders_.size());
+
+ ASSERT_EQ("bar", writer.folders_[0]->name);
+ ASSERT_EQ(MakeTestPath("/foo/bar"), writer.folders_[0]->path);
+ ASSERT_EQ(nullptr, writer.folders_[0]->parent_folder);
+
+ ASSERT_EQ("baz", writer.folders_[1]->name);
+ ASSERT_EQ(MakeTestPath("/foo/bar/baz"), writer.folders_[1]->path);
+ ASSERT_EQ(writer.folders_[0], writer.folders_[1]->parent_folder);
+
+ ASSERT_EQ("chromium", writer.folders_[2]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium"), writer.folders_[2]->path);
+ ASSERT_EQ(nullptr, writer.folders_[2]->parent_folder);
+
+ ASSERT_EQ("src", writer.folders_[3]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src"), writer.folders_[3]->path);
+ ASSERT_EQ(writer.folders_[2], writer.folders_[3]->parent_folder);
+
+ ASSERT_EQ("base", writer.folders_[4]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/base"), writer.folders_[4]->path);
+ ASSERT_EQ(writer.folders_[3], writer.folders_[4]->parent_folder);
+
+ ASSERT_EQ("tools", writer.folders_[5]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/tools"), writer.folders_[5]->path);
+ ASSERT_EQ(writer.folders_[3], writer.folders_[5]->parent_folder);
+
+ ASSERT_EQ("gn", writer.folders_[6]->name);
+ ASSERT_EQ(MakeTestPath("/foo/chromium/src/tools/gn"),
+ writer.folders_[6]->path);
+ ASSERT_EQ(writer.folders_[5], writer.folders_[6]->parent_folder);
+
+ ASSERT_EQ(writer.folders_[4], writer.projects_[0]->parent_folder);
+ ASSERT_EQ(writer.folders_[6], writer.projects_[1]->parent_folder);
+ ASSERT_EQ(writer.folders_[0], writer.projects_[2]->parent_folder);
+ ASSERT_EQ(writer.folders_[1], writer.projects_[3]->parent_folder);
+}

Powered by Google App Engine
This is Rietveld 408576698