提交 f136211b 编写于 作者: H Hongze Cheng

fix TDB encode and decode bug

上级 e707047d
......@@ -84,15 +84,18 @@ static inline int tdbPutVarInt(u8 *p, int v) {
static inline int tdbGetVarInt(const u8 *p, int *v) {
int n = 0;
int tv = 0;
int t;
for (;;) {
if (p[n] <= 0x7f) {
tv = (tv << 7) | p[n];
t = p[n];
tv |= (t << (7 * n));
n++;
break;
}
tv = (tv << 7) | (p[n] & 0x7f);
t = p[n] & 0x7f;
tv |= (t << (7 * n));
n++;
}
......
# tdbTest
add_executable(tdbTest "tdbTest.cpp")
target_link_libraries(tdbTest tdb gtest gtest_main)
\ No newline at end of file
target_link_libraries(tdbTest tdb gtest gtest_main)
# tdbUtilTest
add_executable(tdbUtilTest "tdbUtilTest.cpp")
target_link_libraries(tdbUtilTest tdb gtest gtest_main)
\ No newline at end of file
#include <gtest/gtest.h>
#include "tdbInt.h"
#include <string>
TEST(tdb_util_test, simple_test) {
int vEncode = 5000;
int vDecode;
int nEncode;
int nDecode;
u8 buffer[128];
nEncode = tdbPutVarInt(buffer, vEncode);
nDecode = tdbGetVarInt(buffer, &vDecode);
GTEST_ASSERT_EQ(nEncode, nDecode);
GTEST_ASSERT_EQ(vEncode, vDecode);
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册