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/aidl_unittest.cpp b/aidl_unittest.cpp
index f9165c5..69f1091 100644
--- a/aidl_unittest.cpp
+++ b/aidl_unittest.cpp
@@ -220,11 +220,13 @@
   io_delegate_.SetFileContents("one/IBar.aidl", "package one; import p.Outer;"
                                                 "interface IBar {}");
 
-  Options options;
-  options.output_file_ = "preprocessed";
-  options.input_files_.resize(2);
-  options.input_files_[0] = "p/Outer.aidl";
-  options.input_files_[1] = "one/IBar.aidl";
+  vector<string> args {
+    "aidl",
+    "--preprocess",
+    "preprocessed",
+    "p/Outer.aidl",
+    "one/IBar.aidl"};
+  Options options = Options::From(args);
   EXPECT_TRUE(::android::aidl::preprocess_aidl(options, io_delegate_));
 
   string output;
@@ -258,13 +260,13 @@
 }
 
 TEST_F(AidlTest, FailOnParcelable) {
-  Options options;
-  options.input_files_.push_back("p/IFoo.aidl");
-  io_delegate_.SetFileContents(options.input_files_.front(), "package p; parcelable IFoo;");
+  Options options1 = Options::From("aidl p/IFoo.aidl");
+  io_delegate_.SetFileContents(options1.InputFiles().front(), "package p; parcelable IFoo;");
   // By default, we shouldn't fail on parcelable.
-  EXPECT_EQ(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
-  options.fail_on_parcelable_ = true;
-  EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
+  EXPECT_EQ(0, ::android::aidl::compile_aidl_to_java(options1, io_delegate_));
+
+  Options options2 = Options::From("aidl -b p/IFoo.aidl");
+  EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options2, io_delegate_));
 }
 
 TEST_F(AidlTest, FailOnDuplicateConstantNames) {
@@ -408,14 +410,16 @@
   // While the in tree build system always gives us an output file name,
   // other android tools take advantage of our ability to infer the intended
   // file name.  This test makes sure we handle this correctly.
-  Options options;
-  options.input_files_.push_back("p/IFoo.aidl");
-  options.output_dir_ = "place/for/output";
-  options.dependency_file_ = "dep/file/path";
-  io_delegate_.SetFileContents(options.input_files_.front(), "package p; interface IFoo {}");
+  vector<string> args = {
+    "aidl",
+    "-d dep/file/path",
+    "-o place/for/output",
+    "p/IFoo.aidl"};
+  Options options = Options::From(args);
+  io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}");
   EXPECT_EQ(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
   string actual_dep_file_contents;
-  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.dependency_file_, &actual_dep_file_contents));
+  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents));
   EXPECT_EQ(actual_dep_file_contents, kExpectedDepFileContents);
 }
 
@@ -423,15 +427,17 @@
   // While the in tree build system always gives us an output file name,
   // other android tools take advantage of our ability to infer the intended
   // file name.  This test makes sure we handle this correctly.
-  Options options;
-  options.input_files_.push_back("p/IFoo.aidl");
-  options.output_dir_ = "place/for/output";
-  options.dependency_file_ = "dep/file/path";
-  options.dependency_file_ninja_ = true;
-  io_delegate_.SetFileContents(options.input_files_.front(), "package p; interface IFoo {}");
+  vector<string> args = {
+    "aidl",
+    "-d dep/file/path",
+    "--ninja",
+    "-o place/for/output",
+    "p/IFoo.aidl"};
+  Options options = Options::From(args);
+  io_delegate_.SetFileContents(options.InputFiles().front(), "package p; interface IFoo {}");
   EXPECT_EQ(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
   string actual_dep_file_contents;
-  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.dependency_file_, &actual_dep_file_contents));
+  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents));
   EXPECT_EQ(actual_dep_file_contents, kExpectedNinjaDepFileContents);
 }
 
@@ -441,14 +447,16 @@
   // generated dependency files.  Those that reference .java output files are
   // for interfaces and those that do not are parcelables.  However, for both
   // parcelables and interfaces, we *must* generate a non-empty dependency file.
-  Options options;
-  options.input_files_.push_back("p/Foo.aidl");
-  options.output_dir_ = "place/for/output";
-  options.dependency_file_ = "dep/file/path";
-  io_delegate_.SetFileContents(options.input_files_.front(), "package p; parcelable Foo;");
+  vector<string> args = {
+    "aidl",
+    "-o place/for/output",
+    "-d dep/file/path",
+    "p/Foo.aidl"};
+  Options options = Options::From(args);
+  io_delegate_.SetFileContents(options.InputFiles().front(), "package p; parcelable Foo;");
   EXPECT_EQ(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
   string actual_dep_file_contents;
-  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.dependency_file_, &actual_dep_file_contents));
+  EXPECT_TRUE(io_delegate_.GetWrittenContents(options.DependencyFile(), &actual_dep_file_contents));
   EXPECT_EQ(actual_dep_file_contents, kExpectedParcelableDepFileContents);
 }
 
@@ -487,9 +495,13 @@
                                "   List<foo.bar.IFoo> b;\n"
                                "}\n");
   io_delegate_.SetFileContents("api.aidl", "");
-  Options options;
-  options.input_files_ = {"foo/bar/IFoo.aidl", "foo/bar/Data.aidl"};
-  options.output_file_ = "api.aidl";
+  vector<string> args = {
+    "aidl",
+    "--dumpapi",
+    "api.aidl",
+    "foo/bar/IFoo.aidl",
+    "foo/bar/Data.aidl"};
+  Options options = Options::From(args);
   bool result = dump_api(options, io_delegate_);
   ASSERT_TRUE(result);
   string actual;
@@ -515,30 +527,27 @@
 }
 
 TEST_F(AidlTest, CheckNumGenericTypeSecifier) {
-  Options options;
-  options.input_files_ = {"p/IFoo.aidl"};
-  options.output_file_ = "IFoo.java";
-  io_delegate_.SetFileContents(options.input_files_.at(0),
+  Options options = Options::From("aidl p/IFoo.aidl IFoo.java");
+  io_delegate_.SetFileContents(options.InputFiles().front(),
                                "package p; interface IFoo {"
                                "void foo(List<String, String> a);}");
   EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
 
-  io_delegate_.SetFileContents(options.input_files_.at(0),
+  io_delegate_.SetFileContents(options.InputFiles().front(),
                                "package p; interface IFoo {"
                                "void foo(Map<String> a);}");
   EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
 
-  options.input_files_ = {"p/Data.aidl"};
-  options.output_file_ = "Data.java";
-  io_delegate_.SetFileContents(options.input_files_.at(0),
+  Options options2 = Options::From("aidl p/Data.aidl Data.java");
+  io_delegate_.SetFileContents(options2.InputFiles().front(),
                                "package p; parcelable Data {"
                                "List<String, String> foo;}");
-  EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
+  EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options2, io_delegate_));
 
-  io_delegate_.SetFileContents(options.input_files_.at(0),
+  io_delegate_.SetFileContents(options2.InputFiles().front(),
                                "package p; parcelable Data {"
                                "Map<String> foo;}");
-  EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options, io_delegate_));
+  EXPECT_NE(0, ::android::aidl::compile_aidl_to_java(options2, io_delegate_));
 }
 
 }  // namespace aidl