2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2016 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/file-util.h"
20 #include "hphp/runtime/base/shared-string.h"
21 #include "hphp/runtime/base/zend-string.h"
22 #include "hphp/runtime/base/config.h"
24 #define VERIFY_DUMP(map, exp) \
26 printf("%s:%d: [" #exp "] is false\n", __FILE__, __LINE__); \
28 return Count(false); \
31 ///////////////////////////////////////////////////////////////////////////////
33 TestUtil::TestUtil() {
36 ///////////////////////////////////////////////////////////////////////////////
38 bool TestUtil::RunTests(const std::string
&which
) {
40 RUN_TEST(TestSharedString
);
41 RUN_TEST(TestCanonicalize
);
46 ///////////////////////////////////////////////////////////////////////////////
50 size_t operator()(const String
& s
) const {
51 return hash_string_unsafe(s
.data(), s
.size());
56 bool operator()(const String
& s1
, const String
& s2
) const {
57 return string_strcmp(s1
.data(), s1
.size(), s2
.data(), s2
.size()) == 0;
62 size_t operator()(int i
) const { return i
; }
65 bool operator()(int i
, int j
) const { return i
== j
; }
68 bool TestUtil::TestSharedString() {
70 SharedString foo
= "foo";
71 SharedString
bah("bah");
72 VERIFY(bah
->getString() == "bah");
74 SharedString bah2
= bah
;
75 VERIFY(bah2
->getString() == "bah");
76 VERIFY(bah
.get() == bah2
.get());
77 SharedString bah3
= "bah";
78 VERIFY(bah
.get() == bah3
.get());
80 VERIFY(bah
->getString() == "bah");
81 VERIFY(foo
->getString() == "foo");
84 hphp_shared_string_map
<int64_t> map
;
85 for (int i
= 0; i
< 100; i
++) {
90 for (int i
= 0; i
< 100; i
++) {
93 auto const it
= map
.find(k
);
94 VERIFY(it
!= map
.end());
95 VERIFY(it
->second
== i
);
102 bool TestUtil::TestCanonicalize() {
103 VERIFY(FileUtil::canonicalize(String("foo")) == String("foo"));
104 VERIFY(FileUtil::canonicalize(String("/foo")) == String("/foo"));
105 VERIFY(FileUtil::canonicalize(String("foo/bar")) == String("foo/bar"));
106 VERIFY(FileUtil::canonicalize(String("foo/////bar")) == String("foo/bar"));
107 VERIFY(FileUtil::canonicalize(String("foo/bar/")) == String("foo/bar/"));
108 VERIFY(FileUtil::canonicalize(String("./foo")) == String("foo"));
109 VERIFY(FileUtil::canonicalize(String(".")) == String("."));
110 VERIFY(FileUtil::canonicalize(String("./")) == String("./"));
111 VERIFY(FileUtil::canonicalize(String("././")) == String("./"));
112 VERIFY(FileUtil::canonicalize(String("foo/./")) == String("foo/"));
113 VERIFY(FileUtil::canonicalize(String("foo/../bar")) == String("bar"));
114 VERIFY(FileUtil::canonicalize(String("./foo/../bar")) == String("bar"));
115 VERIFY(FileUtil::canonicalize(String(".////foo/xyz////..////../bar"))
117 VERIFY(FileUtil::canonicalize(String("a/foo../bar"))
118 == String("a/foo../bar"));
119 VERIFY(FileUtil::canonicalize(String("a./foo/./bar"))
120 == String("a./foo/bar"));
121 VERIFY(FileUtil::canonicalize(String("////a/foo")) == String("/a/foo"));
122 VERIFY(FileUtil::canonicalize(String("../foo")) == String("../foo"));
123 VERIFY(FileUtil::canonicalize(String("foo/../../bar")) == String("../bar"));
124 VERIFY(FileUtil::canonicalize(String("./../../")) == String("../../"));
125 VERIFY(FileUtil::canonicalize(String("/test\0", 6, CopyString
))
127 VERIFY(FileUtil::canonicalize(String("/test\0test", 10, CopyString
))
132 bool TestUtil::TestHDF() {
133 // This was causing a crash
140 IniSetting::Map ini
= IniSetting::Map::object
;
146 VS(Config::GetString(ini
, doc
, "node.0.name"), "value");