Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "net/der/parse_values.h" | 8 #include "net/der/parse_values.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 SCOPED_TRACE(i); | 188 SCOPED_TRACE(i); |
| 189 | 189 |
| 190 uint64_t result; | 190 uint64_t result; |
| 191 EXPECT_EQ(test_case.should_pass, | 191 EXPECT_EQ(test_case.should_pass, |
| 192 ParseUint64(Input(test_case.input, test_case.length), &result)); | 192 ParseUint64(Input(test_case.input, test_case.length), &result)); |
| 193 if (test_case.should_pass) | 193 if (test_case.should_pass) |
| 194 EXPECT_EQ(test_case.expected_value, result); | 194 EXPECT_EQ(test_case.expected_value, result); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 // Tests parsing an empty BIT STRING. | |
| 199 TEST(ParseValuesTest, ParseBitString_Empty_NoUnusedBits) { | |
|
nharper
2015/07/21 23:23:47
Test names shouldn't contain underscores (accordin
eroman
2015/07/22 17:05:23
Ah, thanks for pointing this out! (I was not aware
| |
| 200 const uint8_t kData[] = {0x00}; | |
| 201 | |
| 202 Input bytes; | |
| 203 uint8_t unused_bits; | |
| 204 ASSERT_TRUE(ParseBitString(Input(kData), &bytes, &unused_bits)); | |
| 205 | |
| 206 EXPECT_EQ(0u, unused_bits); | |
| 207 EXPECT_EQ(0u, bytes.Length()); | |
| 208 } | |
| 209 | |
| 210 // Tests parsing an empty BIT STRING that incorrectly claims one unused bit. | |
| 211 TEST(ParseValuesTest, ParseBitString_Empty_OneUnusedBit) { | |
| 212 const uint8_t kData[] = {0x01}; | |
| 213 | |
| 214 Input bytes; | |
| 215 uint8_t unused_bits; | |
| 216 ASSERT_FALSE(ParseBitString(Input(kData), &bytes, &unused_bits)); | |
|
nharper
2015/07/21 23:23:47
I generally prefer the EXPECT_* macros to ASSERT_*
eroman
2015/07/22 17:05:23
Done.
These are the result of copy-paste from suc
| |
| 217 } | |
| 218 | |
| 219 // Tests parsing an empty BIT STRING that is not minmally encoded (the entire | |
| 220 // last byte is comprised of unused bits). | |
| 221 TEST(ParseValuesTest, ParseBitString_NonEmpty_TooManyUnusedBits) { | |
| 222 const uint8_t kData[] = {0x08, 0x00}; | |
| 223 | |
| 224 Input bytes; | |
| 225 uint8_t unused_bits; | |
| 226 ASSERT_FALSE(ParseBitString(Input(kData), &bytes, &unused_bits)); | |
| 227 } | |
| 228 | |
| 229 // Tests parsing a BIT STRING of 7 bits each of which are 1. | |
| 230 TEST(ParseValuesTest, ParseBitString_SevenOneBits) { | |
| 231 const uint8_t kData[] = {0x01, 0xFE}; | |
| 232 | |
| 233 Input bytes; | |
| 234 uint8_t unused_bits; | |
| 235 ASSERT_TRUE(ParseBitString(Input(kData), &bytes, &unused_bits)); | |
| 236 | |
| 237 EXPECT_EQ(1u, unused_bits); | |
| 238 EXPECT_EQ(1u, bytes.Length()); | |
| 239 EXPECT_EQ(0xFE, bytes.UnsafeData()[0]); | |
| 240 } | |
| 241 | |
| 242 // Tests parsing a BIT STRING of 7 bits each of which are 1. The unused bit | |
| 243 // however is set to 1, which is an invalid encoding. | |
| 244 TEST(ParseValuesTest, ParseBitString_SevenOneBits_UnusedBitIsOne) { | |
| 245 const uint8_t kData[] = {0x01, 0xFF}; | |
| 246 | |
| 247 Input bytes; | |
| 248 uint8_t unused_bits; | |
| 249 ASSERT_FALSE(ParseBitString(Input(kData), &bytes, &unused_bits)); | |
| 250 } | |
| 251 | |
| 198 } // namespace test | 252 } // namespace test |
| 199 } // namespace der | 253 } // namespace der |
| 200 } // namespace net | 254 } // namespace net |
| OLD | NEW |