diff --git a/tests/examples/c/-g b/tests/examples/c/-g new file mode 100755 index 0000000000000000000000000000000000000000..3909909e8fe531a7b6d35ca315b8277e7270bb02 Binary files /dev/null and b/tests/examples/c/-g differ diff --git a/tests/examples/c/clientcfgtest-taosd.c b/tests/examples/c/clientcfgtest-taosd.c new file mode 100644 index 0000000000000000000000000000000000000000..fbfbd8935a34481c23e806bbe461882ed9a10437 --- /dev/null +++ b/tests/examples/c/clientcfgtest-taosd.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include +#include +#include "os.h" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsocket.h" +#include "tutil.h" +extern SGlobalCfg *taosGetConfigOption(const char *option) ; +int main( int argc, char *argv[]){ + + printf("start to test\n"); + + //case1: + //Test config to wrong type + const char config1[128] = "{\"cache\":\"4\"}";//input the parameter which want to be configured + taos_set_config(config1); //configure the parameter + + SGlobalCfg *cfg1 ; + + cfg1 = taosGetConfigOption("cache");//check the option result + if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config cache to '4'success!\n"); + else + printf("config cache failure!\n"); + return 0 ; + +} diff --git a/tests/examples/c/clientcfgtest-wrongjson.c b/tests/examples/c/clientcfgtest-wrongjson.c new file mode 100644 index 0000000000000000000000000000000000000000..eecb5dae6d27c213731afdea005af3fc265dd47f --- /dev/null +++ b/tests/examples/c/clientcfgtest-wrongjson.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include "os.h" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsocket.h" +#include "tutil.h" +extern SGlobalCfg *taosGetConfigOption(const char *option) ; +int main( int argc, char *argv[]){ + + printf("start to test\n"); + + //case1: + //Test config with wrong JSON + //The result is failure + const char config1[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\135\"}";//input the parameter which want to be configured + taos_set_config(config1); //configure the parameter + + SGlobalCfg *cfg1 ; + cfg1 = taosGetConfigOption("firstEp");//check the option result + if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config firstEp 'BCC-2:6030'success!\n"); + else + printf("config firstEp failure!\n"); + SGlobalCfg *cfg2 ; + cfg2 = taosGetConfigOption("debugFlag");//check the option result + if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config debugFlag '135'success!\n"); + else + printf("config debugFlag failure!\n"); + + + //case2: + //repair the JSON and try again + //The result is success + const char config2[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\"135\"}";//input the parameter which want to be configured + taos_set_config(config2); //configure the parameter + + SGlobalCfg *cfg3 ; + + cfg3 = taosGetConfigOption("firstEp");//check the option result + if(cfg3->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config firstEp 'BCC-2:6030'success!\n"); + else + printf("config firstEp failure!\n"); + + SGlobalCfg *cfg4 ; + + cfg4 = taosGetConfigOption("debugFlag");//check the option result + if(cfg4->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config debugFlag '135'success!\n"); + else + printf("config debugFlag failure!\n"); + return 0 ; + +} diff --git a/tests/examples/c/clientcfgtest-wrongtype.c b/tests/examples/c/clientcfgtest-wrongtype.c new file mode 100644 index 0000000000000000000000000000000000000000..d88cbeebe8e5114ed4836e77b9494de1cc54aba8 --- /dev/null +++ b/tests/examples/c/clientcfgtest-wrongtype.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include "os.h" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsocket.h" +#include "tutil.h" +extern SGlobalCfg *taosGetConfigOption(const char *option) ; +int main( int argc, char *argv[]){ + + printf("start to test\n"); + + //case1: + //Test config to wrong type + //The result is failure + const char config1[128] = "{\"debugFlag\":\"9999999999999999999999999\"}";//input the parameter which want to be configured + taos_set_config(config1); //configure the parameter + + SGlobalCfg *cfg1 ; + + cfg1 = taosGetConfigOption("debugFlag");//check the option result + if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config debugFlag '9999999999999999999999999\n"); + else + printf("config debugFlag failure!\n"); + + //case2: + //Try again with right parameter + //The result is failure + const char config2[128] = "{\"debugFlag\":\"135\"}";//input the parameter which want to be configured + taos_set_config(config2); //configure the parameter + + SGlobalCfg *cfg2 ; + + cfg2 = taosGetConfigOption("debugFlag");//check the option result + if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config debugflag '135'success!\n"); + else + printf("config debugflag failure!\n"); + return 0 ; + +} diff --git a/tests/examples/c/clientcfgtest-wrongvalue.c b/tests/examples/c/clientcfgtest-wrongvalue.c new file mode 100644 index 0000000000000000000000000000000000000000..f0d44a47f62696d14844ea12276b74da7d0ff408 --- /dev/null +++ b/tests/examples/c/clientcfgtest-wrongvalue.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include "os.h" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsocket.h" +#include "tutil.h" +extern SGlobalCfg *taosGetConfigOption(const char *option) ; +int main( int argc, char *argv[]){ + + printf("start to test\n"); + + //case1: + //Test config to wrong type + const char config1[128] = "{\"rpcTimer\":\"0\"}";//input the parameter which want to be configured + taos_set_config(config1); //configure the parameter + + SGlobalCfg *cfg1 ; + + cfg1 = taosGetConfigOption("rpcTimer");//check the option result + if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config rpcTimer to '0'success!\n"); + else + printf("config rpcTimer failure!\n"); + + //case2: + //Try again with right parameter + const char config2[128] = "{\"rpcTimer\":\"400\"}";//input the parameter which want to be configured + taos_set_config(config2); //configure the parameter + + SGlobalCfg *cfg2 ; + + cfg2 = taosGetConfigOption("rpcTimer");//check the option result + if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config rpcTimer '400'success!\n"); + else + printf("config rpcTimer failure!\n"); + return 0 ; + +} diff --git a/tests/examples/c/clientcfgtest.c b/tests/examples/c/clientcfgtest.c new file mode 100644 index 0000000000000000000000000000000000000000..5f8f51cdb1156a25544273fc6419f65b86ea4ecc --- /dev/null +++ b/tests/examples/c/clientcfgtest.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include "os.h" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" +#include "tsocket.h" +#include "tutil.h" +extern SGlobalCfg *taosGetConfigOption(const char *option) ; +int main( int argc, char *argv[]){ + + printf("start to test\n"); + + //case1: + //Test config firstEp success + const char config1[128] = "{\"firstEp\":\"BCC-2:6030\",\"debugFlag\":\"135\"}";//input the parameter which want to be configured + taos_set_config(config1); //configure the parameter + + SGlobalCfg *cfg1 ; + + cfg1 = taosGetConfigOption("firstEp");//check the option result + if(cfg1->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config firstEp 'BCC-2:6030'success!\n"); + else + printf("config firstEp failure!\n"); + + + SGlobalCfg *cfg2 ; + + cfg2 = taosGetConfigOption("debugFlag");//check the option result + if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config debugFlag '135' success!\n"); + else + printf("config debugFlag failure!\n"); + //case2: + //Test config only useful at the first time + //The result is failure + const char config2[128] = "{\"fqdn\":\"BCC-3\"}";//input the parameter which want to be configured + taos_set_config(config2); //configure the parameter + + SGlobalCfg *cfg3 ; + + cfg2 = taosGetConfigOption("fqdn");//check the option result + if(cfg2->cfgStatus == 3) //If cfgStatus is 3,it means configure is success + printf("config fqdn to 'BCC-3'success!\n"); + else + printf("config fqdn failure!\n"); + return 0 ; + +} diff --git a/tests/examples/c/makefile b/tests/examples/c/makefile index 304623c27af27cd23a301af134647fb3b9746d64..e05716d1758b5f72926df5ecadaf5d833b6e4e17 100644 --- a/tests/examples/c/makefile +++ b/tests/examples/c/makefile @@ -6,7 +6,11 @@ TARGET=exe LFLAGS = '-Wl,-rpath,/usr/local/taos/driver/' -ltaos -lpthread -lm -lrt CFLAGS = -O3 -g -Wall -Wno-deprecated -fPIC -Wno-unused-result -Wconversion \ -Wno-char-subscripts -D_REENTRANT -Wno-format -D_REENTRANT -DLINUX \ - -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 + -Wno-unused-function -D_M_X64 -I/usr/local/taos/include -std=gnu99 \ + -I/home/ubuntu/TDengine/src/os/inc -I/home/ubuntu/TDengine/src/inc \ + -I/home/ubuntu/TDengine/src/util/inc \ + -I/home/ubuntu/TDengine/src/common/inc + all: $(TARGET) @@ -17,6 +21,12 @@ exe: gcc $(CFLAGS) ./stream.c -o $(ROOT)stream $(LFLAGS) gcc $(CFLAGS) ./subscribe.c -o $(ROOT)subscribe $(LFLAGS) gcc $(CFLAGS) ./apitest.c -o $(ROOT)apitest $(LFLAGS) + gcc $(CFLAGS) ./clientcfgtest.c -o $(ROOT)clientcfgtest $(LFLAGS) + gcc $(CFLAGS) ./clientcfgtest-wrongtype.c -o $(ROOT)clientcfgtest-wrongtype $(LFLAGS) + gcc $(CFLAGS) ./clientcfgtest-wrongjson.c -o $(ROOT)clientcfgtest-wrongjson $(LFLAGS) + gcc $(CFLAGS) ./clientcfgtest-wrongvalue.c -o $(ROOT)clientcfgtest-wrongvalue $(LFLAGS) + gcc $(CFLAGS) ./clientcfgtest-taosd.c -o $(ROOT)clientcfgtest-taosd $(LFLAGS) + clean: rm $(ROOT)asyncdemo @@ -26,3 +36,9 @@ clean: rm $(ROOT)stream rm $(ROOT)subscribe rm $(ROOT)apitest + rm $(ROOT)clientcfgtest + rm $(ROOT)clientcfgtest-wrongtype + rm $(ROOT)clientcfgtest-wrongjson + rm $(ROOT)clientcfgtest-wrongvalue + rm $(ROOT)clientcfgtest-taosd + \ No newline at end of file