1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/TestCOMPtrEq.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,166 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + /** 1.10 + * This attempts to test all the possible variations of |operator==| 1.11 + * used with |nsCOMPtr|s. Currently only the tests where pointers 1.12 + * are to the same class are enabled. It's not clear whether we 1.13 + * should be supporting other tests, and some of them won't work 1.14 + * on at least some platforms. If we add separate comparisons 1.15 + * for nsCOMPtr<nsISupports> we'll need to add more tests for 1.16 + * those cases. 1.17 + */ 1.18 + 1.19 +#include "nsCOMPtr.h" 1.20 + 1.21 + // Don't test these now, since some of them won't work and it's 1.22 + // not clear whether they should (see above). 1.23 +#undef NSCAP_EQTEST_TEST_ACROSS_TYPES 1.24 + 1.25 +#define NS_ICOMPTREQTESTFOO_IID \ 1.26 + {0x8eb5bbef, 0xd1a3, 0x4659, \ 1.27 + {0x9c, 0xf6, 0xfd, 0xf3, 0xe4, 0xd2, 0x00, 0x0e}} 1.28 + 1.29 +class nsICOMPtrEqTestFoo : public nsISupports { 1.30 + public: 1.31 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICOMPTREQTESTFOO_IID) 1.32 +}; 1.33 + 1.34 +NS_DEFINE_STATIC_IID_ACCESSOR(nsICOMPtrEqTestFoo, NS_ICOMPTREQTESTFOO_IID) 1.35 + 1.36 +#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES 1.37 + 1.38 +#define NS_ICOMPTREQTESTFOO2_IID \ 1.39 + {0x6516387b, 0x36c5, 0x4036, \ 1.40 + {0x82, 0xc9, 0xa7, 0x4d, 0xd9, 0xe5, 0x92, 0x2f}} 1.41 + 1.42 +class nsICOMPtrEqTestFoo2 : public nsISupports { 1.43 + public: 1.44 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICOMPTREQTESTFOO2_IID) 1.45 +}; 1.46 + 1.47 +NS_DEFINE_STATIC_IID_ACCESSOR(nsICOMPtrEqTestFoo2, NS_ICOMPTREQTESTFOO2_IID) 1.48 + 1.49 +#endif 1.50 + 1.51 +int 1.52 +main() 1.53 + { 1.54 + nsCOMPtr<nsICOMPtrEqTestFoo> s; 1.55 + nsICOMPtrEqTestFoo* r = 0; 1.56 + const nsCOMPtr<nsICOMPtrEqTestFoo> sc; 1.57 + const nsICOMPtrEqTestFoo* rc = 0; 1.58 + nsICOMPtrEqTestFoo* const rk = 0; 1.59 + const nsICOMPtrEqTestFoo* const rkc = 0; 1.60 + nsICOMPtrEqTestFoo* d = s; 1.61 + 1.62 +#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES 1.63 + nsCOMPtr<nsICOMPtrEqTestFoo2> s2; 1.64 + nsICOMPtrEqTestFoo2* r2 = 0; 1.65 + const nsCOMPtr<nsICOMPtrEqTestFoo2> sc2; 1.66 + const nsICOMPtrEqTestFoo2* rc2 = 0; 1.67 + nsICOMPtrEqTestFoo2* const rk2 = 0; 1.68 + const nsICOMPtrEqTestFoo2* const rkc2 = 0; 1.69 + nsICOMPtrEqTestFoo2* d2 = s2; 1.70 +#endif 1.71 + 1.72 + return (!(true && 1.73 + (s == s) && 1.74 + (s == r) && 1.75 + (s == sc) && 1.76 + (s == rc) && 1.77 + (s == rk) && 1.78 + (s == rkc) && 1.79 + (s == d) && 1.80 + (r == s) && 1.81 + (r == sc) && 1.82 + (r == rc) && 1.83 + (r == rk) && 1.84 + (r == rkc) && 1.85 + (r == d) && 1.86 + (sc == s) && 1.87 + (sc == r) && 1.88 + (sc == sc) && 1.89 + (sc == rc) && 1.90 + (sc == rk) && 1.91 + (sc == rkc) && 1.92 + (sc == d) && 1.93 + (rc == s) && 1.94 + (rc == r) && 1.95 + (rc == sc) && 1.96 + (rc == rk) && 1.97 + (rc == rkc) && 1.98 + (rc == d) && 1.99 + (rk == s) && 1.100 + (rk == r) && 1.101 + (rk == sc) && 1.102 + (rk == rc) && 1.103 + (rk == rkc) && 1.104 + (rk == d) && 1.105 + (rkc == s) && 1.106 + (rkc == r) && 1.107 + (rkc == sc) && 1.108 + (rkc == rc) && 1.109 + (rkc == rk) && 1.110 + (rkc == d) && 1.111 + (d == s) && 1.112 + (d == r) && 1.113 + (d == sc) && 1.114 + (d == rc) && 1.115 + (d == rk) && 1.116 + (d == rkc) && 1.117 +#ifdef NSCAP_EQTEST_TEST_ACROSS_TYPES 1.118 + (s == s2) && 1.119 + (s == r2) && 1.120 + (s == sc2) && 1.121 + (s == rc2) && 1.122 + (s == rk2) && 1.123 + (s == rkc2) && 1.124 + (s == d2) && 1.125 + (r == s2) && 1.126 + (r == r2) && 1.127 + (r == sc2) && 1.128 + (r == rc2) && 1.129 + (r == rk2) && 1.130 + (r == rkc2) && 1.131 + (r == d2) && 1.132 + (sc == s2) && 1.133 + (sc == r2) && 1.134 + (sc == sc2) && 1.135 + (sc == rc2) && 1.136 + (sc == rk2) && 1.137 + (sc == rkc2) && 1.138 + (sc == d2) && 1.139 + (rc == s2) && 1.140 + (rc == r2) && 1.141 + (rc == sc2) && 1.142 + (rc == rc2) && 1.143 + (rc == rk2) && 1.144 + (rc == rkc2) && 1.145 + (rc == d2) && 1.146 + (rk == s2) && 1.147 + (rk == r2) && 1.148 + (rk == sc2) && 1.149 + (rk == rc2) && 1.150 + (rk == rk2) && 1.151 + (rk == rkc2) && 1.152 + (rk == d2) && 1.153 + (rkc == s2) && 1.154 + (rkc == r2) && 1.155 + (rkc == sc2) && 1.156 + (rkc == rc2) && 1.157 + (rkc == rk2) && 1.158 + (rkc == rkc2) && 1.159 + (rkc == d2) && 1.160 + (d == s2) && 1.161 + (d == r2) && 1.162 + (d == sc2) && 1.163 + (d == rc2) && 1.164 + (d == rk2) && 1.165 + (d == rkc2) && 1.166 + (d == d2) && 1.167 +#endif 1.168 + true)); 1.169 + }