transport: protocol handler for sqlite
[abstract.git] / transport / sqlite / test / aaSqliteTransportTestModule.cpp
blob8e09f623b9ec965fbf08bfc264c53e3d74628312
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) 2008 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 "nsIGenericFactory.h"
25 #include "nsStringAPI.h"
27 /* Unfrozen API */
28 #include "nsIStringEnumerator.h"
29 #include "nsITest.h"
30 #include "nsITestRunner.h"
32 /* Project includes */
33 #include "aaSqliteChannelTest.h"
34 #include "aaSqliteLoadEntityTest.h"
35 #include "aaSqliteCreateTable1Test.h"
37 #define AA_SQLITE_TRANSPORT_TEST_MODULE_CID \
38 {0x8ebe8443, 0xe59b, 0x4ffc, {0xa5, 0x40, 0x93, 0xf5, 0x26, 0xee, 0x1d, 0x5b}}
39 #define AA_SQLITE_TRANSPORT_TEST_MODULE_CONTRACT \
40 "@aasii.org/transport/sqlite/unit;1"
42 class aaSqliteTransportTestModule: public nsITest,
43 public nsIUTF8StringEnumerator
45 public:
46 aaSqliteTransportTestModule() :mSubtest(0) {;}
47 NS_DECL_ISUPPORTS
48 NS_DECL_NSITEST
49 NS_DECL_NSIUTF8STRINGENUMERATOR
50 private:
51 ~aaSqliteTransportTestModule() {;}
52 PRUint32 mSubtest;
55 NS_IMPL_ISUPPORTS2(aaSqliteTransportTestModule,
56 nsITest,
57 nsIUTF8StringEnumerator)
59 NS_IMETHODIMP
60 aaSqliteTransportTestModule::Test(nsITestRunner *aTestRunner)
62 return NS_OK;
65 /* nsIUTF8StringEnumerator */
66 static const char* subtests[] =
68 AA_SQLITE_CREATE_TABLE1_CONTRACT
69 ,"@aasii.org/transport/xml/sqlite;1"
71 #define subtestCount (sizeof(subtests) / sizeof(char*))
73 NS_IMETHODIMP
74 aaSqliteTransportTestModule::HasMore(PRBool *aHasMore)
76 NS_ENSURE_ARG_POINTER(aHasMore);
77 *aHasMore = (mSubtest < subtestCount);
78 return NS_OK;
81 NS_IMETHODIMP
82 aaSqliteTransportTestModule::GetNext(nsACString &aContractID)
84 NS_ENSURE_TRUE(mSubtest < subtestCount, NS_ERROR_FAILURE);
85 aContractID.Assign(subtests[mSubtest++]);
86 return NS_OK;
89 /* Module and Factory code */
90 NS_GENERIC_FACTORY_CONSTRUCTOR(aaSqliteTransportTestModule)
92 static NS_IMETHODIMP
93 aaSqliteLoadEntityTestConstructor(nsISupports *aOuter, REFNSIID aIID,
94 void **aResult)
96 nsresult rv;
97 aaSqliteChannelTest *inst;
99 *aResult = NULL;
100 NS_ENSURE_TRUE(NULL == aOuter, NS_ERROR_NO_AGGREGATION);
102 inst = new aaSqliteChannelTest(AA_SQLITE_LOAD_ENTITY_QUERY,
103 AA_SQLITE_LOAD_ENTITY_RESULT);
104 NS_ENSURE_TRUE(NULL != inst, NS_ERROR_OUT_OF_MEMORY);
106 NS_ADDREF(inst);
107 rv = inst->QueryInterface(aIID, aResult);
108 NS_RELEASE(inst);
110 return rv;
113 static NS_IMETHODIMP
114 aaSqliteCreateTable1TestConstructor(nsISupports *aOuter, REFNSIID aIID,
115 void **aResult)
117 nsresult rv;
118 aaSqliteChannelTest *inst;
120 *aResult = NULL;
121 NS_ENSURE_TRUE(NULL == aOuter, NS_ERROR_NO_AGGREGATION);
123 inst = new aaSqliteChannelTest(AA_SQLITE_CREATE_TABLE1_QUERY,
124 AA_SQLITE_CREATE_TABLE1_RESULT);
125 NS_ENSURE_TRUE(NULL != inst, NS_ERROR_OUT_OF_MEMORY);
127 NS_ADDREF(inst);
128 rv = inst->QueryInterface(aIID, aResult);
129 NS_RELEASE(inst);
131 return rv;
134 static const nsModuleComponentInfo kComponents[] =
136 { "Sqlite Transport Module Test Container",
137 AA_SQLITE_TRANSPORT_TEST_MODULE_CID,
138 AA_SQLITE_TRANSPORT_TEST_MODULE_CONTRACT,
139 aaSqliteTransportTestModuleConstructor}
140 ,{"Sqlite Channel Load Entity Test",
141 AA_SQLITE_LOAD_ENTITY_CID,
142 AA_SQLITE_LOAD_ENTITY_CONTRACT,
143 aaSqliteLoadEntityTestConstructor}
144 ,{"Sqlite Channel Create Table Test",
145 AA_SQLITE_CREATE_TABLE1_CID,
146 AA_SQLITE_CREATE_TABLE1_CONTRACT,
147 aaSqliteCreateTable1TestConstructor}
149 NS_IMPL_NSGETMODULE(aaSqliteTransportTest, kComponents)