Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(999)

Unified Diff: net/quic/crypto/channel_id_test.cc

Issue 54043003: Remove some duplicate code in quic tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/quic/crypto/channel_id_test.cc
diff --git a/net/quic/crypto/channel_id_test.cc b/net/quic/crypto/channel_id_test.cc
index d29bfced05954d9082d631b7592449f02d553d07..a36e881b4b9ffa8cf32807f93774bdffcf766edf 100644
--- a/net/quic/crypto/channel_id_test.cc
+++ b/net/quic/crypto/channel_id_test.cc
@@ -5,6 +5,7 @@
#include "net/quic/crypto/channel_id.h"
#include "net/quic/test_tools/crypto_test_utils.h"
+#include "net/quic/test_tools/quic_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::StringPiece;
@@ -185,85 +186,36 @@ const TestVector test_vector[] = {
{ NULL }
};
-// Returns true if |ch| is a lowercase hexadecimal digit.
-bool IsHexDigit(char ch) {
- return ('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'f');
-}
-
-// Converts a lowercase hexadecimal digit to its integer value.
-int HexDigitToInt(char ch) {
- if ('0' <= ch && ch <= '9') {
- return ch - '0';
- }
- return ch - 'a' + 10;
-}
-
-// |in| is a string consisting of lowercase hexadecimal digits, where
-// every two digits represent one byte. |out| is a buffer of size |max_len|.
-// Converts |in| to bytes and stores the bytes in the |out| buffer. The
-// number of bytes converted is returned in |*out_len|. Returns true on
-// success, false on failure.
-bool DecodeHexString(const char* in,
- char* out,
- size_t* out_len,
- size_t max_len) {
- if (!in) {
- *out_len = (size_t)-1;
- return true;
- }
- *out_len = 0;
- while (*in != '\0') {
- if (!IsHexDigit(*in) || !IsHexDigit(*(in + 1))) {
- return false;
- }
- if (*out_len >= max_len) {
- return false;
- }
- out[*out_len] = HexDigitToInt(*in) * 16 + HexDigitToInt(*(in + 1));
- (*out_len)++;
- in += 2;
- }
- return true;
-}
-
} // namespace
// A known answer test for ChannelIDVerifier.
TEST(ChannelIDTest, VerifyKnownAnswerTest) {
- char msg[1024];
- size_t msg_len;
- char key[64];
- size_t qx_len;
- size_t qy_len;
- char signature[64];
- size_t r_len;
- size_t s_len;
+ string msg;
+ string qx;
+ string qy;
+ string r;
+ string s;
for (size_t i = 0; test_vector[i].msg != NULL; i++) {
SCOPED_TRACE(i);
// Decode the test vector.
- ASSERT_TRUE(
- DecodeHexString(test_vector[i].msg, msg, &msg_len, sizeof(msg)));
- ASSERT_TRUE(DecodeHexString(test_vector[i].qx, key, &qx_len, sizeof(key)));
- ASSERT_TRUE(DecodeHexString(test_vector[i].qy, key + qx_len, &qy_len,
- sizeof(key) - qx_len));
- ASSERT_TRUE(DecodeHexString(test_vector[i].r, signature, &r_len,
- sizeof(signature)));
- ASSERT_TRUE(DecodeHexString(test_vector[i].s, signature + r_len, &s_len,
- sizeof(signature) - r_len));
+ ASSERT_TRUE(DecodeHexString(test_vector[i].msg, &msg));
+ ASSERT_TRUE(DecodeHexString(test_vector[i].qx, &qx));
+ ASSERT_TRUE(DecodeHexString(test_vector[i].qy, &qy));
+ ASSERT_TRUE(DecodeHexString(test_vector[i].r, &r));
+ ASSERT_TRUE(DecodeHexString(test_vector[i].s, &s));
+
+ string key = qx + qy;
+ string signature = r + s;
// The test vector's lengths should look sane.
- EXPECT_EQ(sizeof(key) / 2, qx_len);
- EXPECT_EQ(sizeof(key) / 2, qy_len);
- EXPECT_EQ(sizeof(signature) / 2, r_len);
- EXPECT_EQ(sizeof(signature) / 2, s_len);
+ EXPECT_EQ(key.size() / 2, qx.size());
+ EXPECT_EQ(key.size() / 2, qy.size());
+ EXPECT_EQ(signature.size() / 2, r.size());
+ EXPECT_EQ(signature.size() / 2, s.size());
wtc 2013/11/04 01:58:27 The new tests are weaker than the original tests.
eroman 2013/11/04 19:39:58 Done.
EXPECT_EQ(test_vector[i].result,
- ChannelIDVerifier::VerifyRaw(
- StringPiece(key, sizeof(key)),
- StringPiece(msg, msg_len),
- StringPiece(signature, sizeof(signature)),
- false));
+ ChannelIDVerifier::VerifyRaw(key, msg, signature, false));
}
}

Powered by Google App Engine
This is Rietveld 408576698