function test of actual code
This commit is contained in:
parent
3799c5c62f
commit
6ede012af0
|
@ -23,6 +23,7 @@ class MndTestFunc : public ::testing::Test {
|
|||
void TearDown() override {}
|
||||
|
||||
void SetCode(SCreateFuncReq* pReq, const char* pCode);
|
||||
void SetCode(SCreateFuncReq* pReq, char* pCode, int32_t size);
|
||||
void SetComment(SCreateFuncReq* pReq, const char* pComment);
|
||||
};
|
||||
|
||||
|
@ -35,6 +36,12 @@ void MndTestFunc::SetCode(SCreateFuncReq* pReq, const char* pCode) {
|
|||
pReq->codeLen = len;
|
||||
}
|
||||
|
||||
void MndTestFunc::SetCode(SCreateFuncReq *pReq, char *pCode, int32_t size) {
|
||||
pReq->pCode = (char*)taosMemoryMalloc(size);
|
||||
memcpy(pReq->pCode, pCode, size);
|
||||
pReq->codeLen = size;
|
||||
}
|
||||
|
||||
void MndTestFunc::SetComment(SCreateFuncReq* pReq, const char* pComment) {
|
||||
int32_t len = strlen(pComment);
|
||||
pReq->pComment = (char*)taosMemoryCalloc(1, len + 1);
|
||||
|
@ -439,3 +446,70 @@ TEST_F(MndTestFunc, 04_Drop_Func) {
|
|||
test.SendShowReq(TSDB_MGMT_TABLE_FUNC, "user_functions", "");
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
}
|
||||
|
||||
TEST_F(MndTestFunc, 05_Actual_code) {
|
||||
{
|
||||
SCreateFuncReq createReq = {0};
|
||||
strcpy(createReq.name, "udf1");
|
||||
char code[300] = {0};
|
||||
for (int32_t i = 0; i < sizeof(code); ++i) {
|
||||
code[i] = i % 20;
|
||||
}
|
||||
SetCode(&createReq, code, 300);
|
||||
SetComment(&createReq, "comment1");
|
||||
createReq.bufSize = 8;
|
||||
createReq.igExists = 0;
|
||||
createReq.funcType = 1;
|
||||
createReq.scriptType = 2;
|
||||
createReq.outputType = TSDB_DATA_TYPE_SMALLINT;
|
||||
createReq.outputLen = 12;
|
||||
createReq.bufSize = 4;
|
||||
createReq.signature = 5;
|
||||
|
||||
int32_t contLen = tSerializeSCreateFuncReq(NULL, 0, &createReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSCreateFuncReq(pReq, contLen, &createReq);
|
||||
tFreeSCreateFuncReq(&createReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_FUNC, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
}
|
||||
|
||||
{
|
||||
SRetrieveFuncReq retrieveReq = {0};
|
||||
retrieveReq.numOfFuncs = 1;
|
||||
retrieveReq.pFuncNames = taosArrayInit(1, TSDB_FUNC_NAME_LEN);
|
||||
taosArrayPush(retrieveReq.pFuncNames, "udf1");
|
||||
|
||||
int32_t contLen = tSerializeSRetrieveFuncReq(NULL, 0, &retrieveReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
tSerializeSRetrieveFuncReq(pReq, contLen, &retrieveReq);
|
||||
tFreeSRetrieveFuncReq(&retrieveReq);
|
||||
|
||||
SRpcMsg* pRsp = test.SendReq(TDMT_MND_RETRIEVE_FUNC, pReq, contLen);
|
||||
ASSERT_NE(pRsp, nullptr);
|
||||
ASSERT_EQ(pRsp->code, 0);
|
||||
|
||||
SRetrieveFuncRsp retrieveRsp = {0};
|
||||
tDeserializeSRetrieveFuncRsp(pRsp->pCont, pRsp->contLen, &retrieveRsp);
|
||||
EXPECT_EQ(retrieveRsp.numOfFuncs, 1);
|
||||
EXPECT_EQ(retrieveRsp.numOfFuncs, (int32_t)taosArrayGetSize(retrieveRsp.pFuncInfos));
|
||||
|
||||
SFuncInfo* pFuncInfo = (SFuncInfo*)taosArrayGet(retrieveRsp.pFuncInfos, 0);
|
||||
|
||||
EXPECT_STREQ(pFuncInfo->name, "udf1");
|
||||
EXPECT_EQ(pFuncInfo->funcType, 1);
|
||||
EXPECT_EQ(pFuncInfo->scriptType, 2);
|
||||
EXPECT_EQ(pFuncInfo->outputType, TSDB_DATA_TYPE_SMALLINT);
|
||||
EXPECT_EQ(pFuncInfo->outputLen, 12);
|
||||
EXPECT_EQ(pFuncInfo->bufSize, 4);
|
||||
EXPECT_EQ(pFuncInfo->signature, 5);
|
||||
EXPECT_STREQ("comment1", pFuncInfo->pComment);
|
||||
for (int32_t i = 0; i < 300; ++i) {
|
||||
EXPECT_EQ(pFuncInfo->pCode[i], i % 20);
|
||||
}
|
||||
tFreeSRetrieveFuncRsp(&retrieveRsp);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue