1--TEST--
2Memcached compression test
3--SKIPIF--
4<?php include "skipif.inc";?>
5--FILE--
6<?php
7include dirname (__FILE__) . '/config.inc';
8$m = memc_get_instance ();
9
10$data = file_get_contents(dirname(__FILE__) . '/testdata.res');
11
12function get_compression($name) {
13	switch (strtolower($name)) {
14		case 'zlib':
15			return Memcached::COMPRESSION_ZLIB;
16		case 'fastlz':
17			return Memcached::COMPRESSION_FASTLZ;
18		default:
19			echo "Strange compression type: $name\n";
20			return 0;
21	}
22}
23
24function fetch_with_compression($m, $key, $value, $set_compression = '', $get_compression = '') {
25
26	echo "set=[$set_compression] get=[$get_compression]\n";
27
28	if (!$set_compression) {
29		$m->setOption(Memcached::OPT_COMPRESSION, false);
30	} else {
31		$m->setOption(Memcached::OPT_COMPRESSION, true);
32		$m->setOption(Memcached::OPT_COMPRESSION_TYPE, get_compression($set_compression));
33	}
34
35	$m->set($key, $value, 1800);
36
37	if (!$get_compression) {
38		$m->setOption(Memcached::OPT_COMPRESSION, true);
39	} else {
40		$m->setOption(Memcached::OPT_COMPRESSION, true);
41		$m->setOption(Memcached::OPT_COMPRESSION_TYPE, get_compression($get_compression));
42	}
43
44	$value_back = $m->get($key);
45	var_dump($value === $value_back);
46}
47
48fetch_with_compression($m, 'hello1', $data, 'zlib', 'zlib');
49fetch_with_compression($m, 'hello2', $data, 'zlib', 'fastlz');
50fetch_with_compression($m, 'hello3', $data, 'fastlz', 'fastlz');
51fetch_with_compression($m, 'hello4', $data, 'fastlz', 'zlib');
52fetch_with_compression($m, 'hello5', $data, '', 'zlib');
53fetch_with_compression($m, 'hello6', $data, '', 'fastlz');
54fetch_with_compression($m, 'hello7', $data, 'zlib', '');
55fetch_with_compression($m, 'hello8', $data, 'fastlz', '');
56fetch_with_compression($m, 'hello9', $data, '', '');
57?>
58--EXPECT--
59set=[zlib] get=[zlib]
60bool(true)
61set=[zlib] get=[fastlz]
62bool(true)
63set=[fastlz] get=[fastlz]
64bool(true)
65set=[fastlz] get=[zlib]
66bool(true)
67set=[] get=[zlib]
68bool(true)
69set=[] get=[fastlz]
70bool(true)
71set=[zlib] get=[]
72bool(true)
73set=[fastlz] get=[]
74bool(true)
75set=[] get=[]
76bool(true)
77