#include "wvtest.h"
#include "wvencoderstream.h"
#include "wvloopback.h"
#include "wvgzip.h"
#include <ctype.h>

#if 1

WVTEST_MAIN("gzip")
{
    //FIXME: this test is associated with bug #6166 
    static const char in_data[] = "a line of text\n";
    
    /* deflated "a compressed line" */
    static const char zin_data[] = {
	0x78, 0x9c, 0x4b, 0x54,
	0x48, 0xce, 0xcf, 0x2d,
	0x28, 0x4a, 0x2d, 0x2e,
	0x4e, 0x4d, 0x51, 0xc8,
	0xc9, 0xcc, 0x4b, 0xe5,
	0x02, 0x00, 0x40, 0x15,
	0x06, 0x89
    };
    
    char *line; 
    
    WvLoopback loopy;
    WvEncoderStream gzip((loopy.addRef(), &loopy));
    
    gzip.write(in_data);
    line = gzip.blocking_getline(1000);
    WVPASSEQ(line, "a line of text");
    WVFAIL(gzip.isreadable());
    WvGzipEncoder *inflater = new WvGzipEncoder(WvGzipEncoder::Inflate);
    gzip.readchain.append(inflater, true);
    WVFAIL(gzip.isreadable());
    gzip.write(zin_data);
    line = gzip.blocking_getline(1000);
    WVFAIL(gzip.isreadable());
    WVPASSEQ(line, "a compressed line");
    
    WvLoopback loopy2;
    WvEncoderStream gzip2((loopy.addRef(), &loopy));
    
    gzip2.write(in_data);
    gzip2.write(zin_data);
    line = gzip2.blocking_getline(1000, '\n', 1);
    WVPASSEQ(line, "a line of text");
    WvGzipEncoder *inflater2 = new WvGzipEncoder(WvGzipEncoder::Inflate);
    gzip2.readchain.append(inflater2, true);
    line = gzip2.blocking_getline(1000);
    WVPASSEQ(line, "a compressed line");
}


#include "wvbufstream.h"
#include "wvbase64.h"

WVTEST_MAIN("Base64")
{
    char input_stuff[] = 
"SnVsIDE0IDE3OjI0OjQ4IEVEVDogV3ZFeGNDb25uPCoxPjogQXBwbHlpbmcgcmVzcG9uc2UgZm9y\n"
"IGNvbW1hbmQgKkp1bCAxNCAxNzoyNDo0OCBFRFQ6IFVwZGF0ZUl0ZW08KjE+OiBSZWFkaW5nOiA2\n"
"MSA2MSA2MSA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Yy\n"
"NVQwNDU3NDNaLTI5Mzc1LTEwMC0xLTBAbG91ZmEgaXMgaW50aGUgZXZvIHN0b3JlIGFuZCB0aGUg\n"
"c2VydmVyIHN0b3JlSnVsIDE0IDE3OjI0OjQ4IEVEVDogR2VuTGlzdDwqMT46IDEwODUwOTM2OTUu\n"
"TTc4NzY3NFAxNTQyOFIzODMxUTgubWFpIGlzIGludGhlIGV2byBzdG9yZSBhbmQgdGhlIHNlcnZl\n"
"ciBzdG9yZUp1bCAxNCAxNzoyNDo0OCBFRFQ6IEdlbkxpc3Q8KjE+OiAxMDg0NDc2NzYwLk02MzMy\n"
"NTRQODkzUjEwODRRMS5tYWkgaXMgaW4gdGhlZXZvIHN0b3JlIGFuZCB0aGUgc2VydmVyIHN0b3Jl\n"
"SnVsIDE0IDE3OjI0OjQ4IEVEVDogR2VuTGlzdDwqMT46IDIwMDQwNjIzVDA0MDEyNVotMzI1Nzct\n"
"MTAwLTEtMUBsb3VmYSBpcyBpbnRoZSBldm8gc3RvcmUgYW5kIHRoZSBzZXJ2ZXIgc3RvcmVKdWwg\n"
"MTQgMTc6MjQ6NDggRURUOiBHZW5MaXN0PCoxPjogMjAwNDA2MjNUMDQ1NDQxWi0zMjU3Ny0xMDAt\n"
"MS03QGxvdWZhIGlzIGludGhlIGV2byBzdG9yZSBhbmQgdGhlIHNlcnZlciBzdG9yZQ==\n";

    char output_stuff [] =
"Jul 14 17:24:48 EDT: WvExcConn<*1>: Applying response for co"
"mmand *Jul 14 17:24:48 EDT: UpdateItem<*1>: Reading: 61 61 6"
"1 61 61 61 61 61 61 61 6113 1 Jul 14 17:24:48 EDT: UpdateIte"
"m<*1>: Read 685 bytes of base64Jul 14 17:24:48 EDT: UpdateIt"
"em<*1>: Wrote 672 bytes into decoderJul 14 17:24:48 EDT: Upd"
"ateItem<*1>: (wrote may be less than read, due tonewline tri"
"mming)Jul 14 17:24:48 EDT: CalendarAdaptor<*1>: Told to upda"
"te item:1085093695.M734526P15428R8806Q7.maiJul 14 17:24:48 E"
"DT: ExchangeItAdaptor<*1>: Attempting to convert fromISO8859"
"-1 to UTF-8Jul 14 17:24:48 EDT: CalendarAdaptor<*1>: Got an "
"update for1085093695.M734526P15428R8806Q7.maiJul 14 17:24:48"
" EDT: GenUpdate<*1>: Finished generic UPDATE, returning 1Jul"
" 14 17:24:48 EDT: WvExcConn<*1>: Found 0 newlines and ate th"
"emJul 14 17:24:48 EDT: WvExcConn<*1>: << (* UPDATE pcolijn.C"
"alendarIPF.Appointment 1085093695.M184469P15428R5423Q1.mai)J"
"ul 14 17:24:48 EDT: WvExcConn<*1>: Applying response for com"
"mand *Jul 14 17:24:48 EDT: UpdateItem<*1>: Reading: 61 61 61"
" 61 61 61 61 61 61 61 6113 1 Jul 14 17:24:48 EDT: UpdateItem"
"<*1>: Read 685 bytes of base64Jul 14 17:24:48 EDT: UpdateIte"
"m<*1>: Wrote 672 bytes into decoderJul 14 17:24:48 EDT: Upda"
"teItem<*1>: (wrote may be less than read, due tonewline trim"
"ming)Jul 14 17:24:48 EDT: CalendarAdaptor<*1>: Told to updat"
"e item:1085093695.M184469P15428R5423Q1.maiJul 14 17:24:48 ED"
"T: ExchangeItAdaptor<*1>: Attempting to convert fromISO8859-"
"1 to UTF-8Jul 14 17:24:48 EDT: CalendarAdaptor<*1>: Got an u"
"pdate for1085093695.M184469P15428R5423Q1.maiJul 14 17:24:48 "
"EDT: GenUpdate<*1>: Finished generic UPDATE, returning 1Jul "
"14 17:24:48 EDT: WvExcConn<*1>: Found 0 newlines and ate the"
"mJul 14 17:24:48 EDT: WvExcConn<*1>: << (* UPDATE pcolijn.Ca"
"lendarIPF.Appointment 20040625T025030Z-27348-100-1-2@loufa)J"
"ul 14 17:24:48 EDT: WvExcConn<*1>: Applying response for com"
"mand *Jul 14 17:24:48 EDT: UpdateItem<*1>: Reading: 61 61 61"
" 61 61 61 61 61 61 61 6161 61 61 61 33 1 Jul 14 17:24:48 EDT"
": UpdateItem<*1>: Read 949 bytes of base64Jul 14 17:24:48 ED"
"T: UpdateItem<*1>: Wrote 932 bytes into decoderJul 14 17:24:"
"48 EDT: UpdateItem<*1>: (wrote may be less than read, due to"
"newline trimming)Jul 14 17:24:48 EDT: CalendarAdaptor<*1>: T"
"old to update item:20040625T025030Z-27348-100-1-2@loufaJul 1"
"4 17:24:48 EDT: ExchangeItAdaptor<*1>: Attempting to convert"
" fromISO8859-1 to UTF-8Jul 14 17:24:48 EDT: CalendarAdaptor<"
"*1>: Got an update for20040625T025030Z-27348-100-1-2@loufaJu"
"l 14 17:24:48 EDT: GenUpdate<*1>: Finished generic UPDATE, r"
"eturning 1Jul 14 17:24:48 EDT: WvExcConn<*1>: Found 0 newlin"
"es and ate themJul 14 17:24:48 EDT: WvExcConn<*1>: << (* UPD"
"ATE pcolijn.CalendarIPF.Appointment 1088030663.M726203P2288R"
"6280Q1.mai)Jul 14 17:24:48 EDT: WvExcConn<*1>: Applying resp"
"onse for command *Jul 14 17:24:48 EDT: UpdateItem<*1>: Readi"
"ng: 61 61 61 61 61 61 61 61 61 61 6161 61 61 61 29 1 Jul 14 "
"17:24:48 EDT: UpdateItem<*1>: Read 945 bytes of base64Jul 14"
" 17:24:48 EDT: UpdateItem<*1>: Wrote 928 bytes into decoderJ"
"ul 14 17:24:48 EDT: UpdateItem<*1>: (wrote may be less than "
"read, due tonewline trimming)Jul 14 17:24:48 EDT: CalendarAd"
"aptor<*1>: Told to update item:1088030663.M726203P2288R6280Q"
"1.maiJul 14 17:24:48 EDT: GenUpdate<*1>: Finished generic UP"
"DATE, returning 1Jul 14 17:24:48 EDT: WvExcConn<*1>: Found 0"
" newlines and ate themJul 14 17:24:48 EDT: WvExcConn<*1>: <<"
" (* UPDATE pcolijn.CalendarIPF.Appointment 20040623T045823Z-"
"32577-100-1-9@loufa)Jul 14 17:24:48 EDT: WvExcConn<*1>: Appl"
"ying response for command *Jul 14 17:24:48 EDT: UpdateItem<*"
"1>: Reading: 61 61 61 61 61 61 61 61 61 61 6161 61 61 61 61 "
"61 61 61 61 61 61 61 61 61 61 61 61 61 61 37 1 Jul 14 17:24:"
"48 EDT: UpdateItem<*1>: Read 1868 bytes of base64Jul 14 17:2"
"4:48 EDT: UpdateItem<*1>: Wrote 1836 bytes into decoderJul 1"
"4 17:24:48 EDT: UpdateItem<*1>: (wrote may be less than read"
", due tonewline trimming)Jul 14 17:24:48 EDT: CalendarAdapto"
"r<*1>: Told to update item:20040623T045823Z-32577-100-1-9@lo"
"ufaJul 14 17:24:48 EDT: ExchangeItAdaptor<*1>: Attempting to"
" convert fromISO8859-1 to UTF-8Jul 14 17:24:48 EDT: Calendar"
"Adaptor<*1>: Got an update for20040623T045823Z-32577-100-1-9"
"@loufaJul 14 17:24:48 EDT: GenUpdate<*1>: Finished generic U"
"PDATE, returning 1Jul 14 17:24:48 EDT: WvExcConn<*1>: Found "
"0 newlines and ate themJul 14 17:24:48 EDT: WvExcConn<*1>: <"
"< (* UPDATE pcolijn.CalendarIPF.Appointment 1085093695.M6966"
"42P15428R2169Q6.mai)Jul 14 17:24:48 EDT: WvExcConn<*1>: Appl"
"ying response for command *Jul 14 17:24:48 EDT: UpdateItem<*"
"1>: Reading: 61 61 61 61 61 61 61 61 61 61 6113 1 Jul 14 17:"
"24:48 EDT: UpdateItem<*1>: Read 685 bytes of base64Jul 14 17"
":24:48 EDT: UpdateItem<*1>: Wrote 672 bytes into decoderJul "
"14 17:24:48 EDT: UpdateItem<*1>: (wrote may be less than rea"
"d, due tonewline trimming)Jul 14 17:24:48 EDT: CalendarAdapt"
"or<*1>: Told to update item:1085093695.M696642P15428R2169Q6."
"maiJul 14 17:24:48 EDT: ExchangeItAdaptor<*1>: Attempting to"
" convert fromISO8859-1 to UTF-8Jul 14 17:24:48 EDT: Calendar"
"Adaptor<*1>: Got an update for1085093695.M696642P15428R2169Q"
"6.maiJul 14 17:24:48 EDT: GenUpdate<*1>: Finished generic UP"
"DATE, returning 1Jul 14 17:24:48 EDT: WvExcConn<*1>: Found 0"
" newlines and ate themJul 14 17:24:48 EDT: WvExcConn<*1>: <<"
" (* UPDATE pcolijn.CalendarIPF.Appointment 1074883675.M22449"
"7P3589R3074Q2.mai)Jul 14 17:24:48 EDT: WvExcConn<*1>: Applyi"
"ng response for command *Jul 14 17:24:48 EDT: UpdateItem<*1>"
": Reading: 61 61 61 61 61 61 61 61 61 61 6113 1 Jul 14 17:24"
":48 EDT: UpdateItem<*1>: Read 685 bytes of base64Jul 14 17:2"
"4:48 EDT: UpdateItem<*1>: Wrote 672 bytes into decoderJul 14"
" 17:24:48 EDT: UpdateItem<*1>: (wrote may be less than read,"
" due tonewline trimming)Jul 14 17:24:48 EDT: CalendarAdaptor"
"<*1>: Told to update item:1074883675.M224497P3589R3074Q2.mai"
"Jul 14 17:24:48 EDT: ExchangeItAdaptor<*1>: Attempting to co"
"nvert fromISO8859-1 to UTF-8Jul 14 17:24:48 EDT: CalendarAda"
"ptor<*1>: Got an update for1074883675.M224497P3589R3074Q2.ma"
"iJul 14 17:24:48 EDT: GenUpdate<*1>: Finished generic UPDATE"
", returning 1Jul 14 17:24:48 EDT: WvExcConn<*1>: Found 0 new"
"lines and ate themJul 14 17:24:48 EDT: WvExcConn<*1>: << (* "
"UPDATE pcolijn.CalendarIPF.Appointment 1085093696.M341377P15"
"428R6636Q12.mai)Jul 14 17:24:48 EDT: WvExcConn<*1>: Applying"
" response for command *Jul 14 17:24:48 EDT: UpdateItem<*1>: "
"Reading: 61 61 61 61 61 61 61 61 61 61 6161 17 1 Jul 14 17:2"
"4:48 EDT: UpdateItem<*1>: Read 750 bytes of base64Jul 14 17:"
"24:48 EDT: UpdateItem<*1>: Wrote 736 bytes into decoderJul 1"
"4 17:24:48 EDT: UpdateItem<*1>: (wrote may be less than read"
", due tonewline trimming)Jul 14 17:24:48 EDT: CalendarAdapto"
"r<*1>: Told to update item:1085093696.M341377P15428R6636Q12."
"maiJul 14 17:24:48 EDT: ExchangeItAdaptor<*1>: Attempting to"
" convert fromISO8859-1 to UTF-8Jul 14 17:24:48 EDT: Calendar"
"Adaptor<*1>: Got an update for1085093696.M341377P15428R6636Q"
"12.maiJul 14 17:24:48 EDT: GenUpdate<*1>: Finished generic U"
"PDATE, returning 1Jul 14 17:24:48 EDT: WvExcConn<*1>: Found "
"0 newlines and ate themJul 14 17:24:48 EDT: WvExcConn<*1>: <"
"< (* LIST pcolijn.CalendarIPF.Appointment 3)Jul 14 17:24:48 "
"EDT: WvExcConn<*1>: Applying response for command *Jul 14 17"
":24:48 EDT: GenList<*1>: 30 client itemsJul 14 17:24:48 EDT:"
" GenList<*1>: 1085093696.M341377P15428R6636Q12.mai is inthe "
"evo store and the server storeJul 14 17:24:48 EDT: GenList<*"
"1>: 1074883675.M224497P3589R3074Q2.mai is in theevo store an"
"d the server storeJul 14 17:24:48 EDT: GenList<*1>: 10850936"
"95.M696642P15428R2169Q6.mai is inthe evo store and the serve"
"r storeJul 14 17:24:48 EDT: GenList<*1>: 20040623T045823Z-32"
"577-100-1-9@loufa is inthe evo store and the server storeJul"
" 14 17:24:48 EDT: GenList<*1>: 20040625T025030Z-27348-100-1-"
"2@loufa is inthe evo store and the server storeJul 14 17:24:"
"48 EDT: GenList<*1>: 1085093695.M184469P15428R5423Q1.mai is "
"inthe evo store and the server storeJul 14 17:24:48 EDT: Gen"
"List<*1>: 1085093695.M734526P15428R8806Q7.mai is inthe evo s"
"tore and the server storeJul 14 17:24:48 EDT: GenList<*1>: 2"
"0040623T040114Z-32577-100-1-0@loufa is inthe evo store and t"
"he server storeJul 14 17:24:48 EDT: GenList<*1>: 1087340740."
"M686227P9649R8702Q0.torment is inthe evo store and the serve"
"r storeJul 14 17:24:48 EDT: GenList<*1>: 20040625T045743Z-29"
"375-100-1-0@loufa is inthe evo store and the server storeJul"
" 14 17:24:48 EDT: GenList<*1>: 1085093695.M787674P15428R3831"
"Q8.mai is inthe evo store and the server storeJul 14 17:24:4"
"8 EDT: GenList<*1>: 1084476760.M633254P893R1084Q1.mai is in "
"theevo store and the server storeJul 14 17:24:48 EDT: GenLis"
"t<*1>: 20040623T040125Z-32577-100-1-1@loufa is inthe evo sto"
"re and the server storeJul 14 17:24:48 EDT: GenList<*1>: 200"
"40623T045441Z-32577-100-1-7@loufa is inthe evo store and the"
" server store";
    
    WvBufStream input_stream;
    input_stream.write(input_stuff);

    WvBufStream *buf_stream = new WvBufStream();
    WvEncoderStream b64_stream(buf_stream);
    b64_stream.writechain.append(new WvBase64Decoder, true);
    b64_stream.auto_flush(false);

    time_t timeout = 1000;
    while (true)
    {
	WvString s(input_stream.blocking_getline(timeout));
	timeout = 10; // only allow a _long_ delay once
	if (!s) break;
	b64_stream.write(s);
    }

    WvDynBuf outbuf;
    b64_stream.read(outbuf, 8714);
    WvString output = outbuf.getstr();
//    fprintf(stderr,"We got out: %s\n", output.cstr());
    WVPASS(!strcmp(output, output_stuff));
}


WVTEST_MAIN("encoderstream eof1")
{
    WvEncoderStream s(new WvLoopback);
    s.nowrite(); // done sending
    s.blocking_getline(1000);
    WVFAIL(s.isok()); // should be eof now
}


WVTEST_MAIN("encoderstream eof2")
{
    WvEncoderStream s(new WvLoopback);
    s.write("Hello\n");
    s.write("nonewline");
    s.nowrite();
    WVPASS(s.isok());
    WVPASSEQ(s.blocking_getline(1000), "Hello");
    WVPASS(s.isok());
    WVPASSEQ(s.blocking_getline(1000), "nonewline");
    WVFAIL(s.isok());
}


class ECountStream : public WvStreamClone
{
public:
    ECountStream(IWvStream *s) : WvStreamClone(s)
        { }
    
    virtual size_t uread(void *buf, size_t len)
    {
	size_t count = WvStreamClone::uread(buf, len);
	fprintf(stderr, "uread(%d) == %d\n", (int)len, (int)count);
	return count;
    }
    
    virtual size_t uwrite(const void *buf, size_t len)
    {
	size_t count = WvStreamClone::uwrite(buf, len);
	fprintf(stderr, "uwrite(%d) == %d\n", (int)len, (int)count);
	return count;
    }
};


class LetterPlusEncoder : public WvEncoder
{
    int incr;
    
public:
    LetterPlusEncoder(int _incr) { incr = _incr; }

protected:
    virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
    {
	if (!flush) return true; // don't flush unless we have to
	size_t count = in.used();
	unsigned char *c = const_cast<unsigned char *>(in.get(count));
	for (size_t i = 0; i < count; i++)
	    if (isalpha(c[i]))
		c[i] += incr;
	out.put(c, count);
	return true;
    }
};

#if 0
# define new_enc() (new LetterPlusEncoder(1))
# define new_dec() (new LetterPlusEncoder(-1))
#else
# define new_enc() (new WvGzipEncoder(WvGzipEncoder::Deflate))
# define new_dec() (new WvGzipEncoder(WvGzipEncoder::Inflate))
#endif

// not expected to work if READAHEAD is greater than 1,
// because WvEncoderStream::inbuf can't be re-encoded if it's nonempty.
// Eventually, we'll take the extra buffering out of plain WvStream; that
// should help a bit.  In the meantime, always use a readahead of 1 if you
// expect to add encoders later.
#define READAHEAD (1)



static void closecb(int *i)
{
    (*i)++;
}


WVTEST_MAIN("encoderstream eof3")
{
    int closed = 0;
    
    {
	WvLoopback *l = new WvLoopback;
	WvEncoderStream s(l);
	s.writechain.append(new_enc(), true);
	s.readchain.append(new_dec(), true);
	s.setclosecallback(wv::bind(&closecb, &closed));
	
	s.write("Hello\n");
	s.write("nonewline");
	WVPASS(s.isok());
	WVPASSEQ(s.blocking_getline(1000), "Hello");
	WVPASS(s.isok());
	l->nowrite();
	WVPASSEQ(s.blocking_getline(1000), "nonewline");
	l->close();
	s.runonce(100);
	WVFAIL(s.isok());
	WVPASSEQ(closed, 1);
    }
    WVPASSEQ(closed, 1);
}


WVTEST_MAIN("encoderstream eof4")
{
    WvStream *x = new WvStream;
    WvEncoderStream s(x);
    WVPASS(s.isok());
    x->close();
    WVFAIL(s.isok());
}


WVTEST_MAIN("add filters midstream")
{
    WvEncoderStream s(new ECountStream(new WvLoopback));
    
    // if we don't do this, the flush() commands below should be unnecessary.
    s.delay_output(true);
    
    // this allows big kernel read() calls even though we only read one
    // byte at a time from the *decoded* input stream.  Enabling this
    // tests continue_encode() in WvEncoderChain; otherwise, continue_encode()
    // wouldn't matter.
    s.min_readsize = 1024; 
    
    s.print("First line\n");
    WVPASS("1");
    s.print("Second line\n");
    s.flush(0);
    WVPASS("2");
    s.writechain.prepend(new_enc(), true);
    s.print("Third line\n");
    WVPASS("3a");
    s.print("Third line2\n");
    s.flush(0);
    WVPASS("3b");
    s.writechain.prepend(new_enc(), true);
    s.print("Fourth line\n");
    WVPASS("4a");
    s.print("Fourth line2\n");
    s.flush(0);
    WVPASS("4b");
    WVPASSEQ(s.geterr(), 0);
    
    WVPASSEQ(s.blocking_getline(1000, '\n', READAHEAD), "First line");
    WVPASSEQ(s.blocking_getline(1000, '\n', READAHEAD), "Second line");
    WVPASS("r2");
    WVPASSEQ(s.geterr(), 0);
    s.readchain.append(new_dec(), true);
    WVPASS("e3");
    WVPASSEQ(s.blocking_getline(1000, '\n', READAHEAD), "Third line");
    WVPASSEQ(s.blocking_getline(1000, '\n', READAHEAD), "Third line2");
    WVPASSEQ(s.geterr(), 0);
    WVPASS("r3");
    s.readchain.append(new_dec(), true);
    WVPASS("e4");
    WVPASSEQ(s.blocking_getline(1000, '\n', READAHEAD), "Fourth line");
    WVPASSEQ(s.geterr(), 0);
    WVPASS("r4a");
    s.runonce(1000);
    WVPASSEQ(s.blocking_getline(1000, '\n', READAHEAD), "Fourth line2");
    WVPASSEQ(s.geterr(), 0);
    WVPASS("r4b");
    
    s.nowrite();
    s.noread();
    
    WvDynBuf remainder;
    s.read(remainder, 1024);
    WVPASSEQ(remainder.used(), 0);
    wvcon->print("Remainder: '%s'\n", remainder.getstr());
    
    WVPASSEQ(s.geterr(), 0);
    wvcon->print("Error code: '%s'\n", s.errstr());
}
#endif
