MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / sdsTest

Function sdsTest

src/util/sds/sds.c:1126–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1124
1125#define UNUSED(x) (void)(x)
1126int sdsTest(void) {
1127 {
1128 sds x = sdsnew("foo"), y;
1129
1130 test_cond("Create a string and obtain the length",
1131 sdslen(x) == 3 && memcmp(x,"foo\0",4) == 0)
1132
1133 sdsfree(x);
1134 x = sdsnewlen("foo",2);
1135 test_cond("Create a string with specified length",
1136 sdslen(x) == 2 && memcmp(x,"fo\0",3) == 0)
1137
1138 x = sdscat(x,"bar");
1139 test_cond("Strings concatenation",
1140 sdslen(x) == 5 && memcmp(x,"fobar\0",6) == 0);
1141
1142 x = sdscpy(x,"a");
1143 test_cond("sdscpy() against an originally longer string",
1144 sdslen(x) == 1 && memcmp(x,"a\0",2) == 0)
1145
1146 x = sdscpy(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk");
1147 test_cond("sdscpy() against an originally shorter string",
1148 sdslen(x) == 33 &&
1149 memcmp(x,"xyzxxxxxxxxxxyyyyyyyyyykkkkkkkkkk\0",33) == 0)
1150
1151 sdsfree(x);
1152 x = sdscatprintf(sdsempty(),"%d",123);
1153 test_cond("sdscatprintf() seems working in the base case",
1154 sdslen(x) == 3 && memcmp(x,"123\0",4) == 0)
1155
1156 sdsfree(x);
1157 x = sdsnew("--");
1158 x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN,LLONG_MAX);
1159 test_cond("sdscatfmt() seems working in the base case",
1160 sdslen(x) == 60 &&
1161 memcmp(x,"--Hello Hi! World -9223372036854775808,"
1162 "9223372036854775807--",60) == 0)
1163 printf("[%s]\n",x);
1164
1165 sdsfree(x);
1166 x = sdsnew("--");
1167 x = sdscatfmt(x, "%u,%U--", UINT_MAX, ULLONG_MAX);
1168 test_cond("sdscatfmt() seems working with unsigned numbers",
1169 sdslen(x) == 35 &&
1170 memcmp(x,"--4294967295,18446744073709551615--",35) == 0)
1171
1172 sdsfree(x);
1173 x = sdsnew(" x ");
1174 sdstrim(x," x");
1175 test_cond("sdstrim() works when all chars match",
1176 sdslen(x) == 0)
1177
1178 sdsfree(x);
1179 x = sdsnew(" x ");
1180 sdstrim(x," ");
1181 test_cond("sdstrim() works when a single char remains",
1182 sdslen(x) == 1 && x[0] == 'x')
1183

Callers 1

mainFunction · 0.85

Calls 15

sdsnewFunction · 0.85
sdslenFunction · 0.85
sdsfreeFunction · 0.85
sdsnewlenFunction · 0.85
sdscatFunction · 0.85
sdscpyFunction · 0.85
sdscatprintfFunction · 0.85
sdsemptyFunction · 0.85
sdscatfmtFunction · 0.85
sdstrimFunction · 0.85
sdsdupFunction · 0.85
sdsrangeFunction · 0.85

Tested by

no test coverage detected