/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* * Test harness for XPCOM objects, providing a scoped XPCOM initializer, * nsCOMPtr, nsRefPtr, do_CreateInstance, do_GetService, ns(Auto|C|)String, * and stdio.h/stdlib.h.
*/
/** * Prints the given failure message and arguments using printf, prepending * "TEST-UNEXPECTED-FAIL " for the benefit of the test harness and * appending "\n" to eliminate having to type it at each call site.
*/
MOZ_FORMAT_PRINTF(1, 2) void fail(constchar* msg, ...) {
va_list ap;
printf("TEST-UNEXPECTED-FAIL | ");
va_start(ap, msg);
vprintf(msg, ap);
va_end(ap);
putchar('\n');
++gFailCount;
}
/** * Prints the given success message and arguments using printf, prepending * "TEST-PASS " for the benefit of the test harness and * appending "\n" to eliminate having to type it at each call site.
*/
MOZ_FORMAT_PRINTF(1, 2) void passed(constchar* msg, ...) {
va_list ap;
mInitRv = NS_InitXPCOM(nullptr, nullptr, this); if (NS_FAILED(mInitRv)) {
fail("NS_InitXPCOM returned failure code 0x%" PRIx32, static_cast<uint32_t>(mInitRv)); return;
}
}
~ScopedXPCOM() { // If we created a profile directory, we need to remove it. if (mProfD) {
mozilla::AppShutdown::AdvanceShutdownPhase(
mozilla::ShutdownPhase::AppShutdownNetTeardown);
mozilla::AppShutdown::AdvanceShutdownPhase(
mozilla::ShutdownPhase::AppShutdownTeardown);
mozilla::AppShutdown::AdvanceShutdownPhase(
mozilla::ShutdownPhase::AppShutdown);
mozilla::AppShutdown::AdvanceShutdownPhase(
mozilla::ShutdownPhase::AppShutdownQM);
mozilla::AppShutdown::AdvanceShutdownPhase(
mozilla::ShutdownPhase::AppShutdownTelemetry);
if (NS_FAILED(mProfD->Remove(true))) {
NS_WARNING("Problem removing profile directory");
}
mProfD = nullptr;
}
if (NS_SUCCEEDED(mInitRv)) {
nsresult rv = NS_ShutdownXPCOM(nullptr); if (NS_FAILED(rv)) {
fail("XPCOM shutdown failed with code 0x%" PRIx32, static_cast<uint32_t>(rv)); exit(1);
}
}
// Create a unique temporary folder to use for this test. // Note that runcppunittests.py will run tests with a temp // directory as the cwd, so just put something under that.
nsCOMPtr<nsIFile> profD;
nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR,
getter_AddRefs(profD));
NS_ENSURE_SUCCESS(rv, nullptr);
NS_IMETHOD GetFile(constchar* aProperty, bool* _persistent,
nsIFile** _result) override { // If we were supplied a directory service provider, ask it first. if (mDirSvcProvider && NS_SUCCEEDED(mDirSvcProvider->GetFile(
aProperty, _persistent, _result))) { return NS_OK;
}
// Otherwise, the test harness provides some directories automatically. if (0 == strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) ||
0 == strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR) ||
0 == strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
nsCOMPtr<nsIFile> profD = GetProfileDirectory();
NS_ENSURE_TRUE(profD, NS_ERROR_FAILURE);
NS_IMETHOD GetFiles(constchar* aProperty,
nsISimpleEnumerator** _enum) override { // If we were supplied a directory service provider, ask it first.
nsCOMPtr<nsIDirectoryServiceProvider2> provider =
do_QueryInterface(mDirSvcProvider); if (provider && NS_SUCCEEDED(provider->GetFiles(aProperty, _enum))) { return NS_OK;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.