-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nativefunction for function testcase
- Loading branch information
1 parent
76c3153
commit 677be17
Showing
6 changed files
with
263 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// @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 "NativeFunctions.h" | ||
|
||
namespace dummyext | ||
{ | ||
|
||
using zapi::lang::Variant; | ||
|
||
void show_something() | ||
{ | ||
zapi::out << "hello world, zapi" << std::flush; | ||
} | ||
|
||
void get_value_ref(NumericVariant &number) | ||
{ | ||
number = 321; | ||
} | ||
|
||
void passby_value(NumericVariant &number) | ||
{ | ||
// have no effect | ||
number = 321; | ||
} | ||
|
||
Variant get_name() | ||
{ | ||
return "zzu_softboy"; | ||
} | ||
|
||
void print_name(const StringVariant &name) | ||
{ | ||
zapi::out << name << std::flush; | ||
} | ||
|
||
void print_sum(NumericVariant argQuantity, ...) | ||
{ | ||
va_list args; | ||
va_start(args, argQuantity); | ||
NumericVariant result; | ||
for (int i = 0; i < argQuantity; ++i) { | ||
result += NumericVariant(va_arg(args, zapi_varidic_item_type), false); | ||
} | ||
zapi::out << result << std::flush; | ||
} | ||
|
||
Variant calculate_sum(NumericVariant argQuantity, ...) | ||
{ | ||
va_list args; | ||
va_start(args, argQuantity); | ||
NumericVariant result; | ||
for (int i = 0; i < argQuantity; ++i) { | ||
result += NumericVariant(va_arg(args, zapi_varidic_item_type), false); | ||
} | ||
return result; | ||
} | ||
|
||
void print_name_and_age(const StringVariant &name, const NumericVariant &age) | ||
{ | ||
zapi::out << "name: " << name << " age: " << age << std::flush; | ||
} | ||
|
||
Variant add_two_number(const NumericVariant &num1, const NumericVariant &num2) | ||
{ | ||
return num1 + num2; | ||
} | ||
|
||
void say_hello(StringVariant &name) | ||
{ | ||
if (name.getCapacity() == 0) { | ||
name = "zapi"; | ||
} | ||
zapi::out << "hello, " << name << std::endl; | ||
} | ||
|
||
Variant return_arg(Variant &value) | ||
{ | ||
return value; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// @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_NATIVE_FUNCTIONS_H | ||
#define ZAPI_TEST_DUMMYEXT_NATIVE_FUNCTIONS_H | ||
|
||
#include "zapi/ZendApi.h" | ||
|
||
namespace dummyext | ||
{ | ||
|
||
using zapi::ds::StringVariant; | ||
using zapi::ds::NumericVariant; | ||
|
||
ZAPI_DECL_EXPORT Variant return_arg(Variant &value); | ||
ZAPI_DECL_EXPORT void show_something(); | ||
ZAPI_DECL_EXPORT Variant get_name(); | ||
ZAPI_DECL_EXPORT void get_value_ref(NumericVariant &number); | ||
ZAPI_DECL_EXPORT void passby_value(NumericVariant &number); | ||
ZAPI_DECL_EXPORT void print_sum(NumericVariant argQuantity, ...); | ||
ZAPI_DECL_EXPORT void print_name(const StringVariant &name); | ||
ZAPI_DECL_EXPORT void print_name_and_age(const StringVariant &name, const NumericVariant &age); | ||
ZAPI_DECL_EXPORT Variant calculate_sum(NumericVariant argQuantity, ...); | ||
ZAPI_DECL_EXPORT Variant add_two_number(const NumericVariant &num1, const NumericVariant &num2); | ||
ZAPI_DECL_EXPORT void say_hello(StringVariant &name); | ||
|
||
} | ||
|
||
#endif // ZAPI_TEST_DUMMYEXT_NATIVE_FUNCTIONS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,57 @@ | ||
--TEST-- | ||
test function argument pass | ||
--FILE-- | ||
<?php | ||
|
||
// here we test argument passed | ||
if (function_exists("print_name")) { | ||
$ret = ""; | ||
ob_start(); | ||
print_name("unicorn team"); | ||
echo "\n"; | ||
$ret = ob_get_clean(); | ||
if ("unicorn team" != $ret) { | ||
goto error; | ||
} | ||
ob_start(); | ||
print_name(3.14); | ||
echo "\n"; | ||
$ret = ob_get_clean(); | ||
if ("3.14" != $ret) { | ||
goto error; | ||
} | ||
ob_start(); | ||
print_name(true); | ||
$ret = ob_get_clean(); | ||
if ("1" != $ret) { | ||
goto error; | ||
} | ||
|
||
} else { | ||
goto error; | ||
} | ||
echo "\n"; | ||
|
||
if (function_exists("\zapi\io\print_name")) { | ||
ob_start(); | ||
print_name("hello, zapi"); | ||
echo "\n"; | ||
$ret = ob_get_clean(); | ||
|
||
if ("hello, zapi" != $ret) { | ||
goto error; | ||
} | ||
ob_start(); | ||
print_name(4.16); | ||
echo "\n"; | ||
$ret = ob_get_clean(); | ||
|
||
if ("4.16" != $ret) { | ||
goto error; | ||
} | ||
ob_start(); | ||
print_name(false); | ||
$ret = ob_get_clean(); | ||
if ("" != $ret) { | ||
goto error; | ||
} | ||
} else { | ||
goto error; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
unicorn team | ||
3.14 | ||
1 | ||
hello, zapi | ||
4.16 | ||
success: | ||
exit(0); | ||
error: | ||
exit(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,38 @@ | ||
--TEST-- | ||
Function exists test | ||
--FILE-- | ||
<?php | ||
if (function_exists("show_something")) { | ||
echo "show_something exist\n"; | ||
if (!function_exists("show_something")) { | ||
goto error; | ||
} | ||
|
||
if (function_exists("get_name")) { | ||
echo "get_name exist\n"; | ||
if (!function_exists("get_name")) { | ||
goto error; | ||
} | ||
|
||
if (function_exists("print_name")) { | ||
echo "print_name exist\n"; | ||
if (!function_exists("print_name")) { | ||
goto error; | ||
} | ||
|
||
if (function_exists("print_name_and_age")) { | ||
echo "print_name_and_age exist\n"; | ||
if (!function_exists("print_name_and_age")) { | ||
goto error; | ||
} | ||
|
||
if (function_exists("add_two_number")) { | ||
echo "add_two_number exist\n"; | ||
if (!function_exists("add_two_number")) { | ||
goto error; | ||
} | ||
|
||
// test function in namespace | ||
if (function_exists("\zapi\get_name")) { | ||
echo "\zapi\get_name exist\n"; | ||
if (!function_exists("\zapi\get_name")) { | ||
goto error; | ||
} | ||
|
||
if (function_exists("\zapi\io\print_name")) { | ||
echo "\zapi\io\print_name exist\n"; | ||
if (!function_exists("\zapi\io\print_name")) { | ||
goto error; | ||
} | ||
|
||
if (function_exists("\zapi\io\show_something")) { | ||
echo "\zapi\io\show_something exist\n"; | ||
if (!function_exists("\zapi\io\show_something")) { | ||
goto error; | ||
} | ||
|
||
?> | ||
--EXPECT-- | ||
show_something exist | ||
get_name exist | ||
print_name exist | ||
print_name_and_age exist | ||
add_two_number exist | ||
\zapi\get_name exist | ||
\zapi\io\print_name exist | ||
\zapi\io\show_something exist | ||
success: | ||
exit(0); | ||
error: | ||
exit(1); |