#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include char buf[100]; stralloc sa; void zap() { size_t i; for (i=0; i4096); fseek(f,0,SEEK_SET); assert(stdiocopy=malloc(flen)); assert(fread(stdiocopy,1,flen,f)==flen); fclose(f); assert(openreadclose("test/marshal.c",&sa,4096)==1); assert(sa.len == flen); assert(byte_equal(sa.s,flen,stdiocopy)); assert((mmapcopy=mmap_read("test/marshal.c",&mlen)) && mlen==flen); assert(byte_equal(sa.s,flen,mmapcopy)); mmap_unmap(mmapcopy,mlen); } stralloc_free(&sa); assert(stralloc_ready(&sa,0x1000)); assert(sa.a >= 0x1000); assert(stralloc_copyb(&sa,stdiocopy,0x900)); assert(sa.len == 0x900); assert(stralloc_catb(&sa,stdiocopy+0x900,0x700)); assert(sa.len == 0x1000); assert(byte_equal(sa.s,0x1000,stdiocopy)); assert(stralloc_readyplus(&sa,0x1000)); assert(sa.a >= 0x2000); assert(stralloc_readyplus(&sa,(size_t)-1)==0); assert(stralloc_ready(&sa,(size_t)-1)==0); stralloc_zero(&sa); assert(stralloc_copys(&sa,"hello, ")); assert(stralloc_cats(&sa,"world!")); assert(stralloc_diffs(&sa,"hello, world!") == 0); assert(stralloc_equals(&sa,"hello, world!")); assert(stralloc_0(&sa)); assert(str_equal(sa.s,"hello, world!")); assert(stralloc_equal(&sa,&sa)); assert(stralloc_copym(&sa,"hallo",", ","welt","!\n")); assert(stralloc_equals(&sa,"hallo, welt!\n")); stralloc_zero(&sa); assert(stralloc_catlong(&sa,1)); assert(stralloc_catint(&sa,2)); assert(stralloc_catulong(&sa,3)); assert(stralloc_catuint(&sa,4)); assert(stralloc_equals(&sa,"1234")); assert(stralloc_catulong0(&sa,5678,6)); assert(stralloc_equals(&sa,"1234005678")); stralloc_zero(&sa); assert(stralloc_catlong0(&sa,-5678,6)); assert(stralloc_equals(&sa,"-005678")); assert(stralloc_chop(&sa)); assert(stralloc_equals(&sa,"-00567")); assert(stralloc_chomp(&sa)==0); assert(stralloc_equals(&sa,"-00567")); assert(stralloc_cats(&sa,"\r\n")); assert(stralloc_equals(&sa,"-00567\r\n")); assert(stralloc_chomp(&sa)==2); assert(stralloc_equals(&sa,"-00567")); stralloc_zero(&sa); assert(stralloc_copys(&sa,"foo\nbar\r\nbaz")); { buffer b; stralloc s; buffer_fromsa(&b,&sa); stralloc_init(&s); assert(buffer_getline_sa(&b,&s)==1 && stralloc_equals(&s,"foo\n")); assert(buffer_getnewline_sa(&b,&s)==1 && stralloc_equals(&s,"bar\r\n")); assert(buffer_getnewline_sa(&b,&s)==0 && stralloc_equals(&s,"baz")); buffer_close(&b); } return 0; }