MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_string2l

Function test_string2l

app/redis-6.2.6/src/util.c:858–905  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

856}
857
858static void test_string2l(void) {
859 char buf[32];
860 long v;
861
862 /* May not start with +. */
863 strcpy(buf,"+1");
864 assert(string2l(buf,strlen(buf),&v) == 0);
865
866 /* May not start with 0. */
867 strcpy(buf,"01");
868 assert(string2l(buf,strlen(buf),&v) == 0);
869
870 strcpy(buf,"-1");
871 assert(string2l(buf,strlen(buf),&v) == 1);
872 assert(v == -1);
873
874 strcpy(buf,"0");
875 assert(string2l(buf,strlen(buf),&v) == 1);
876 assert(v == 0);
877
878 strcpy(buf,"1");
879 assert(string2l(buf,strlen(buf),&v) == 1);
880 assert(v == 1);
881
882 strcpy(buf,"99");
883 assert(string2l(buf,strlen(buf),&v) == 1);
884 assert(v == 99);
885
886 strcpy(buf,"-99");
887 assert(string2l(buf,strlen(buf),&v) == 1);
888 assert(v == -99);
889
890#if LONG_MAX != LLONG_MAX
891 strcpy(buf,"-2147483648");
892 assert(string2l(buf,strlen(buf),&v) == 1);
893 assert(v == LONG_MIN);
894
895 strcpy(buf,"-2147483649"); /* overflow */
896 assert(string2l(buf,strlen(buf),&v) == 0);
897
898 strcpy(buf,"2147483647");
899 assert(string2l(buf,strlen(buf),&v) == 1);
900 assert(v == LONG_MAX);
901
902 strcpy(buf,"2147483648"); /* overflow */
903 assert(string2l(buf,strlen(buf),&v) == 0);
904#endif
905}
906
907static void test_ll2string(void) {
908 char buf[32];

Callers 1

utilTestFunction · 0.85

Calls 1

string2lFunction · 0.85

Tested by

no test coverage detected