From e7097c296928fe813d9612d5d1d8b5ee8448f034 Mon Sep 17 00:00:00 2001 From: Trapenok Victor Date: Thu, 10 Aug 2017 00:43:20 +1000 Subject: [PATCH] Automatic tests for CometQL api --- api/readme.md | 4 ++ coverage/readme.md | 4 ++ tests/api-tests/index.html | 0 tests/api-tests/readme.md | 3 + tests/api-tests/test.php | 66 +++++++++++++++++++++ tests/api-tests/tests/mysqli_connect.php | 13 ++++ tests/api-tests/tests/users_auth_insert.php | 17 ++++++ tests/api-tests/utils/testClass.php | 35 +++++++++++ tests/api-tests/utils/timetest.php | 23 +++++++ {test => tests/tsung-tests}/readme.md | 0 {test => tests/tsung-tests}/tsung-mysql.xml | 0 {test => tests/tsung-tests}/tsung.xml | 0 12 files changed, 165 insertions(+) create mode 100644 api/readme.md create mode 100644 coverage/readme.md create mode 100644 tests/api-tests/index.html create mode 100644 tests/api-tests/readme.md create mode 100644 tests/api-tests/test.php create mode 100644 tests/api-tests/tests/mysqli_connect.php create mode 100644 tests/api-tests/tests/users_auth_insert.php create mode 100644 tests/api-tests/utils/testClass.php create mode 100644 tests/api-tests/utils/timetest.php rename {test => tests/tsung-tests}/readme.md (100%) rename {test => tests/tsung-tests}/tsung-mysql.xml (100%) rename {test => tests/tsung-tests}/tsung.xml (100%) diff --git a/api/readme.md b/api/readme.md new file mode 100644 index 0000000..4486d48 --- /dev/null +++ b/api/readme.md @@ -0,0 +1,4 @@ + +## JavaScript API + +See documentation here [EN](https://comet-server.com/wiki/doku.php/en:comet:javascript_api#javascript_api) [RU](https://comet-server.com/wiki/doku.php/comet:javascript_api#javascript_api) \ No newline at end of file diff --git a/coverage/readme.md b/coverage/readme.md new file mode 100644 index 0000000..0eb2cd0 --- /dev/null +++ b/coverage/readme.md @@ -0,0 +1,4 @@ + +## Calculate coverage + +Scripts for calculate coverage in tests \ No newline at end of file diff --git a/tests/api-tests/index.html b/tests/api-tests/index.html new file mode 100644 index 0000000..e69de29 diff --git a/tests/api-tests/readme.md b/tests/api-tests/readme.md new file mode 100644 index 0000000..3f99f3c --- /dev/null +++ b/tests/api-tests/readme.md @@ -0,0 +1,3 @@ +## Automatic tests + +Automatic tests for CometQL api \ No newline at end of file diff --git a/tests/api-tests/test.php b/tests/api-tests/test.php new file mode 100644 index 0000000..9dfab2a --- /dev/null +++ b/tests/api-tests/test.php @@ -0,0 +1,66 @@ + 100) + { + return "-1"; + } +} + +$test = preg_replace("#[^A-z0-9\_\-]#usi", "", $_GET['test']); +if(!file_exists("./tests/".$test.".php")) +{ + return "-1"; +} + +include "./tests/".$test.".php"; + +// We connect to the comet server with login and password for the access demo (you can get your data for connection after registration at comet-server.com) +// Login 15 +// Password lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8 +// CometQL_v1 database +$cppTest->init([ + "host" => "app.comet-server.ru", + "user" => "15", + "password" => "lPXBFPqNg3f661JcegBY0N0dPXqUBdHXqj2cHf04PZgLHxT6z55e20ozojvMRvB8", + "api_version" => "CometQL_v1" +]); + + +$cppTest->start(); +timeTest::test('cpp', 'test'); +for($i =0; $i<$count; $i++) +{ + $cppTest->test(); +} +$t = timeTest::test('cpp','test'); +$t = $t[count($t) - 1]; + +$cppTest->stop(); + +echo json_encode([ + 'count' => $count, + 'test' => $test, + 'time' => $t['time'] +]); diff --git a/tests/api-tests/tests/mysqli_connect.php b/tests/api-tests/tests/mysqli_connect.php new file mode 100644 index 0000000..889de25 --- /dev/null +++ b/tests/api-tests/tests/mysqli_connect.php @@ -0,0 +1,13 @@ +opt['host'], $this->opt['user'], $this->opt['password'], $this->opt['api_version']); + echo mysqli_error($l)."\n"; + mysqli_close($l); + } +} + +$cppTest = new test_mysqli_connect(); diff --git a/tests/api-tests/tests/users_auth_insert.php b/tests/api-tests/tests/users_auth_insert.php new file mode 100644 index 0000000..4b4c03e --- /dev/null +++ b/tests/api-tests/tests/users_auth_insert.php @@ -0,0 +1,17 @@ +count++; + $query = "INSERT INTO users_auth (id, hash )VALUES (".$this->count.", 'hash".$this->count."');"; + mysqli_query($this->link, $query); + } +} + +$cppTest = new users_auth_insert(); + \ No newline at end of file diff --git a/tests/api-tests/utils/testClass.php b/tests/api-tests/utils/testClass.php new file mode 100644 index 0000000..450d635 --- /dev/null +++ b/tests/api-tests/utils/testClass.php @@ -0,0 +1,35 @@ +opt = $opt; + } + + function start() + { + $this->link = mysqli_connect( + $this->opt['host'], + $this->opt['user'], + $this->opt['password'], + $this->opt['api_version']); + if(!$this->link || mysqli_errno($this->link)) + { + echo "Error:". mysqli_error($this->link); + exit(); + } + } + + function test(){ + + } + + function stop() + { + mysqli_close($this->link); + } + +} \ No newline at end of file diff --git a/tests/api-tests/utils/timetest.php b/tests/api-tests/utils/timetest.php new file mode 100644 index 0000000..53f22c8 --- /dev/null +++ b/tests/api-tests/utils/timetest.php @@ -0,0 +1,23 @@ +microtime(true), "name" => $name, "delta" => 0, "time" => 0 ); + return self::$timeTestArray[$group]; + } + + self::$timeTestArray[$group][] = array( + "now" =>microtime(true), + "name" => $name, + "time" => microtime(true) - self::$timeTestArray[$group][0]["now"], // Общее время на группу + "delta" => microtime(true) - self::$timeTestArray[$group][count(self::$timeTestArray[$group])-1]["now"] // Время на последнеею операцию + ); + return self::$timeTestArray[$group]; + } +} diff --git a/test/readme.md b/tests/tsung-tests/readme.md similarity index 100% rename from test/readme.md rename to tests/tsung-tests/readme.md diff --git a/test/tsung-mysql.xml b/tests/tsung-tests/tsung-mysql.xml similarity index 100% rename from test/tsung-mysql.xml rename to tests/tsung-tests/tsung-mysql.xml diff --git a/test/tsung.xml b/tests/tsung-tests/tsung.xml similarity index 100% rename from test/tsung.xml rename to tests/tsung-tests/tsung.xml