osl_SocketAddr.cxx (87d2adbc) | osl_SocketAddr.cxx (63d99982) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 40 unchanged lines hidden (view full) --- 49 4. following functions are declared but not implemented: 50 inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; 51 */ 52 53//------------------------------------------------------------------------ 54// include files 55//------------------------------------------------------------------------ 56 | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 40 unchanged lines hidden (view full) --- 49 4. following functions are declared but not implemented: 50 inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; 51 */ 52 53//------------------------------------------------------------------------ 54// include files 55//------------------------------------------------------------------------ 56 |
57#include <testshl/simpleheader.hxx> | 57#include "gtest/gtest.h" |
58 59//#include "osl_Socket_Const.h" 60#include "sockethelper.hxx" 61 62using namespace osl; 63using namespace rtl; 64 65#define IP_PORT_ZERO 0 --- 16 unchanged lines hidden (view full) --- 82 /** testing the methods: 83 inline SocketAddr(); 84 inline SocketAddr(const SocketAddr& Addr); 85 inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy ); 86 inline SocketAddr(oslSocketAddr Addr); 87 inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort ); 88 */ 89 | 58 59//#include "osl_Socket_Const.h" 60#include "sockethelper.hxx" 61 62using namespace osl; 63using namespace rtl; 64 65#define IP_PORT_ZERO 0 --- 16 unchanged lines hidden (view full) --- 82 /** testing the methods: 83 inline SocketAddr(); 84 inline SocketAddr(const SocketAddr& Addr); 85 inline SocketAddr(const oslSocketAddr , __osl_socket_NoCopy nocopy ); 86 inline SocketAddr(oslSocketAddr Addr); 87 inline SocketAddr( const ::rtl::OUString& strAddrOrHostName, sal_Int32 nPort ); 88 */ 89 |
90 class ctors : public CppUnit::TestFixture | 90 class ctors : public ::testing::Test |
91 { 92 public: | 91 { 92 public: |
93 }; // class ctors |
|
93 | 94 |
94 void ctors_none() 95 { 96 /// SocketAddr constructor. 97 ::osl::SocketAddr saSocketAddr; | 95 TEST_F(ctors, ctors_none) 96 { 97 /// SocketAddr constructor. 98 ::osl::SocketAddr saSocketAddr; |
98 | 99 |
99 // oslSocketResult aResult; 100 // rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); | 100 // oslSocketResult aResult; 101 // rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); |
101 | 102 |
102 // rtl::OUString suHost2 = getThisHostname(); | 103 // rtl::OUString suHost2 = getThisHostname(); |
103 | 104 |
104 CPPUNIT_ASSERT_MESSAGE("test for none parameter constructor function: check if the socket address was created successfully", 105 sal_True == saSocketAddr.is( ) ); 106 } | 105 ASSERT_TRUE(sal_True == saSocketAddr.is( )) << "test for none parameter constructor function: check if the socket address was created successfully"; 106 } |
107 | 107 |
108 void ctors_none_000() 109 { 110 /// SocketAddr constructor. 111 ::osl::SocketAddr saSocketAddr; | 108 TEST_F(ctors, ctors_none_000) 109 { 110 /// SocketAddr constructor. 111 ::osl::SocketAddr saSocketAddr; |
112 | 112 |
113 oslSocketResult aResult; 114 rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); 115 rtl::OUString suHost2 = getThisHostname(); | 113 oslSocketResult aResult; 114 rtl::OUString suHost = saSocketAddr.getLocalHostname( &aResult); 115 rtl::OUString suHost2 = getThisHostname(); |
116 | 116 |
117 sal_Bool bOk = compareUString(suHost, suHost2); | 117 sal_Bool bOk = compareUString(suHost, suHost2); |
118 | 118 |
119 rtl::OUString suError = rtl::OUString::createFromAscii("Host names should be the same. From SocketAddr.getLocalHostname() it is'"); 120 suError += suHost; 121 suError += rtl::OUString::createFromAscii("', from getThisHostname() it is '"); 122 suError += suHost2; 123 suError += rtl::OUString::createFromAscii("'."); | 119 rtl::OUString suError = rtl::OUString::createFromAscii("Host names should be the same. From SocketAddr.getLocalHostname() it is'"); 120 suError += suHost; 121 suError += rtl::OUString::createFromAscii("', from getThisHostname() it is '"); 122 suError += suHost2; 123 suError += rtl::OUString::createFromAscii("'."); |
124 | 124 |
125 CPPUNIT_ASSERT_MESSAGE(suError, sal_True == bOk); 126 } | 125 ASSERT_TRUE(sal_True == bOk) << suError.pData; 126 } |
127 | 127 |
128 void ctors_copy() 129 { 130 /// SocketAddr copy constructor. 131 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 132 ::osl::SocketAddr saCopySocketAddr( saSocketAddr ); | 128 TEST_F(ctors, ctors_copy) 129 { 130 /// SocketAddr copy constructor. 131 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 132 ::osl::SocketAddr saCopySocketAddr( saSocketAddr ); |
133 | 133 |
134 sal_Int32 nPort = saCopySocketAddr.getPort( ); | 134 sal_Int32 nPort = saCopySocketAddr.getPort( ); |
135 | 135 |
136 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy constructor function: copy constructor, do an action of copy construction then check the port with original set.", 137 ( sal_True == saCopySocketAddr.is( ) ) && ( nPort == IP_PORT_HTTP1 ) ); 138 } | 136 ASSERT_TRUE(( sal_True == saCopySocketAddr.is( ) ) && ( nPort == IP_PORT_HTTP1 )) << "test for SocketAddr copy constructor function: copy constructor, do an action of copy construction then check the port with original set."; 137 } |
139 | 138 |
140 void ctors_copy_no_001() 141 { | 139 TEST_F(ctors, ctors_copy_no_001) 140 { |
142#if 0 | 141#if 0 |
143 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 144 oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); | 142 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 143 oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); |
145 | 144 |
146 ::osl::SocketAddr saSocketAddrCopy( psaOSLSocketAddr, SAL_NO_COPY ); 147 saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); | 145 ::osl::SocketAddr saSocketAddrCopy( psaOSLSocketAddr, SAL_NO_COPY ); 146 saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); |
148 | 147 |
149 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", 150 saSocketAddr.getPort( ) == IP_PORT_HTTP2 ); | 148 ASSERT_TRUE(saSocketAddr.getPort( ) == IP_PORT_HTTP2) << "test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one."; |
151#endif | 149#endif |
152 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 153 CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); | 150 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 151 ASSERT_TRUE(pSocketAddr != NULL) << "check for new SocketAddr"; |
154 | 152 |
155 oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); | 153 oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); |
156 | 154 |
157 ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); | 155 ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); |
158 | 156 |
159 pSocketAddrCopy->setPort( IP_PORT_HTTP2 ); 160 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", 161 pSocketAddr->getPort( ) == IP_PORT_HTTP2 ); | 157 pSocketAddrCopy->setPort( IP_PORT_HTTP2 ); 158 ASSERT_TRUE(pSocketAddr->getPort( ) == IP_PORT_HTTP2) << "test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one."; |
162 | 159 |
163 delete pSocketAddrCopy; 164 // LLA: don't do this also: delete pSocketAddr; 165 } | 160 delete pSocketAddrCopy; 161 // LLA: don't do this also: delete pSocketAddr; 162 } |
166 | 163 |
167 void ctors_copy_no_002() 168 { 169 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 170 CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); 171 oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); 172 ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); | 164 TEST_F(ctors, ctors_copy_no_002) 165 { 166 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 167 ASSERT_TRUE(pSocketAddr != NULL) << "check for new SocketAddr"; 168 oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); 169 ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); |
173 | 170 |
174 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", 175 pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) ); | 171 ASSERT_TRUE(pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( )) << "test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one."; |
176 | 172 |
177 delete pSocketAddrCopy; 178 } | 173 delete pSocketAddrCopy; 174 } |
179 | 175 |
180 void ctors_copy_handle_001() 181 { 182 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 183 ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); | 176 TEST_F(ctors, ctors_copy_handle_001) 177 { 178 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 179 ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); |
184 | 180 |
185 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, get its port to check copy effect.", 186 saSocketAddrCopy.getPort( ) == IP_PORT_HTTP1 ); 187 } | 181 ASSERT_TRUE(saSocketAddrCopy.getPort( ) == IP_PORT_HTTP1) << "test for SocketAddr copy handle constructor function: copy another Socket's handle, get its port to check copy effect."; 182 } |
188 | 183 |
189 void ctors_copy_handle_002() 190 { 191 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 192 ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); 193 saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); | 184 TEST_F(ctors, ctors_copy_handle_002) 185 { 186 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 187 ::osl::SocketAddr saSocketAddrCopy( saSocketAddr.getHandle( ) ); 188 saSocketAddrCopy.setPort( IP_PORT_HTTP2 ); |
194 | 189 |
195 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr copy handle constructor function: copy another Socket's handle, the original one should not be changed.", 196 saSocketAddr.getPort( ) != IP_PORT_HTTP2 ); 197 } | 190 ASSERT_TRUE(saSocketAddr.getPort( ) != IP_PORT_HTTP2) << "test for SocketAddr copy handle constructor function: copy another Socket's handle, the original one should not be changed."; 191 } |
198 | 192 |
199 void ctors_hostname_port_001() 200 { 201 /// tcpip-specif constructor. 202 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 203 printUString( saSocketAddr.getHostname( ), "ctors_hostname_port_001:getHostname"); | 193 TEST_F(ctors, ctors_hostname_port_001) 194 { 195 /// tcpip-specif constructor. 196 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 197 printUString( saSocketAddr.getHostname( ), "ctors_hostname_port_001:getHostname"); |
204 | 198 |
205 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specif constructor function: do a constructor using tcpip spec, check the result.", 206 saSocketAddr.is( ) == sal_True && 207 ( saSocketAddr.getPort( ) == IP_PORT_FTP )/*&& 208 ( sal_True == compareUString( saSocketAddr.getHostname( ), aHostName1 ) ) */); 209 } | 199 ASSERT_TRUE(saSocketAddr.is( ) == sal_True && 200 ( saSocketAddr.getPort( ) == IP_PORT_FTP )/*&& 201 ( sal_True == compareUString( saSocketAddr.getHostname( ), aHostName1 ) ) */) << "test for SocketAddr tcpip specif constructor function: do a constructor using tcpip spec, check the result."; 202 } |
210 | 203 |
211 //same as is_002 212 void ctors_hostname_port_002() 213 { 214 /// tcpip-specif constructor. 215 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT2 ); | 204 //same as is_002 205 TEST_F(ctors, ctors_hostname_port_002) 206 { 207 /// tcpip-specif constructor. 208 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT2 ); |
216 | 209 |
217 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr tcpip specif constructor function: using an invalid IP address, the socketaddr ctors should fail", sal_False == saSocketAddr.is( )); 218 } 219 CPPUNIT_TEST_SUITE( ctors ); 220 CPPUNIT_TEST( ctors_none ); 221 CPPUNIT_TEST( ctors_none_000 ); 222 CPPUNIT_TEST( ctors_copy ); 223 CPPUNIT_TEST( ctors_copy_no_001 ); 224 CPPUNIT_TEST( ctors_copy_no_002 ); 225 CPPUNIT_TEST( ctors_copy_handle_001 ); 226 CPPUNIT_TEST( ctors_copy_handle_002 ); 227 CPPUNIT_TEST( ctors_hostname_port_001 ); 228 CPPUNIT_TEST( ctors_hostname_port_002 ); 229 CPPUNIT_TEST_SUITE_END(); | 210 ASSERT_TRUE(sal_False == saSocketAddr.is( )) << "test for SocketAddr tcpip specif constructor function: using an invalid IP address, the socketaddr ctors should fail"; 211 } |
230 | 212 |
231 }; // class ctors | |
232 | 213 |
233 | |
234 /** testing the method: 235 inline sal_Bool is() const; 236 */ 237 | 214 /** testing the method: 215 inline sal_Bool is() const; 216 */ 217 |
238 class is : public CppUnit::TestFixture | 218 class is : public ::testing::Test |
239 { 240 public: | 219 { 220 public: |
241 void is_001() 242 { 243 ::osl::SocketAddr saSocketAddr; | 221 }; // class is |
244 | 222 |
245 CPPUNIT_ASSERT_MESSAGE("test for is() function: create an unknown type socket, it should be True when call is.", 246 sal_True == saSocketAddr.is( ) ); 247 } 248 // refer to setPort_003() 249 void is_002() 250 { 251 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_INVAL ); | 223 TEST_F(is, is_001) 224 { 225 ::osl::SocketAddr saSocketAddr; |
252 | 226 |
253 CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid port number", 254 sal_True == saSocketAddr.is( ) ); 255 } | 227 ASSERT_TRUE(sal_True == saSocketAddr.is( )) << "test for is() function: create an unknown type socket, it should be True when call is."; 228 } 229 // refer to setPort_003() 230 TEST_F(is, is_002) 231 { 232 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_INVAL ); |
256 | 233 |
257 void is_003() 258 { 259 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT ); | 234 ASSERT_TRUE(sal_True == saSocketAddr.is( )) << "test for is() function: create a tcp-ip socket using invalid port number"; 235 } |
260 | 236 |
261 CPPUNIT_ASSERT_MESSAGE("test for is() function: create a tcp-ip socket using invalid Ip number", 262 sal_True != saSocketAddr.is( ) ); 263 } | 237 TEST_F(is, is_003) 238 { 239 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_MYPORT ); |
264 | 240 |
265 CPPUNIT_TEST_SUITE( is ); 266 CPPUNIT_TEST( is_001 ); 267 CPPUNIT_TEST( is_002 ); 268 CPPUNIT_TEST( is_003 ); 269 CPPUNIT_TEST_SUITE_END(); | 241 ASSERT_TRUE(sal_True != saSocketAddr.is( )) << "test for is() function: create a tcp-ip socket using invalid Ip number"; 242 } |
270 | 243 |
271 }; // class is 272 273 | |
274 /** testing the method: 275 inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const; 276 */ 277 | 244 /** testing the method: 245 inline ::rtl::OUString SAL_CALL getHostname( oslSocketResult *pResult = 0 ) const; 246 */ 247 |
278 class getHostname : public CppUnit::TestFixture | 248 class getHostname : public ::testing::Test |
279 { 280 public: | 249 { 250 public: |
281 void setUp() | 251 void SetUp() |
282 { 283 } 284 | 252 { 253 } 254 |
285 void tearDown() | 255 void TearDown() |
286 { 287 } | 256 { 257 } |
258 }; // class getHostname |
|
288 | 259 |
289 void getHostname_000() 290 { 291 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.107"), IP_PORT_FTP ); 292 rtl::OUString suResult = saSocketAddr.getHostname( 0 ); | 260 TEST_F(getHostname, getHostname_000) 261 { 262 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.107"), IP_PORT_FTP ); 263 rtl::OUString suResult = saSocketAddr.getHostname( 0 ); |
293 | 264 |
294 } | 265 } |
295 | 266 |
296 /** it will search the Ip in current machine's /etc/hosts at first, if find, then return the 297 mapped hostname, otherwise, it will search via DNS server, and often return hostname+ Domain name 298 like "sceri.PRC.Sun.COM" 299 The process is same as Socket::getLocalHost(), but getLocalHost can only return hostname of the current machine. 300 */ 301 void getHostname_001() 302 { 303 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.107"), IP_PORT_FTP ); 304 rtl::OUString suResult = saSocketAddr.getHostname( 0 ); 305 rtl::OUString suError = outputError(suResult, rtl::OUString::createFromAscii("sceri.PRC.Sun.COM"), "test for getHostname(0)"); 306 sal_Bool bOK = compareUString( suResult, rtl::OUString::createFromAscii("sceri.PRC.Sun.COM") ); 307 // search the returned hostname in /etc/hosts, if find, and the IP in the row is same as IP 308 // in the Addr, it's right also. 309 if ( bOK == sal_False) 310 { 311 rtl::OString aString = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); 312 if ( compareUString( getIPbyName( aString ), rtl::OUString::createFromAscii("129.158.217.107") ) == sal_True ) 313 bOK = sal_True; 314 } 315 CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK); 316 } | 267 /** it will search the Ip in current machine's /etc/hosts at first, if find, then return the 268 mapped hostname, otherwise, it will search via DNS server, and often return hostname+ Domain name 269 like "sceri.PRC.Sun.COM" 270 The process is same as Socket::getLocalHost(), but getLocalHost can only return hostname of the current machine. 271 */ 272 TEST_F(getHostname, getHostname_001) 273 { 274 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.107"), IP_PORT_FTP ); 275 rtl::OUString suResult = saSocketAddr.getHostname( 0 ); 276 rtl::OUString suError = outputError(suResult, rtl::OUString::createFromAscii("sceri.PRC.Sun.COM"), "test for getHostname(0)"); 277 sal_Bool bOK = compareUString( suResult, rtl::OUString::createFromAscii("sceri.PRC.Sun.COM") ); 278 // search the returned hostname in /etc/hosts, if find, and the IP in the row is same as IP 279 // in the Addr, it's right also. 280 if ( bOK == sal_False) 281 { 282 rtl::OString aString = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); 283 if ( compareUString( getIPbyName( aString ), rtl::OUString::createFromAscii("129.158.217.107") ) == sal_True ) 284 bOK = sal_True; 285 } 286 ASSERT_TRUE(sal_True == bOK) << suError.pData; 287 } |
317 318// LLA: now we have to control, if this behaviour is right. 319// LLA: this function does not work in company (Linux, Windows) but at home | 288 289// LLA: now we have to control, if this behaviour is right. 290// LLA: this function does not work in company (Linux, Windows) but at home |
320 void getHostname_002() 321 { 322 rtl::OUString suHostname = rtl::OUString::createFromAscii("cn-1.germany.sun.com"); 323 rtl::OString aString = ::rtl::OUStringToOString( suHostname, RTL_TEXTENCODING_ASCII_US ); 324 rtl::OUString aHostIP = getIPbyName( aString ); | 291 TEST_F(getHostname, getHostname_002) 292 { 293 rtl::OUString suHostname = rtl::OUString::createFromAscii("cn-1.germany.sun.com"); 294 rtl::OString aString = ::rtl::OUStringToOString( suHostname, RTL_TEXTENCODING_ASCII_US ); 295 rtl::OUString aHostIP = getIPbyName( aString ); |
325 | 296 |
326 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_FTP ); 327 sal_Bool bOK = saSocketAddr.setHostname( suHostname ); 328 CPPUNIT_ASSERT_MESSAGE("#SocketAddr.setHostname failed", sal_True == bOK ); 329 oslSocketResult aResult; 330 rtl::OUString suResult = saSocketAddr.getHostname( &aResult ); 331 CPPUNIT_ASSERT_MESSAGE("SocketAddr.getHostname failed.", aResult == osl_Socket_Ok); | 297 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_FTP ); 298 sal_Bool bOK = saSocketAddr.setHostname( suHostname ); 299 ASSERT_TRUE(sal_True == bOK) << "#SocketAddr.setHostname failed"; 300 oslSocketResult aResult; 301 rtl::OUString suResult = saSocketAddr.getHostname( &aResult ); 302 ASSERT_TRUE(aResult == osl_Socket_Ok) << "SocketAddr.getHostname failed."; |
332 | 303 |
333 rtl::OUString suError = outputError(suResult, suHostname, "test for getHostname(0)"); 334 bOK = compareUString( suResult, suHostname ); 335 if ( bOK == sal_False) 336 { 337 rtl::OString aStringResult = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); 338 rtl::OString aStringHostname = ::rtl::OUStringToOString( suHostname, RTL_TEXTENCODING_ASCII_US ); 339 if ( compareUString( getIPbyName( aStringResult ) , getIPbyName( aStringHostname ) ) == sal_True ) 340 { 341 bOK = sal_True; 342 } | 304 rtl::OUString suError = outputError(suResult, suHostname, "test for getHostname(0)"); 305 bOK = compareUString( suResult, suHostname ); 306 if ( bOK == sal_False) 307 { 308 rtl::OString aStringResult = ::rtl::OUStringToOString( suResult, RTL_TEXTENCODING_ASCII_US ); 309 rtl::OString aStringHostname = ::rtl::OUStringToOString( suHostname, RTL_TEXTENCODING_ASCII_US ); 310 if ( compareUString( getIPbyName( aStringResult ) , getIPbyName( aStringHostname ) ) == sal_True ) 311 { 312 bOK = sal_True; |
343 } | 313 } |
314 } |
|
344 | 315 |
345 CPPUNIT_ASSERT_MESSAGE( suError, sal_True == bOK ); 346 } | 316 ASSERT_TRUE(sal_True == bOK) << suError.pData; 317 } |
347 | 318 |
348 349 CPPUNIT_TEST_SUITE( getHostname ); 350 CPPUNIT_TEST( getHostname_001 ); 351 CPPUNIT_TEST( getHostname_002 ); 352 CPPUNIT_TEST_SUITE_END(); 353 354 }; // class getHostname 355 356 | |
357 /** testing the method: 358 inline sal_Int32 SAL_CALL getPort() const; 359 */ 360 | 319 /** testing the method: 320 inline sal_Int32 SAL_CALL getPort() const; 321 */ 322 |
361 class getPort : public CppUnit::TestFixture | 323 class getPort : public ::testing::Test |
362 { 363 public: | 324 { 325 public: |
364 void getPort_001() 365 { 366 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); | 326 }; // class getPort |
367 | 327 |
368 CPPUNIT_ASSERT_MESSAGE( "test for getPort() function: get a normal port number.", 369 IP_PORT_FTP == saSocketAddr.getPort( ) ); 370 } | 328 TEST_F(getPort, getPort_001) 329 { 330 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); |
371 | 331 |
372 void getPort_002() 373 { 374 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_INVAL ); | 332 ASSERT_TRUE(IP_PORT_FTP == saSocketAddr.getPort( )) << "test for getPort() function: get a normal port number."; 333 } |
375 | 334 |
376 //t_print("#getPort_002: Port number is %d \n", saSocketAddr.getPort( )); | 335 TEST_F(getPort, getPort_002) 336 { 337 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_INVAL ); |
377 | 338 |
378 CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid port to a SocketAddr, get the port to see if it can detect. it did not pass in (W32).", 379 saSocketAddr.getPort( )>=1 && saSocketAddr.getPort( ) <= 65535 ); 380 } 381 //two cases will return OSL_INVALID_PORT: 1. not valid SocketAddr 382 //2. SocketAddr family is not osl_Socket_FamilyInet, but case 2 could not be constructed 383 void getPort_003() 384 { 385 rtl::OUString suInvalidIP = rtl::OUString::createFromAscii("123.345.67.89"); 386 ::osl::SocketAddr saSocketAddr( suInvalidIP, IP_PORT_MYPORT ); | 339 //t_print("#getPort_002: Port number is %d \n", saSocketAddr.getPort( )); |
387 | 340 |
388 CPPUNIT_ASSERT_MESSAGE( "test for getPort( ) function: give an invalid IP to a SocketAddr, get the port to see returned value. ", 389 saSocketAddr.getPort( ) == OSL_INVALID_PORT ); 390 } | 341 ASSERT_TRUE(saSocketAddr.getPort( )>=1 && saSocketAddr.getPort( ) <= 65535) << "test for getPort( ) function: give an invalid port to a SocketAddr, get the port to see if it can detect. it did not pass in (W32)."; 342 } 343 //two cases will return OSL_INVALID_PORT: 1. not valid SocketAddr 344 //2. SocketAddr family is not osl_Socket_FamilyInet, but case 2 could not be constructed 345 TEST_F(getPort, getPort_003) 346 { 347 rtl::OUString suInvalidIP = rtl::OUString::createFromAscii("123.345.67.89"); 348 ::osl::SocketAddr saSocketAddr( suInvalidIP, IP_PORT_MYPORT ); |
391 | 349 |
392 CPPUNIT_TEST_SUITE( getPort ); 393 CPPUNIT_TEST( getPort_001 ); 394 CPPUNIT_TEST( getPort_002 ); 395 CPPUNIT_TEST( getPort_003 ); 396 CPPUNIT_TEST_SUITE_END( ); | 350 ASSERT_TRUE(saSocketAddr.getPort( ) == OSL_INVALID_PORT) << "test for getPort( ) function: give an invalid IP to a SocketAddr, get the port to see returned value. "; 351 } |
397 | 352 |
398 }; // class getPort 399 400 | |
401 /** testing the method: 402 inline sal_Bool SAL_CALL setPort( sal_Int32 nPort ); 403 rfc1413.txt: TCP port numbers are from 1-65535 404 rfc1700.txt: 0/tcp Reserved ; 0/udp Reserved 405 */ 406 | 353 /** testing the method: 354 inline sal_Bool SAL_CALL setPort( sal_Int32 nPort ); 355 rfc1413.txt: TCP port numbers are from 1-65535 356 rfc1700.txt: 0/tcp Reserved ; 0/udp Reserved 357 */ 358 |
407 class setPort : public CppUnit::TestFixture | 359 class setPort : public ::testing::Test |
408 { 409 public: | 360 { 361 public: |
410 void setPort_001() 411 { 412 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 413 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_TELNET ); | 362 }; // class setPort |
414 | 363 |
415 CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: modify a port number setting, and check it.", 416 ( sal_True == bOK ) && 417 ( IP_PORT_TELNET == saSocketAddr.getPort( ) ) ); 418 } | 364 TEST_F(setPort, setPort_001) 365 { 366 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 367 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_TELNET ); |
419 | 368 |
420 /** 0 to 1024 is known as the reserved port range (traditionally only root can assign programs to ports in 421 this range) and the ephemeral port range from 1025 to 65535. 422 As many of you programmers will know, when you specify the source port of 0 when you connect to a host, 423 the OS automatically reassigns the port number to high numbered ephemeral port. The same happens if you 424 try to bind a listening socket to port 0. 425 http://www.securiteam.com/securityreviews/5XP0Q2AAKS.html 426 another: http://www.muq.org/~cynbe/muq/mufref_564.html 427 */ 428 void setPort_002() 429 { 430 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 431 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_ZERO ); | 369 ASSERT_TRUE(( sal_True == bOK ) && 370 ( IP_PORT_TELNET == saSocketAddr.getPort( ) )) << "test for setPort() function: modify a port number setting, and check it."; 371 } |
432 | 372 |
433 oslSocket sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); 434 ::osl::Socket sSocket(sHandle); 435 sSocket.setOption( osl_Socket_OptionReuseAddr, 1 );//sal_True); 436 sal_Bool bOK1 = sSocket.bind( saSocketAddr ); 437 CPPUNIT_ASSERT_MESSAGE( "bind SocketAddr failed", bOK1 == sal_True ); | 373 /** 0 to 1024 is known as the reserved port range (traditionally only root can assign programs to ports in 374 this range) and the ephemeral port range from 1025 to 65535. 375 As many of you programmers will know, when you specify the source port of 0 when you connect to a host, 376 the OS automatically reassigns the port number to high numbered ephemeral port. The same happens if you 377 try to bind a listening socket to port 0. 378 http://www.securiteam.com/securityreviews/5XP0Q2AAKS.html 379 another: http://www.muq.org/~cynbe/muq/mufref_564.html 380 */ 381 TEST_F(setPort, setPort_002) 382 { 383 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 384 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_ZERO ); |
438 | 385 |
439 sal_Int32 newPort = sSocket.getLocalPort(); 440 //t_print("#new port is %d\n", newPort ); | 386 oslSocket sHandle = osl_createSocket( osl_Socket_FamilyInet, osl_Socket_TypeStream, osl_Socket_ProtocolIp ); 387 ::osl::Socket sSocket(sHandle); 388 sSocket.setOption( osl_Socket_OptionReuseAddr, 1 );//sal_True); 389 sal_Bool bOK1 = sSocket.bind( saSocketAddr ); 390 ASSERT_TRUE(bOK1 == sal_True) << "bind SocketAddr failed"; |
441 | 391 |
442 CPPUNIT_ASSERT_MESSAGE( "test for setPort() function: port number should be in 1 ~ 65535, set port 0, it should be converted to a port number between 1024~65535.", 443 ( 1024 <= newPort ) && ( 65535 >= newPort ) && ( bOK == sal_True ) ); | 392 sal_Int32 newPort = sSocket.getLocalPort(); 393 //t_print("#new port is %d\n", newPort ); |
444 | 394 |
445 } | 395 ASSERT_TRUE(( 1024 <= newPort ) && ( 65535 >= newPort ) && ( bOK == sal_True )) << "test for setPort() function: port number should be in 1 ~ 65535, set port 0, it should be converted to a port number between 1024~65535."; |
446 | 396 |
447 void setPort_003() 448 { 449 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP); 450 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_INVAL ); 451 //on Linux, getPort return 34463 452 //t_print("#Port number is %d \n", saSocketAddr.getPort( )); | 397 } |
453 | 398 |
454 CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an address with invalid port. it should return error or convert it to a valid port.", 455 ( ( 1 <= saSocketAddr.getPort( ) ) && ( 65535 >= saSocketAddr.getPort( ) ) &&( bOK == sal_True ) ) || 456 bOK == sal_False); 457 } | 399 TEST_F(setPort, setPort_003) 400 { 401 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP); 402 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_INVAL ); 403 //on Linux, getPort return 34463 404 //t_print("#Port number is %d \n", saSocketAddr.getPort( )); |
458 | 405 |
459 /* this is not a inet-addr => can't set port */ 460 void setPort_004() 461 { 462 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_FTP); 463 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_MYPORT ); | 406 ASSERT_TRUE(( ( 1 <= saSocketAddr.getPort( ) ) && ( 65535 >= saSocketAddr.getPort( ) ) &&( bOK == sal_True ) ) || 407 bOK == sal_False) << "test for setPort( ) function: set an address with invalid port. it should return error or convert it to a valid port."; 408 } |
464 | 409 |
465 CPPUNIT_ASSERT_MESSAGE( "test for setPort( ) function: set an invalid address with valid port. it should return error.", 466 bOK == sal_False); 467 } | 410 /* this is not a inet-addr => can't set port */ 411 TEST_F(setPort, setPort_004) 412 { 413 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("123.345.67.89"), IP_PORT_FTP); 414 sal_Bool bOK = saSocketAddr.setPort( IP_PORT_MYPORT ); |
468 | 415 |
416 ASSERT_TRUE(bOK == sal_False) << "test for setPort( ) function: set an invalid address with valid port. it should return error."; 417 } |
|
469 | 418 |
470 CPPUNIT_TEST_SUITE( setPort ); 471 CPPUNIT_TEST( setPort_001 ); 472 CPPUNIT_TEST( setPort_002 ); 473 CPPUNIT_TEST( setPort_003 ); 474 CPPUNIT_TEST( setPort_004 ); 475 CPPUNIT_TEST_SUITE_END( ); 476 477 }; // class setPort 478 479 | |
480 /** tester comment: 481 482 In the following two functions, it use ::rtl::ByteSequence as an intermediate storage for address, 483 the ByteSequence object can hold sal_Int8 arrays, which is raged [-127, 127], in case of IP addr 484 that is greater than 127, say 129.158.217.202, it will stored as -127, -98, -39, -54, it is unique 485 in the range of sal_Int8, but lack of readability. 486 so may be a sal_uInt8 array is better. 487 */ 488 489 490 /** testing the method: 491 inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address ); 492 */ 493 | 419 /** tester comment: 420 421 In the following two functions, it use ::rtl::ByteSequence as an intermediate storage for address, 422 the ByteSequence object can hold sal_Int8 arrays, which is raged [-127, 127], in case of IP addr 423 that is greater than 127, say 129.158.217.202, it will stored as -127, -98, -39, -54, it is unique 424 in the range of sal_Int8, but lack of readability. 425 so may be a sal_uInt8 array is better. 426 */ 427 428 429 /** testing the method: 430 inline sal_Bool SAL_CALL setAddr( const ::rtl::ByteSequence & address ); 431 */ 432 |
494 class setAddr : public CppUnit::TestFixture | 433 class setAddr : public ::testing::Test |
495 { 496 public: | 434 { 435 public: |
497 void setAddr_001() 498 { 499 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); 500 saSocketAddr.setAddr( UStringIPToByteSequence( rtl::OUString::createFromAscii("127.0.0.1") ) ); 501 ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); 502 sal_Bool bOK = sal_False; | 436 }; // class setAddr |
503 | 437 |
504 // if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) && ( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 505 // bOK = sal_True; 506 bOK = ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ); | 438 TEST_F(setAddr, setAddr_001) 439 { 440 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); 441 saSocketAddr.setAddr( UStringIPToByteSequence( rtl::OUString::createFromAscii("127.0.0.1") ) ); 442 ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); 443 sal_Bool bOK = sal_False; |
507 | 444 |
508 CPPUNIT_ASSERT_MESSAGE( "test for setAddr() function: construct Addr with \"129.158.217.202\", set it to \"127.0.0.1\", and check the correctness ", 509 sal_True == bOK ); 510 } | 445 // if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) && ( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 446 // bOK = sal_True; 447 bOK = ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ); |
511 | 448 |
449 ASSERT_TRUE(sal_True == bOK) << "test for setAddr() function: construct Addr with \"129.158.217.202\", set it to \"127.0.0.1\", and check the correctness "; 450 } |
|
512 | 451 |
513 CPPUNIT_TEST_SUITE( setAddr ); 514 CPPUNIT_TEST( setAddr_001 ); 515 CPPUNIT_TEST_SUITE_END( ); 516 517 }; // class setAddr 518 519 | |
520 /** testing the method: 521 inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const; 522 */ 523 | 452 /** testing the method: 453 inline ::rtl::ByteSequence SAL_CALL getAddr( oslSocketResult *pResult = 0 ) const; 454 */ 455 |
524 class getAddr : public CppUnit::TestFixture | 456 class getAddr : public ::testing::Test |
525 { 526 public: | 457 { 458 public: |
527 void getAddr_001() 528 { 529 oslSocketResult SocketResult; 530 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 531 ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( &SocketResult ); | 459 }; // class getAddr |
532 | 460 |
533 sal_Bool bOK = sal_False; | 461 TEST_F(getAddr, getAddr_001) 462 { 463 oslSocketResult SocketResult; 464 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_FTP ); 465 ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( &SocketResult ); |
534 | 466 |
535 //if ( ( osl_Socket_Ok == SocketResult ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 536 // bOK = sal_True; 537 bOK = ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ); | 467 sal_Bool bOK = sal_False; |
538 | 468 |
539 CPPUNIT_ASSERT_MESSAGE( "test for getAddr() function: construct a socketaddr with IP assigned, get the address to check correctness.Caught unknown exception on (Win32)", 540 sal_True == bOK && SocketResult == osl_Socket_Ok); 541 } | 469 //if ( ( osl_Socket_Ok == SocketResult ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 470 // bOK = sal_True; 471 bOK = ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ); |
542 | 472 |
543 CPPUNIT_TEST_SUITE( getAddr ); 544 CPPUNIT_TEST( getAddr_001 ); 545 CPPUNIT_TEST_SUITE_END( ); | 473 ASSERT_TRUE(sal_True == bOK && SocketResult == osl_Socket_Ok) << "test for getAddr() function: construct a socketaddr with IP assigned, get the address to check correctness.Caught unknown exception on (Win32)"; 474 } |
546 | 475 |
547 }; // class getAddr 548 549 | |
550 /** testing the methods: 551 inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr); 552 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr); 553 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy ); 554 inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const; 555 inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; /// not implemented. 556 */ 557 | 476 /** testing the methods: 477 inline SocketAddr & SAL_CALL operator= (oslSocketAddr Addr); 478 inline SocketAddr & SAL_CALL operator= (const SocketAddr& Addr); 479 inline SocketAddr & SAL_CALL assign( oslSocketAddr Addr, __osl_socket_NoCopy nocopy ); 480 inline sal_Bool SAL_CALL operator== (oslSocketAddr Addr) const; 481 inline sal_Bool SAL_CALL operator== (const SocketAddr & Addr) const; /// not implemented. 482 */ 483 |
558 class operator_equal : public CppUnit::TestFixture | 484 class operator_equal : public ::testing::Test |
559 { 560 public: | 485 { 486 public: |
561 void operator_equal_001() 562 { 563 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 564 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); | 487 }; // class operator_equal |
565 | 488 |
566 saSocketAddrEqual = saSocketAddr; 567 sal_Bool bOK = sal_False; 568 ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); | 489 TEST_F(operator_equal, operator_equal_001) 490 { 491 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 492 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); |
569 | 493 |
570 // if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 571 if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) && ( ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ) == sal_True ) ) 572 bOK = sal_True; | 494 saSocketAddrEqual = saSocketAddr; 495 sal_Bool bOK = sal_False; 496 ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); |
573 | 497 |
574 CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: use operator= to assign Ip1 to Ip2, check its modification.", 575 sal_True == bOK ); 576 } | 498 // if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 499 if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) && ( ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ) == sal_True ) ) 500 bOK = sal_True; |
577 | 501 |
502 ASSERT_TRUE(sal_True == bOK) << "test for operator_equal() function: use operator= to assign Ip1 to Ip2, check its modification."; 503 } |
|
578 | 504 |
579 void operator_equal_002() 580 { 581 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.199"), IP_PORT_TELNET); 582 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); | |
583 | 505 |
584 saSocketAddrEqual = saSocketAddr; 585 CPPUNIT_ASSERT_MESSAGE( "after assign, the assigned SocketAddr is not same as the original Addr", 586 IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ); 587 saSocketAddrEqual.setPort( IP_PORT_MYPORT3 ); 588 saSocketAddr.setPort( IP_PORT_HTTP2 ); | 506 TEST_F(operator_equal, operator_equal_002) 507 { 508 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.199"), IP_PORT_TELNET); 509 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); |
589 | 510 |
590 CPPUNIT_ASSERT_MESSAGE( "test for operator_equal() function: perform an equal action, then try to change the original address's port. it should not be changed ( handle released), it did not pass in (W32), this is under discussion.", 591 IP_PORT_MYPORT3 == saSocketAddrEqual.getPort( ) ); 592 } | 511 saSocketAddrEqual = saSocketAddr; 512 ASSERT_TRUE(IP_PORT_TELNET == saSocketAddrEqual.getPort( )) << "after assign, the assigned SocketAddr is not same as the original Addr"; 513 saSocketAddrEqual.setPort( IP_PORT_MYPORT3 ); 514 saSocketAddr.setPort( IP_PORT_HTTP2 ); |
593 | 515 |
594 void operator_equal_const_001() 595 { 596 const ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 597 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); | 516 ASSERT_TRUE(IP_PORT_MYPORT3 == saSocketAddrEqual.getPort( )) << "test for operator_equal() function: perform an equal action, then try to change the original address's port. it should not be changed ( handle released), it did not pass in (W32), this is under discussion."; 517 } |
598 | 518 |
599 saSocketAddrEqual = saSocketAddr; 600 sal_Bool bOK = sal_False; 601 ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); | 519 TEST_F(operator_equal, operator_equal_const_001) 520 { 521 const ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 522 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); |
602 | 523 |
603 // if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 604 if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) && ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ) == sal_True ) 605 bOK = sal_True; | 524 saSocketAddrEqual = saSocketAddr; 525 sal_Bool bOK = sal_False; 526 ::rtl::ByteSequence bsSocketAddr = saSocketAddrEqual.getAddr( 0 ); |
606 | 527 |
607 CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: use operator= const to assign Ip1 to Ip2, verify the change on the second one.", 608 sal_True == bOK ); 609 } | 528 // if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) &&( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 529 if ( ( IP_PORT_TELNET == saSocketAddrEqual.getPort( ) ) && ifIpv4is( bsSocketAddr, 127, 0, 0, 1 ) == sal_True ) 530 bOK = sal_True; |
610 | 531 |
611 void operator_equal_const_002() 612 { 613 const ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 614 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); | 532 ASSERT_TRUE(sal_True == bOK) << "test for operator_equal_const() function: use operator= const to assign Ip1 to Ip2, verify the change on the second one."; 533 } |
615 | 534 |
616 saSocketAddrEqual = saSocketAddr; 617 saSocketAddrEqual.setPort( IP_PORT_HTTP1 ); | 535 TEST_F(operator_equal, operator_equal_const_002) 536 { 537 const ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 538 ::osl::SocketAddr saSocketAddrEqual( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); |
618 | 539 |
619 CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_const() function: change the second instance, the first one should not be altered, since it does not released the handle.", 620 IP_PORT_HTTP1 != saSocketAddr.getPort( ) ); 621 } | 540 saSocketAddrEqual = saSocketAddr; 541 saSocketAddrEqual.setPort( IP_PORT_HTTP1 ); |
622 | 542 |
623 void operator_equal_assign_001() 624 { 625 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); 626 CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); 627 ::osl::SocketAddr* pSocketAddrAssign = new ::osl::SocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); 628 oslSocketAddr poslSocketAddr = pSocketAddr->getHandle( ); 629 //if( m_handle ) osl_destroySocketAddr( m_handle ); so pSocketAddrAssign had been destroyed and then point to pSocketAddr 630 pSocketAddrAssign->assign(poslSocketAddr, SAL_NO_COPY); | 543 ASSERT_TRUE(IP_PORT_HTTP1 != saSocketAddr.getPort( )) << "test for operator_equal_const() function: change the second instance, the first one should not be altered, since it does not released the handle."; 544 } |
631 | 545 |
632 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", 633 pSocketAddrAssign->getPort( ) == IP_PORT_TELNET ); | 546 TEST_F(operator_equal, operator_equal_assign_001) 547 { 548 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); 549 ASSERT_TRUE(pSocketAddr != NULL) << "check for new SocketAddr"; 550 ::osl::SocketAddr* pSocketAddrAssign = new ::osl::SocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP ); 551 oslSocketAddr poslSocketAddr = pSocketAddr->getHandle( ); 552 //if( m_handle ) osl_destroySocketAddr( m_handle ); so pSocketAddrAssign had been destroyed and then point to pSocketAddr 553 pSocketAddrAssign->assign(poslSocketAddr, SAL_NO_COPY); |
634 | 554 |
635 delete pSocketAddrAssign; 636 } | 555 ASSERT_TRUE(pSocketAddrAssign->getPort( ) == IP_PORT_TELNET) << "test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one."; |
637 | 556 |
638 void operator_is_equal_001() 639 { 640 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 641 ::osl::SocketAddr saSocketAddrequal( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); | 557 delete pSocketAddrAssign; 558 } |
642 | 559 |
643 CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two identical Address.", 644 sal_True == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) ); 645 } | 560 TEST_F(operator_equal, operator_is_equal_001) 561 { 562 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET); 563 ::osl::SocketAddr saSocketAddrequal( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); |
646 | 564 |
647 void operator_is_equal_002() 648 { 649 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP); 650 ::osl::SocketAddr saSocketAddrequal( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); | 565 ASSERT_TRUE(sal_True == ( saSocketAddrequal == saSocketAddr.getHandle( ) )) << "test for operator_equal_equal() function: check two identical Address."; 566 } |
651 | 567 |
652 CPPUNIT_ASSERT_MESSAGE( "test for operator_equal_equal() function: check two different Address.", 653 sal_False == ( saSocketAddrequal == saSocketAddr.getHandle( ) ) ); 654 } | 568 TEST_F(operator_equal, operator_is_equal_002) 569 { 570 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("129.158.217.202"), IP_PORT_FTP); 571 ::osl::SocketAddr saSocketAddrequal( rtl::OUString::createFromAscii("127.0.0.1"), IP_PORT_TELNET ); |
655 | 572 |
656 CPPUNIT_TEST_SUITE( operator_equal ); 657 CPPUNIT_TEST( operator_equal_001 ); 658 CPPUNIT_TEST( operator_equal_002 ); 659 CPPUNIT_TEST( operator_equal_const_001 ); 660 CPPUNIT_TEST( operator_equal_const_002 ); 661 CPPUNIT_TEST( operator_equal_assign_001 ); 662 CPPUNIT_TEST( operator_is_equal_001 ); 663 CPPUNIT_TEST( operator_is_equal_002 ); 664 CPPUNIT_TEST_SUITE_END( ); | 573 ASSERT_TRUE(sal_False == ( saSocketAddrequal == saSocketAddr.getHandle( ) )) << "test for operator_equal_equal() function: check two different Address."; 574 } |
665 | 575 |
666 }; // class operator_equal | |
667 | 576 |
668 669 | |
670 /** testing the method: 671 inline oslSocketAddr SAL_CALL getHandle() const; 672 */ 673 | 577 /** testing the method: 578 inline oslSocketAddr SAL_CALL getHandle() const; 579 */ 580 |
674 class getSocketAddrHandle : public CppUnit::TestFixture | 581 class getSocketAddrHandle : public ::testing::Test |
675 { 676 public: | 582 { 583 public: |
584 }; // class getSocketAddrHandle |
|
677 | 585 |
678 void getSocketAddrHandle_001() 679 { 680 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 681 CPPUNIT_ASSERT_MESSAGE("check for new SocketAddr", pSocketAddr != NULL); 682 oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); 683 ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); | 586 TEST_F(getSocketAddrHandle, getSocketAddrHandle_001) 587 { 588 ::osl::SocketAddr* pSocketAddr = new ::osl::SocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 589 ASSERT_TRUE(pSocketAddr != NULL) << "check for new SocketAddr"; 590 oslSocketAddr psaOSLSocketAddr = pSocketAddr->getHandle( ); 591 ::osl::SocketAddr* pSocketAddrCopy = new ::osl::SocketAddr( psaOSLSocketAddr, SAL_NO_COPY ); |
684 | 592 |
685 CPPUNIT_ASSERT_MESSAGE("test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one.", 686 pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( ) ); | 593 ASSERT_TRUE(pSocketAddr->getHandle( ) == pSocketAddrCopy->getHandle( )) << "test for SocketAddr no copy constructor function: do a no copy constructor on a given SocketAddr instance, modify the new instance's port, check the original one."; |
687 | 594 |
688 delete pSocketAddrCopy; 689 } | 595 delete pSocketAddrCopy; 596 } |
690 | 597 |
691 void getSocketAddrHandle_002() 692 { 693 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("deuce.PRC.Sun.COM"), IP_PORT_MYPORT4 ); 694 oslSocketAddr poslSocketAddr = saSocketAddr.getHandle( ); | 598 TEST_F(getSocketAddrHandle, getSocketAddrHandle_002) 599 { 600 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("deuce.PRC.Sun.COM"), IP_PORT_MYPORT4 ); 601 oslSocketAddr poslSocketAddr = saSocketAddr.getHandle( ); |
695 | 602 |
696 sal_Bool bOK = ( saSocketAddr == poslSocketAddr ); 697 //t_print("getSocketAddrHandle_002\n"); 698 CPPUNIT_ASSERT_MESSAGE( "test for getHandle() function: use getHandle() function as an intermediate way to create identical address.", 699 sal_True == bOK ); 700 } | 603 sal_Bool bOK = ( saSocketAddr == poslSocketAddr ); 604 //t_print("getSocketAddrHandle_002\n"); 605 ASSERT_TRUE(sal_True == bOK) << "test for getHandle() function: use getHandle() function as an intermediate way to create identical address."; 606 } |
701 | 607 |
702 CPPUNIT_TEST_SUITE( getSocketAddrHandle ); 703 CPPUNIT_TEST( getSocketAddrHandle_001 ); 704 CPPUNIT_TEST( getSocketAddrHandle_002 ); 705 CPPUNIT_TEST_SUITE_END( ); 706 707 }; // class getSocketAddrHandle 708 709 | |
710 /** testing the method: 711 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0); 712 */ 713 | 608 /** testing the method: 609 static inline ::rtl::OUString SAL_CALL getLocalHostname( oslSocketResult *pResult = 0); 610 */ 611 |
714 class getLocalHostname : public CppUnit::TestFixture | 612 class getLocalHostname : public ::testing::Test |
715 { 716 public: | 613 { 614 public: |
717 /* the process of getLocalHostname: 1.gethostname (same as /bin/hostname) returned name A 718 2. search A in /etc/hosts, if there is an alias name is A, return the name in the same row 719 */ | 615 }; // class getLocalHostname |
720 | 616 |
721 void getLocalHostname_000() 722 { 723 // _osl_getFullQualifiedDomainName( ); 724 oslSocketResult aResult = osl_Socket_Error; 725 rtl::OUString suHostname = osl::SocketAddr::getLocalHostname(&aResult); 726 CPPUNIT_ASSERT_MESSAGE("getLocalHostname failed", aResult == osl_Socket_Ok); 727 } | 617 /* the process of getLocalHostname: 1.gethostname (same as /bin/hostname) returned name A 618 2. search A in /etc/hosts, if there is an alias name is A, return the name in the same row 619 */ |
728 | 620 |
729 void getLocalHostname_001() 730 { 731 oslSocketResult *pResult = NULL; 732 //printSocketResult(*pResult); 733 ::rtl::OUString suResult = ::osl::SocketAddr::getLocalHostname( pResult ); | 621 TEST_F(getLocalHostname, getLocalHostname_000) 622 { 623 // _osl_getFullQualifiedDomainName( ); 624 oslSocketResult aResult = osl_Socket_Error; 625 rtl::OUString suHostname = osl::SocketAddr::getLocalHostname(&aResult); 626 ASSERT_TRUE(aResult == osl_Socket_Ok) << "getLocalHostname failed"; 627 } |
734 | 628 |
735 // LLA: IMHO localhost, or hostname by itself should be ok. 736 rtl::OUString suThisHost = getThisHostname( ); 737 bool bOk = false; 738 if (suThisHost.equals(rtl::OUString::createFromAscii("localhost"))) | 629 TEST_F(getLocalHostname, getLocalHostname_001) 630 { 631 oslSocketResult *pResult = NULL; 632 //printSocketResult(*pResult); 633 ::rtl::OUString suResult = ::osl::SocketAddr::getLocalHostname( pResult ); 634 635 // LLA: IMHO localhost, or hostname by itself should be ok. 636 rtl::OUString suThisHost = getThisHostname( ); 637 bool bOk = false; 638 if (suThisHost.equals(rtl::OUString::createFromAscii("localhost"))) 639 { 640 bOk = true; 641 } 642 else 643 { 644 if (suThisHost.equals(suResult)) |
739 { 740 bOk = true; 741 } | 645 { 646 bOk = true; 647 } |
742 else 743 { 744 if (suThisHost.equals(suResult)) 745 { 746 bOk = true; 747 } 748 } | 648 } |
749 | 649 |
750 ::rtl::OUString suError; 751 suError = outputError(suResult, getThisHostname( ), "test for getLocalHostname() function"); | 650 ::rtl::OUString suError; 651 suError = outputError(suResult, getThisHostname( ), "test for getLocalHostname() function"); |
752 | 652 |
753 CPPUNIT_ASSERT_MESSAGE( suError, bOk == true ); 754 } | 653 ASSERT_TRUE(bOk == true) << suError.pData; 654 } |
755 | 655 |
756 CPPUNIT_TEST_SUITE( getLocalHostname ); 757 CPPUNIT_TEST( getLocalHostname_000 ); 758 CPPUNIT_TEST( getLocalHostname_001 ); 759 CPPUNIT_TEST_SUITE_END( ); 760 761 }; // class getLocalHostname 762 763 | |
764 /** testing the method: 765 static inline void SAL_CALL resolveHostname( const ::rtl::OUString & strHostName , SocketAddr & Addr ); 766 */ 767 | 656 /** testing the method: 657 static inline void SAL_CALL resolveHostname( const ::rtl::OUString & strHostName , SocketAddr & Addr ); 658 */ 659 |
768 class resolveHostname : public CppUnit::TestFixture | 660 class resolveHostname : public ::testing::Test |
769 { 770 public: | 661 { 662 public: |
771 void resolveHostname_001() 772 { 773 ::osl::SocketAddr saSocketAddr; 774 ::osl::SocketAddr::resolveHostname( rtl::OUString::createFromAscii("127.0.0.1"), saSocketAddr ); 775 ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); 776 sal_Bool bOK = sal_False; | 663 }; // class resolveHostname |
777 | 664 |
778 if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 779 bOK = sal_True; | 665 TEST_F(resolveHostname, resolveHostname_001) 666 { 667 ::osl::SocketAddr saSocketAddr; 668 ::osl::SocketAddr::resolveHostname( rtl::OUString::createFromAscii("127.0.0.1"), saSocketAddr ); 669 ::rtl::ByteSequence bsSocketAddr = saSocketAddr.getAddr( 0 ); 670 sal_Bool bOK = sal_False; |
780 | 671 |
781 CPPUNIT_ASSERT_MESSAGE( "test for resolveHostname() function: try to resolve localhost to 127.0.0.1.", 782 sal_True == bOK ); 783 } | 672 if ( ( bsSocketAddr[0] == 127 ) && ( bsSocketAddr[1] == 0 ) &&( bsSocketAddr[2] == 0 ) && ( bsSocketAddr[3] == 1 ) ) 673 bOK = sal_True; |
784 | 674 |
785 CPPUNIT_TEST_SUITE( resolveHostname ); 786 CPPUNIT_TEST( resolveHostname_001 ); 787 CPPUNIT_TEST_SUITE_END( ); | 675 ASSERT_TRUE(sal_True == bOK) << "test for resolveHostname() function: try to resolve localhost to 127.0.0.1."; 676 } |
788 | 677 |
789 }; // class resolveHostname 790 791 | |
792 /** testing the method: 793 static inline sal_Int32 SAL_CALL getServicePort( 794 const ::rtl::OUString& strServiceName, 795 const ::rtl::OUString & strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) ); 796 */ 797 | 678 /** testing the method: 679 static inline sal_Int32 SAL_CALL getServicePort( 680 const ::rtl::OUString& strServiceName, 681 const ::rtl::OUString & strProtocolName= ::rtl::OUString::createFromAscii( "tcp" ) ); 682 */ 683 |
798 class gettheServicePort : public CppUnit::TestFixture | 684 class gettheServicePort : public ::testing::Test |
799 { 800 public: | 685 { 686 public: |
801 void gettheServicePort_001() 802 { 803 rtl::OUString suServiceFTP = rtl::OUString::createFromAscii( "ftp" ); 804 rtl::OUString suProtocolTCP = rtl::OUString::createFromAscii( "tcp" ); | 687 }; // class gettheServicePort |
805 | 688 |
806 CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get ftp service port on TCP protocol.", 807 IP_PORT_FTP== ::osl::SocketAddr::getServicePort( suServiceFTP, suProtocolTCP ) ); 808 } | 689 TEST_F(gettheServicePort, gettheServicePort_001) 690 { 691 rtl::OUString suServiceFTP = rtl::OUString::createFromAscii( "ftp" ); 692 rtl::OUString suProtocolTCP = rtl::OUString::createFromAscii( "tcp" ); |
809 | 693 |
810 void gettheServicePort_002() 811 { 812 rtl::OUString suServiceTELNET = rtl::OUString::createFromAscii( "telnet" ); 813 rtl::OUString suProtocolTCP = rtl::OUString::createFromAscii( "tcp" ); 814 CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get telnet service port on TCP protocol.", 815 IP_PORT_TELNET== ::osl::SocketAddr::getServicePort( suServiceTELNET, suProtocolTCP ) ); 816 } | 694 ASSERT_TRUE(IP_PORT_FTP== ::osl::SocketAddr::getServicePort( suServiceFTP, suProtocolTCP )) << "test for getServicePort() function: try to get ftp service port on TCP protocol."; 695 } |
817 | 696 |
818 void gettheServicePort_003() 819 { 820 //Solaris has no service called "https", please see /etc/services 821 rtl::OUString suServiceNETBIOS = rtl::OUString::createFromAscii( "netbios-dgm" ); 822 rtl::OUString suProtocolUDP = rtl::OUString::createFromAscii( "udp" ); 823 CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get netbios-ssn service port on UDP protocol.", 824 IP_PORT_NETBIOS_DGM == ::osl::SocketAddr::getServicePort( suServiceNETBIOS, suProtocolUDP ) ); 825 } | 697 TEST_F(gettheServicePort, gettheServicePort_002) 698 { 699 rtl::OUString suServiceTELNET = rtl::OUString::createFromAscii( "telnet" ); 700 rtl::OUString suProtocolTCP = rtl::OUString::createFromAscii( "tcp" ); 701 ASSERT_TRUE(IP_PORT_TELNET== ::osl::SocketAddr::getServicePort( suServiceTELNET, suProtocolTCP )) << "test for getServicePort() function: try to get telnet service port on TCP protocol."; 702 } |
826 | 703 |
827 void gettheServicePort_004() 828 { 829 rtl::OUString suProtocolUDP = rtl::OUString::createFromAscii( "udp" ); 830 CPPUNIT_ASSERT_MESSAGE( "test for getServicePort() function: try to get a service port which is not exist.", 831 OSL_INVALID_PORT == ::osl::SocketAddr::getServicePort( ::rtl::OUString::createFromAscii( "notexist" ), suProtocolUDP ) ); 832 } | 704 TEST_F(gettheServicePort, gettheServicePort_003) 705 { 706 //Solaris has no service called "https", please see /etc/services 707 rtl::OUString suServiceNETBIOS = rtl::OUString::createFromAscii( "netbios-dgm" ); 708 rtl::OUString suProtocolUDP = rtl::OUString::createFromAscii( "udp" ); 709 ASSERT_TRUE(IP_PORT_NETBIOS_DGM == ::osl::SocketAddr::getServicePort( suServiceNETBIOS, suProtocolUDP )) << "test for getServicePort() function: try to get netbios-ssn service port on UDP protocol."; 710 } |
833 | 711 |
834 CPPUNIT_TEST_SUITE( gettheServicePort ); 835 CPPUNIT_TEST( gettheServicePort_001 ); 836 CPPUNIT_TEST( gettheServicePort_002 ); 837 CPPUNIT_TEST( gettheServicePort_003 ); 838 CPPUNIT_TEST( gettheServicePort_004 ); 839 CPPUNIT_TEST_SUITE_END( ); | 712 TEST_F(gettheServicePort, gettheServicePort_004) 713 { 714 rtl::OUString suProtocolUDP = rtl::OUString::createFromAscii( "udp" ); 715 ASSERT_TRUE(OSL_INVALID_PORT == ::osl::SocketAddr::getServicePort( ::rtl::OUString::createFromAscii( "notexist" ), suProtocolUDP )) << "test for getServicePort() function: try to get a service port which is not exist."; 716 } |
840 | 717 |
841 }; // class gettheServicePort 842 | |
843 /** testing the method: 844 845 */ 846 | 718 /** testing the method: 719 720 */ 721 |
847 class getFamilyOfSocketAddr : public CppUnit::TestFixture | 722 class getFamilyOfSocketAddr : public ::testing::Test |
848 { 849 public: | 723 { 724 public: |
850 void getFamilyOfSocketAddr_001() 851 { 852 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 853 oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); 854 CPPUNIT_ASSERT_EQUAL( 855 osl_Socket_FamilyInet, 856 osl_getFamilyOfSocketAddr( psaOSLSocketAddr ) ); 857 858 CPPUNIT_ASSERT_MESSAGE( "test for osl_getFamilyOfSocketAddr.", 859 osl_getFamilyOfSocketAddr( psaOSLSocketAddr ) == osl_Socket_FamilyInet ); 860 } 861 862 CPPUNIT_TEST_SUITE( getFamilyOfSocketAddr ); 863 CPPUNIT_TEST( getFamilyOfSocketAddr_001 ); 864 CPPUNIT_TEST_SUITE_END( ); 865 | |
866 }; // class getFamilyOfSocketAddr 867 | 725 }; // class getFamilyOfSocketAddr 726 |
868// ----------------------------------------------------------------------------- | 727 TEST_F(getFamilyOfSocketAddr, getFamilyOfSocketAddr_001) 728 { 729 ::osl::SocketAddr saSocketAddr( rtl::OUString::createFromAscii("localhost"), IP_PORT_HTTP1 ); 730 oslSocketAddr psaOSLSocketAddr = saSocketAddr.getHandle( ); 731 ASSERT_EQ( 732 osl_Socket_FamilyInet, 733 osl_getFamilyOfSocketAddr( psaOSLSocketAddr ) ); |
869 | 734 |
735 ASSERT_TRUE(osl_getFamilyOfSocketAddr( psaOSLSocketAddr ) == osl_Socket_FamilyInet) << "test for osl_getFamilyOfSocketAddr."; 736 } |
|
870 | 737 |
871CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::ctors, "osl_SocketAddr"); 872CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::is, "osl_SocketAddr"); 873CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getHostname, "osl_SocketAddr"); 874CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getPort, "osl_SocketAddr"); 875CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setPort, "osl_SocketAddr"); 876CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::setAddr, "osl_SocketAddr"); 877CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getAddr, "osl_SocketAddr"); 878CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::operator_equal, "osl_SocketAddr"); 879CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getSocketAddrHandle, "osl_SocketAddr"); 880CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getLocalHostname, "osl_SocketAddr"); 881CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::resolveHostname, "osl_SocketAddr"); 882CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::gettheServicePort, "osl_SocketAddr"); 883CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_SocketAddr::getFamilyOfSocketAddr, "osl_SocketAddr"); 884 | |
885} // namespace osl_SocketAddr 886 | 738} // namespace osl_SocketAddr 739 |
887// ----------------------------------------------------------------------------- 888 889// this macro creates an empty function, which will called by the RegisterAllFunctions() 890// to let the user the possibility to also register some functions by hand. 891NOADDITIONAL; | 740int main(int argc, char **argv) 741{ 742 ::testing::InitGoogleTest(&argc, argv); 743 return RUN_ALL_TESTS(); 744} |