[xpunit] Rename from 'cxxunit' and switch to mozbuild (bug #114)
[abstract.git] / xpunit / nsTestModule.cpp
bloba367d619c3e327ce4a7d9f86898dbc568875cb45
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent tw=79 ft=cpp: */
3 /*
4 * Copyright (C) 2007 Sergey Yanovich <ynvich@gmail.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "xpcom-config.h"
24 #include "nsXPCOM.h"
25 #include "nsMemory.h"
26 #include "nsEmbedString.h"
27 #include "nsIGenericFactory.h"
28 #include "nsIServiceManager.h"
29 #include "nsICategoryManager.h"
30 #include "nsComponentManagerUtils.h"
31 #include "nsIWebProgressListener.h"
32 #include "nsWeakReference.h"
34 /* Unfrozen interfaces */
35 #include "nsIConsoleListener.h"
36 #include "nsITimer.h"
37 #include "nsICommandLineHandler.h"
38 #include "nsDeque.h"
40 /* Project includes */
41 #include "nsITestRunner.h"
42 #include "nsITestResult.h"
43 #include "nsITest.h"
44 #include "nsTestRunner.h"
45 #include "nsTestResult.h"
47 #define NS_TESTRUNNER_CLH "m-aatest"
49 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsTestRunner,
50 nsTestRunner::GetTestRunner)
51 NS_GENERIC_FACTORY_CONSTRUCTOR(nsTestResult)
53 static NS_METHOD ModuleRegistration(nsIComponentManager *aCompMgr,
54 nsIFile *aPath, const char *registryLocation, const char *componentType,
55 const nsModuleComponentInfo *info)
57 nsresult rv;
59 nsCOMPtr<nsIServiceManager> servman;
60 servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
61 NS_ENSURE_SUCCESS(rv,rv);
63 nsCOMPtr<nsICategoryManager> catman;
64 rv = servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
65 NS_GET_IID(nsICategoryManager), getter_AddRefs(catman));
66 NS_ENSURE_SUCCESS(rv,rv);
68 char* previous = nsnull;
69 rv = catman->AddCategoryEntry("command-line-handler",
70 NS_TESTRUNNER_CLH, NS_TESTRUNNER_CONTRACT_ID, PR_TRUE, PR_TRUE,
71 &previous);
72 if (previous)
73 nsMemory::Free(previous);
74 return rv;
77 static NS_METHOD ModuleUnregistration(nsIComponentManager *aCompMgr,
78 nsIFile *aPath, const char *registryLocation,
79 const nsModuleComponentInfo *info)
81 nsresult rv;
83 nsCOMPtr<nsIServiceManager> servman;
84 servman = do_QueryInterface((nsISupports*)aCompMgr, &rv);
85 NS_ENSURE_SUCCESS(rv,rv);
87 nsCOMPtr<nsICategoryManager> catman;
88 rv = servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
89 NS_GET_IID(nsICategoryManager), getter_AddRefs(catman));
90 NS_ENSURE_SUCCESS(rv,rv);
92 rv = catman->DeleteCategoryEntry("command-line-handler",
93 NS_TESTRUNNER_CLH, PR_TRUE);
94 return rv;
97 static const nsModuleComponentInfo components[] =
99 { "CxxUnit Test Runner",
100 NS_TESTRUNNER_CID,
101 NS_TESTRUNNER_CONTRACT_ID,
102 nsTestRunnerConstructor,
103 ModuleRegistration,
104 ModuleUnregistration },
105 { "CxxUnit Test Result",
106 NS_TESTRESULT_CID,
107 NS_TESTRESULT_CONTRACT_ID,
108 nsTestResultConstructor }
110 NS_IMPL_NSGETMODULE(nsTest, components)