Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 1 | import { ThriftTest } from "./gen-js/ThriftTest_types"; |
| 2 | import "./gen-js/ThriftTest"; |
| 3 | |
| 4 | var Int64 = require("node-int64"); |
| 5 | var JSONInt64 = require("json-int64"); |
| 6 | var QUnit = require("./qunit"); |
| 7 | |
| 8 | const transport: Thrift.Transport = new Thrift.Transport("/service"); |
| 9 | const protocol: Thrift.Protocol = new Thrift.Protocol(transport); |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 10 | const client: ThriftTest.ThriftTestClient = new ThriftTest.ThriftTestClient( |
| 11 | protocol, |
| 12 | ); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 13 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 14 | const int64_2_pow_60: typeof Int64 = new Int64("1000000000000000"); |
| 15 | const int64_minus_2_pow_60: typeof Int64 = new Int64("f000000000000000"); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 16 | |
| 17 | // Work around for old API used by QUnitAdapter of jsTestDriver |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 18 | if (typeof QUnit.log == "function") { |
| 19 | // When using real QUnit (fron PhantomJS) log failures to console |
| 20 | QUnit.log(function (details) { |
| 21 | if (!details.result) { |
| 22 | console.log("======== FAIL ========"); |
| 23 | console.log("TestName: " + details.name); |
| 24 | if (details.message) console.log(details.message); |
| 25 | console.log("Expected: " + JSONInt64.stringify(details.expected)); |
| 26 | console.log("Actual : " + JSONInt64.stringify(details.actual)); |
| 27 | console.log("======================"); |
| 28 | } |
| 29 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // all Languages in UTF-8 |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 33 | const stringTest: string = |
| 34 | "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ú, 粵語"; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 35 | |
| 36 | function checkRecursively(assert, map1: Object, map2: Object): void { |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 37 | if (typeof map1 !== "function" && typeof map2 !== "function") { |
| 38 | if (!map1 || typeof map1 !== "object") { |
| 39 | assert.equal(map1, map2); |
| 40 | } else { |
| 41 | for (let key in map1) { |
| 42 | checkRecursively(assert, map1[key], map2[key]); |
| 43 | } |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 44 | } |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 45 | } |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 46 | } |
| 47 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 48 | QUnit.module("Base Types"); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 49 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 50 | QUnit.test("Void", function (assert) { |
| 51 | assert.equal(client.testVoid(), undefined); |
| 52 | }); |
| 53 | QUnit.test("Binary (String)", function (assert) { |
| 54 | let binary: string = ""; |
| 55 | for (let v = 255; v >= 0; --v) { |
| 56 | binary += String.fromCharCode(v); |
| 57 | } |
| 58 | assert.equal(client.testBinary(binary), binary); |
| 59 | }); |
| 60 | QUnit.test("Binary (Uint8Array)", function (assert) { |
| 61 | let binary: string = ""; |
| 62 | for (let v = 255; v >= 0; --v) { |
| 63 | binary += String.fromCharCode(v); |
| 64 | } |
| 65 | const arr: Uint8Array = new Uint8Array(binary.length); |
| 66 | for (let i = 0; i < binary.length; ++i) { |
| 67 | arr[i] = binary[i].charCodeAt(0); |
| 68 | } |
| 69 | const hexEncodedString = Array.from(arr, function (byte) { |
| 70 | return String.fromCharCode(byte); |
| 71 | }).join(""); |
| 72 | assert.equal(client.testBinary(hexEncodedString), binary); |
| 73 | }); |
| 74 | QUnit.test("String", function (assert) { |
| 75 | assert.equal(client.testString(""), ""); |
| 76 | assert.equal(client.testString(stringTest), stringTest); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 77 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 78 | const specialCharacters: string = |
| 79 | 'quote: \" backslash:' + |
| 80 | " forwardslash-escaped: \/ " + |
| 81 | " backspace: \b formfeed: \f newline: \n return: \r tab: " + |
| 82 | ' now-all-of-them-together: "\\\/\b\n\r\t' + |
| 83 | " now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><"; |
| 84 | assert.equal(client.testString(specialCharacters), specialCharacters); |
| 85 | }); |
| 86 | QUnit.test("Double", function (assert) { |
| 87 | assert.equal(client.testDouble(0), 0); |
| 88 | assert.equal(client.testDouble(-1), -1); |
| 89 | assert.equal(client.testDouble(3.14), 3.14); |
| 90 | assert.equal(client.testDouble(Math.pow(2, 60)), Math.pow(2, 60)); |
| 91 | }); |
| 92 | QUnit.test("Byte", function (assert) { |
| 93 | assert.equal(client.testByte(0), 0); |
| 94 | assert.equal(client.testByte(0x01), 0x01); |
| 95 | }); |
| 96 | QUnit.test("I32", function (assert) { |
| 97 | assert.equal(client.testI32(0), 0); |
| 98 | assert.equal(client.testI32(Math.pow(2, 30)), Math.pow(2, 30)); |
| 99 | assert.equal(client.testI32(-Math.pow(2, 30)), -Math.pow(2, 30)); |
| 100 | }); |
| 101 | QUnit.test("I64", function (assert) { |
| 102 | assert.equal(client.testI64(new Int64(0)), 0); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 103 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 104 | let int64_2_pow_60_result: typeof Int64 = client.testI64(int64_2_pow_60); |
| 105 | assert.ok(int64_2_pow_60.equals(int64_2_pow_60_result)); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 106 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 107 | let int64_minus_2_pow_60_result: typeof Int64 = |
| 108 | client.testI64(int64_minus_2_pow_60); |
| 109 | assert.ok(int64_minus_2_pow_60.equals(int64_minus_2_pow_60_result)); |
| 110 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 111 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 112 | QUnit.module("Structured Types"); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 113 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 114 | QUnit.test("Struct", function (assert) { |
| 115 | const structTestInput: ThriftTest.Xtruct = new ThriftTest.Xtruct(); |
| 116 | structTestInput.string_thing = "worked"; |
| 117 | structTestInput.byte_thing = 0x01; |
| 118 | structTestInput.i32_thing = Math.pow(2, 30); |
| 119 | structTestInput.i64_thing = int64_2_pow_60; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 120 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 121 | const structTestOutput: ThriftTest.Xtruct = |
| 122 | client.testStruct(structTestInput); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 123 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 124 | assert.equal(structTestOutput.string_thing, structTestInput.string_thing); |
| 125 | assert.equal(structTestOutput.byte_thing, structTestInput.byte_thing); |
| 126 | assert.equal(structTestOutput.i32_thing, structTestInput.i32_thing); |
| 127 | assert.ok(structTestOutput.i64_thing.equals(structTestInput.i64_thing)); |
| 128 | assert.ok(structTestInput.i64_thing.equals(structTestOutput.i64_thing)); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 129 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 130 | assert.equal( |
| 131 | JSONInt64.stringify(structTestOutput), |
| 132 | JSONInt64.stringify(structTestInput), |
| 133 | ); |
| 134 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 135 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 136 | QUnit.test("Nest", function (assert) { |
| 137 | const xtrTestInput: ThriftTest.Xtruct = new ThriftTest.Xtruct(); |
| 138 | xtrTestInput.string_thing = "worked"; |
| 139 | xtrTestInput.byte_thing = 0x01; |
| 140 | xtrTestInput.i32_thing = Math.pow(2, 30); |
| 141 | xtrTestInput.i64_thing = int64_2_pow_60; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 142 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 143 | const nestTestInput: ThriftTest.Xtruct2 = new ThriftTest.Xtruct2(); |
| 144 | nestTestInput.byte_thing = 0x02; |
| 145 | nestTestInput.struct_thing = xtrTestInput; |
| 146 | nestTestInput.i32_thing = Math.pow(2, 15); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 147 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 148 | const nestTestOutput: ThriftTest.Xtruct2 = client.testNest(nestTestInput); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 149 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 150 | assert.equal(nestTestOutput.byte_thing, nestTestInput.byte_thing); |
| 151 | assert.equal( |
| 152 | nestTestOutput.struct_thing.string_thing, |
| 153 | nestTestInput.struct_thing.string_thing, |
| 154 | ); |
| 155 | assert.equal( |
| 156 | nestTestOutput.struct_thing.byte_thing, |
| 157 | nestTestInput.struct_thing.byte_thing, |
| 158 | ); |
| 159 | assert.equal( |
| 160 | nestTestOutput.struct_thing.i32_thing, |
| 161 | nestTestInput.struct_thing.i32_thing, |
| 162 | ); |
| 163 | assert.ok( |
| 164 | nestTestOutput.struct_thing.i64_thing.equals( |
| 165 | nestTestInput.struct_thing.i64_thing, |
| 166 | ), |
| 167 | ); |
| 168 | assert.equal(nestTestOutput.i32_thing, nestTestInput.i32_thing); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 169 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 170 | assert.equal( |
| 171 | JSONInt64.stringify(nestTestOutput), |
| 172 | JSONInt64.stringify(nestTestInput), |
| 173 | ); |
| 174 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 175 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 176 | QUnit.test("Map", function (assert) { |
| 177 | const mapTestInput: { [k: number]: number } = { 7: 77, 8: 88, 9: 99 }; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 178 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 179 | const mapTestOutput: { [k: number]: number } = client.testMap(mapTestInput); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 180 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 181 | for (let key in mapTestOutput) { |
| 182 | assert.equal(mapTestOutput[key], mapTestInput[key]); |
| 183 | } |
| 184 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 185 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 186 | QUnit.test("StringMap", function (assert) { |
| 187 | const mapTestInput: { [k: string]: string } = { |
| 188 | a: "123", |
| 189 | "a b": "with spaces ", |
| 190 | same: "same", |
| 191 | "0": "numeric key", |
| 192 | longValue: stringTest, |
| 193 | stringTest: "long key", |
| 194 | }; |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 195 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 196 | const mapTestOutput: { [k: string]: string } = |
| 197 | client.testStringMap(mapTestInput); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 198 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 199 | for (let key in mapTestOutput) { |
| 200 | assert.equal(mapTestOutput[key], mapTestInput[key]); |
| 201 | } |
| 202 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 203 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 204 | QUnit.test("Set", function (assert) { |
| 205 | const setTestInput: number[] = [1, 2, 3]; |
| 206 | assert.ok(client.testSet(setTestInput), setTestInput); |
| 207 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 208 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 209 | QUnit.test("List", function (assert) { |
| 210 | const listTestInput: number[] = [1, 2, 3]; |
| 211 | assert.ok(client.testList(listTestInput), listTestInput); |
| 212 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 213 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 214 | QUnit.test("Enum", function (assert) { |
| 215 | assert.equal(client.testEnum(ThriftTest.Numberz.ONE), ThriftTest.Numberz.ONE); |
| 216 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 217 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 218 | QUnit.test("TypeDef", function (assert) { |
| 219 | assert.equal(client.testTypedef(new Int64(69)), 69); |
| 220 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 221 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 222 | QUnit.module("deeper!"); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 223 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 224 | QUnit.test("MapMap", function (assert) { |
| 225 | const mapMapTestExpectedResult: { [K: number]: { [k: number]: number } } = { |
| 226 | "4": { "1": 1, "2": 2, "3": 3, "4": 4 }, |
| 227 | "-4": { "-4": -4, "-3": -3, "-2": -2, "-1": -1 }, |
| 228 | }; |
| 229 | |
| 230 | const mapMapTestOutput = client.testMapMap(1); |
| 231 | |
| 232 | for (let key in mapMapTestOutput) { |
| 233 | for (let key2 in mapMapTestOutput[key]) { |
| 234 | assert.equal( |
| 235 | mapMapTestOutput[key][key2], |
| 236 | mapMapTestExpectedResult[key][key2], |
| 237 | ); |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | checkRecursively(assert, mapMapTestOutput, mapMapTestExpectedResult); |
| 242 | }); |
| 243 | |
| 244 | QUnit.module("Exception"); |
| 245 | |
| 246 | QUnit.test("Xception", function (assert) { |
| 247 | assert.expect(2); |
| 248 | const done = assert.async(); |
| 249 | try { |
| 250 | client.testException("Xception"); |
| 251 | assert.ok(false); |
| 252 | } catch (e) { |
| 253 | assert.equal(e.errorCode, 1001); |
| 254 | assert.equal(e.message, "Xception"); |
| 255 | done(); |
| 256 | } |
| 257 | }); |
| 258 | |
| 259 | QUnit.test("no Exception", function (assert) { |
| 260 | assert.expect(1); |
| 261 | try { |
| 262 | client.testException("no Exception"); |
| 263 | assert.ok(true); |
| 264 | } catch (e) { |
| 265 | assert.ok(false); |
| 266 | } |
| 267 | }); |
| 268 | |
| 269 | QUnit.test("TException", function (assert) { |
| 270 | //ThriftTest does not list TException as a legal exception so it will |
| 271 | // generate an exception on the server that does not propagate back to |
| 272 | // the client. This test has been modified to equate to "no exception" |
| 273 | assert.expect(1); |
| 274 | try { |
| 275 | client.testException("TException"); |
| 276 | } catch (e) { |
| 277 | //assert.ok(false); |
| 278 | } |
| 279 | assert.ok(true); |
| 280 | }); |
| 281 | |
| 282 | QUnit.module("Insanity"); |
| 283 | |
| 284 | const crazy: ThriftTest.Insanity = { |
| 285 | userMap: { "5": new Int64(5), "8": new Int64(8) }, |
| 286 | xtructs: [ |
| 287 | { |
| 288 | string_thing: "Goodbye4", |
| 289 | byte_thing: 4, |
| 290 | i32_thing: 4, |
| 291 | i64_thing: new Int64(4), |
| 292 | }, |
| 293 | { |
| 294 | string_thing: "Hello2", |
| 295 | byte_thing: 2, |
| 296 | i32_thing: 2, |
| 297 | i64_thing: new Int64(2), |
| 298 | }, |
| 299 | ], |
| 300 | }; |
| 301 | QUnit.test("testInsanity", function (assert) { |
| 302 | const insanity: { |
| 303 | [k: number]: ThriftTest.Insanity | { [k: number]: ThriftTest.Insanity }; |
| 304 | } = { |
| 305 | "1": { |
| 306 | "2": crazy, |
| 307 | "3": crazy, |
| 308 | }, |
| 309 | "2": { "6": new ThriftTest.Insanity() }, |
| 310 | }; |
| 311 | const res = client.testInsanity(new ThriftTest.Insanity(crazy)); |
| 312 | assert.ok(res, JSONInt64.stringify(res)); |
| 313 | assert.ok(insanity, JSONInt64.stringify(insanity)); |
| 314 | |
| 315 | checkRecursively(assert, res, insanity); |
| 316 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 317 | |
| 318 | ////////////////////////////////// |
| 319 | //Run same tests asynchronously |
| 320 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 321 | QUnit.module("Async"); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 322 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 323 | QUnit.test("Double", function (assert) { |
| 324 | assert.expect(1); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 325 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 326 | const done = assert.async(); |
| 327 | client.testDouble(3.14159265, function (result) { |
| 328 | assert.equal(result, 3.14159265); |
| 329 | done(); |
| 330 | }); |
| 331 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 332 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 333 | QUnit.test("Byte", function (assert) { |
| 334 | assert.expect(1); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 335 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 336 | const done = assert.async(); |
| 337 | client.testByte(0x01, function (result) { |
| 338 | assert.equal(result, 0x01); |
| 339 | done(); |
| 340 | }); |
| 341 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 342 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 343 | QUnit.test("I32", function (assert) { |
| 344 | assert.expect(2); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 345 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 346 | const done = assert.async(2); |
| 347 | client.testI32(Math.pow(2, 30), function (result) { |
| 348 | assert.equal(result, Math.pow(2, 30)); |
| 349 | done(); |
| 350 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 351 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 352 | client.testI32(Math.pow(-2, 31), function (result) { |
| 353 | assert.equal(result, Math.pow(-2, 31)); |
| 354 | done(); |
| 355 | }); |
| 356 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 357 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 358 | QUnit.test("I64", function (assert) { |
| 359 | assert.expect(2); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 360 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 361 | const done = assert.async(2); |
| 362 | client.testI64(int64_2_pow_60, function (result) { |
| 363 | assert.ok(int64_2_pow_60.equals(result)); |
| 364 | done(); |
| 365 | }); |
Mustafa Senol Cosar | f86845e | 2018-12-05 17:50:18 +0300 | [diff] [blame] | 366 | |
Cameron Martin | caef0ed | 2025-01-15 11:58:39 +0100 | [diff] [blame] | 367 | client.testI64(int64_minus_2_pow_60, function (result) { |
| 368 | assert.ok(int64_minus_2_pow_60.equals(result)); |
| 369 | done(); |
| 370 | }); |
| 371 | }); |