2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2013 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 "hphp/test/ext/test_util.h"
18 #include "hphp/util/logger.h"
19 #include "hphp/runtime/base/complex_types.h"
20 #include "hphp/runtime/base/shared_string.h"
21 #include "hphp/runtime/base/zend-string.h"
23 #define VERIFY_DUMP(map, exp) \
25 printf("%s:%d: [" #exp "] is false\n", __FILE__, __LINE__); \
27 return Count(false); \
30 ///////////////////////////////////////////////////////////////////////////////
32 TestUtil::TestUtil() {
35 ///////////////////////////////////////////////////////////////////////////////
37 bool TestUtil::RunTests(const std::string
&which
) {
39 RUN_TEST(TestSharedString
);
40 RUN_TEST(TestCanonicalize
);
45 ///////////////////////////////////////////////////////////////////////////////
49 size_t operator()(CStrRef s
) const {
50 return hash_string(s
.data(), s
.size());
55 bool operator()(CStrRef s1
, CStrRef s2
) const {
56 return string_strcmp(s1
.data(), s1
.size(), s2
.data(), s2
.size()) == 0;
61 size_t operator()(int i
) const { return i
; }
64 bool operator()(int i
, int j
) const { return i
== j
; }
67 bool TestUtil::TestSharedString() {
69 SharedString foo
= "foo";
70 SharedString
bah("bah");
71 VERIFY(bah
->getString() == "bah");
73 SharedString bah2
= bah
;
74 VERIFY(bah2
->getString() == "bah");
75 VERIFY(bah
.get() == bah2
.get());
76 SharedString bah3
= "bah";
77 VERIFY(bah
.get() == bah3
.get());
79 VERIFY(bah
->getString() == "bah");
80 VERIFY(foo
->getString() == "foo");
83 hphp_shared_string_map
<int64_t> map
;
84 for (int i
= 0; i
< 100; i
++) {
89 for (int i
= 0; i
< 100; i
++) {
92 hphp_shared_string_map
<int64_t>::const_iterator it
= map
.find(k
);
93 VERIFY(it
!= map
.end());
94 VERIFY(it
->second
== i
);
101 bool TestUtil::TestCanonicalize() {
102 VERIFY(Util::canonicalize("foo") == "foo");
103 VERIFY(Util::canonicalize("/foo") == "/foo");
104 VERIFY(Util::canonicalize("./foo") == "foo");
105 VERIFY(Util::canonicalize("foo/bar") == "foo/bar");
106 VERIFY(Util::canonicalize("foo/////bar") == "foo/bar");
107 VERIFY(Util::canonicalize("foo/bar/") == "foo/bar/");
108 VERIFY(Util::canonicalize("foo/../bar") == "bar");
109 VERIFY(Util::canonicalize("./foo/../bar") == "bar");
110 VERIFY(Util::canonicalize(".////foo/xyz////..////../bar") == "bar");
111 VERIFY(Util::canonicalize("a/foo../bar") == "a/foo../bar");
112 VERIFY(Util::canonicalize("a./foo/./bar") == "a./foo/bar");
113 VERIFY(Util::canonicalize("////a/foo") == "/a/foo");
114 VERIFY(Util::canonicalize("../foo") == "../foo");
115 VERIFY(Util::canonicalize("foo/../../bar") == "../bar");
116 VERIFY(Util::canonicalize("./../../") == "../../");
120 bool TestUtil::TestHDF() {
121 // This was causing a crash
133 VS(doc
["node"][0]["name"].getString(), "value");