diff options
author | Keith Bostic <keith@wiredtiger.com> | 2016-01-19 12:28:54 -0500 |
---|---|---|
committer | Keith Bostic <keith@wiredtiger.com> | 2016-01-19 12:28:54 -0500 |
commit | b7f10136bb4baf8d72194ac573bf6a2009577b62 (patch) | |
tree | 3b9e77cb0721c2c55e855b5b68ff183d005ea9e9 | |
parent | 9000c9ecc7d39011e712e7fc58abd167d3d85583 (diff) | |
download | mongo-b7f10136bb4baf8d72194ac573bf6a2009577b62.tar.gz |
WT-1517: schema format edge cases
Fixes for the default 's' format, if no size is specified, the size is 1.
Add some smoke tests for the 'S' and 's' formats, with counts.
-rw-r--r-- | src/include/packing.i | 16 | ||||
-rw-r--r-- | test/suite/test_config06.py | 45 |
2 files changed, 56 insertions, 5 deletions
diff --git a/src/include/packing.i b/src/include/packing.i index a3061985dc0..3409438ee31 100644 --- a/src/include/packing.i +++ b/src/include/packing.i @@ -273,8 +273,10 @@ __pack_size(WT_SESSION_IMPL *session, WT_PACK_VALUE *pv) return (s); case 's': case 'S': - if (pv->type == 's' || pv->havesize) + if (pv->havesize) s = pv->size; + else if (pv->type == 's') + s = 1; else s = strlen(pv->u.s) + 1; return (s); @@ -330,9 +332,11 @@ __pack_write( *pp += pv->size; break; case 's': - WT_SIZE_CHECK_PACK(pv->size, maxlen); - memcpy(*pp, pv->u.s, pv->size); - *pp += pv->size; + s = pv->havesize ? pv->size : 1; + WT_SIZE_CHECK_PACK(s, maxlen); + if (s > 0) + memcpy(*pp, pv->u.s, s); + *pp += s; break; case 'S': s = strlen(pv->u.s); @@ -467,8 +471,10 @@ __unpack_read(WT_SESSION_IMPL *session, break; case 's': case 'S': - if (pv->type == 's' || pv->havesize) + if (pv->havesize) s = pv->size; + else if (pv->type == 's') + s = 1; else s = strlen((const char *)*pp) + 1; if (s > 0) diff --git a/test/suite/test_config06.py b/test/suite/test_config06.py index e03b9301437..7fed9bb99bc 100644 --- a/test/suite/test_config06.py +++ b/test/suite/test_config06.py @@ -32,6 +32,8 @@ import wiredtiger, wttest # Test session.create configurations. class test_config06(wttest.WiredTigerTestCase): uri = 'table:test_config06' + key = 'keyABCDEFGHIJKLMNOPQRSTUVWXYZ' + value = 'valueABCDEFGHIJKLMNOPQRSTUVWXYZ' def session_config(self, config): msg = '/Invalid argument/' @@ -47,5 +49,48 @@ class test_config06(wttest.WiredTigerTestCase): self.session_config('key_format=0t,value_format=4t') self.session_config('key_format=4t,value_format=0t') + # Smoke-test the string formats with length specifiers; both formats should + # ignore trailing bytes, verify that. + def format_string(self, fmt, len): + k = self.key + v = self.value + self.session.create(self.uri, \ + "key_format=" + str(len) + fmt + ",value_format=" + str(len) + fmt) + cursor = self.session.open_cursor(self.uri, None) + cursor[k] = v + self.assertEquals(cursor[k[:len]], v[:len]) + def test_format_string_S_1(self): + self.format_string('S', 1) + def test_format_string_S_4(self): + self.format_string('S', 4) + def test_format_string_S_10(self): + self.format_string('S', 10) + def test_format_string_s_1(self): + self.format_string('s', 1) + def test_format_string_s_4(self): + self.format_string('s', 4) + def test_format_string_s_10(self): + self.format_string('s', 10) + + def test_format_string_S_default(self): + k = self.key + v = self.value + self.session.create(self.uri, "key_format=S,value_format=S") + cursor = self.session.open_cursor(self.uri, None) + cursor[k] = v + self.assertEquals(cursor[k], v) + + ''' + CURRENTLY DOES NOT WORK + def test_format_string_s_default(self): + k = self.key + v = self.value + self.session.create(self.uri, "key_format=s,value_format=s") + cursor = self.session.open_cursor(self.uri, None) + cursor[k] = v + self.assertEquals(cursor[k[:1]], v[:1]) + ''' + + if __name__ == '__main__': wttest.run() |