123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace loyalsoft;
- include_once __DIR__ . '/AppServer.php';
- require_once __DIR__ . '/../process/ActiveProc/CipheredBase32.php'; # 算法库
- /**
- * Description of TestServer
- * UT 测试
- * @author jgao
- */
- class TestServer {
- //put your code here
- /**
- * 入口函数专用测试
- * @param type $req
- */
- static public function testApi($req) {
- DebugHelper::debug($req);
- $app = new AppServer();
- $ret = $app->api(new Req($req));
- DebugHelper::debug($ret);
- }
- /**
- * 运行环境自检:
- * PHP 版本,扩展模块
- * redis操作性
- * sqldb操作性
- */
- static function selfTest() {
- echoLine("phpver: " . PHP_VERSION . PHP_EOL); # 打印下PHP版本
- SelfChecker::CheckConfig(); # 进行配置环境检测
- }
- public function testMemDelete($key) {
- $mem = gMem();
- $res = $mem->delete($key);
- return $res;
- }
- public function testMemSet($key, $value) {
- $mem = gMem();
- $res = $mem->set($key, $value);
- return $res;
- }
- public function testMemGet($key) {
- $mem = gMem();
- $res = $mem->get($key);
- return $res;
- }
- public static function dtCurrent() {
- $timezone = date_default_timezone_get();
- echoLine($timezone . " " . date('Y-m-d H:i:s'));
- echoLine("tsweek: " . TimeUtil::tsWeek());
- echoLine("tsday: " . TimeUtil::tsDay());
- }
- //----------------------------------------------------
- public static function efficiencyOfOldLog() {
- /**
- * 测试结果说明,采用写本地文件的性能还是略高于写redis数据库的.
- */
- for ($i = 0; $i < 1000; $i++) {
- CLog::pay("我们的祖国像花园,花园里花朵真鲜艳.和暖的阳光照耀着我们,每个人的脸上都笑开颜.");
- }
- }
- public function testRedisGet($key) {
- $mem = gMem();
- $ret = $mem->get($key);
- DebugHelper:: var_dump($ret);
- $mem->close();
- return $ret;
- }
- /**
- * 删除某个key
- * @param type $key
- */
- public function testRedisDel($key) {
- $mem = gMem();
- $num = $mem->delete($key);
- echo $num > 0 ? 'ok' : 'not exist';
- $mem->close();
- }
- public function testRedisLua($key, $value) {
- $mem = gMem();
- $script = <<<SCR
- if redis.call("get",KEYS[1]) == ARGV[1]
- then
- return redis.call("del",KEYS[1])
- else
- return 0
- end
- SCR;
- DebugHelper:: var_dump($script);
- $ret = $mem->redis->eval($script, 1, $key, $value);
- DebugHelper:: var_dump($ret);
- $mem->close();
- }
- public function testBinSearch($v) {
- $arr = array(1, 2, 3, 4, 4, 11, 12, 124);
- $start = 0;
- $end = count($arr) - 1;
- while ($start <= $end) {
- $index = intval(($start + $end) / 2);
- if ($v < $arr[$index]) {
- $end = $index - 1;
- } elseif ($v > $arr[$index]) {
- $start = $index + 1;
- } else {
- echo($index);
- return;
- }
- }
- echo($index);
- }
- public function tsetIp() {
- DebugHelper::debug(HttpUtil::getClientEP());
- }
- public function testLogfile() {
- CLog::warn("日志测试", 'log');
- }
- public static function testDecodeToken($token) {
- echoLine("中文显示");
- $activeCode = CipheredBase32::Decode($token); # 解码
- var_dump($activeCode);
- $codePlatStr = GameConstants::GetPlatStringByActivteCode($activeCode); # platstr
- var_dump($codePlatStr);
- }
- }
|