00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "check.h"
00010 #include <vl/stringop.h>
00011 #include <string.h>
00012
00013 int
00014 main (int argc VL_UNUSED, char *argv[] VL_UNUSED)
00015 {
00016 vl_size q ;
00017 int err, protocol ;
00018 char const *repl = "vision" ;
00019 char const *str = "*: * '\\*' *" ;
00020 char const *subst = "vision: vision '*' vision" ;
00021 char const *t1 = "a/b/c/d.tar.gz" ;
00022 char const *t3 = "t" ;
00023 char const *next ;
00024
00025 enum { buf_len = 1024 } ;
00026 char buf [buf_len] ;
00027
00028 enum { sml_len = 2 } ;
00029 char sml [sml_len] ;
00030
00031
00032
00033
00034 q = vl_string_copy (sml, sml_len, t3) ;
00035 err = (q >= sml_len) ;
00036 check (! err, "vl_string_copy") ;
00037 check (q == strlen(t3), "vl_string_copy") ;
00038
00039
00040 q = vl_string_copy (sml, sml_len, t1) ;
00041 err = (q >= sml_len) ;
00042 check (err, "vl_string_copy") ;
00043 check (q == strlen(t1), "vl_string_copy") ;
00044
00045
00046
00047
00048 q = vl_string_replace_wildcard (buf, buf_len,
00049 str, '*', '\\', repl) ;
00050 err = (q >= buf_len) ;
00051 check (! err, "vl_string_replace_wildcard") ;
00052 check (strcmp(buf, subst) == 0, "vl_string_replace_wildcard") ;
00053 check (strlen(subst) == q, "vl_string_replace_wildcard") ;
00054
00055
00056
00057 q = vl_string_replace_wildcard (sml, sml_len,
00058 str, '*', '\\', repl) ;
00059 err = (q >= sml_len) ;
00060 check (err, "vl_string_replace_wildcard") ;
00061 check (strlen(subst) == q, "vl_string_replace_wildcard") ;
00062
00063
00064 q = vl_string_replace_wildcard (0,0,
00065 str, '*', '\\', repl) ;
00066 err = (q >= sml_len) ;
00067 check (err, "vl_string_replace_wildcard") ;
00068 check (strlen(subst) == q, "vl_string_replace_wildcard") ;
00069
00070
00071 q = vl_string_basename (buf, buf_len, "a/b/c/d.tar.gz", 0) ;
00072 err = (q >= buf_len) ;
00073 check (! err, "vl_string_basename") ;
00074 check (strcmp(buf, "d.tar.gz") == 0, "vl_string_basename") ;
00075
00076 q = vl_string_basename (buf, buf_len, "a/b/c/d.tar.gz", 1) ;
00077 err = (q >= buf_len) ;
00078 check (! err, "vl_string_basename") ;
00079 check (strcmp(buf, "d.tar") == 0, "vl_string_basename") ;
00080
00081 q = vl_string_basename (buf, buf_len, "a/b/c/d.tar.gz", 2) ;
00082 err = (q >= buf_len) ;
00083 check (! err, "vl_string_basename") ;
00084 check (strcmp(buf, "d") == 0, "vl_string_basename") ;
00085
00086 q = vl_string_basename (buf, buf_len, "a/b/c/d.tar.gz", 3) ;
00087 err = (q >= buf_len) ;
00088 check (! err, "vl_string_basename") ;
00089 check (strcmp(buf, "d") == 0, "vl_string_basename") ;
00090
00091
00092 next = "ascii://bin://ascii://bin://unkown1://unknown2://bin:///which remains/" ;
00093 next = vl_string_parse_protocol(next, &protocol) ;
00094 check (protocol == VL_PROT_ASCII,) ;
00095 next = vl_string_parse_protocol(next, &protocol) ;
00096 check (protocol == VL_PROT_BINARY,) ;
00097 next = vl_string_parse_protocol(next, &protocol) ;
00098 check (protocol == VL_PROT_ASCII,) ;
00099 next = vl_string_parse_protocol(next, &protocol) ;
00100 check (protocol == VL_PROT_BINARY,) ;
00101 next = vl_string_parse_protocol(next, &protocol) ;
00102 check (protocol == VL_PROT_UNKNOWN,) ;
00103 next = vl_string_parse_protocol(next, &protocol) ;
00104 check (protocol == VL_PROT_UNKNOWN,) ;
00105 next = vl_string_parse_protocol(next, &protocol) ;
00106 check (protocol == VL_PROT_BINARY,) ;
00107 check (strcmp(next, "/which remains/") == 0,"%s",next) ;
00108
00109 check_signoff() ;
00110 return 0 ;
00111 }