Mercurial > code
comparison C++/tests/Socket/main.cpp @ 447:828d3dc89f2d
Socket: use own tests for SSL
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 28 Oct 2015 21:16:27 +0100 |
parents | 8396fd66e57a |
children | 41d1a36cc461 |
comparison
equal
deleted
inserted
replaced
446:8396fd66e57a | 447:828d3dc89f2d |
---|---|
568 | 568 |
569 /* -------------------------------------------------------- | 569 /* -------------------------------------------------------- |
570 * Socket SSL | 570 * Socket SSL |
571 * -------------------------------------------------------- */ | 571 * -------------------------------------------------------- */ |
572 | 572 |
573 class SslTest : public testing::Test { | 573 class TlsRecvTest : public testing::Test { |
574 protected: | 574 protected: |
575 SocketTls<Ipv4> client; | 575 SocketTls<Ipv4> m_server; |
576 }; | 576 SocketTls<Ipv4> m_client; |
577 | 577 |
578 TEST_F(SslTest, connect) | 578 std::thread m_tserver; |
579 { | 579 std::thread m_tclient; |
580 try { | 580 |
581 client.connect(Ipv4{"google.fr", 443}); | 581 public: |
582 } catch (const Error &error) { | 582 TlsRecvTest() |
583 FAIL() << error.what(); | 583 : m_server{Ipv4{}, Tls{Tls::Tlsv1, false, "Socket/test.key", "Socket/test.crt"}} |
584 } | 584 , m_client{Ipv4{}, Tls{Tls::Tlsv1, false, "", "Socket/test.crt"}} |
585 } | 585 { |
586 | 586 m_server.set(SOL_SOCKET, SO_REUSEADDR, 1); |
587 TEST_F(SslTest, recv) | 587 m_server.bind(Ipv4{"*", 16000}); |
588 { | 588 m_server.listen(); |
589 try { | 589 } |
590 client.connect(Ipv4{"google.fr", 443}); | 590 |
591 client.send("GET / HTTP/1.0\r\n\r\n"); | 591 ~TlsRecvTest() |
592 | 592 { |
593 std::string msg = client.recv(512); | 593 if (m_tserver.joinable()) |
594 std::string content = msg.substr(0, 18); | 594 m_tserver.join(); |
595 | 595 if (m_tclient.joinable()) |
596 ASSERT_EQ("HTTP/1.0 302 Found", content); | 596 m_tclient.join(); |
597 } catch (const Error &error) { | 597 } |
598 FAIL() << error.what(); | 598 }; |
599 } | 599 |
600 } | 600 TEST_F(TlsRecvTest, blockingSuccess) |
601 | 601 { |
602 #if 0 | 602 m_tserver = std::thread([this] () { |
603 | 603 try { |
604 /* -------------------------------------------------------- | 604 auto client = m_server.accept(); |
605 * Operators | 605 |
606 * -------------------------------------------------------- */ | 606 ASSERT_EQ("hello", client.recv(32)); |
607 | 607 } catch (const std::exception &ex) { |
608 TEST(AddressOperator, less) | 608 FAIL() << ex.what(); |
609 { | 609 } |
610 Ipv4 ip1{"*", 8000}; | 610 }); |
611 Ipv4 ip2{"*", 8002}; | 611 |
612 | 612 std::this_thread::sleep_for(100ms); |
613 ASSERT_LT(ip1, ip2); | 613 |
614 } | 614 m_tclient = std::thread([this] () { |
615 | 615 try { |
616 TEST(AddressOperator, same) | 616 m_client.connect(Ipv4{"127.0.0.1", 16000}); |
617 { | 617 m_client.send("hello"); |
618 Ipv4 ip1{"*", 8000}; | 618 m_client.close(); |
619 Ipv4 ip2{"*", 8000}; | 619 } catch (const std::exception &ex) { |
620 | 620 FAIL() << ex.what(); |
621 ASSERT_EQ(ip1, ip2); | 621 } |
622 } | 622 }); |
623 | 623 } |
624 #endif | |
625 | 624 |
626 int main(int argc, char **argv) | 625 int main(int argc, char **argv) |
627 { | 626 { |
628 testing::InitGoogleTest(&argc, argv); | 627 testing::InitGoogleTest(&argc, argv); |
629 | 628 |