Ejemplo n.º 1
0
int main(int /*argc*/, char * /*argv*/[])
{
#ifdef CUBEB_GECKO_BUILD
  ScopedXPCOM xpcom("test_duplex");
#endif

  cubeb *ctx;
  cubeb_stream *stream;
  cubeb_stream_params input_params;
  cubeb_stream_params output_params;
  int r;
  user_state stream_state = { false };
  uint32_t latency_frames = 0;

  r = cubeb_init(&ctx, "Cubeb duplex example");
  if (r != CUBEB_OK) {
    fprintf(stderr, "Error initializing cubeb library\n");
    return r;
  }

  /* This test needs an available input device, skip it if this host does not
   * have one. */
  if (!has_available_input_device(ctx)) {
    return 0;
  }

  /* typical user-case: mono input, stereo output, low latency. */
  input_params.format = STREAM_FORMAT;
  input_params.rate = 48000;
  input_params.channels = 1;
  output_params.format = STREAM_FORMAT;
  output_params.rate = 48000;
  output_params.channels = 2;

  r = cubeb_get_min_latency(ctx, output_params, &latency_frames);

  if (r != CUBEB_OK) {
    fprintf(stderr, "Could not get minimal latency\n");
    return r;
  }

  r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
                        NULL, &input_params, NULL, &output_params,
                        latency_frames, data_cb, state_cb, &stream_state);
  if (r != CUBEB_OK) {
    fprintf(stderr, "Error initializing cubeb stream\n");
    return r;
  }

  cubeb_stream_start(stream);
  delay(500);
  cubeb_stream_stop(stream);

  cubeb_stream_destroy(stream);
  cubeb_destroy(ctx);

  assert(stream_state.seen_noise);

  return CUBEB_OK;
}
int main(int argc, char** argv)
{
  if (argc < 2)
  {
    fprintf(stderr, "not enough arguments -- need registration dir path\n");
    return 1;
  }

  ScopedLogging logging;
  
  const char *regPath = argv[1];
  XRE_AddManifestLocation(NS_COMPONENT_LOCATION,
                          nsCOMPtr<nsILocalFile>(GetRegDirectory(regPath, "core", "component.manifest")));
  XRE_AddManifestLocation(NS_COMPONENT_LOCATION,
                          nsCOMPtr<nsILocalFile>(GetRegDirectory(regPath, "extension", "extComponent.manifest")));
  XRE_AddJarManifestLocation(NS_COMPONENT_LOCATION,
                          nsCOMPtr<nsILocalFile>(GetRegDirectory(regPath, "extension2.jar", NULL)));
  ScopedXPCOM xpcom("RegistrationOrder");
  if (xpcom.failed())
    return 1;

  int rv = 0;
  if (NS_FAILED(TestRegular()))
    rv = 1;

  if (NS_FAILED(TestJar()))
    rv = 1;

  if (!TestContractFirst())
    rv = 1;

  return rv;
}
Ejemplo n.º 3
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("Base64");
  NS_ENSURE_FALSE(xpcom.failed(), 1);

  nsCOMPtr<nsIScriptableBase64Encoder> encoder =
    do_CreateInstance("@mozilla.org/scriptablebase64encoder;1");
  NS_ENSURE_TRUE(encoder, 1);

  nsRefPtr<FakeInputStream> stream = new FakeInputStream();
  do {
    nsString wideString;
    nsCString string;

    nsresult rv;
    rv = encoder->EncodeToString(stream, 0, wideString);
    NS_ENSURE_SUCCESS(rv, 1);

    stream->Reset();

    rv = encoder->EncodeToCString(stream, 0, string);
    NS_ENSURE_SUCCESS(rv, 1);

    if (!stream->CheckTest(wideString) || !stream->CheckTest(string))
      fail("Failed to convert properly\n");

  } while (stream->NextTest());

  return 0;
}
Ejemplo n.º 4
0
int main(int argc, char **argv)
{
  ScopedXPCOM xpcom("TestMimeCrash");
  if (xpcom.failed())
    return 1;

  // We cannot use malloc() since this crashes depends on memory allocation.
  // By using mmap()/PR_MemMap(), end of buffer that is last in the page
  // sets LF.

  PRUint32 bufsize = PR_GetPageSize();
  PRFileMap *fm = PR_OpenAnonFileMap(".", bufsize, PR_PROT_READWRITE);
  if (!fm)
    return 1;
  char *addr = (char *) PR_MemMap(fm, 0, bufsize);
  if (!addr)
    return 1;
  memset(addr, '\r', bufsize);

  nsresult rv = do_test(addr, bufsize);

  PR_MemUnmap(addr, bufsize);
  PR_CloseFileMap(fm);

  if (NS_FAILED(rv)) {
    fail("cannot use nsIMimeConverter error=%08x\n", rv);
    return -1;
  }

  passed("no crash");

  return 0;
}
Ejemplo n.º 5
0
int main(int argc, char** argv) {

  ScopedXPCOM xpcom("ContentSecurityPolicyParser");
  if (xpcom.failed()) {
    return 1;
  }

  if (NS_FAILED(TestDirectives()))                           { return 1; }
  if (NS_FAILED(TestKeywords()))                             { return 1; }
  if (NS_FAILED(TestIgnoreUpperLowerCasePolicies()))         { return 1; }
  if (NS_FAILED(TestIgnorePaths()))                          { return 1; }
  if (NS_FAILED(TestSimplePolicies()))                       { return 1; }
  if (NS_FAILED(TestPoliciesWithInvalidSrc()))               { return 1; }
  if (NS_FAILED(TestBadPolicies()))                          { return 1; }
  if (NS_FAILED(TestGoodGeneratedPolicies()))                { return 1; }
  if (NS_FAILED(TestBadGeneratedPolicies()))                 { return 1; }
  if (NS_FAILED(TestGoodGeneratedPoliciesForPathHandling())) { return 1; }
  if (NS_FAILED(TestBadGeneratedPoliciesForPathHandling()))  { return 1; }
  if (NS_FAILED(TestShorteningPolicies()))                   { return 1; }

#if RUN_OFFLINE_TESTS
  if (NS_FAILED(TestFuzzyPolicies()))                        { return 1; }
  if (NS_FAILED(TestFuzzyPoliciesIncDir()))                  { return 1; }
  if (NS_FAILED(TestFuzzyPoliciesIncDirLimASCII()))          { return 1; }
#endif

  return 0;
}
Ejemplo n.º 6
0
int main(int argc, char** argv) {
  ScopedXPCOM xpcom("TestRegion");
  if (xpcom.failed())
    return -1;
  if (!TestLargestRegion::Test())
    return -1;
  return 0;
}
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("");
  if (xpcom.failed())
    return 1;
  DoAttrValueTest();
  return 0;
}
Ejemplo n.º 8
0
int main (void) {
  ScopedXPCOM xpcom("TestDeque");
  NS_ENSURE_FALSE(xpcom.failed(), 1);

  _TestDeque test;
  int result = test.Test();
  TEST(result == 0, "All tests pass");
  return 0;
}
Ejemplo n.º 9
0
int
main(int argc, char** argv)
{
  // Prevents some log spew
  ScopedXPCOM xpcom("jsep_track_unittest");

  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}
Ejemplo n.º 10
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("ThreadUtils");
  NS_ENSURE_FALSE(xpcom.failed(), 1);

  memset(gRunnableExecuted, false, MAX_TESTS * sizeof(bool));
  // Scope the smart ptrs so that the runnables need to hold on to whatever they need
  {
    nsRefPtr<nsFoo> foo = new nsFoo();
    nsRefPtr<nsBar> bar = new nsBar();

    // This pointer will be freed at the end of the block
    // Do not dereference this pointer in the runnable method!
    nsFoo * rawFoo = new nsFoo();

    // Read only string. Dereferencing in runnable method to check this works.
    char* message = (char*)"Test message";

    NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar1));
    NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar2));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< nsRefPtr<nsFoo> >
      (bar, &nsBar::DoBar3, foo));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< nsRefPtr<nsFoo> >
      (bar, &nsBar::DoBar4, foo));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg<nsFoo*>(bar, &nsBar::DoBar5, rawFoo));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg<char*>(bar, &nsBar::DoBar6, message));
#ifdef HAVE_STDCALL
    NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar1std));
    NS_DispatchToMainThread(NS_NewRunnableMethod(bar, &nsBar::DoBar2std));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< nsRefPtr<nsFoo> >
      (bar, &nsBar::DoBar3std, foo));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg< nsRefPtr<nsFoo> >
      (bar, &nsBar::DoBar4std, foo));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg<nsFoo*>(bar, &nsBar::DoBar5std, rawFoo));
    NS_DispatchToMainThread(NS_NewRunnableMethodWithArg<char*>(bar, &nsBar::DoBar6std, message));
#endif

    delete rawFoo;
  }

  // Spin the event loop
  NS_ProcessPendingEvents(nullptr);

  int result = 0;

  for (uint32_t i = 0; i < MAX_TESTS; i++) {
    if (gRunnableExecuted[i]) {
      passed("Test %d passed",i);
    } else {
      fail("Error in test %d", i);
      result = 1;
    }
  }

  return result;
}
Ejemplo n.º 11
0
int main(int argc, char** argv)
{
  int rv = 0;
  ScopedXPCOM xpcom("jemalloc");
  if (xpcom.failed())
      return 1;

  if (NS_FAILED(TestJemallocUsableSizeInAdvance()))
    rv = 1;

  return rv;
}
Ejemplo n.º 12
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("PlainTextSerializer");
  if (xpcom.failed())
    return 1;

  int retval = 0;
  if (NS_FAILED(TestPlainTextSerializer())) {
    retval = 1;
  }

  return retval;
}
Ejemplo n.º 13
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("XMLHttpRequest");
  if (xpcom.failed())
    return 1;

  int retval = 0;
  if (NS_FAILED(TestNativeXMLHttpRequest())) {
    retval = 1;
  }

  return retval;
}
int main(int argc, char** argv)
{
    ScopedXPCOM xpcom("WinFileAttributes");
    if (xpcom.failed())
        return 1;

    int rv = 0;

    if(NS_FAILED(TestWinAttribs()))
        rv = 1;

    return rv;

}
Ejemplo n.º 15
0
int main(int argc, char** argv)
{
    ScopedXPCOM xpcom("NTFSPermissionsTests"); // name for tests being run
    if (xpcom.failed())
        return 1;

    int rv = 0;

    if(NS_FAILED(TestPermissions()))
        rv = 1;

    return rv;

}
Ejemplo n.º 16
0
int main(int argc, char * argv[])
{
#ifdef CUBEB_GECKO_BUILD
  ScopedXPCOM xpcom("test_latency");
#endif

  cubeb * ctx = NULL;
  int r;
  uint32_t max_channels;
  uint32_t preferred_rate;
  uint32_t latency_ms;

  LOG("latency_test start");
  r = cubeb_init(&ctx, "Cubeb audio test");
  assert(r == CUBEB_OK && "Cubeb init failed.");
  LOG("cubeb_init ok");

  r = cubeb_get_max_channel_count(ctx, &max_channels);
  assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
  if (r == CUBEB_OK) {
    assert(max_channels > 0 && "Invalid max channel count.");
    LOG("cubeb_get_max_channel_count ok");
  }

  r = cubeb_get_preferred_sample_rate(ctx, &preferred_rate);
  assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
  if (r == CUBEB_OK) {
    assert(preferred_rate > 0 && "Invalid preferred sample rate.");
    LOG("cubeb_get_preferred_sample_rate ok");
  }

  cubeb_stream_params params = {
    CUBEB_SAMPLE_FLOAT32NE,
    preferred_rate,
    max_channels
  };
  r = cubeb_get_min_latency(ctx, params, &latency_ms);
  assert(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
  if (r == CUBEB_OK) {
    assert(latency_ms > 0 && "Invalid minimal latency.");
    LOG("cubeb_get_min_latency ok");
  }

  cubeb_destroy(ctx);
  LOG("cubeb_destroy ok");
  return EXIT_SUCCESS;
}
Ejemplo n.º 17
0
int
main(int argc, char * argv[])
{
#ifdef CUBEB_GECKO_BUILD
  ScopedXPCOM xpcom("test_sanity");
#endif

  test_init_destroy_context();
  test_init_destroy_multiple_contexts();
  test_context_variables();
  test_init_destroy_stream();
  test_init_destroy_multiple_streams();
  test_configure_stream();
  test_basic_stream_operations();
  test_stream_position();

  /* Sometimes, when using WASAPI on windows 7 (vista and 8 are okay), and
   * calling Activate a lot on an AudioClient, 0x800700b7 is returned. This is
   * the HRESULT value for "Cannot create a file when that file already exists",
   * and is not documented as a possible return value for this call. Hence, we
   * try to limit the number of streams we create in this test. */
  if (!is_windows_7()) {
    test_init_destroy_multiple_contexts_and_streams();

    delay_callback = 0;
    test_init_start_stop_destroy_multiple_streams(0, 0);
    test_init_start_stop_destroy_multiple_streams(1, 0);
    test_init_start_stop_destroy_multiple_streams(0, 150);
    test_init_start_stop_destroy_multiple_streams(1, 150);
    delay_callback = 1;
    test_init_start_stop_destroy_multiple_streams(0, 0);
    test_init_start_stop_destroy_multiple_streams(1, 0);
    test_init_start_stop_destroy_multiple_streams(0, 150);
    test_init_start_stop_destroy_multiple_streams(1, 150);
  }
  delay_callback = 0;
  test_drain();
/*
  to implement:
  test_eos_during_prefill();
  test_stream_destroy_pending_drain();
*/
  printf("\n");

  return 0;
}
int
main(int argc, char** argv)
{
    ScopedXPCOM xpcom("Deadlock detector scalability (" __FILE__ ")");
    if (xpcom.failed())
        return 1;

    int rv = 0;

    // Uncomment these tests to run them.  Not expected to be common.

#ifndef DD_TEST1
    puts("Skipping not-requested LengthNDepChain() test");
#else
    if (NS_FAILED(LengthNDepChain(1 << 14))) // 16K
        rv = 1;
#endif

#ifndef DD_TEST2
    puts("Skipping not-requested OneLockNDeps() test");
#else
    // NB: Using a larger test size to stress our traversal logic.
    if (NS_FAILED(OneLockNDeps(1 << 17, 100))) // 131k
        rv = 1;
#endif

#ifndef DD_TEST3
    puts("Skipping not-requested MaxDepsNsq() test");
#else
    if (NS_FAILED(MaxDepsNsq(1 << 10, 10))) // 1k
        rv = 1;
#endif

#ifndef DD_TEST4
    puts("Skipping not-requested OneLockNDepsUsedSeveralTimes() test");
#else
    if (NS_FAILED(OneLockNDepsUsedSeveralTimes(1 << 17, 3))) // 131k
        rv = 1;
#endif

    size_t memory_used = mozilla::BlockingResourceBase::SizeOfDeadlockDetector(
        DeadlockDetectorMallocSizeOf);
    printf_stderr("Used %d bytes\n", (int)memory_used);

    return rv;
}
Ejemplo n.º 19
0
int main(int argc, char *argv[])
{
#ifdef CUBEB_GECKO_BUILD
  ScopedXPCOM xpcom("test_record");
#endif

  cubeb *ctx;
  cubeb_stream *stream;
  cubeb_stream_params params;
  int r;
  user_state stream_state = { false };

  r = cubeb_init(&ctx, "Cubeb record example");
  if (r != CUBEB_OK) {
    fprintf(stderr, "Error initializing cubeb library\n");
    return r;
  }

  /* This test needs an available input device, skip it if this host does not
   * have one. */
  if (!has_available_input_device(ctx)) {
    return 0;
  }

  params.format = STREAM_FORMAT;
  params.rate = SAMPLE_FREQUENCY;
  params.channels = 1;

  r = cubeb_stream_init(ctx, &stream, "Cubeb record (mono)", NULL, &params, NULL, nullptr,
                        250, data_cb, state_cb, &stream_state);
  if (r != CUBEB_OK) {
    fprintf(stderr, "Error initializing cubeb stream\n");
    return r;
  }

  cubeb_stream_start(stream);
  delay(500);
  cubeb_stream_stop(stream);

  cubeb_stream_destroy(stream);
  cubeb_destroy(ctx);

  assert(stream_state.seen_noise);

  return CUBEB_OK;
}
Ejemplo n.º 20
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("Test Windows Drag and Drop");

  nsCOMPtr<nsIFile> file;
  file = xpcom.GetProfileDirectory();
  xferFile = file;

  if (NS_SUCCEEDED(Do_Test1()))
    passed("Basic Drag and Drop data type tests (single transferable) succeeded!");

  if (NS_SUCCEEDED(Do_Test2()))
    passed("Basic Drag and Drop data type tests (multiple transferables) succeeded!");

//if (NS_SUCCEEDED(Do_Test3()))
//  passed("Advanced Drag and Drop data type tests succeeded!");

  return gFailCount;
}
Ejemplo n.º 21
0
int main(int argc, char** argv)
{
  if (argc <  2) {
    printf("Usage: TestGetURL <url>\n");
    exit(0);
  }

  ScopedXPCOM xpcom("XMLHttpRequest");
  if (xpcom.failed())
    return 1;

  nsAutoCString targetURL(argv[1]);

  int retval = 0;
  if (NS_FAILED(TestGetURL(targetURL))) {
    retval = 1;
  }

  return retval;
}
int main(int argc, char **argv)
{
  ScopedXPCOM xpcom("URLClassiferUtils");

  TestUnescape();
  TestEnc();
  TestCanonicalize();
  TestCanonicalNum();
  TestParseIPAddress();
  TestHostname();
  TestLongHostname();
  TestFragmentSet();

  if (gPassedTests == gTotalTests)
    passed(__FILE__);
  printf("%d of %d tests passed\n", gPassedTests, gTotalTests);
  // Non-zero return status signals test failure to build system.

  return (gPassedTests != gTotalTests);
}
Ejemplo n.º 23
0
int LibFuzzerRunner::Run(int* argc, char*** argv) {
  ScopedXPCOM xpcom("LibFuzzer");
  std::string moduleNameStr(getenv("LIBFUZZER"));
  LibFuzzerFunctions funcs = LibFuzzerRegistry::getInstance().getModuleFunctions(moduleNameStr);
  LibFuzzerInitFunc initFunc = funcs.first;
  LibFuzzerTestingFunc testingFunc = funcs.second;
  if (initFunc) {
    int ret = initFunc(argc, argv);
    if (ret) {
      fprintf(stderr, "LibFuzzer: Error: Initialize callback failed\n");
      return ret;
    }
  }

  if (!testingFunc) {
      fprintf(stderr, "LibFuzzer: Error: No testing callback found\n");
      return 1;
  }

  return mFuzzerDriver(argc, argv, testingFunc);
}
Ejemplo n.º 24
0
int main(int argc, char** argv)
{
    ScopedXPCOM xpcom("nsLocalFile");
    if (xpcom.failed())
        return 1;

    nsCOMPtr<nsIFile> base;
    nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(base));
    if (!VerifyResult(rv, "Getting temp directory"))
        return 1;
    rv = base->AppendNative(nsDependentCString("mozfiletests"));
    if (!VerifyResult(rv, "Appending mozfiletests to temp directory name"))
        return 1;
    // Remove the directory in case tests failed and left it behind.
    // don't check result since it might not be there
    base->Remove(true);

    // Now create the working directory we're going to use
    rv = base->Create(nsIFile::DIRECTORY_TYPE, 0700);
    if (!VerifyResult(rv, "Creating temp directory"))
        return 1;
    // Now we can safely normalize the path
    rv = base->Normalize();
    if (!VerifyResult(rv, "Normalizing temp directory name"))
        return 1;

    // Initialize subdir object for later use
    nsCOMPtr<nsIFile> subdir = NewFile(base);
    if (!subdir)
        return 1;
    rv = subdir->AppendNative(nsDependentCString("subdir"));
    if (!VerifyResult(rv, "Appending 'subdir' to test dir name"))
        return 1;

    passed("Setup");

    // Test path parsing
    if (TestInvalidFileName(base, "a/b")) {
        passed("AppendNative with invalid file name");
    }
    if (TestParent(base, subdir)) {
        passed("GetParent");
    }

    // Test file creation
    if (TestCreate(base, "file.txt", nsIFile::NORMAL_FILE_TYPE, 0600)) {
        passed("Create file");
    }
    if (TestRemove(base, "file.txt", false)) {
        passed("Remove file");
    }

    // Test directory creation
    if (TestCreate(base, "subdir", nsIFile::DIRECTORY_TYPE, 0700)) {
        passed("Create directory");
    }

    // Test move and copy in the base directory
    if (TestCreate(base, "file.txt", nsIFile::NORMAL_FILE_TYPE, 0600) &&
        TestMove(base, base, "file.txt", "file2.txt")) {
        passed("MoveTo rename file");
    }
    if (TestCopy(base, base, "file2.txt", "file3.txt")) {
        passed("CopyTo copy file");
    }
    // Test moving across directories
    if (TestMove(base, subdir, "file2.txt", "file2.txt")) {
        passed("MoveTo move file");
    }
    // Test moving across directories and renaming at the same time
    if (TestMove(subdir, base, "file2.txt", "file4.txt")) {
        passed("MoveTo move and rename file");
    }
    // Test copying across directoreis
    if (TestCopy(base, subdir, "file4.txt", "file5.txt")) {
        passed("CopyTo copy file across directories");
    }

    // Run normalization tests while the directory exists
    if (TestNormalizeNativePath(base, subdir)) {
        passed("Normalize with native paths");
    }

    // Test recursive directory removal
    if (TestRemove(base, "subdir", true)) {
        passed("Remove directory");
    }

    if (TestCreateUnique(base, "foo", nsIFile::NORMAL_FILE_TYPE, 0600) &&
        TestCreateUnique(base, "foo", nsIFile::NORMAL_FILE_TYPE, 0600)) {
        passed("CreateUnique file");
    }
    if (TestCreateUnique(base, "bar.xx", nsIFile::DIRECTORY_TYPE, 0700) &&
        TestCreateUnique(base, "bar.xx", nsIFile::DIRECTORY_TYPE, 0700)) {
        passed("CreateUnique directory");
    }

    if (TestDeleteOnClose(base, "file7.txt", PR_RDWR | PR_CREATE_FILE, 0600)) {
        passed("OpenNSPRFileDesc DELETE_ON_CLOSE");
    }

    gFunction = "main";
    // Clean up temporary stuff
    rv = base->Remove(true);
    VerifyResult(rv, "Cleaning up temp directory");

    return gFailCount > 0;
}
Ejemplo n.º 25
0
int
main(int32_t argc, char *argv[])
{
    nsresult rv;
    ScopedXPCOM xpcom("STS Parser Tests");
    if (xpcom.failed())
      return -1;
    // Initialize a profile folder to ensure a clean shutdown.
    nsCOMPtr<nsIFile> profile = xpcom.GetProfileDirectory();
    if (!profile) {
      fail("Couldn't get the profile directory.");
      return -1;
    }

    // grab handle to the service
    nsCOMPtr<nsISiteSecurityService> sss;
    sss = do_GetService("@mozilla.org/ssservice;1", &rv);
    NS_ENSURE_SUCCESS(rv, -1);

    int rv0, rv1;

    nsTArray<bool> rvs(24);

    // *** parsing tests
    printf("*** Attempting to parse valid STS headers ...\n");

    // SHOULD SUCCEED:
    rvs.AppendElement(TestSuccess("max-age=100", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("max-age  =100", false, 100, false, sss));
    rvs.AppendElement(TestSuccess(" max-age=100", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("max-age = 100 ", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("max-age = \"100\" ", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("max-age=\"100\"", false, 100, false, sss));
    rvs.AppendElement(TestSuccess(" max-age =\"100\" ", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("\tmax-age\t=\t\"100\"\t", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("max-age  =       100             ", false, 100, false, sss));

    rvs.AppendElement(TestSuccess("maX-aGe=100", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("MAX-age  =100", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("max-AGE=100", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("Max-Age = 100 ", false, 100, false, sss));
    rvs.AppendElement(TestSuccess("MAX-AGE = 100 ", false, 100, false, sss));

    rvs.AppendElement(TestSuccess("max-age=100;includeSubdomains", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("max-age=100\t; includeSubdomains", false, 100, true, sss));
    rvs.AppendElement(TestSuccess(" max-age=100; includeSubdomains", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("max-age = 100 ; includeSubdomains", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("max-age  =       100             ; includeSubdomains", false, 100, true, sss));

    rvs.AppendElement(TestSuccess("maX-aGe=100; includeSUBDOMAINS", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("MAX-age  =100; includeSubDomains", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("max-AGE=100; iNcLuDeSuBdoMaInS", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("Max-Age = 100; includesubdomains ", false, 100, true, sss));
    rvs.AppendElement(TestSuccess("INCLUDESUBDOMAINS;MaX-AgE = 100 ", false, 100, true, sss));
    // Turns out, the actual directive is entirely optional (hence the
    // trailing semicolon)
    rvs.AppendElement(TestSuccess("max-age=100;includeSubdomains;", true, 100, true, sss));

    // these are weird tests, but are testing that some extended syntax is
    // still allowed (but it is ignored)
    rvs.AppendElement(TestSuccess("max-age=100 ; includesubdomainsSomeStuff", true, 100, false, sss));
    rvs.AppendElement(TestSuccess("\r\n\t\t    \tcompletelyUnrelated = foobar; max-age= 34520103    \t \t; alsoUnrelated;asIsThis;\tincludeSubdomains\t\t \t", true, 34520103, true, sss));
    rvs.AppendElement(TestSuccess("max-age=100; unrelated=\"quoted \\\"thingy\\\"\"", true, 100, false, sss));

    rv0 = rvs.Contains(false) ? 1 : 0;
    if (rv0 == 0)
      passed("Successfully Parsed STS headers with mixed case and LWS");

    rvs.Clear();

    // SHOULD FAIL:
    printf("*** Attempting to parse invalid STS headers (should not parse)...\n");
    // invalid max-ages
    rvs.AppendElement(TestFailure("max-age", sss));
    rvs.AppendElement(TestFailure("max-age ", sss));
    rvs.AppendElement(TestFailure("max-age=p", sss));
    rvs.AppendElement(TestFailure("max-age=*1p2", sss));
    rvs.AppendElement(TestFailure("max-age=.20032", sss));
    rvs.AppendElement(TestFailure("max-age=!20032", sss));
    rvs.AppendElement(TestFailure("max-age==20032", sss));

    // invalid headers
    rvs.AppendElement(TestFailure("foobar", sss));
    rvs.AppendElement(TestFailure("maxage=100", sss));
    rvs.AppendElement(TestFailure("maxa-ge=100", sss));
    rvs.AppendElement(TestFailure("max-ag=100", sss));
    rvs.AppendElement(TestFailure("includesubdomains", sss));
    rvs.AppendElement(TestFailure(";", sss));
    rvs.AppendElement(TestFailure("max-age=\"100", sss));
    // The max-age directive here doesn't conform to the spec, so it MUST
    // be ignored. Consequently, the REQUIRED max-age directive is not
    // present in this header, and so it is invalid.
    rvs.AppendElement(TestFailure("max-age=100, max-age=200; includeSubdomains", sss));
    rvs.AppendElement(TestFailure("max-age=100 includesubdomains", sss));
    rvs.AppendElement(TestFailure("max-age=100 bar foo", sss));
    rvs.AppendElement(TestFailure("max-age=100randomstuffhere", sss));
    // All directives MUST appear only once in an STS header field.
    rvs.AppendElement(TestFailure("max-age=100; max-age=200", sss));
    rvs.AppendElement(TestFailure("includeSubdomains; max-age=200; includeSubdomains", sss));
    rvs.AppendElement(TestFailure("max-age=200; includeSubdomains; includeSubdomains", sss));
    // The includeSubdomains directive is valueless.
    rvs.AppendElement(TestFailure("max-age=100; includeSubdomains=unexpected", sss));
    // LWS must have at least one space or horizontal tab
    rvs.AppendElement(TestFailure("\r\nmax-age=200", sss));

    rv1 = rvs.Contains(false) ? 1 : 0;
    if (rv1 == 0)
      passed("Avoided parsing invalid STS headers");

    return (rv0 + rv1);
}
// General note about return values:
// return 1 for a setup or xpcom type failure, return 2 for a real test failure
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("TestImapFlagAndUidState.cpp");
  if (xpcom.failed())
    return 1;

  struct msgState msgState1[] = {
  {10, kImapMsgSeenFlag, 0},
  {15, kImapMsgSeenFlag, 1},
  {16, kImapMsgSeenFlag, 2},
  {17, kImapMsgSeenFlag, 3},
  {18, kImapMsgSeenFlag, 4}};

  nsRefPtr<nsImapFlagAndUidState> flagState = new nsImapFlagAndUidState(10);
  int32_t numMsgs = sizeof(msgState1) / sizeof(msgState1[0]);
  for (int32_t i = 0; i < numMsgs; i++)
        flagState->AddUidFlagPair(msgState1[i].uid, msgState1[i].flag,
                                  msgState1[i].index);

  const char * error = MainChecks(flagState, msgState1, numMsgs, 0);
  if (error)
  {
    printf("TEST-UNEXPECTED-FAIL | %s | %s\n", __FILE__, error);
    return 1;
  }

  // Now reset all
  flagState->Reset();

  // This tests adding some messages to a partial uid flag state,
  // i.e., CONDSTORE.
  struct msgState msgState2[] = {
    {68, kImapMsgSeenFlag, 69},
    {71, kImapMsgSeenFlag, 70},
    {73, kImapMsgSeenFlag, 71}};
  numMsgs = sizeof(msgState2) / sizeof(msgState2[0]);
  for (int32_t i = 0; i < numMsgs; i++)
    flagState->AddUidFlagPair(msgState2[i].uid, msgState2[i].flag,
                              msgState2[i].index);
  error = MainChecks(flagState, msgState2, numMsgs, 0);
  if (error)
  {
    printf("TEST-UNEXPECTED-FAIL | %s | %s\n", __FILE__, error);
    return 1;
  }
  // Reset all
  flagState->Reset();
  // This tests generating a uid string from a non-sequential set of
  // messages where the first message is not in the flag state, but the
  // missing message from the sequence is in the set. I.e., we're
  // generating a uid string from 69,71, but only 70 and 71 are in
  // the flag state.
  struct msgState msgState3[] = {
    {10, kImapMsgSeenFlag, 0},
    {69, kImapMsgSeenFlag, 1},
    {70, kImapMsgSeenFlag, 2},
    {71, kImapMsgSeenFlag, 3}};

  flagState->SetPartialUIDFetch(false);
  numMsgs = sizeof(msgState3) / sizeof(msgState3[0]);
  for (int32_t i = 0; i < numMsgs; i++)
    flagState->AddUidFlagPair(msgState3[i].uid, msgState3[i].flag,
                              msgState3[i].index);
  flagState->ExpungeByIndex(2);
  nsCString uidString;
  uint32_t msgUids[] = {69,71};
  uint32_t msgCount = 2;
  AllocateImapUidString(&msgUids[0], msgCount, flagState, uidString);
  if (!uidString.EqualsLiteral("71"))
  {
    printf("TEST-UNEXPECTED-FAIL | uid String is %s, not 71 | %s\n", uidString.get(), __FILE__);
    return -1;
  }
  // Reset all
  flagState->Reset();
  // This tests the middle message missing from the flag state.
  struct msgState msgState4[] = {
    {10, kImapMsgSeenFlag, 0},
    {69, kImapMsgSeenFlag, 1},
    {70, kImapMsgSeenFlag, 2},
    {71, kImapMsgSeenFlag, 3},
    {73, kImapMsgSeenFlag, 4}};

  flagState->SetPartialUIDFetch(false);
  numMsgs = sizeof(msgState4) / sizeof(msgState4[0]);
  for (int32_t i = 0; i < numMsgs; i++)
    flagState->AddUidFlagPair(msgState4[i].uid, msgState4[i].flag,
                              msgState4[i].index);
  flagState->ExpungeByIndex(4);
  uint32_t msgUids2[] = {69,71,73};
  msgCount = 3;
  nsCString uidString2;

  AllocateImapUidString(&msgUids2[0], msgCount, flagState, uidString2);
  if (!uidString2.EqualsLiteral("69,73"))
  {
    printf("TEST-UNEXPECTED-FAIL | uid String is %s, not 71 | %s\n", uidString.get(), __FILE__);
    return -1;
  }

  printf("TEST-PASS | %s | all tests passed\n", __FILE__);
  return 0;
}
Ejemplo n.º 27
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("TestColorNames");
  if (xpcom.failed())
    return 1;

  nscolor rgb;
  int rv = 0;

  // First make sure we can find all of the tags that are supposed to
  // be in the table. Futz with the case to make sure any case will
  // work

  for (PRUint32 index = 0 ; index < ArrayLength(kColorNames); index++) {
    // Lookup color by name and make sure it has the right id
    nsCString tagName(kColorNames[index]);

    // Check that color lookup by name gets the right rgb value
    if (!NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) {
      fail("can't find '%s'", tagName.get());
      rv = 1;
    }
    if (rgb != kColors[index]) {
      fail("name='%s' ColorNameToRGB=%x kColors[%d]=%08x",
           tagName.get(), rgb, index, kColors[index]);
      rv = 1;
    }

    // fiddle with the case to make sure we can still find it
    tagName.SetCharAt(tagName.CharAt(0) - 32, 0);
    if (!NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tagName), &rgb)) {
      fail("can't find '%s'", tagName.get());
      rv = 1;
    }
    if (rgb != kColors[index]) {
      fail("name='%s' ColorNameToRGB=%x kColors[%d]=%08x",
           tagName.get(), rgb, index, kColors[index]);
      rv = 1;
    }

    // Check that parsing an RGB value in hex gets the right values
    PRUint8 r = NS_GET_R(rgb);
    PRUint8 g = NS_GET_G(rgb);
    PRUint8 b = NS_GET_B(rgb);
    PRUint8 a = NS_GET_A(rgb);
    if (a != PR_UINT8_MAX) {
      // NS_HexToRGB() can not handle a color with alpha channel
      rgb = NS_RGB(r, g, b);
    }
    char cbuf[50];
    PR_snprintf(cbuf, sizeof(cbuf), "%02x%02x%02x", r, g, b);
    nscolor hexrgb;
    if (!NS_HexToRGB(NS_ConvertASCIItoUTF16(cbuf), &hexrgb)) {
      fail("hex conversion to color of '%s'", cbuf);
      rv = 1;
    }
    if (hexrgb != rgb) {
      fail("rgb=%x hexrgb=%x", rgb, hexrgb);
      rv = 1;
    }
  }

  // Now make sure we don't find some garbage
  for (PRUint32 i = 0; i < ArrayLength(kJunkNames); i++) {
    nsCString tag(kJunkNames[i]);
    if (NS_ColorNameToRGB(NS_ConvertASCIItoUTF16(tag), &rgb)) {
      fail("found '%s'", kJunkNames[i] ? kJunkNames[i] : "(null)");
      rv = 1;
    }
  }

  if (rv == 0)
    passed("TestColorNames");
  return rv;
}
Ejemplo n.º 28
0
int main(int argc, char* argv[])
{
  ScopedXPCOM xpcom("NtPathToDosPath");
  if (xpcom.failed()) {
    fail("XPCOM Startup");
    return 1;
  }
  nsAutoString cDrive;
  if (!DriveToNtPath(L'C', cDrive)) {
    fail("Querying for this machine's C:");
    return 1;
  }

  int result = 0;

  // empty string
  if (!TestNtPathToDosPath(L"", L"")) {
    fail("Empty string");
    result = 1;
  }
  // non-existent device, must fail
  if (TestNtPathToDosPath(L"\\Device\\ThisDeviceDoesNotExist\\Foo", nullptr)) {
    fail("Non-existent device");
    result = 1;
  }
  // base case
  nsAutoString testPath(cDrive);
  testPath.Append(L"\\Foo");
  if (!TestNtPathToDosPath(testPath.get(), L"C:\\Foo")) {
    fail("Base case");
    result = 1;
  }
  // drive letters as symbolic links (NtCreateFile uses these)
  if (!TestNtPathToDosPath(L"\\??\\C:\\Foo", L"C:\\Foo")) {
    fail("Path specified as symbolic link");
    result = 1;
  }
  // other symbolic links (should fail)
  if (TestNtPathToDosPath(L"\\??\\MountPointManager", nullptr)) {
    fail("Other symbolic link");
    result = 1;
  }
  // socket (should fail)
  if (TestNtPathToDosPath(L"\\Device\\Afd\\Endpoint", nullptr)) {
    fail("Socket");
    result = 1;
  }
  // currently UNC paths that are not mapped to drive letters are unsupported,
  // so this should fail
  if (TestNtPathToDosPath(L"\\Device\\Mup\\127.0.0.1\\C$", nullptr)) {
    fail("Unmapped UNC path");
    result = 1;
  }
  DriveMapping drvMapping(NS_LITERAL_STRING("\\\\127.0.0.1\\C$"));
  // Only run these tests if we were able to map; some machines don't have perms
  if (drvMapping.Init()) {
    wchar_t expected[] = L" :\\";
    expected[0] = drvMapping.GetDriveLetter();
    nsAutoString networkPath;
    if (!DriveToNtPath(drvMapping.GetDriveLetter(), networkPath)) {
      fail("Querying network drive");
      return 1;
    }
    networkPath += L"\\";
    if (!TestNtPathToDosPath(networkPath.get(), expected)) {
      fail("Mapped UNC path");
      result = 1;
    }
    // NtPathToDosPath must correctly handle paths whose drive letter mapping has
    // changed. We need to test this because the APIs called by NtPathToDosPath
    // return different info if this has happened.
    if (!drvMapping.ChangeDriveLetter()) {
      fail("Change drive letter");
      return 1;
    }
    expected[0] = drvMapping.GetDriveLetter();
    if (!DriveToNtPath(drvMapping.GetDriveLetter(), networkPath)) {
      fail("Querying second network drive");
      return 1;
    }
    networkPath += L"\\";
    if (!TestNtPathToDosPath(networkPath.get(), expected)) {
      fail("Re-mapped UNC path");
      result = 1;
    }
  }

  return result;
}
Ejemplo n.º 29
0
int
main(int argc, char* argv[])
{
  ScopedXPCOM xpcom("TestCertDB");
  if (xpcom.failed()) {
    fail("couldn't initialize XPCOM");
    return 1;
  }
  {
    nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
    if (!prefs) {
      fail("couldn't get nsIPrefBranch");
      return 1;
    }
    // When PSM initializes, it attempts to get some localized strings.
    // As a result, Android flips out if this isn't set.
    nsresult rv = prefs->SetBoolPref("intl.locale.matchOS", true);
    if (NS_FAILED(rv)) {
      fail("couldn't set pref 'intl.locale.matchOS'");
      return 1;
    }
    nsCOMPtr<nsIX509CertDB> certdb(do_GetService(NS_X509CERTDB_CONTRACTID));
    if (!certdb) {
      fail("couldn't get certdb");
      return 1;
    }
    nsCOMPtr<nsIX509CertList> certList;
    rv = certdb->GetCerts(getter_AddRefs(certList));
    if (NS_FAILED(rv)) {
      fail("couldn't get list of certificates");
      return 1;
    }
    nsCOMPtr<nsISimpleEnumerator> enumerator;
    rv = certList->GetEnumerator(getter_AddRefs(enumerator));
    if (NS_FAILED(rv)) {
      fail("couldn't enumerate certificate list");
      return 1;
    }
    bool foundBuiltIn = false;
    bool hasMore = false;
    while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMore)) && hasMore) {
      nsCOMPtr<nsISupports> supports;
      if (NS_FAILED(enumerator->GetNext(getter_AddRefs(supports)))) {
        fail("couldn't get next certificate");
        return 1;
      }
      nsCOMPtr<nsIX509Cert> cert(do_QueryInterface(supports));
      if (!cert) {
        fail("couldn't QI to nsIX509Cert");
        return 1;
      }
      if (NS_FAILED(cert->GetIsBuiltInRoot(&foundBuiltIn))) {
        fail("GetIsBuiltInRoot failed");
        return 1;
      }
      if (foundBuiltIn) {
        break;
      }
    }
    if (foundBuiltIn) {
      passed("successfully loaded at least one built-in certificate");
    } else {
      fail("didn't load any built-in certificates");
      return 1;
    }
  } // this scopes the nsCOMPtrs
  // no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
  return 0;
}
Ejemplo n.º 30
0
int main(int argc, char** argv)
{
  ScopedXPCOM xpcom("TestStaticAtoms");
  if (xpcom.failed()) {
    return 1;
  }

  TestingAtoms::AddRefAtoms();

  NS_SealStaticAtomTable();

  nsCOMPtr<nsIAtom> atom = NS_Atomize("foo");
  if (!atom) {
    fail("Didn't get an atom for foo.");
    return 1;
  }
  if (atom->IsStaticAtom()) {
    passed("foo is a static atom");
  } else {
    fail("foo is not a static atom.");
    return 1;
  }
  if (atom == TestingAtoms::foo) {
    passed("foo is the right pointer");
  } else {
    fail("foo was not the right pointer");
    return 1;
  }
  nsIAtom* staticAtom = NS_GetStaticAtom(NS_LITERAL_STRING("foo"));
  if (!staticAtom) {
    fail("Did not get a static atom for foo");
    return 1;
  }

  if (atom == staticAtom) {
    passed("NS_Atomize and NS_GetStaticAtom returned the same atom.");
  } else {
    fail("NS_Atomize and NS_GetStaticAtom returned different atoms.");
    return 1;
  }

  MoreTestingAtoms::AddRefAtoms();
  
  atom = NS_Atomize("qux");
  if (!atom) {
    fail("Didn't get an atom for qux.");
    return 1;
  }
  if (atom->IsStaticAtom()) {
    passed("qux is a static atom");
  } else {
    fail("qux is not a static atom.");
    return 1;
  }
  if (atom == MoreTestingAtoms::qux) {
    passed("qux is the right pointer");
  } else {
    fail("qux was not the right pointer");
    return 1;
  }
  staticAtom = NS_GetStaticAtom(NS_LITERAL_STRING("qux"));
  if (staticAtom) {
    fail("Got an atom for qux. The static atom table was not sealed properly.");
    return 1;
  }
  return 0;
}