VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/xpcom/tests/TestCOMPtrEq.cpp@ 95259

Last change on this file since 95259 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is TestCOMPtrEq.cpp.
16 *
17 * The Initial Developer of the Original Code is
18 * L. David Baron.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * L. David Baron <dbaron@dbaron.org> (original author)
24 *
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
36 *
37 * ***** END LICENSE BLOCK ***** */
38
39 /**
40 * This attempts to test all the possible variations of |operator==|
41 * used with |nsCOMPtr|s. Currently only the tests where pointers
42 * are to the same class are enabled. It's not clear whether we
43 * should be supporting other tests, and some of them won't work
44 * on at least some platforms. If we add separate comparisons
45 * for nsCOMPtr<nsISupports> we'll need to add more tests for
46 * those cases.
47 */
48
49#include "nsCOMPtr.h"
50
51 // Don't test these now, since some of them won't work and it's
52 // not clear whether they should (see above).
53#undef NSCAP_EQTEST_TEST_ACROSS_TYPES
54
55#define NS_ICOMPTREQTESTFOO_IID \
56 {0x8eb5bbef, 0xd1a3, 0x4659, \
57 {0x9c, 0xf6, 0xfd, 0xf3, 0xe4, 0xd2, 0x00, 0x0e}}
58
59class nsICOMPtrEqTestFoo : public nsISupports {
60 public:
61 NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOMPTREQTESTFOO_IID)
62};
63
64#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
65
66#define NS_ICOMPTREQTESTFOO2_IID \
67 {0x6516387b, 0x36c5, 0x4036, \
68 {0x82, 0xc9, 0xa7, 0x4d, 0xd9, 0xe5, 0x92, 0x2f}}
69
70class nsICOMPtrEqTestFoo2 : public nsISupports {
71 public:
72 NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOMPTREQTESTFOO2_IID)
73};
74
75#endif
76
77int
78main()
79 {
80 nsCOMPtr<nsICOMPtrEqTestFoo> s;
81 nsICOMPtrEqTestFoo* r = 0;
82 const nsCOMPtr<nsICOMPtrEqTestFoo> sc;
83 const nsICOMPtrEqTestFoo* rc = 0;
84 nsICOMPtrEqTestFoo* const rk = 0;
85 const nsICOMPtrEqTestFoo* const rkc = 0;
86 nsDerivedSafe<nsICOMPtrEqTestFoo>* d = s.get();
87
88#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
89 nsCOMPtr<nsICOMPtrEqTestFoo2> s2;
90 nsICOMPtrEqTestFoo2* r2 = 0;
91 const nsCOMPtr<nsICOMPtrEqTestFoo2> sc2;
92 const nsICOMPtrEqTestFoo2* rc2 = 0;
93 nsICOMPtrEqTestFoo2* const rk2 = 0;
94 const nsICOMPtrEqTestFoo2* const rkc2 = 0;
95 nsDerivedSafe<nsICOMPtrEqTestFoo2>* d2 = s2.get();
96#endif
97
98 return (!(PR_TRUE &&
99 (s == s) &&
100 (s == r) &&
101 (s == sc) &&
102 (s == rc) &&
103 (s == rk) &&
104 (s == rkc) &&
105 (s == d) &&
106 (r == s) &&
107 (r == r) &&
108 (r == sc) &&
109 (r == rc) &&
110 (r == rk) &&
111 (r == rkc) &&
112 (r == d) &&
113 (sc == s) &&
114 (sc == r) &&
115 (sc == sc) &&
116 (sc == rc) &&
117 (sc == rk) &&
118 (sc == rkc) &&
119 (sc == d) &&
120 (rc == s) &&
121 (rc == r) &&
122 (rc == sc) &&
123 (rc == rc) &&
124 (rc == rk) &&
125 (rc == rkc) &&
126 (rc == d) &&
127 (rk == s) &&
128 (rk == r) &&
129 (rk == sc) &&
130 (rk == rc) &&
131 (rk == rk) &&
132 (rk == rkc) &&
133 (rk == d) &&
134 (rkc == s) &&
135 (rkc == r) &&
136 (rkc == sc) &&
137 (rkc == rc) &&
138 (rkc == rk) &&
139 (rkc == rkc) &&
140 (rkc == d) &&
141 (d == s) &&
142 (d == r) &&
143 (d == sc) &&
144 (d == rc) &&
145 (d == rk) &&
146 (d == rkc) &&
147 (d == d) &&
148#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES
149 (s == s2) &&
150 (s == r2) &&
151 (s == sc2) &&
152 (s == rc2) &&
153 (s == rk2) &&
154 (s == rkc2) &&
155 (s == d2) &&
156 (r == s2) &&
157 (r == r2) &&
158 (r == sc2) &&
159 (r == rc2) &&
160 (r == rk2) &&
161 (r == rkc2) &&
162 (r == d2) &&
163 (sc == s2) &&
164 (sc == r2) &&
165 (sc == sc2) &&
166 (sc == rc2) &&
167 (sc == rk2) &&
168 (sc == rkc2) &&
169 (sc == d2) &&
170 (rc == s2) &&
171 (rc == r2) &&
172 (rc == sc2) &&
173 (rc == rc2) &&
174 (rc == rk2) &&
175 (rc == rkc2) &&
176 (rc == d2) &&
177 (rk == s2) &&
178 (rk == r2) &&
179 (rk == sc2) &&
180 (rk == rc2) &&
181 (rk == rk2) &&
182 (rk == rkc2) &&
183 (rk == d2) &&
184 (rkc == s2) &&
185 (rkc == r2) &&
186 (rkc == sc2) &&
187 (rkc == rc2) &&
188 (rkc == rk2) &&
189 (rkc == rkc2) &&
190 (rkc == d2) &&
191 (d == s2) &&
192 (d == r2) &&
193 (d == sc2) &&
194 (d == rc2) &&
195 (d == rk2) &&
196 (d == rkc2) &&
197 (d == d2) &&
198#endif
199 PR_TRUE));
200 }
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette