2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include <gtest/gtest.h>
19 #include "hphp/runtime/base/comparisons.h"
20 #include "hphp/runtime/base/type-object.h"
21 #include "hphp/runtime/ext/string/ext_string.h"
22 #include "hphp/runtime/ext/collections/ext_collections-vector.h"
23 #include "hphp/runtime/ext/collections/ext_collections-map.h"
27 TEST(Object
, Serialization
) {
28 String s
= "O:1:\"B\":1:{s:3:\"obj\";O:1:\"A\":1:{s:1:\"a\";i:10;}}";
29 Variant v
= unserialize_from_string(s
, VariableUnserializer::Type::Serialize
);
30 EXPECT_TRUE(v
.isObject());
31 auto o
= v
.toObject();
33 !o
->getClassName().asString().compare("__PHP_Incomplete_Class")
35 auto os
= HHVM_FN(serialize
)(o
);
37 !os
.compare( "O:1:\"B\":1:{s:3:\"obj\";O:1:\"A\":1:{s:1:\"a\";i:10;}}")
42 // Test cast operations
44 EXPECT_FALSE(isa
<c_Vector
>(Object()));
45 EXPECT_TRUE(isa_or_null
<c_Vector
>(Object()));
47 auto dummy
= req::make
<c_Vector
>();
50 EXPECT_TRUE(isa
<c_Vector
>(res
));
51 EXPECT_TRUE(isa_or_null
<c_Vector
>(res
));
53 EXPECT_FALSE(isa
<c_Map
>(res
));
54 EXPECT_FALSE(isa_or_null
<c_Map
>(res
));
57 // Bad types and null pointers should throw.
58 EXPECT_EQ(cast
<c_Vector
>(res
), dummy
);
59 EXPECT_EQ(cast
<ObjectData
>(res
), dummy
);
67 cast
<c_Vector
>(empty
);
74 // Bad types should throw, null pointers are ok.
75 EXPECT_EQ(cast_or_null
<ObjectData
>(empty
), nullptr);
76 EXPECT_EQ(cast_or_null
<ObjectData
>(res
), dummy
);
79 cast_or_null
<c_Map
>(res
);
86 // Bad types are ok, null pointers should throw.
87 EXPECT_EQ(dyn_cast
<c_Vector
>(res
), dummy
);
88 EXPECT_EQ(dyn_cast
<ObjectData
>(res
), dummy
);
89 EXPECT_EQ(dyn_cast
<c_Map
>(res
), nullptr);
92 dyn_cast
<c_Vector
>(empty
);
99 // Bad types and null pointers are ok. Should never throw.
100 EXPECT_EQ(dyn_cast_or_null
<c_Map
>(res
), nullptr);
101 EXPECT_EQ(dyn_cast_or_null
<ObjectData
>(res
), dummy
);
102 EXPECT_EQ(dyn_cast_or_null
<ObjectData
>(empty
), nullptr);