Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | * or more contributor license agreements. See the NOTICE file |
| 6 | * distributed with this work for additional information |
| 7 | * regarding copyright ownership. The ASF licenses this file |
| 8 | * to you under the Apache License, Version 2.0 (the |
| 9 | * "License"); you may not use this file except in compliance |
| 10 | * with the License. You may obtain a copy of the License at |
| 11 | * |
| 12 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | * |
| 14 | * Unless required by applicable law or agreed to in writing, |
| 15 | * software distributed under the License is distributed on an |
| 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | * KIND, either express or implied. See the License for the |
| 18 | * specific language governing permissions and limitations |
| 19 | * under the License. |
| 20 | * |
| 21 | * @package thrift.test |
| 22 | */ |
| 23 | |
| 24 | namespace Test\Thrift; |
| 25 | |
| 26 | use ThriftTest\Xtruct; |
| 27 | use ThriftTest\Xtruct2; |
| 28 | use ThriftTest\Numberz; |
| 29 | use ThriftTest\Insanity; |
| 30 | |
| 31 | class Fixtures |
| 32 | { |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 33 | public static $bufsize = 8192; //big enough to read biggest serialized Fixture arg. |
| 34 | public static $testArgs = array(); |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 35 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 36 | public static function populateTestArgs() |
| 37 | { |
| 38 | self::$testArgs['testString1'] = "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, Bahasa Melayu, مازِرونی, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, Occitan, Иронау, Papiamentu, Deitsch, Norfuk / Pitkern, Polski, پنجابی, پښتو, Português, Runa Simi, Rumantsch, Romani, Română, Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, Bân-lâm-gú, 粵語"; |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 39 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 40 | self::$testArgs['testString2'] = |
| 41 | "quote: \\\" backslash:" . |
| 42 | " forwardslash-escaped: \\/ " . |
| 43 | " backspace: \b formfeed: \f newline: \n return: \r tab: " . |
| 44 | " now-all-of-them-together: \"\\\/\b\n\r\t" . |
| 45 | " now-a-bunch-of-junk: !@#\$%&()(&%$#{}{}<><><"; |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 46 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 47 | self::$testArgs['testString3'] = |
| 48 | "string that ends in double-backslash \\\\"; |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 49 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 50 | self::$testArgs['testUnicodeStringWithNonBMP'] = |
| 51 | "สวัสดี/𝒯"; |
Phongphan Phuttha | 90ea4f6 | 2015-10-30 00:00:10 +0700 | [diff] [blame] | 52 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 53 | self::$testArgs['testDouble'] = 3.1415926535898; |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 54 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 55 | // TODO: add testBinary() call |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 56 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 57 | self::$testArgs['testByte'] = 0x01; |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 58 | |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 59 | self::$testArgs['testI32'] = pow(2, 30); |
| 60 | |
| 61 | if (PHP_INT_SIZE == 8) { |
| 62 | self::$testArgs['testI64'] = pow(2, 60); |
| 63 | } else { |
| 64 | self::$testArgs['testI64'] = "1152921504606847000"; |
| 65 | } |
| 66 | |
| 67 | self::$testArgs['testStruct'] = |
| 68 | new Xtruct( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 69 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 70 | 'string_thing' => 'worked', |
| 71 | 'byte_thing' => 0x01, |
| 72 | 'i32_thing' => pow(2, 30), |
| 73 | 'i64_thing' => self::$testArgs['testI64'] |
| 74 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 75 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 76 | |
| 77 | self::$testArgs['testNestNested'] = |
| 78 | new Xtruct( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 79 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 80 | 'string_thing' => 'worked', |
| 81 | 'byte_thing' => 0x01, |
| 82 | 'i32_thing' => pow(2, 30), |
| 83 | 'i64_thing' => self::$testArgs['testI64'] |
| 84 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 85 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 86 | |
| 87 | self::$testArgs['testNest'] = |
| 88 | new Xtruct2( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 89 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 90 | 'byte_thing' => 0x01, |
| 91 | 'struct_thing' => self::$testArgs['testNestNested'], |
| 92 | 'i32_thing' => pow(2, 15) |
| 93 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 94 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 95 | |
| 96 | self::$testArgs['testMap'] = |
| 97 | array( |
| 98 | 7 => 77, |
| 99 | 8 => 88, |
| 100 | 9 => 99 |
| 101 | ); |
| 102 | |
| 103 | self::$testArgs['testStringMap'] = |
| 104 | array( |
| 105 | "a" => "123", |
| 106 | "a b" => "with spaces ", |
| 107 | "same" => "same", |
| 108 | "0" => "numeric key", |
| 109 | "longValue" => self::$testArgs['testString1'], |
| 110 | self::$testArgs['testString1'] => "long key" |
| 111 | ); |
| 112 | |
| 113 | self::$testArgs['testSet'] = array(1 => true, 5 => true, 6 => true); |
| 114 | |
| 115 | self::$testArgs['testList'] = array(1, 2, 3); |
| 116 | |
| 117 | self::$testArgs['testEnum'] = Numberz::ONE; |
| 118 | |
| 119 | self::$testArgs['testTypedef'] = 69; |
| 120 | |
| 121 | self::$testArgs['testMapMapExpectedResult'] = |
| 122 | array( |
| 123 | 4 => array( |
| 124 | 1 => 1, |
| 125 | 2 => 2, |
| 126 | 3 => 3, |
| 127 | 4 => 4, |
| 128 | ), |
| 129 | -4 => array( |
| 130 | -4 => -4, |
| 131 | -3 => -3, |
| 132 | -2 => -2, |
| 133 | -1 => -1 |
| 134 | ) |
| 135 | ); |
| 136 | |
| 137 | // testInsanity ... takes a few steps to set up! |
| 138 | |
| 139 | $xtruct1 = |
| 140 | new Xtruct( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 141 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 142 | 'string_thing' => 'Goodbye4', |
| 143 | 'byte_thing' => 4, |
| 144 | 'i32_thing' => 4, |
| 145 | 'i64_thing' => 4 |
| 146 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 147 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 148 | |
| 149 | $xtruct2 = |
| 150 | new Xtruct( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 151 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 152 | 'string_thing' => 'Hello2', |
| 153 | 'byte_thing' => 2, |
| 154 | 'i32_thing' => 2, |
| 155 | 'i64_thing' => 2 |
| 156 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 157 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 158 | |
| 159 | $userMap = |
| 160 | array( |
| 161 | Numberz::FIVE => 5, |
| 162 | Numberz::EIGHT => 8 |
| 163 | ); |
| 164 | |
| 165 | $insanity2 = |
| 166 | new Insanity( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 167 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 168 | 'userMap' => $userMap, |
| 169 | 'xtructs' => array($xtruct1, $xtruct2) |
| 170 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 171 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 172 | |
| 173 | $insanity3 = $insanity2; |
| 174 | |
| 175 | $insanity6 = |
| 176 | new Insanity( |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 177 | array( |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 178 | 'userMap' => null, |
| 179 | 'xtructs' => null |
| 180 | ) |
Jens Geyer | 9ea48f3 | 2019-11-02 12:20:29 +0100 | [diff] [blame] | 181 | ); |
Robert Lu | 12f124c | 2018-01-25 23:19:41 +0800 | [diff] [blame] | 182 | |
| 183 | self::$testArgs['testInsanityExpectedResult'] = |
| 184 | array( |
| 185 | "1" => array( |
| 186 | Numberz::TWO => $insanity2, |
| 187 | Numberz::THREE => $insanity3 |
| 188 | ), |
| 189 | "2" => array( |
| 190 | Numberz::SIX => $insanity6 |
| 191 | ) |
| 192 | ); |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 193 | } |
Roger Meier | 21c0a85 | 2012-09-05 19:47:14 +0000 | [diff] [blame] | 194 | } |