From 9f2db2f6c0ab7162760526e6f74c5925bc322581 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Tue, 12 May 2026 11:05:09 +0800 Subject: [PATCH] =?UTF-8?q?test(aot):=20=E6=B7=BB=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E5=87=86=E5=AE=B9=E5=99=A8=E5=A4=8D=E6=9D=82=E5=80=BC=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为std::vector添加复杂值类型测试用例 - 为std::map添加复杂值类型测试用例 - 为std::unordered_map添加复杂值类型测试用例 - 为std::array添加复杂值类型测试用例 - 测试字符串、数组、对象、变体等复杂类型的存储和访问 - 验证精确类值类型的容器行为 - 包含错误处理和异常情况的测试场景 --- tests/aot/std-array/005.phpt | 48 ++++++++++++++++++++ tests/aot/std-map/003.phpt | 48 ++++++++++++++++++++ tests/aot/std-map/004.phpt | 67 ++++++++++++++++++++++++++++ tests/aot/std-unordered-map/003.phpt | 48 ++++++++++++++++++++ tests/aot/std-vector/002.phpt | 48 ++++++++++++++++++++ 5 files changed, 259 insertions(+) create mode 100644 tests/aot/std-array/005.phpt create mode 100644 tests/aot/std-map/003.phpt create mode 100644 tests/aot/std-map/004.phpt create mode 100644 tests/aot/std-unordered-map/003.phpt create mode 100644 tests/aot/std-vector/002.phpt diff --git a/tests/aot/std-array/005.phpt b/tests/aot/std-array/005.phpt new file mode 100644 index 00000000..5610b572 --- /dev/null +++ b/tests/aot/std-array/005.phpt @@ -0,0 +1,48 @@ +--TEST-- +std array: complex value types +--FILE-- +value; + } +} + +function main() { + $strings = std::array(complex_types::type_string, 2); + $strings[0] = 321; + var_dump($strings[0]); + + $arrays = std::array(complex_types::type_array, 2); + $arrays[0] = ["name" => "array", "value" => 64]; + $array = $arrays[0]; + var_dump($array["name"]); + var_dump($array["value"]); + + $objects = std::array(complex_types::type_object, 2); + $objects[0] = new StdArrayComplexValue(28); + var_dump($objects[0] instanceof StdArrayComplexValue); + $object = objval($objects[0], StdArrayComplexValue::class); + var_dump($object->getValue()); + + $variants = std::array(complex_types::type_any, 2); + $variants[0] = 123; + $variants[1] = "variant"; + var_dump($variants[0]); + var_dump($variants[1]); +} +?> +--EXPECT-- +string(3) "321" +string(5) "array" +int(64) +bool(true) +int(28) +int(123) +string(7) "variant" diff --git a/tests/aot/std-map/003.phpt b/tests/aot/std-map/003.phpt new file mode 100644 index 00000000..d124a6d1 --- /dev/null +++ b/tests/aot/std-map/003.phpt @@ -0,0 +1,48 @@ +--TEST-- +std map: complex value types +--FILE-- +value; + } +} + +function main() { + $strings = std::map(native_types::type_int, complex_types::type_str); + $strings[1] = 456; + var_dump($strings[1]); + + $arrays = std::map(native_types::type_int, complex_types::type_array); + $arrays[2] = ["name" => "map", "value" => 84]; + $array = $arrays[2]; + var_dump($array["name"]); + var_dump($array["value"]); + + $objects = std::map(complex_types::type_string, complex_types::type_object); + $objects["item"] = new StdMapComplexValue(14); + var_dump($objects["item"] instanceof StdMapComplexValue); + $object = objval($objects["item"], StdMapComplexValue::class); + var_dump($object->getValue()); + + $variants = std::map(native_types::type_int, complex_types::type_any); + $variants[3] = 12.5; + $variants[4] = "any"; + var_dump($variants[3]); + var_dump($variants[4]); +} +?> +--EXPECT-- +string(3) "456" +string(3) "map" +int(84) +bool(true) +int(14) +float(12.5) +string(3) "any" diff --git a/tests/aot/std-map/004.phpt b/tests/aot/std-map/004.phpt new file mode 100644 index 00000000..bcc38127 --- /dev/null +++ b/tests/aot/std-map/004.phpt @@ -0,0 +1,67 @@ +--TEST-- +std containers: exact class value type +--FILE-- +value; + } +} + +class StdContainerClassValueChild extends StdContainerClassValue +{ +} + +class StdContainerClassValueOther +{ +} + +function std_container_class_value_mixed(mixed $value): mixed +{ + return $value; +} + +function main() { + $map = std::map(complex_types::type_str, StdContainerClassValue::class); + $map["a"] = new StdContainerClassValue(1); + $item = $map["a"]; + var_dump($item->getValue()); + + $vector = std::vector(StdContainerClassValue::class); + $vector[] = new StdContainerClassValue(2); + var_dump($vector[0]->getValue()); + + $array = std::array(StdContainerClassValue::class, 2); + $array[0] = new StdContainerClassValue(3); + var_dump($array[0]->getValue()); + + $unordered = std::unordered_map(native_types::type_int, StdContainerClassValue::class); + $unordered[1] = std_container_class_value_mixed(new StdContainerClassValue(4)); + var_dump($unordered[1]->getValue()); + + try { + $unordered[2] = std_container_class_value_mixed(new StdContainerClassValueChild(5)); + } catch (Throwable $e) { + echo $e->getMessage(), "\n"; + } + + try { + $unordered[3] = std_container_class_value_mixed(new StdContainerClassValueOther()); + } catch (Throwable $e) { + echo $e->getMessage(), "\n"; + } +} +?> +--EXPECT-- +int(1) +int(2) +int(3) +int(4) +std container value expects exact object of class `StdContainerClassValue` +std container value expects exact object of class `StdContainerClassValue` diff --git a/tests/aot/std-unordered-map/003.phpt b/tests/aot/std-unordered-map/003.phpt new file mode 100644 index 00000000..12625f7e --- /dev/null +++ b/tests/aot/std-unordered-map/003.phpt @@ -0,0 +1,48 @@ +--TEST-- +std unordered map: complex value types +--FILE-- +value; + } +} + +function main() { + $strings = std::unordered_map(native_types::type_int, complex_types::type_string); + $strings[1] = 789; + var_dump($strings[1]); + + $arrays = std::unordered_map(complex_types::type_string, complex_types::type_array); + $arrays["item"] = ["name" => "unordered", "value" => 168]; + $array = $arrays["item"]; + var_dump($array["name"]); + var_dump($array["value"]); + + $objects = std::unordered_map(native_types::type_int, complex_types::type_object); + $objects[2] = new StdUnorderedMapComplexValue(21); + var_dump($objects[2] instanceof StdUnorderedMapComplexValue); + $object = objval($objects[2], StdUnorderedMapComplexValue::class); + var_dump($object->getValue()); + + $variants = std::unordered_map(native_types::type_int, complex_types::type_var); + $variants[3] = false; + $variants[4] = "variant"; + var_dump($variants[3]); + var_dump($variants[4]); +} +?> +--EXPECT-- +string(3) "789" +string(9) "unordered" +int(168) +bool(true) +int(21) +bool(false) +string(7) "variant" diff --git a/tests/aot/std-vector/002.phpt b/tests/aot/std-vector/002.phpt new file mode 100644 index 00000000..71c335b7 --- /dev/null +++ b/tests/aot/std-vector/002.phpt @@ -0,0 +1,48 @@ +--TEST-- +std vector: complex value types +--FILE-- +value; + } +} + +function main() { + $strings = std::vector(complex_types::type_string); + $strings[] = 123; + var_dump($strings[0]); + + $arrays = std::vector(complex_types::type_array); + $arrays[] = ["name" => "vector", "value" => 42]; + $array = $arrays[0]; + var_dump($array["name"]); + var_dump($array["value"]); + + $objects = std::vector(complex_types::type_object); + $objects[] = new StdVectorComplexValue(7); + var_dump($objects[0] instanceof StdVectorComplexValue); + $object = objval($objects[0], StdVectorComplexValue::class); + var_dump($object->getValue()); + + $variants = std::vector(complex_types::type_variant); + $variants[] = 99; + $variants[] = "mixed"; + var_dump($variants[0]); + var_dump($variants[1]); +} +?> +--EXPECT-- +string(3) "123" +string(6) "vector" +int(42) +bool(true) +int(7) +int(99) +string(5) "mixed"