예제 #1
0
TEST_F(EndToEndTest, IExampleInterface) {
  FakeIoDelegate io_delegate;
  JavaOptions options;
  options.fail_on_parcelable_ = true;
  options.import_paths_.push_back("");
  options.input_file_name_ =
      CanonicalNameToPath(kIExampleInterfaceClass, ".aidl").value();
  options.output_file_name_for_deps_test_ =
      CanonicalNameToPath(kIExampleInterfaceClass, ".java").value();
  options.output_base_folder_ = outputDir_.value();
  options.dep_file_name_ = outputDir_.Append(FilePath("test.d")).value();

  // Load up our fake file system with data.
  io_delegate.SetFileContents(options.input_file_name_,
                              kIExampleInterfaceContents);
  io_delegate.AddCompoundParcelable("android.test.CompoundParcelable", 
                                    {"Subclass1", "Subclass2"});
  AddStubAidls(kIExampleInterfaceParcelables, kIExampleInterfaceInterfaces,
               &io_delegate);

  // Check that we parse correctly.
  EXPECT_EQ(android::aidl::compile_aidl_to_java(options, io_delegate), 0);
  CheckFileContents(CanonicalNameToPath(kIExampleInterfaceClass, ".java"),
                    kIExampleInterfaceJava);
  CheckFileContents(FilePath("test.d"), kIExampleInterfaceDeps);
}
void TestSave(const char *temp_data_path)
{
  ++gTotalTests;
  static const char kFilename[] = "test-save.xml";
  static const char kExpectedContents[] =
    "<response xmlns=\"http://www.mozilla.org/metrics\"><config>"
    "<collectors>"
      "<collector type=\"uielement\"/>"
    "</collectors>"
    "<limit events=\"300\"/>"
    "<upload interval=\"500\"/>"
    "</config></response>";

  nsMetricsConfig config;
  ASSERT_TRUE(config.Init());

  // The data file goes to the current directory
  config.SetEventEnabled(NS_LITERAL_STRING(NS_METRICS_NAMESPACE),
                         NS_LITERAL_STRING("uielement"), PR_TRUE);
  config.SetUploadInterval(500);
  config.SetEventLimit(300);

  nsCOMPtr<nsILocalFile> outFile;
  NS_NewNativeLocalFile(nsDependentCString(temp_data_path),
                        PR_TRUE, getter_AddRefs(outFile));
  ASSERT_TRUE(outFile);
  ASSERT_SUCCESS(outFile->AppendNative(nsDependentCString(kFilename)));

  ASSERT_SUCCESS(config.Save(outFile));
  ASSERT_TRUE(CheckFileContents(outFile, kExpectedContents));

  // Now test with no collectors
  static const char kExpectedOutputNoEvents[] =
    "<response xmlns=\"http://www.mozilla.org/metrics\"><config>"
    "<collectors/>"
    "<limit events=\"300\"/>"
    "<upload interval=\"500\"/>"
    "</config></response>";

  config.ClearEvents();
  ASSERT_SUCCESS(config.Save(outFile));
  ASSERT_TRUE(CheckFileContents(outFile, kExpectedOutputNoEvents));

  ++gPassedTests;
}