[storage] Partially test 'balanceRow.setFact()'
[abstract.git] / view / aaViewTest.cpp
blob5eafe450f8a73d619de4e039d35d0f3a63053de3
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 <abstract/aacore.h>
24 #include "nsIGenericFactory.h"
25 #include "nsComponentManagerUtils.h"
26 #include "nsISHistory.h"
27 #include "nsIInterfaceRequestor.h"
29 /* Unfrozen API */
30 #include "unstable/nsISHistoryInternal.h"
31 #include "unstable/nsIWebNavigation.h"
32 #include "unstable/nsISHEntry.h"
33 #include "unstable/nsISHContainer.h"
34 #include <abstract/cxxunit/nsTestUtils.h>
35 #include <abstract/cxxunit/nsITest.h>
36 #include <abstract/cxxunit/nsITestRunner.h>
38 /* Project includes */
39 #include <abstract/view/aaIPageView.h>
40 #include "aaSessionHistory.h"
41 #include "aaPageView.h"
43 #define AA_VIEW_TEST_CID \
44 {0x39010bed, 0x1087, 0x4363, {0x99, 0x19, 0xf9, 0xe7, 0x1a, 0x74, 0xce, 0x9b}}
45 #define AA_VIEW_TEST_CONTRACT_ID "@aasii.org/view/unit;1"
47 class aaViewTest: public nsITest {
48 public:
49 aaViewTest() {;}
50 virtual ~aaViewTest() {;}
51 NS_DECL_ISUPPORTS
52 NS_DECL_NSITEST
53 private:
54 nsresult testSH(nsITestRunner *aTestRunner);
55 nsresult testSHE(nsITestRunner *aTestRunner);
58 NS_IMPL_ISUPPORTS1(aaViewTest, nsITest);
60 NS_IMETHODIMP
61 aaViewTest::Test(nsITestRunner *aTestRunner)
63 nsITestRunner *cxxUnitTestRunner = aTestRunner;
64 NS_TEST_ASSERT_OK( testSH( aTestRunner ) );
65 NS_TEST_ASSERT_OK( testSHE( aTestRunner ) );
66 return NS_OK;
69 /* Private methods */
70 nsresult
71 aaViewTest::testSH(nsITestRunner *aTestRunner)
73 nsresult rv;
74 NS_TEST_BEGIN( aTestRunner );
76 nsCOMPtr<nsISHistory> sh( do_CreateInstance(
77 AA_SESSIONHISTORY_CONTRACT_ID) );
78 NS_TEST_ASSERT_MSG(sh, "aaSessionHistory intance creation");
80 nsCOMPtr<nsIWebNavigation> wn = do_QueryInterface(sh);
81 NS_TEST_ASSERT_MSG(wn, "aaSessionHistory WebNavigation interface");
83 PRInt32 count = 1;
84 rv = sh->GetCount( &count );
85 NS_TEST_ASSERT_OK(rv);
86 NS_TEST_ASSERT_MSG(! count, "aaSessionHistory wrong item count");
88 nsCOMPtr<nsISHistoryInternal> shi = do_QueryInterface(sh);
89 NS_TEST_ASSERT_MSG(shi, "aaSessionHistory SHInternal interface");
90 nsCOMPtr<nsISHEntry> entry(do_CreateInstance(NS_SHENTRY_CONTRACTID));
91 NS_ENSURE_TRUE(entry, NS_ERROR_UNEXPECTED);
93 rv = shi->AddEntry(entry, PR_TRUE);
94 NS_TEST_ASSERT_OK(rv);
96 rv = sh->GetCount( &count );
97 NS_TEST_ASSERT_OK(rv);
98 NS_TEST_ASSERT_MSG(count == 1, "aaSessionHistory wrong item count");
100 PRInt32 index = 0;
101 rv = sh->GetIndex( &index );
102 NS_TEST_ASSERT_OK(rv);
103 NS_TEST_ASSERT_MSG(count == 1, "aaSessionHistory wrong index");
105 return NS_OK;
108 nsresult
109 aaViewTest::testSHE(nsITestRunner *aTestRunner)
111 nsresult rv;
112 NS_TEST_BEGIN( aTestRunner );
114 nsCOMPtr<nsISHEntry> wrapped( do_CreateInstance(
115 NS_SHENTRY_CONTRACTID, &rv) );
116 NS_ENSURE_TRUE(wrapped, rv);
118 nsCOMPtr<nsISHEntry> she( do_CreateInstance(
119 AA_PAGEVIEW_CONTRACT_ID, wrapped));
120 NS_TEST_ASSERT_MSG(she, "aaPageView intance creation");
122 nsCOMPtr<nsISHContainer> shc = do_QueryInterface(she);
123 NS_TEST_ASSERT_MSG(shc, "aaPageView SHContainer interface");
125 nsCOMPtr<nsIHistoryEntry> he = do_QueryInterface(she);
126 NS_TEST_ASSERT_MSG(he, "aaPageView HistoryEntry interface");
128 return NS_OK;
131 /* Module and Factory code */
132 NS_GENERIC_FACTORY_CONSTRUCTOR(aaViewTest)
134 static const nsModuleComponentInfo kComponents[] =
137 "View Module Unit Test",
138 AA_VIEW_TEST_CID,
139 AA_VIEW_TEST_CONTRACT_ID,
140 aaViewTestConstructor
143 NS_IMPL_NSGETMODULE(aaviewt, kComponents)