Browse Source

[805] suggested minor changes: newline for readability; constify; distinguish
false and NULL; typo

JINMEI Tatuya 13 years ago
parent
commit
d93776a769

+ 1 - 1
src/lib/server_common/portconfig.cc

@@ -92,7 +92,7 @@ setAddresses(DNSService& service, const AddressList& addresses) {
     }
     current_sockets.clear();
     BOOST_FOREACH(const AddressPair &address, addresses) {
-        int af(IOAddress(address.first).getFamily());
+        const int af(IOAddress(address.first).getFamily());
         // TODO: Support sharing somehow in future.
         const SocketRequestor::SocketID
             tcp(socketRequestor().requestSocket(SocketRequestor::TCP,

+ 4 - 3
src/lib/server_common/tests/portconfig_unittest.cc

@@ -148,12 +148,13 @@ struct InstallListenAddresses : public testutils::TestSocketRequestor {
     // But this shouldn't work
     AddressList invalid_;
     // Check that the store_ addresses are the same as expected
-    void checkAddresses(const AddressList& expected, const string& name) {
+    void checkAddresses(const AddressList& expected, const string& name) const
+    {
         SCOPED_TRACE(name);
 
         ASSERT_EQ(expected.size(), store_.size()) <<
             "Different amount of elements, not checking content";
-        // Run in parallel trough the vectors
+        // Run in parallel through the vectors
         for (AddressList::const_iterator ei(expected.begin()),
              si(store_.begin()); ei != expected.end(); ++ei, ++si) {
             EXPECT_EQ(ei->first, si->first);
@@ -244,7 +245,7 @@ TEST_F(InstallListenAddresses, rollback) {
     checkTokens(released1, released_tokens_, "Released after rollback");
 }
 
-// Try it at last returns everything when even the rollback fails.
+// Try it at least returns everything when even the rollback fails.
 TEST_F(InstallListenAddresses, brokenRollback) {
     EXPECT_NO_THROW(installListenAddresses(valid_, store_, dnss_));
     checkAddresses(valid_, "Before rollback");

+ 14 - 5
src/lib/testutils/socket_request.h

@@ -72,12 +72,15 @@ protected:
         last_token_(0), break_rollback_(false), dnss_(dnss), store_(store),
         expect_port_(expect_port)
     {}
+
     /// \brief Destructor
     virtual ~ TestSocketRequestor() {}
+
     /// \brief Tokens released by releaseSocket
     ///
     /// They are stored here by this class and you can examine them.
     std::vector<std::string> released_tokens_;
+
     /// \brief Tokens returned from requestSocket
     ///
     /// They are stored here by this class and you can examine them.
@@ -91,6 +94,7 @@ protected:
     /// If this is set to true, the requestSocket will throw when the
     /// ::1 address is requested.
     bool break_rollback_;
+
     /// \brief Release a socket
     ///
     /// This only stores the token passed.
@@ -98,9 +102,10 @@ protected:
     void releaseSocket(const std::string& token) {
         released_tokens_.push_back(token);
     }
+
     /// \brief Request a socket
     ///
-    /// This creates a new token and fakes a new socket and returs it.
+    /// This creates a new token and fakes a new socket and returns it.
     /// The token is stored.
     ///
     /// In case the address is 192.0.2.2 or if the break_rollback_ is true
@@ -133,7 +138,7 @@ protected:
                       "This address is available, but not for you");
         }
         const std::string proto(protocol == TCP ? "TCP" : "UDP");
-        size_t number = ++ last_token_;
+        const size_t number = ++ last_token_;
         EXPECT_EQ(expect_port_, port);
         EXPECT_EQ(DONT_SHARE, mode);
         EXPECT_EQ("dummy_app", name);
@@ -143,6 +148,7 @@ protected:
         given_tokens_.push_back(token);
         return (SocketID(number, token));
     }
+
     /// \brief Initialize the test
     ///
     /// It installs itself as the socket requestor. It also turns on portconfig
@@ -156,6 +162,7 @@ protected:
         // Don't manipulate the real sockets
         server_common::portconfig::test_mode = true;
     }
+
     /// \brief Cleanup after the test
     ///
     /// Removes the addresses (if any) installed by installListenAddresses,
@@ -173,6 +180,7 @@ protected:
         // And return the mode
         server_common::portconfig::test_mode = false;
     }
+
     /// \brief Check the list of tokens is as expected
     ///
     /// Compares the expected and real tokens.
@@ -186,21 +194,22 @@ protected:
     ///     It is printed as a part of failure message.
     void checkTokens(const char** expected,
                      const std::vector<std::string>& real,
-                     const char* scope)
+                     const char* scope) const
     {
         SCOPED_TRACE(scope);
         size_t position(0);
-        while (expected[position]) {
+        while (expected[position] != NULL) {
             ASSERT_LT(position, real.size());
             EXPECT_EQ(expected[position], real[position]) << position;
             position ++;
         }
         EXPECT_EQ(position, real.size());
     }
+
 private:
     asiodns::DNSService& dnss_;
     server_common::portconfig::AddressList& store_;
-    uint16_t expect_port_;
+    const uint16_t expect_port_;
 };
 
 }