summaryrefslogtreecommitdiff
path: root/src/mongo/db/storage/key_string_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/storage/key_string_test.cpp')
-rw-r--r--src/mongo/db/storage/key_string_test.cpp25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp
index 32d2919904c..465a43fe1a9 100644
--- a/src/mongo/db/storage/key_string_test.cpp
+++ b/src/mongo/db/storage/key_string_test.cpp
@@ -205,17 +205,32 @@ TEST(TypeBitsTest, AppendLotsOfZeroTypeBits) {
}
TEST_F(KeyStringTest, TooManyElementsInCompoundKey) {
- // Construct an illegal KeyString with more than the limit of 32 elements in a compound index
- // key. Encode 33 kBoolTrue ('o') values.
+ // Construct a KeyString with more than the limit of 32 elements in a compound index key. Encode
+ // 33 kBoolTrue ('o') values.
+ // Note that this KeyString encoding is legal, but it may not be legally stored in an index.
const char* data = "ooooooooooooooooooooooooooooooooo";
const size_t size = 33;
KeyString ks(KeyString::Version::V1);
ks.resetFromBuffer(data, size);
- ASSERT_THROWS_CODE(KeyString::toBsonSafe(data, size, ALL_ASCENDING, ks.getTypeBits()),
- AssertionException,
- ErrorCodes::Overflow);
+ // No exceptions should be thrown.
+ KeyString::toBsonSafe(data, size, ALL_ASCENDING, ks.getTypeBits());
+ KeyString::getKeySize(ks.getBuffer(), ks.getSize(), ALL_ASCENDING, ks.getTypeBits());
+}
+
+TEST_F(KeyStringTest, MaxElementsInCompoundKey) {
+ // Construct a KeyString with 32 elements in a compound index key followed by an end byte.
+ // Encode 32 kBoolTrue ('o') values and an end byte, 0x4.
+ const char* data = "oooooooooooooooooooooooooooooooo\x4";
+ const size_t size = 33;
+
+ KeyString ks(KeyString::Version::V1);
+ ks.resetFromBuffer(data, size);
+
+ // No exceptions should be thrown.
+ KeyString::toBsonSafe(data, size, ALL_ASCENDING, ks.getTypeBits());
+ KeyString::getKeySize(ks.getBuffer(), ks.getSize(), ALL_ASCENDING, ks.getTypeBits());
}
TEST_F(KeyStringTest, ExceededBSONDepth) {