case: tarray.c unit case add
This commit is contained in:
parent
00c9218b32
commit
400f466f62
|
@ -430,6 +430,7 @@ int32_t taosArraySearchIdx(const SArray* pArray, const void* key, __compar_fn_t
|
||||||
return item == NULL ? -1 : (int32_t)((char*)item - (char*)pArray->pData) / pArray->elemSize;
|
return item == NULL ? -1 : (int32_t)((char*)item - (char*)pArray->pData) / pArray->elemSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef BUILD_NO_CALL
|
||||||
static int32_t taosArrayPartition(SArray* pArray, int32_t i, int32_t j, __ext_compar_fn_t fn, const void* userData) {
|
static int32_t taosArrayPartition(SArray* pArray, int32_t i, int32_t j, __ext_compar_fn_t fn, const void* userData) {
|
||||||
void* key = taosArrayGetP(pArray, i);
|
void* key = taosArrayGetP(pArray, i);
|
||||||
while (i < j) {
|
while (i < j) {
|
||||||
|
@ -485,6 +486,7 @@ static void taosArrayInsertSort(SArray* pArray, __ext_compar_fn_t fn, const void
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode) {
|
int32_t taosEncodeArray(void** buf, const SArray* pArray, FEncode encode) {
|
||||||
int32_t tlen = 0;
|
int32_t tlen = 0;
|
||||||
|
|
|
@ -106,6 +106,7 @@ TEST(arrayTest, array_data_correct) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(pa);
|
taosArrayDestroy(pa);
|
||||||
|
taosArrayDestroy(pa1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// free
|
// free
|
||||||
|
@ -139,7 +140,7 @@ TEST(arrayTest, check_duplicate_nofree) {
|
||||||
for (int32_t i = 1; i <= count; i++) {
|
for (int32_t i = 1; i <= count; i++) {
|
||||||
for (int32_t j = 0; j < i; j++) {
|
for (int32_t j = 0; j < i; j++) {
|
||||||
taosArrayPush(pa, &i);
|
taosArrayPush(pa, &i);
|
||||||
printf(" nofree put i=%d v=%d\n",i, i);
|
//printf(" nofree put i=%d v=%d\n",i, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +149,7 @@ TEST(arrayTest, check_duplicate_nofree) {
|
||||||
ASSERT_EQ(taosArrayGetSize(pa), count);
|
ASSERT_EQ(taosArrayGetSize(pa), count);
|
||||||
for (int32_t i = 1; i <= count; i++) {
|
for (int32_t i = 1; i <= count; i++) {
|
||||||
int32_t v = *(int32_t*)taosArrayGet(pa, i-1);
|
int32_t v = *(int32_t*)taosArrayGet(pa, i-1);
|
||||||
printf(" nofree get i=%d v=%d\n",i, v);
|
//printf(" nofree get i=%d v=%d\n",i, v);
|
||||||
ASSERT_EQ(v, i);
|
ASSERT_EQ(v, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,8 +166,8 @@ TEST(arrayTest, check_duplicate_needfree) {
|
||||||
for (int32_t j = 0; j < i; j++) {
|
for (int32_t j = 0; j < i; j++) {
|
||||||
char *v = (char *)taosMemoryCalloc(100, sizeof(char));
|
char *v = (char *)taosMemoryCalloc(100, sizeof(char));
|
||||||
sprintf(v, format, i);
|
sprintf(v, format, i);
|
||||||
printf(" needfree put i=%d v=%s\n", i, v);
|
//printf(" needfree put i=%d v=%s\n", i, v);
|
||||||
taosArrayPush(pa, v);
|
taosArrayPush(pa, &v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,21 +178,42 @@ TEST(arrayTest, check_duplicate_needfree) {
|
||||||
for (int32_t i = 1; i <= count; i++) {
|
for (int32_t i = 1; i <= count; i++) {
|
||||||
sprintf(value, format, i);
|
sprintf(value, format, i);
|
||||||
char * v = (char *)taosArrayGetP(pa, i - 1);
|
char * v = (char *)taosArrayGetP(pa, i - 1);
|
||||||
printf(" needfree get i=%d v=%s\n", i, v);
|
//printf(" needfree get i=%d v=%s\n", i, v);
|
||||||
ASSERT_STREQ(v, value);
|
ASSERT_STREQ(v, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroyP(pa, arrayFree);
|
taosArrayClearP(pa, taosMemoryFree);
|
||||||
|
taosArrayDestroyP(pa, taosMemoryFree);
|
||||||
}
|
}
|
||||||
|
|
||||||
// over all
|
// over all
|
||||||
TEST(arrayTest, check_overall) {
|
TEST(arrayTest, check_overall) {
|
||||||
|
|
||||||
ASSERT_EQ(taosArrayInit(1, 0), nullptr);
|
ASSERT_EQ(taosArrayInit(1, 0), nullptr);
|
||||||
ASSERT_EQ(taosArrayInit(9999999999999, 10000), nullptr);
|
ASSERT_EQ(taosArrayGet(NULL, 1), nullptr);
|
||||||
ASSERT_EQ(taosArrayInit_s(10000,9999999999999), nullptr);
|
ASSERT_EQ(taosArrayGetP(NULL, 1), nullptr);
|
||||||
|
ASSERT_EQ(taosArrayInsert(NULL, 1, NULL), nullptr);
|
||||||
|
|
||||||
|
//ASSERT_EQ(taosArrayInit(0x10000000, 10000), nullptr);
|
||||||
|
//ASSERT_EQ(taosArrayInit_s(10000,0x10000000-1), nullptr);
|
||||||
|
|
||||||
SArray* pa = taosArrayInit(1, sizeof(uint64_t));
|
SArray* pa = taosArrayInit(1, sizeof(uint64_t));
|
||||||
|
ASSERT_EQ(taosArrayGet(pa, 10), nullptr);
|
||||||
|
ASSERT_EQ(taosArrayGetLast(pa), nullptr);
|
||||||
|
|
||||||
taosArrayDestroy(pa);
|
uint64_t v = 100;
|
||||||
|
taosArrayPush(pa, &v);
|
||||||
|
taosArrayPopFrontBatch(pa, 100);
|
||||||
|
FDelete fnNull = NULL;
|
||||||
|
taosArrayClearEx(pa, fnNull);
|
||||||
|
taosArrayDestroyEx(pa, fnNull);
|
||||||
|
|
||||||
|
int32_t count = 5;
|
||||||
|
uint64_t list[5]= {1,2,3,4,5};
|
||||||
|
|
||||||
|
SArray* pb = taosArrayFromList(list, count, sizeof(uint64_t));
|
||||||
|
for (int32_t i=0; i < count; i++) {
|
||||||
|
ASSERT_EQ(*(uint64_t*)taosArrayGet(pb, i), list[i]);
|
||||||
|
}
|
||||||
|
taosArrayDestroy(pb);
|
||||||
}
|
}
|
Loading…
Reference in New Issue