unittests are no longer friend of Options

Add factory methods to Options class so that an Options object can be
create from a cmdline string or a vector of argument string. All
unittests are modified to use the new factory methods and thus they are
removed from friends of the Options class.

Bug: 110967839
Test: m -j
Test: runtests.sh

Change-Id: Ic4765ce076c139f40c27d18494643cc5bf545f68
diff --git a/generate_cpp_unittest.cpp b/generate_cpp_unittest.cpp
index 20fce2f..f6836d2 100644
--- a/generate_cpp_unittest.cpp
+++ b/generate_cpp_unittest.cpp
@@ -1380,24 +1380,23 @@
 
 class ASTTest : public ::testing::Test {
  protected:
-  ASTTest(string file_path, string file_contents)
-      : file_path_(file_path),
-        file_contents_(file_contents) {
+  ASTTest(const string& cmdline, const string& file_contents)
+      : options_(Options::From(cmdline)), file_contents_(file_contents) {
     types_.Init();
   }
 
   unique_ptr<AidlInterface> ParseInterface() {
-    io_delegate_.SetFileContents(file_path_, file_contents_);
+    io_delegate_.SetFileContents(options_.InputFiles().at(0), file_contents_);
 
     unique_ptr<AidlDefinedType> ret;
     std::vector<std::unique_ptr<AidlImport>> imports;
     ImportResolver import_resolver{io_delegate_, {"."}, {}};
-    AidlError err =
-        ::android::aidl::internals::load_and_validate_aidl({},  // no preprocessed files
-                                                           import_resolver, file_path_,
-                                                           false,  // generate_traces
-                                                           false,  // is_structured
-                                                           io_delegate_, &types_, &ret, &imports);
+    AidlError err = ::android::aidl::internals::load_and_validate_aidl(
+        {},  // no preprocessed files
+        import_resolver, options_.InputFiles().front(),
+        false,  // generate_traces
+        false,  // is_structured
+        io_delegate_, &types_, &ret, &imports);
 
     if (err != AidlError::OK) {
       return nullptr;
@@ -1422,7 +1421,7 @@
     FAIL() << "Document contents did not match expected contents";
   }
 
-  const string file_path_;
+  const Options options_;
   const string file_contents_;
   FakeIoDelegate io_delegate_;
   TypeNamespace types_;
@@ -1431,7 +1430,7 @@
 class ComplexTypeInterfaceASTTest : public ASTTest {
  public:
   ComplexTypeInterfaceASTTest()
-      : ASTTest("android/os/IComplexTypeInterface.aidl",
+      : ASTTest("aidl --lang=cpp -o out android/os/IComplexTypeInterface.aidl",
                 kComplexTypeInterfaceAIDL) {
     io_delegate_.SetFileContents("foo/IFooType.aidl",
                                  "package foo; interface IFooType {}");
@@ -1503,34 +1502,20 @@
 const char kHeaderDir[] = "headers";
 const char kInterfaceHeaderRelPath[] = "a/IFoo.h";
 
+const string kCmdline = string("aidl-cpp ") + kInputPath + " " + kHeaderDir + " " + kOutputPath;
+
 }  // namespace test_io_handling
 
 class IoErrorHandlingTest : public ASTTest {
  public:
-  IoErrorHandlingTest ()
-      : ASTTest(test_io_handling::kInputPath,
-                "package a; interface IFoo {}"),
-        options_(GetOptions()) {}
-
-  const unique_ptr<Options> options_;
-
- private:
-  static unique_ptr<Options> GetOptions() {
-    using namespace test_io_handling;
-
-    const int argc = 4;
-    const char* cmdline[argc] = {
-      "aidl-cpp", kInputPath, kHeaderDir, kOutputPath
-    };
-    return unique_ptr<Options>(new Options(argc, cmdline, Options::Language::CPP));
-  }
+  IoErrorHandlingTest() : ASTTest(test_io_handling::kCmdline, "package a; interface IFoo {}") {}
 };
 
 TEST_F(IoErrorHandlingTest, GenerateCorrectlyAbsentErrors) {
   // Confirm that this is working correctly without I/O problems.
   const unique_ptr<AidlInterface> interface = ParseInterface();
   ASSERT_NE(interface, nullptr);
-  ASSERT_TRUE(GenerateCpp(options_->OutputFile(), *options_, types_, *interface, io_delegate_));
+  ASSERT_TRUE(GenerateCpp(options_.OutputFile(), options_, types_, *interface, io_delegate_));
 }
 
 TEST_F(IoErrorHandlingTest, HandlesBadHeaderWrite) {
@@ -1543,7 +1528,7 @@
       StringPrintf("%s%c%s", kHeaderDir, OS_PATH_SEPARATOR,
                    kInterfaceHeaderRelPath);
   io_delegate_.AddBrokenFilePath(header_path);
-  ASSERT_FALSE(GenerateCpp(options_->OutputFile(), *options_, types_, *interface, io_delegate_));
+  ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, types_, *interface, io_delegate_));
   // We should never attempt to write the C++ file if we fail writing headers.
   ASSERT_FALSE(io_delegate_.GetWrittenContents(kOutputPath, nullptr));
   // We should remove partial results.
@@ -1557,7 +1542,7 @@
 
   // Simulate issues closing the cpp file.
   io_delegate_.AddBrokenFilePath(kOutputPath);
-  ASSERT_FALSE(GenerateCpp(options_->OutputFile(), *options_, types_, *interface, io_delegate_));
+  ASSERT_FALSE(GenerateCpp(options_.OutputFile(), options_, types_, *interface, io_delegate_));
   // We should remove partial results.
   ASSERT_TRUE(io_delegate_.PathWasRemoved(kOutputPath));
 }