Skip to content

Commit

Permalink
finished refactor const testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
zzusoftboy committed Nov 2, 2017
1 parent f218b77 commit 76c3153
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 81 deletions.
4 changes: 3 additions & 1 deletion tests/dummyext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ set(DUMMYEXT_SRCS
InterfaceTestcases.h
InterfaceTestcases.cpp
NamespaceTestcases.h
NamespaceTestcases.cpp)
NamespaceTestcases.cpp
ConstantTestcases.h
ConstantTestcases.cpp)

add_library(dummyext MODULE
${DUMMYEXT_SRCS})
Expand Down
40 changes: 40 additions & 0 deletions tests/dummyext/ConstantTestcases.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// @copyright 2017-2018 zzu_softboy <zzu_softboy@163.com>
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Created by softboy on 2017/11/02.

#include "ConstantTestcases.h"

namespace dummyext
{

using zapi::lang::Constant;
using zapi::lang::Namespace;

void register_constant_testcases(Extension &extension)
{
extension.registerConstant(Constant("MY_CONST", 12333));
extension.registerConstant(Constant("PI", 3.14));
Constant nameConst("ZAPI_NAME", "zapi");
extension.registerConstant(nameConst);
extension.registerConstant(Constant("ZAPI_VERSION", "v0.0.1"));
extension.registerConstant(Constant("QIHOO", "beijing qihoo"));
// register constant in namespace
Namespace *zapi = extension.findNamespace("zapi");
Namespace *io = zapi->findNamespace("io");
io->registerConstant(Constant("IO_TYPE", "ASYNC"));
io->registerConstant(Constant("NATIVE_STREAM", true));
zapi->registerConstant(Constant("SYS_VERSION", "0.1.1-alpha"));
}

} // dummyext
30 changes: 30 additions & 0 deletions tests/dummyext/ConstantTestcases.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @copyright 2017-2018 zzu_softboy <zzu_softboy@163.com>
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Created by softboy on 2017/11/02.

#ifndef ZAPI_TEST_DUMMYEXT_CONSTANT_TESTCASES_H
#define ZAPI_TEST_DUMMYEXT_CONSTANT_TESTCASES_H

#include "zapi/ZendApi.h"

namespace dummyext
{

using zapi::lang::Extension;

ZAPI_DECL_EXPORT void register_constant_testcases(Extension &extension);

} // dummyext

#endif // ZAPI_TEST_DUMMYEXT_CONSTANT_TESTCASES_H
2 changes: 2 additions & 0 deletions tests/dummyext/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "FunctionTestcases.h"
#include "ClassTestcases.h"
#include "InterfaceTestcases.h"
#include "ConstantTestcases.h"

using zapi::lang::Extension;

Expand All @@ -31,6 +32,7 @@ ZAPI_DECL_EXPORT void *get_module()
dummyext::register_ini_testcases(extension);
dummyext::register_cyclehandler_testcases(extension);
dummyext::register_namespace_testcases(extension);
dummyext::register_constant_testcases(extension);
dummyext::register_interface_testcases(extension);
dummyext::register_function_testcases(extension);
dummyext::register_class_testcases(extension);
Expand Down
7 changes: 6 additions & 1 deletion tests/dummyext/NamespaceTestcases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
namespace dummyext
{

using zapi::lang::Namespace;

void register_namespace_testcases(Extension &extension)
{

Namespace zapi("zapi");
Namespace io("io");
zapi.registerNamespace(io);
extension.registerNamespace(zapi);
}

} // dummyext
34 changes: 14 additions & 20 deletions tests/lang/const/ConstantExistTest.phpt
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
--TEST--
Contant register test
--FILE--
<?php

if(defined("MY_CONST"))
if(!defined("MY_CONST"))
{
echo "MY_CONST defined\n";
goto error;
}

if(defined("PI"))
if(!defined("PI"))
{
echo "PI defined\n";
goto error;
}

if(defined("ZAPI_NAME"))
if(!defined("ZAPI_NAME"))
{
echo "ZAPI_NAME defined\n";
goto error;
}

if(defined("ZAPI_VERSION"))
if(!defined("ZAPI_VERSION"))
{
echo "ZAPI_NAME defined\n";
goto error;
}

if(defined("QIHOO"))
if(!defined("QIHOO"))
{
echo "QIHOO defined\n";
goto error;
}

?>
--EXPECT--
MY_CONST defined
PI defined
ZAPI_NAME defined
ZAPI_NAME defined
QIHOO defined
success:
exit(0);
error:
exit(1);
24 changes: 10 additions & 14 deletions tests/lang/const/ConstantNsTest.phpt
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
--TEST--
Contant namespace exist test
--FILE--
<?php

if(defined("\zapi\SYS_VERSION"))
if(!defined("\zapi\SYS_VERSION"))
{
echo "\zapi\SYS_VERSION defined\n";
goto error;
}

if(defined("\zapi\io\IO_TYPE"))
if(!defined("\zapi\io\IO_TYPE"))
{
echo "\zapi\io\IO_TYPE defined\n";
goto error;
}

if(defined("\zapi\io\NATIVE_STREAM"))
if(!defined("\zapi\io\NATIVE_STREAM"))
{
echo "\zapi\io\NATIVE_STREAM defined\n";
goto error;
}

?>
--EXPECT--
\zapi\SYS_VERSION defined
\zapi\io\IO_TYPE defined
\zapi\io\NATIVE_STREAM defined
success:
exit(0);
error:
exit(1);
65 changes: 20 additions & 45 deletions tests/lang/const/ConstantTypeTest.phpt
Original file line number Diff line number Diff line change
@@ -1,71 +1,46 @@
--TEST--
Contant type test
--FILE--
<?php

if(defined("MY_CONST"))
if(!defined("MY_CONST") || !is_int(MY_CONST))
{
if (is_int(MY_CONST)) {
echo "MY_CONST is int\n";
}
goto error;
}

if(defined("PI"))
if(!defined("PI") || !is_double(PI))
{
if (is_double(PI)) {
echo "PI is double\n";
}
goto error;
}

if(defined("ZAPI_NAME"))
if(!defined("ZAPI_NAME") || !is_string(ZAPI_NAME))
{
if (is_string(ZAPI_NAME)) {
echo "ZAPI_NAME is string\n";
}
goto error;
}

if(defined("ZAPI_VERSION"))
if(!defined("ZAPI_VERSION") || !is_string(ZAPI_VERSION))
{
if (is_string(ZAPI_VERSION)) {
echo "ZAPI_VERSION is string\n";
}
goto error;
}

if(defined("QIHOO"))
if(!defined("QIHOO") || !is_string(QIHOO))
{
if (is_string(QIHOO)) {
echo "QIHOO is string\n";
}
goto error;
}

if(defined("\zapi\SYS_VERSION"))
if(!defined("\zapi\SYS_VERSION") || !is_string(\zapi\SYS_VERSION))
{
if (is_string(\zapi\SYS_VERSION)) {
echo "\zapi\SYS_VERSION is string\n";
}
goto error;
}

if(defined("\zapi\io\IO_TYPE"))
if(!defined("\zapi\io\IO_TYPE") || !is_string(\zapi\io\IO_TYPE))
{
if (is_string(\zapi\io\IO_TYPE)) {
echo "\zapi\io\IO_TYPE is string\n";
}
goto error;
}

if(defined("\zapi\io\NATIVE_STREAM"))
if(!defined("\zapi\io\NATIVE_STREAM") || !is_bool(\zapi\io\NATIVE_STREAM))
{
if (is_bool(\zapi\io\NATIVE_STREAM)) {
echo "\zapi\io\NATIVE_STREAM is bool\n";
}
goto error;
}

?>
--EXPECT--
MY_CONST is int
PI is double
ZAPI_NAME is string
ZAPI_VERSION is string
QIHOO is string
\zapi\SYS_VERSION is string
\zapi\io\IO_TYPE is string
\zapi\io\NATIVE_STREAM is bool
success:
exit(0);
error:
exit(1);

0 comments on commit 76c3153

Please sign in to comment.