From b2e2aa93754a12fac360e8de5196e45cd2f0f2aa Mon Sep 17 00:00:00 2001 From: valmat Date: Thu, 27 Mar 2014 23:36:57 +0600 Subject: add test: 007-Iterate-internal-array.phpt Iterate internal array --- tests/cpp/include/ValueIterator.h | 27 ++++++++++++++++++++++ tests/cpp/main.cpp | 1 + tests/php/dbg.php | 3 +++ .../valueiterator/007-Iterate-internal-array.phpt | 15 ++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt diff --git a/tests/cpp/include/ValueIterator.h b/tests/cpp/include/ValueIterator.h index a9329c9..689797a 100644 --- a/tests/cpp/include/ValueIterator.h +++ b/tests/cpp/include/ValueIterator.h @@ -19,6 +19,33 @@ namespace TestValueIterator { } return; } + + void loopArray(void) + { + + Php::Value value; + /* + If we fill the array in this form, we get the following: + *** Error in `/usr/bin/php': double free or corruption (fasttop): 0x0000000001956d60 *** + value[0] = "val0"; + value[1] = "val1"; + value["third"] = "val3"; + value["fourth"] = "val3"; + */ + value.set(0 , "val0"); + value.set(1 , "val1"); + value.set("third" , "val3"); + value.set("fourth", "val3"); + + std::cout << "Array/Object contains " << value.size() << " items" << std::endl; + // assum the value variable holds an array or object, it then + // is possible to iterator over the values or properties + for (auto &iter : value) + { + // output key and value + Php::out << "["<< iter.first << "]="<< iter.second << std::endl; + } + } /** * End of namespace diff --git a/tests/cpp/main.cpp b/tests/cpp/main.cpp index 6b1502b..4e781d2 100644 --- a/tests/cpp/main.cpp +++ b/tests/cpp/main.cpp @@ -52,6 +52,7 @@ extern "C" // add function to extension //extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue/*, { extension.add("TestValueIterator\\loopValue", TestValueIterator::loopValue); + extension.add("TestValueIterator\\loopArray", TestValueIterator::loopArray); /** diff --git a/tests/php/dbg.php b/tests/php/dbg.php index 9a28fc6..4728700 100644 --- a/tests/php/dbg.php +++ b/tests/php/dbg.php @@ -11,3 +11,6 @@ + +//--------- +TestValueIterator\loopArray(); \ No newline at end of file diff --git a/tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt b/tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt new file mode 100644 index 0000000..1f18203 --- /dev/null +++ b/tests/php/phpt/valueiterator/007-Iterate-internal-array.phpt @@ -0,0 +1,15 @@ +--TEST-- +Iterate internal array +--SKIPIF-- + +--FILEEOF-- +